KHtml

kjs_clientrect.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (C) 2013 Bernd Buschinski <[email protected]>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #include "kjs_clientrect.h"
21 
22 #include "kjs_clientrect.lut.h"
23 
24 namespace KJS
25 {
26 
27 // table for ClientRect object
28 /*
29 @begin ClientRectTable 6
30  height ClientRect::Height DontEnum|ReadOnly
31  width ClientRect::Width DontEnum|ReadOnly
32  top ClientRect::Top DontEnum|ReadOnly
33  left ClientRect::Left DontEnum|ReadOnly
34  bottom ClientRect::Bottom DontEnum|ReadOnly
35  right ClientRect::Right DontEnum|ReadOnly
36 @end
37 */
38 
39 const ClassInfo ClientRect::info = { "ClientRect", nullptr, &ClientRectTable, nullptr };
40 
41 ClientRect::ClientRect(ExecState * /*exec*/, float left, float top, float width, float height)
42  : JSObject(),
43  m_rect(left, top, width, height)
44 {
45 }
46 
47 ClientRect::ClientRect(ExecState * /*exec*/, const QRectF &rect)
48  : JSObject(),
49  m_rect(rect)
50 {
51 }
52 
53 JSValue *ClientRect::getValueProperty(ExecState * /*exec*/, int token) const
54 {
55  switch (token) {
56  case Top:
57  return jsNumber(top());
58  case Right:
59  return jsNumber(right());
60  case Left:
61  return jsNumber(left());
62  case Bottom:
63  return jsNumber(bottom());
64  case Height:
65  return jsNumber(height());
66  case Width:
67  return jsNumber(width());
68  }
69  return jsUndefined();
70 }
71 
72 bool ClientRect::getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot)
73 {
74  return getStaticValueSlot<ClientRect, JSObject>(exec, &ClientRectTable, this, propertyName, slot);
75 }
76 
77 float ClientRect::bottom() const
78 {
79  return static_cast<float>(m_rect.bottom());
80 }
81 
82 float ClientRect::height() const
83 {
84  return static_cast<float>(m_rect.height());
85 }
86 
87 float ClientRect::left() const
88 {
89  return static_cast<float>(m_rect.left());
90 }
91 
92 float ClientRect::right() const
93 {
94  return static_cast<float>(m_rect.right());
95 }
96 
97 float ClientRect::top() const
98 {
99  return static_cast<float>(m_rect.top());
100 }
101 
102 float ClientRect::width() const
103 {
104  return static_cast<float>(m_rect.width());
105 }
106 
107 void ClientRect::setHeight(float height)
108 {
109  m_rect.setHeight(height);
110 }
111 
112 void ClientRect::setLeft(float left)
113 {
114  m_rect.setLeft(left);
115 }
116 
117 void ClientRect::setTop(float top)
118 {
119  m_rect.setTop(top);
120 }
121 
122 void ClientRect::setWidth(float width)
123 {
124  m_rect.setWidth(width);
125 }
126 
127 // ---------------------- ClientRectList --------------------------
128 
129 // table for ClientRectList object
130 /*
131 @begin ClientRectListTable 1
132  length ClientRectList::Length DontEnum|ReadOnly
133 @end
134 */
135 
136 const ClassInfo ClientRectList::info = { "ClientRectList", nullptr, &ClientRectListTable, nullptr };
137 
138 ClientRectList::ClientRectList(ExecState * /*exec*/)
139  : JSObject()
140 {
141 }
142 
143 ClientRectList::ClientRectList(ExecState *exec, const QList< QRectF > &list)
144  : JSObject()
145 {
146  foreach (const QRectF &rect, list) {
147  m_list.append(new ClientRect(exec, rect));
148  }
149 }
150 
151 unsigned int ClientRectList::length() const
152 {
153  return m_list.size();
154 }
155 
156 JSValue *ClientRectList::getValueProperty(ExecState * /*exec*/, int token) const
157 {
158  switch (token) {
159  case Length:
160  return jsNumber(length());
161  }
162  return jsUndefined();
163 }
164 
165 bool ClientRectList::getOwnPropertySlot(ExecState *exec, unsigned int index, PropertySlot &slot)
166 {
167  if (index >= length()) {
168  setDOMException(exec, DOM::DOMException::INDEX_SIZE_ERR);
169  return false;
170  }
171  slot.setValue(this, m_list.at(index));
172  return true;
173 }
174 
175 bool ClientRectList::getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot)
176 {
177  bool ok;
178  unsigned int index = propertyName.toArrayIndex(&ok);
179  if (ok) {
180  return ClientRectList::getOwnPropertySlot(exec, index, slot);
181  }
182 
183  bool ret = getStaticValueSlot<ClientRectList, JSObject>(exec, &ClientRectListTable, this, propertyName, slot);
184 
185  if (ret) {
186  return ret;
187  }
188 
189  setDOMException(exec, DOM::DOMException::INDEX_SIZE_ERR);
190  return false;
191 }
192 
193 ClientRect *ClientRectList::item(unsigned int index)
194 {
195  ASSERT(index < length());
196  return m_list.at(index);
197 }
198 
199 void ClientRectList::append(ClientRect *item)
200 {
201  m_list.append(item);
202 }
203 
204 } //namespace KJS
205 
Left
QTextStream & right(QTextStream &stream)
QTextStream & left(QTextStream &stream)
Width
Right
Top
Height
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 16 2021 22:47:57 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.