File indexing completed on 2023-10-03 03:17:38
0001 /* 0002 * This file is part of the KDE libraries 0003 * Copyright (C) 2013 Bernd Buschinski <b.buschinski@googlemail.com> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Lesser General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Lesser General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Lesser General Public 0016 * License along with this library; if not, write to the Free Software 0017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0018 */ 0019 0020 #include "kjs_clientrect.h" 0021 0022 #include "kjs_clientrect.lut.h" 0023 0024 namespace KJS 0025 { 0026 0027 // table for ClientRect object 0028 /* 0029 @begin ClientRectTable 6 0030 height ClientRect::Height DontEnum|ReadOnly 0031 width ClientRect::Width DontEnum|ReadOnly 0032 top ClientRect::Top DontEnum|ReadOnly 0033 left ClientRect::Left DontEnum|ReadOnly 0034 bottom ClientRect::Bottom DontEnum|ReadOnly 0035 right ClientRect::Right DontEnum|ReadOnly 0036 @end 0037 */ 0038 0039 const ClassInfo ClientRect::info = { "ClientRect", nullptr, &ClientRectTable, nullptr }; 0040 0041 ClientRect::ClientRect(ExecState * /*exec*/, float left, float top, float width, float height) 0042 : JSObject(), 0043 m_rect(left, top, width, height) 0044 { 0045 } 0046 0047 ClientRect::ClientRect(ExecState * /*exec*/, const QRectF &rect) 0048 : JSObject(), 0049 m_rect(rect) 0050 { 0051 } 0052 0053 JSValue *ClientRect::getValueProperty(ExecState * /*exec*/, int token) const 0054 { 0055 switch (token) { 0056 case Top: 0057 return jsNumber(top()); 0058 case Right: 0059 return jsNumber(right()); 0060 case Left: 0061 return jsNumber(left()); 0062 case Bottom: 0063 return jsNumber(bottom()); 0064 case Height: 0065 return jsNumber(height()); 0066 case Width: 0067 return jsNumber(width()); 0068 } 0069 return jsUndefined(); 0070 } 0071 0072 bool ClientRect::getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) 0073 { 0074 return getStaticValueSlot<ClientRect, JSObject>(exec, &ClientRectTable, this, propertyName, slot); 0075 } 0076 0077 float ClientRect::bottom() const 0078 { 0079 return static_cast<float>(m_rect.bottom()); 0080 } 0081 0082 float ClientRect::height() const 0083 { 0084 return static_cast<float>(m_rect.height()); 0085 } 0086 0087 float ClientRect::left() const 0088 { 0089 return static_cast<float>(m_rect.left()); 0090 } 0091 0092 float ClientRect::right() const 0093 { 0094 return static_cast<float>(m_rect.right()); 0095 } 0096 0097 float ClientRect::top() const 0098 { 0099 return static_cast<float>(m_rect.top()); 0100 } 0101 0102 float ClientRect::width() const 0103 { 0104 return static_cast<float>(m_rect.width()); 0105 } 0106 0107 void ClientRect::setHeight(float height) 0108 { 0109 m_rect.setHeight(height); 0110 } 0111 0112 void ClientRect::setLeft(float left) 0113 { 0114 m_rect.setLeft(left); 0115 } 0116 0117 void ClientRect::setTop(float top) 0118 { 0119 m_rect.setTop(top); 0120 } 0121 0122 void ClientRect::setWidth(float width) 0123 { 0124 m_rect.setWidth(width); 0125 } 0126 0127 // ---------------------- ClientRectList -------------------------- 0128 0129 // table for ClientRectList object 0130 /* 0131 @begin ClientRectListTable 1 0132 length ClientRectList::Length DontEnum|ReadOnly 0133 @end 0134 */ 0135 0136 const ClassInfo ClientRectList::info = { "ClientRectList", nullptr, &ClientRectListTable, nullptr }; 0137 0138 ClientRectList::ClientRectList(ExecState * /*exec*/) 0139 : JSObject() 0140 { 0141 } 0142 0143 ClientRectList::ClientRectList(ExecState *exec, const QList< QRectF > &list) 0144 : JSObject() 0145 { 0146 foreach (const QRectF &rect, list) { 0147 m_list.append(new ClientRect(exec, rect)); 0148 } 0149 } 0150 0151 unsigned int ClientRectList::length() const 0152 { 0153 return m_list.size(); 0154 } 0155 0156 JSValue *ClientRectList::getValueProperty(ExecState * /*exec*/, int token) const 0157 { 0158 switch (token) { 0159 case Length: 0160 return jsNumber(length()); 0161 } 0162 return jsUndefined(); 0163 } 0164 0165 bool ClientRectList::getOwnPropertySlot(ExecState *exec, unsigned int index, PropertySlot &slot) 0166 { 0167 if (index >= length()) { 0168 setDOMException(exec, DOM::DOMException::INDEX_SIZE_ERR); 0169 return false; 0170 } 0171 slot.setValue(this, m_list.at(index)); 0172 return true; 0173 } 0174 0175 bool ClientRectList::getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) 0176 { 0177 bool ok; 0178 unsigned int index = propertyName.toArrayIndex(&ok); 0179 if (ok) { 0180 return ClientRectList::getOwnPropertySlot(exec, index, slot); 0181 } 0182 0183 bool ret = getStaticValueSlot<ClientRectList, JSObject>(exec, &ClientRectListTable, this, propertyName, slot); 0184 0185 if (ret) { 0186 return ret; 0187 } 0188 0189 setDOMException(exec, DOM::DOMException::INDEX_SIZE_ERR); 0190 return false; 0191 } 0192 0193 ClientRect *ClientRectList::item(unsigned int index) 0194 { 0195 ASSERT(index < length()); 0196 return m_list.at(index); 0197 } 0198 0199 void ClientRectList::append(ClientRect *item) 0200 { 0201 m_list.append(item); 0202 } 0203 0204 } //namespace KJS 0205