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>
56 WidgetPrivate() : m_client(0), m_widget(0), m_webFrame(0), m_parentScrollView(0) { }
57 ~WidgetPrivate() { delete m_webFrame; }
59 void setGeometry(const QRect &rect) {
61 m_widget->setGeometry(rect);
64 QRect geometry() const {
70 WidgetClient* m_client;
74 QWidget *m_widget; //for plugins
75 QWebFrame *m_webFrame;
76 ScrollView *m_parentScrollView;
80 : data(new WidgetPrivate())
90 void Widget::setClient(WidgetClient* c)
95 WidgetClient* Widget::client() const
97 return data->m_client;
100 IntRect Widget::frameGeometry() const
102 return data->geometry();
105 void Widget::setFocus()
109 void Widget::setCursor(const Cursor& cursor)
113 qwidget()->setCursor(cursor.impl());
120 data->m_widget->show();
128 data->m_widget->hide();
133 QWebFrame* Widget::qwebframe() const
135 return data->m_webFrame;
138 void Widget::setQWebFrame(QWebFrame* webFrame)
140 data->m_webFrame = webFrame;
143 QWidget* Widget::qwidget() const
146 return data->m_widget;
148 if (data->m_webFrame)
149 return data->m_webFrame->page()->view();
154 void Widget::setQWidget(QWidget *widget)
156 data->m_widget = widget;
159 void Widget::setFrameGeometry(const IntRect& r)
161 data->setGeometry(r);
164 void Widget::paint(GraphicsContext *, const IntRect &rect)
168 bool Widget::isEnabled() const
171 return data->m_widget->isEnabled();
172 return data->enabled;
175 void Widget::setEnabled(bool e)
178 data->m_widget->setEnabled(e);
180 if (e != data->enabled) {
186 void Widget::setIsSelected(bool)
191 void Widget::invalidate()
193 invalidateRect(IntRect(0, 0, width(), height()));
196 void Widget::invalidateRect(const IntRect& r)
198 if (data->m_widget) //plugins
199 return data->m_widget->update(r);
201 IntRect windowRect = convertToContainingWindow(r);
203 // Get our clip rect and intersect with it to ensure we don't invalidate too much.
204 IntRect clipRect = windowClipRect();
205 windowRect.intersect(clipRect);
207 QWidget *canvas = qwidget(); //regular frameview
208 if (!canvas && parent())
209 canvas = parent()->qwidget(); //scrollbars
211 if (!canvas) // not visible anymore
214 bool shouldPaint = canvas->testAttribute(Qt::WA_WState_InPaintEvent);
215 if (parent() && parent()->isFrameView() && static_cast<FrameView*>(parent())->needsLayout())
221 QWebPage* page = qobject_cast<QWebPage*>(canvas);
223 page->mainFrame()->render(&p, windowRect);
225 canvas->update(windowRect);
230 void Widget::removeFromParent()
233 parent()->removeChild(this);
236 void Widget::setParent(ScrollView* sv)
238 data->m_parentScrollView = sv;
241 ScrollView* Widget::parent() const
243 return data->m_parentScrollView;
246 void Widget::geometryChanged() const
250 IntPoint Widget::convertToContainingWindow(const IntPoint& point) const
252 IntPoint windowPoint = point;
253 for (const Widget *parentWidget = parent(), *childWidget = this;
255 childWidget = parentWidget, parentWidget = parentWidget->parent()) {
256 IntPoint oldPoint = windowPoint;
257 windowPoint = parentWidget->convertChildToSelf(childWidget, oldPoint);
262 IntPoint Widget::convertFromContainingWindow(const IntPoint& point) const
264 IntPoint widgetPoint = point;
265 for (const Widget *parentWidget = parent(), *childWidget = this;
267 childWidget = parentWidget, parentWidget = parentWidget->parent()) {
268 IntPoint oldPoint = widgetPoint;
269 widgetPoint = parentWidget->convertSelfToChild(childWidget, oldPoint);
274 IntRect Widget::convertToContainingWindow(const IntRect& rect) const
276 IntRect convertedRect = rect;
277 convertedRect.setLocation(convertToContainingWindow(convertedRect.location()));
278 return convertedRect;
281 IntPoint Widget::convertChildToSelf(const Widget* child, const IntPoint& point) const
283 return IntPoint(point.x() + child->x(), point.y() + child->y());
286 IntPoint Widget::convertSelfToChild(const Widget* child, const IntPoint& point) const
288 return IntPoint(point.x() - child->x(), point.y() - child->y());
291 QWidget *Widget::containingWindow() const