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"
46 #include "qwebframe_p.h"
49 #include <QPaintEngine>
60 , suppressInvalidation(false)
62 , m_parentScrollView(0) { }
65 WidgetClient* m_client;
68 bool suppressInvalidation;
70 QWidget *m_widget; //for plugins
71 ScrollView *m_parentScrollView;
75 : 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)
117 if (QWidget* widget = containingWindow())
118 widget->setCursor(cursor.impl());
125 data->m_widget->show();
131 data->m_widget->hide();
134 QWidget* Widget::nativeWidget() const
136 return data->m_widget;
139 void Widget::setNativeWidget(QWidget *widget)
141 data->m_widget = widget;
144 void Widget::paint(GraphicsContext *, const IntRect &rect)
148 bool Widget::isEnabled() const
151 return data->m_widget->isEnabled();
152 return data->enabled;
155 void Widget::setEnabled(bool e)
158 data->m_widget->setEnabled(e);
160 if (e != data->enabled) {
166 void Widget::setIsSelected(bool)
171 bool Widget::suppressInvalidation() const
173 return data->suppressInvalidation;
176 void Widget::setSuppressInvalidation(bool suppress)
178 data->suppressInvalidation = suppress;
181 void Widget::invalidate()
183 invalidateRect(IntRect(0, 0, width(), height()));
186 void Widget::invalidateRect(const IntRect& r)
188 if (data->suppressInvalidation)
191 if (data->m_widget) { //plugins
192 data->m_widget->update(r);
198 static_cast<FrameView*>(this)->addToDirtyRegion(r);
202 // Get the root widget.
203 ScrollView* outermostView = topLevel();
207 IntRect windowRect = convertToContainingWindow(r);
209 // Get our clip rect and intersect with it to ensure we don't invalidate too much.
210 IntRect clipRect = windowClipRect();
211 windowRect.intersect(clipRect);
213 outermostView->addToDirtyRegion(windowRect);
216 void Widget::removeFromParent()
219 parent()->removeChild(this);
222 void Widget::setParent(ScrollView* sv)
224 data->m_parentScrollView = sv;
227 ScrollView* Widget::parent() const
229 return data->m_parentScrollView;
232 ScrollView* Widget::topLevel() const
234 if (!data->m_parentScrollView)
235 return isFrameView() ? const_cast<ScrollView*>(static_cast<const ScrollView*>(this)) : 0;
236 ScrollView* topLevel = data->m_parentScrollView;
237 while (topLevel->data->m_parentScrollView)
238 topLevel = topLevel->data->m_parentScrollView;
242 QWidget *Widget::containingWindow() const
244 ScrollView *topLevel = this->topLevel();
248 if (!topLevel->isFrameView())
249 return data->m_widget;
251 QWebFrame* frame = QWebFramePrivate::kit(static_cast<FrameView*>(topLevel)->frame());
252 QWidget* view = frame->page()->view();
254 return view ? view : data->m_widget;
258 void Widget::geometryChanged() const
262 IntPoint Widget::convertToContainingWindow(const IntPoint& point) const
264 IntPoint windowPoint = point;
265 for (const Widget *parentWidget = parent(), *childWidget = this;
267 childWidget = parentWidget, parentWidget = parentWidget->parent()) {
268 IntPoint oldPoint = windowPoint;
269 windowPoint = parentWidget->convertChildToSelf(childWidget, oldPoint);
274 IntPoint Widget::convertFromContainingWindow(const IntPoint& point) const
276 IntPoint widgetPoint = point;
277 for (const Widget *parentWidget = parent(), *childWidget = this;
279 childWidget = parentWidget, parentWidget = parentWidget->parent()) {
280 IntPoint oldPoint = widgetPoint;
281 widgetPoint = parentWidget->convertSelfToChild(childWidget, oldPoint);
286 IntRect Widget::convertToContainingWindow(const IntRect& rect) const
288 IntRect convertedRect = rect;
289 convertedRect.setLocation(convertToContainingWindow(convertedRect.location()));
290 return convertedRect;
293 IntPoint Widget::convertChildToSelf(const Widget* child, const IntPoint& point) const
295 return IntPoint(point.x() + child->x(), point.y() + child->y());
298 IntPoint Widget::convertSelfToChild(const Widget* child, const IntPoint& point) const
300 return IntPoint(point.x() - child->x(), point.y() - child->y());