2 * Copyright (C) 2006 Dirk Mueller <mueller@kde.org>
3 * Copyright (C) 2006 George Stiakos <staikos@kde.org>
4 * Copyright (C) 2006 Zack Rusin <zack@kde.org>
5 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "FrameView.h"
36 #include "GraphicsContext.h"
38 #include "RenderObject.h"
39 #include "ScrollView.h"
41 #include "WidgetClient.h"
42 #include "PlatformScrollBar.h"
43 #include "NotImplemented.h"
45 #include "qwebframe.h"
48 #include <QPaintEngine>
59 , suppressInvalidation(false)
62 , m_parentScrollView(0) { }
63 ~WidgetPrivate() { delete m_webFrame; }
65 WidgetClient* m_client;
68 bool suppressInvalidation;
70 QWidget *m_widget; //for plugins
71 QWebFrame *m_webFrame;
72 ScrollView *m_parentScrollView;
76 : data(new WidgetPrivate())
86 void Widget::setClient(WidgetClient* c)
91 WidgetClient* Widget::client() const
93 return data->m_client;
96 IntRect Widget::frameGeometry() const
99 data->m_widget->geometry();
100 return data->m_geometry;
103 void Widget::setFrameGeometry(const IntRect& r)
106 data->m_widget->setGeometry(r);
107 data->m_geometry = r;
110 void Widget::setFocus()
114 void Widget::setCursor(const Cursor& cursor)
118 data->m_widget->setCursor(cursor.impl());
125 data->m_widget->show();
131 data->m_widget->hide();
134 QWebFrame* Widget::qwebframe() const
136 return data->m_webFrame;
139 void Widget::setQWebFrame(QWebFrame* webFrame)
141 data->m_webFrame = webFrame;
144 QWidget* Widget::nativeWidget() const
146 return data->m_widget;
149 void Widget::setNativeWidget(QWidget *widget)
151 data->m_widget = widget;
154 void Widget::paint(GraphicsContext *, const IntRect &rect)
158 bool Widget::isEnabled() const
161 return data->m_widget->isEnabled();
162 return data->enabled;
165 void Widget::setEnabled(bool e)
168 data->m_widget->setEnabled(e);
170 if (e != data->enabled) {
176 void Widget::setIsSelected(bool)
181 bool Widget::suppressInvalidation() const
183 return data->suppressInvalidation;
186 void Widget::setSuppressInvalidation(bool suppress)
188 data->suppressInvalidation = suppress;
191 void Widget::invalidate()
193 invalidateRect(IntRect(0, 0, width(), height()));
196 void Widget::invalidateRect(const IntRect& r)
198 if (data->suppressInvalidation)
201 if (data->m_widget) { //plugins
202 data->m_widget->update(r);
208 static_cast<FrameView*>(this)->addToDirtyRegion(r);
212 // Get the root widget.
213 ScrollView* outermostView = topLevel();
217 IntRect windowRect = convertToContainingWindow(r);
219 // Get our clip rect and intersect with it to ensure we don't invalidate too much.
220 IntRect clipRect = windowClipRect();
221 windowRect.intersect(clipRect);
223 outermostView->addToDirtyRegion(windowRect);
226 void Widget::removeFromParent()
229 parent()->removeChild(this);
232 void Widget::setParent(ScrollView* sv)
234 data->m_parentScrollView = sv;
237 ScrollView* Widget::parent() const
239 return data->m_parentScrollView;
242 ScrollView* Widget::topLevel() const
244 if (!data->m_parentScrollView)
245 return isFrameView() ? const_cast<ScrollView*>(static_cast<const ScrollView*>(this)) : 0;
246 ScrollView* topLevel = data->m_parentScrollView;
247 while (topLevel->data->m_parentScrollView)
248 topLevel = topLevel->data->m_parentScrollView;
252 QWidget *Widget::containingWindow() const
254 ScrollView *topLevel = this->topLevel();
258 if (topLevel->data->m_webFrame)
259 view = topLevel->data->m_webFrame->page()->view();
261 view = data->m_widget;
266 void Widget::geometryChanged() const
270 IntPoint Widget::convertToContainingWindow(const IntPoint& point) const
272 IntPoint windowPoint = point;
273 for (const Widget *parentWidget = parent(), *childWidget = this;
275 childWidget = parentWidget, parentWidget = parentWidget->parent()) {
276 IntPoint oldPoint = windowPoint;
277 windowPoint = parentWidget->convertChildToSelf(childWidget, oldPoint);
282 IntPoint Widget::convertFromContainingWindow(const IntPoint& point) const
284 IntPoint widgetPoint = point;
285 for (const Widget *parentWidget = parent(), *childWidget = this;
287 childWidget = parentWidget, parentWidget = parentWidget->parent()) {
288 IntPoint oldPoint = widgetPoint;
289 widgetPoint = parentWidget->convertSelfToChild(childWidget, oldPoint);
294 IntRect Widget::convertToContainingWindow(const IntRect& rect) const
296 IntRect convertedRect = rect;
297 convertedRect.setLocation(convertToContainingWindow(convertedRect.location()));
298 return convertedRect;
301 IntPoint Widget::convertChildToSelf(const Widget* child, const IntPoint& point) const
303 return IntPoint(point.x() + child->x(), point.y() + child->y());
306 IntPoint Widget::convertSelfToChild(const Widget* child, const IntPoint& point) const
308 return IntPoint(point.x() - child->x(), point.y() - child->y());