OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions | |
6 * are met: | |
7 * 1. Redistributions of source code must retain the above copyright | |
8 * notice, this list of conditions and the following disclaimer. | |
9 * 2. Redistributions in binary form must reproduce the above copyright | |
10 * notice, this list of conditions and the following disclaimer in the | |
11 * documentation and/or other materials provided with the distribution. | |
12 * | |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 */ | |
25 | |
26 #include "config.h" | |
27 #include "Widget.h" | |
28 | |
29 #include "Cursor.h" | |
30 #include "Document.h" | |
31 #include "Element.h" | |
32 #include "Frame.h" | |
33 #include "FrameView.h" | |
34 #include "GraphicsContext.h" | |
35 #include "IntRect.h" | |
36 #include "WidgetClientWin.h" | |
37 | |
38 namespace WebCore { | |
39 | |
40 class WidgetPrivate | |
41 { | |
42 public: | |
43 WidgetClientWin* client; | |
44 ScrollView* parent; | |
45 IntRect frameRect; | |
46 bool enabled; | |
47 bool suppressInvalidation; | |
48 }; | |
49 | |
50 Widget::Widget() | |
51 : data(new WidgetPrivate) | |
52 { | |
53 data->client = 0; | |
54 data->parent = 0; | |
55 data->enabled = true; | |
56 data->suppressInvalidation = false; | |
57 } | |
58 | |
59 Widget::~Widget() | |
60 { | |
61 if (parent()) | |
62 parent()->removeChild(this); | |
63 delete data; | |
64 } | |
65 | |
66 void Widget::setContainingWindow(HWND containingWindow) | |
67 { | |
68 ASSERT_NOT_REACHED(); | |
69 } | |
70 | |
71 HWND Widget::containingWindow() const | |
72 { | |
73 if (!data->client) | |
74 return NULL; | |
75 return data->client->containingWindow(); | |
76 } | |
77 | |
78 void Widget::setClient(WidgetClient* c) | |
79 { | |
80 data->client = static_cast<WidgetClientWin*>(c); | |
81 } | |
82 | |
83 WidgetClient* Widget::client() const | |
84 { | |
85 return data->client; | |
86 } | |
87 | |
88 IntRect Widget::frameGeometry() const | |
89 { | |
90 return data->frameRect; | |
91 } | |
92 | |
93 void Widget::setFrameGeometry(const IntRect &rect) | |
94 { | |
95 data->frameRect = rect; | |
96 } | |
97 | |
98 void Widget::setParent(ScrollView* v) | |
99 { | |
100 if (!v || !v->isAttachedToWindow()) | |
101 detachFromWindow(); | |
102 data->parent = v; | |
103 if (v && v->isAttachedToWindow()) | |
104 attachToWindow(); | |
105 } | |
106 | |
107 ScrollView* Widget::parent() const | |
108 { | |
109 return data->parent; | |
110 } | |
111 | |
112 void Widget::removeFromParent() | |
113 { | |
114 if (parent()) | |
115 parent()->removeChild(this); | |
116 } | |
117 | |
118 void Widget::show() | |
119 { | |
120 } | |
121 | |
122 void Widget::hide() | |
123 { | |
124 } | |
125 | |
126 void Widget::setCursor(const Cursor& cursor) | |
127 { | |
128 if (data->client) | |
129 data->client->setCursor(cursor); | |
130 } | |
131 | |
132 IntPoint Widget::convertToContainingWindow(const IntPoint& point) const | |
133 { | |
134 IntPoint windowPoint = point; | |
135 for (const Widget *parentWidget = parent(), *childWidget = this; | |
136 parentWidget; | |
137 childWidget = parentWidget, parentWidget = parentWidget->parent()) | |
138 windowPoint = parentWidget->convertChildToSelf(childWidget, windowPoint)
; | |
139 return windowPoint; | |
140 } | |
141 | |
142 IntPoint Widget::convertFromContainingWindow(const IntPoint& point) const | |
143 { | |
144 IntPoint widgetPoint = point; | |
145 for (const Widget *parentWidget = parent(), *childWidget = this; | |
146 parentWidget; | |
147 childWidget = parentWidget, parentWidget = parentWidget->parent()) | |
148 widgetPoint = parentWidget->convertSelfToChild(childWidget, widgetPoint)
; | |
149 return widgetPoint; | |
150 } | |
151 | |
152 IntRect Widget::convertToContainingWindow(const IntRect& rect) const | |
153 { | |
154 IntRect convertedRect = rect; | |
155 convertedRect.setLocation(convertToContainingWindow(convertedRect.location()
)); | |
156 return convertedRect; | |
157 } | |
158 | |
159 IntPoint Widget::convertChildToSelf(const Widget* child, const IntPoint& point)
const | |
160 { | |
161 return IntPoint(point.x() + child->x(), point.y() + child->y()); | |
162 } | |
163 | |
164 IntPoint Widget::convertSelfToChild(const Widget* child, const IntPoint& point)
const | |
165 { | |
166 return IntPoint(point.x() - child->x(), point.y() - child->y()); | |
167 } | |
168 | |
169 void Widget::paint(GraphicsContext*, const IntRect&) | |
170 { | |
171 } | |
172 | |
173 bool Widget::isEnabled() const | |
174 { | |
175 return data->enabled; | |
176 } | |
177 | |
178 void Widget::setEnabled(bool e) | |
179 { | |
180 if (e != data->enabled) { | |
181 data->enabled = e; | |
182 invalidate(); | |
183 } | |
184 } | |
185 | |
186 bool Widget::suppressInvalidation() const | |
187 { | |
188 return data->suppressInvalidation; | |
189 } | |
190 | |
191 void Widget::setSuppressInvalidation(bool suppress) | |
192 { | |
193 data->suppressInvalidation = suppress; | |
194 } | |
195 | |
196 void Widget::invalidate() | |
197 { | |
198 invalidateRect(IntRect(0, 0, width(), height())); | |
199 } | |
200 | |
201 void Widget::invalidateRect(const IntRect& r) | |
202 { | |
203 if (data->suppressInvalidation) | |
204 return; | |
205 | |
206 if (!data->client) | |
207 return; | |
208 | |
209 IntRect windowRect = convertToContainingWindow(r); | |
210 | |
211 // Get our clip rect and intersect with it to ensure we don't invalidate too
much. | |
212 IntRect clipRect = windowClipRect(); | |
213 windowRect.intersect(clipRect); | |
214 | |
215 data->client->invalidateRect(windowRect); | |
216 } | |
217 | |
218 void Widget::setFocus() | |
219 { | |
220 if (data->client) | |
221 data->client->setFocus(); | |
222 } | |
223 | |
224 void Widget::setIsSelected(bool) | |
225 { | |
226 } | |
227 | |
228 } // namespace WebCore | |
OLD | NEW |