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())
87 void Widget::setClient(WidgetClient* c)
92 WidgetClient* Widget::client() const
94 return data->m_client;
97 IntRect Widget::frameGeometry() const
100 data->m_widget->geometry();
101 return data->m_geometry;
104 void Widget::setFrameGeometry(const IntRect& r)
107 data->m_widget->setGeometry(r);
108 data->m_geometry = r;
111 void Widget::setFocus()
115 void Widget::setCursor(const Cursor& cursor)
118 if (QWidget* widget = containingWindow())
119 widget->setCursor(cursor.impl());
126 data->m_widget->show();
132 data->m_widget->hide();
135 QWebFrame* Widget::qwebframe() const
137 return data->m_webFrame;
140 void Widget::setQWebFrame(QWebFrame* webFrame)
142 data->m_webFrame = webFrame;
145 QWidget* Widget::nativeWidget() const
147 return data->m_widget;
150 void Widget::setNativeWidget(QWidget *widget)
152 data->m_widget = widget;
155 void Widget::paint(GraphicsContext *, const IntRect &rect)
159 bool Widget::isEnabled() const
162 return data->m_widget->isEnabled();
163 return data->enabled;
166 void Widget::setEnabled(bool e)
169 data->m_widget->setEnabled(e);
171 if (e != data->enabled) {
177 void Widget::setIsSelected(bool)
182 bool Widget::suppressInvalidation() const
184 return data->suppressInvalidation;
187 void Widget::setSuppressInvalidation(bool suppress)
189 data->suppressInvalidation = suppress;
192 void Widget::invalidate()
194 invalidateRect(IntRect(0, 0, width(), height()));
197 void Widget::invalidateRect(const IntRect& r)
199 if (data->suppressInvalidation)
202 if (data->m_widget) { //plugins
203 data->m_widget->update(r);
209 static_cast<FrameView*>(this)->addToDirtyRegion(r);
213 // Get the root widget.
214 ScrollView* outermostView = topLevel();
218 IntRect windowRect = convertToContainingWindow(r);
220 // Get our clip rect and intersect with it to ensure we don't invalidate too much.
221 IntRect clipRect = windowClipRect();
222 windowRect.intersect(clipRect);
224 outermostView->addToDirtyRegion(windowRect);
227 void Widget::removeFromParent()
230 parent()->removeChild(this);
233 void Widget::setParent(ScrollView* sv)
235 data->m_parentScrollView = sv;
238 ScrollView* Widget::parent() const
240 return data->m_parentScrollView;
243 ScrollView* Widget::topLevel() const
245 if (!data->m_parentScrollView)
246 return isFrameView() ? const_cast<ScrollView*>(static_cast<const ScrollView*>(this)) : 0;
247 ScrollView* topLevel = data->m_parentScrollView;
248 while (topLevel->data->m_parentScrollView)
249 topLevel = topLevel->data->m_parentScrollView;
253 QWidget *Widget::containingWindow() const
255 ScrollView *topLevel = this->topLevel();
259 if (topLevel->data->m_webFrame)
260 view = topLevel->data->m_webFrame->page()->view();
262 view = data->m_widget;
267 void Widget::geometryChanged() const
271 IntPoint Widget::convertToContainingWindow(const IntPoint& point) const
273 IntPoint windowPoint = point;
274 for (const Widget *parentWidget = parent(), *childWidget = this;
276 childWidget = parentWidget, parentWidget = parentWidget->parent()) {
277 IntPoint oldPoint = windowPoint;
278 windowPoint = parentWidget->convertChildToSelf(childWidget, oldPoint);
283 IntPoint Widget::convertFromContainingWindow(const IntPoint& point) const
285 IntPoint widgetPoint = point;
286 for (const Widget *parentWidget = parent(), *childWidget = this;
288 childWidget = parentWidget, parentWidget = parentWidget->parent()) {
289 IntPoint oldPoint = widgetPoint;
290 widgetPoint = parentWidget->convertSelfToChild(childWidget, oldPoint);
295 IntRect Widget::convertToContainingWindow(const IntRect& rect) const
297 IntRect convertedRect = rect;
298 convertedRect.setLocation(convertToContainingWindow(convertedRect.location()));
299 return convertedRect;
302 IntPoint Widget::convertChildToSelf(const Widget* child, const IntPoint& point) const
304 return IntPoint(point.x() + child->x(), point.y() + child->y());
307 IntPoint Widget::convertSelfToChild(const Widget* child, const IntPoint& point) const
309 return IntPoint(point.x() - child->x(), point.y() - child->y());