+2008-01-04 Lars Knoll <lars@trolltech.com>
+
+ Reviewed by Simon.
+
+ Remove most dependencies of Widget/ScrollView onto native QWidgets.
+
+ This also brings the code closer in line with the Windows code. Seems
+ to work nicely on first try :)
+
+ * page/qt/FrameQt.cpp:
+ (WebCore::Frame::createScriptInstanceForWidget):
+ * platform/Widget.h:
+ * platform/qt/PlatformScreenQt.cpp:
+ (WebCore::screenDepth):
+ (WebCore::screenDepthPerComponent):
+ (WebCore::screenIsMonochrome):
+ (WebCore::screenRect):
+ * platform/qt/PlatformScrollBarQt.cpp:
+ (WebCore::PlatformScrollbar::thumbPosition):
+ (WebCore::PlatformScrollbar::handleMouseMoveEvent):
+ * platform/qt/ScrollViewQt.cpp:
+ (WebCore::ScrollView::ScrollViewPrivate::ScrollViewPrivate):
+ (WebCore::ScrollView::ScrollViewPrivate::scrollBackingStore):
+ (WebCore::ScrollView::updateContents):
+ (WebCore::ScrollView::update):
+ (WebCore::ScrollView::scrollRectIntoViewRecursively):
+ (WebCore::ScrollView::updateScrollbars):
+ (WebCore::ScrollView::addChild):
+ (WebCore::ScrollView::removeChild):
+ (WebCore::ScrollView::paint):
+ * platform/qt/WidgetQt.cpp:
+ (WebCore::WidgetPrivate::WidgetPrivate):
+ (WebCore::WidgetPrivate::~WidgetPrivate):
+ (WebCore::Widget::frameGeometry):
+ (WebCore::Widget::setFrameGeometry):
+ (WebCore::Widget::setCursor):
+ (WebCore::Widget::show):
+ (WebCore::Widget::hide):
+ (WebCore::Widget::nativeWidget):
+ (WebCore::Widget::setNativeWidget):
+ (WebCore::Widget::suppressInvalidation):
+ (WebCore::Widget::setSuppressInvalidation):
+ (WebCore::Widget::invalidateRect):
+ (WebCore::Widget::topLevel):
+ (WebCore::Widget::containingWindow):
+
2008-01-04 Lars Knoll <lars@trolltech.com>
Reviewed by Simon.
KJS::Bindings::Instance* Frame::createScriptInstanceForWidget(WebCore::Widget* widget)
{
+ QWidget* nativeWidget = widget->nativeWidget();
+ if (!nativeWidget)
+ return 0;
return KJS::Bindings::Instance::createBindingForLanguageInstance(KJS::Bindings::Instance::QtLanguage,
- widget->qwidget(),
+ nativeWidget,
bindingRootObject());
}
#endif
#if PLATFORM(QT)
- QWidget* qwidget() const;
- void setQWidget(QWidget *widget);
- QWidget* containingWindow() const;
+ void setNativeWidget(QWidget *widget);
+ QWidget* nativeWidget() const;
+
+ QWidget *containingWindow() const;
QWebFrame* qwebframe() const;
void setQWebFrame(QWebFrame *webFrame);
virtual void setParent(ScrollView*);
ScrollView* parent() const;
virtual void geometryChanged() const;
+ ScrollView* topLevel() const;
IntRect convertToContainingWindow(const IntRect&) const;
IntPoint convertToContainingWindow(const IntPoint&) const;
virtual IntPoint convertChildToSelf(const Widget*, const IntPoint&) const;
virtual IntPoint convertSelfToChild(const Widget*, const IntPoint&) const;
+
+ bool suppressInvalidation() const;
+ void setSuppressInvalidation(bool);
#endif
#if PLATFORM(MAC)
#include <QDesktopWidget>
namespace WebCore {
-
+
int screenDepth(Widget* w)
{
QDesktopWidget* d = QApplication::desktop();
- return d->screen(d->screenNumber(w->qwidget()))->depth();
+ QWidget *view = w->containingWindow();
+ int screenNumber = view ? d->screenNumber(view) : 0;
+ return d->screen(screenNumber)->depth();
}
int screenDepthPerComponent(Widget* w)
{
- return w->qwidget()->depth();
+ QWidget *view = w->containingWindow();
+ return view ? view->depth() : QApplication::desktop()->screen(0)->depth();
}
bool screenIsMonochrome(Widget* w)
{
QDesktopWidget* d = QApplication::desktop();
- return d->screen(d->screenNumber(w->qwidget()))->numColors() < 2;
+ QWidget *view = w->containingWindow();
+ int screenNumber = view ? d->screenNumber(view) : 0;
+ return d->screen(screenNumber)->numColors() < 2;
}
FloatRect screenRect(Widget* w)
{
- QRect r = QApplication::desktop()->screenGeometry(w->qwidget());
+ QRect r = QApplication::desktop()->screenGeometry(w->containingWindow());
return FloatRect(r.x(), r.y(), r.width(), r.height());
}
FloatRect screenAvailableRect(Widget* w)
{
- QRect r = QApplication::desktop()->availableGeometry(w->qwidget());
+ QRect r = QApplication::desktop()->availableGeometry(w->containingWindow());
return FloatRect(r.x(), r.y(), r.width(), r.height());
}
int PlatformScrollbar::thumbPosition() const
{
if (isEnabled())
- return (float)m_currentPos * (trackLength() - thumbLength()) / (m_totalSize - m_visibleSize);
+ return (int)((float)m_currentPos * (trackLength() - thumbLength()) / (m_totalSize - m_visibleSize));
return 0;
}
delta = max(-thumbPos, delta);
if (delta != 0) {
- setValue((float)(thumbPos + delta) * (m_totalSize - m_visibleSize) / (trackLen - thumbLen));
+ setValue((int)((float)(thumbPos + delta) * (m_totalSize - m_visibleSize) / (trackLen - thumbLen)));
m_pressedPos += thumbPosition() - thumbPos;
}
, m_vScrollbarMode(ScrollbarAuto)
, m_hScrollbarMode(ScrollbarAuto)
{
- setHasHorizontalScrollbar(true);
- setHasVerticalScrollbar(true);
}
~ScrollViewPrivate()
m_view->scrollBackingStore(-scrollDelta.width(), -scrollDelta.height(),
scrollViewRect, clipRect);
} else {
- // We need to go ahead and repaint the entire backing store.
- m_view->update();
+ // We need to go ahead and repaint the entire backing store. Do it now before moving the
+ // plugins.
+ m_view->addToDirtyRegion(updateRect);
+ m_view->updateBackingStore();
}
m_view->geometryChanged();
IntRect containingWindowRect = rect;
containingWindowRect.setLocation(windowPoint);
- //In QWebPage::paintEvent we paint the ev->region().rects()
- //individually. Unfortunately, webkit expects we'll draw the
- //boundingrect of all update rects instead. This is unfortunate,
- //because if we want to draw the scrollbar rects along with the update
- //rects this results in redrawing the entire page for a 1px scroll.
- //In light of this we cache the update rects that webkit sends us here
- //and send the bound along to QWebPage. The cache is cleared everytime
- //an actual paint occurs in ScrollView::paint...
-
- QRect r(containingWindowRect);
- QWebPage* page = qwebframe()->page();
- r = r.intersect(QRect(QPoint(0, 0), page->viewportSize()));
- if (r.isEmpty())
- return;
// Cache the dirty spot.
- if (!m_data->m_dirtyRegion.isEmpty())
- m_data->m_dirtyRegion = m_data->m_dirtyRegion.united(QRegion(r));
- else
- m_data->m_dirtyRegion = QRegion(r);
-
-#if 0
- // ### QWebPage
- bool painting = containingWindow()->testAttribute(Qt::WA_WState_InPaintEvent);
- if (painting && now) {
- QWebPage *page = qobject_cast<QWebPage*>(containingWindow());
- QPainter p(page);
- page->mainFrame()->render(&p, m_data->m_dirtyRegion.boundingRect());
- } else if (now) {
- containingWindow()->repaint(m_data->m_dirtyRegion.boundingRect());
- } else {
- containingWindow()->update(m_data->m_dirtyRegion.boundingRect());
- }
-#endif
+ addToDirtyRegion(containingWindowRect);
+
+ if (now)
+ updateBackingStore();
}
void ScrollView::update()
{
- QWidget* window = containingWindow();
- if (window)
- window->update(frameGeometry());
+ QWidget* native = nativeWidget();
+ if (native) {
+ native->update();
+ return;
+ }
+ updateContents(IntRect(0, 0, width(), height()));
}
int ScrollView::visibleWidth() const
{
IntPoint p(max(0, r.x()), max(0, r.y()));
ScrollView* view = this;
- ScrollView* oldView = view;
while (view) {
view->setContentsPos(p.x(), p.y());
p.move(view->x() - view->scrollOffset().width(), view->y() - view->scrollOffset().height());
if (!m_data->m_scrollbarsSuppressed && oldRect != m_data->m_hBar->frameGeometry())
m_data->m_hBar->invalidate();
+ if (m_data->m_scrollbarsSuppressed)
+ m_data->m_hBar->setSuppressInvalidation(true);
m_data->m_hBar->setSteps(LINE_STEP, pageStep);
m_data->m_hBar->setProportion(clientWidth, contentsWidth());
m_data->m_hBar->setValue(scroll.width());
+ if (m_data->m_scrollbarsSuppressed)
+ m_data->m_hBar->setSuppressInvalidation(false);
}
if (m_data->m_vBar) {
if (!m_data->m_scrollbarsSuppressed && oldRect != m_data->m_vBar->frameGeometry())
m_data->m_vBar->invalidate();
+ if (m_data->m_scrollbarsSuppressed)
+ m_data->m_vBar->setSuppressInvalidation(true);
m_data->m_vBar->setSteps(LINE_STEP, pageStep);
m_data->m_vBar->setProportion(clientHeight, contentsHeight());
m_data->m_vBar->setValue(scroll.height());
+ if (m_data->m_scrollbarsSuppressed)
+ m_data->m_vBar->setSuppressInvalidation(false);
}
if (oldHasVertical != (m_data->m_vBar != 0) || oldHasHorizontal != (m_data->m_hBar != 0))
void ScrollView::addChild(Widget* child)
{
- QWidget* w = child->qwidget();
- if (w)
- m_data->m_children.add(child);
-
child->setParent(this);
+ m_data->m_children.add(child);
}
void ScrollView::removeChild(Widget* child)
{
child->setParent(0);
child->hide();
- QWidget* w = child->qwidget();
- if (w)
- m_data->m_children.remove(child);
+ m_data->m_children.remove(child);
}
void ScrollView::paint(GraphicsContext* context, const IntRect& rect)
{
- Q_ASSERT(isFrameView());
-
- m_data->m_dirtyRegion = QRegion(); //clear the cache...
+ // FIXME: This code is here so we don't have to fork FrameView.h/.cpp.
+ // In the end, FrameView should just merge with ScrollView.
+ ASSERT(isFrameView());
if (context->paintingDisabled())
return;
IntRect documentDirtyRect = rect;
-
- QPainter *p = context->platformContext();
+ documentDirtyRect.intersect(frameGeometry());
context->save();
- QRect canvasRect = frameGeometry();
- documentDirtyRect.intersect(canvasRect);
- context->translate(canvasRect.x(), canvasRect.y());
- documentDirtyRect.move(-canvasRect.x(), -canvasRect.y());
+ context->translate(x(), y());
+ documentDirtyRect.move(-x(), -y());
context->translate(-contentsX(), -contentsY());
documentDirtyRect.move(contentsX(), contentsY());
- IntRect clipRect = enclosingIntRect(visibleContentRect());
-
- context->clip(clipRect);
-
-#ifdef DEBUG_SCROLLVIEW
- qDebug() << "ScrollView::paint --> "
- << "isSubframe" << (qwebframe() != qwebframe()->page()->mainFrame() ? "true" : "false")
- << "rect" << rect
- << "canvasRect" << canvasRect
- << "clipRect" << clipRect
- << "documentDirtyRect" << documentDirtyRect
- << endl;
-#endif
+ context->clip(enclosingIntRect(visibleContentRect()));
static_cast<const FrameView*>(this)->frame()->paint(context, documentDirtyRect);
// Now paint the scrollbars.
if (!m_data->m_scrollbarsSuppressed && (m_data->m_hBar || m_data->m_vBar)) {
context->save();
-
IntRect scrollViewDirtyRect = rect;
- scrollViewDirtyRect.intersect(canvasRect);
-
- context->translate(canvasRect.x(), canvasRect.y());
- scrollViewDirtyRect.move(-canvasRect.x(), -canvasRect.y());
-
+ scrollViewDirtyRect.intersect(frameGeometry());
+ context->translate(x(), y());
+ scrollViewDirtyRect.move(-x(), -y());
if (m_data->m_hBar)
m_data->m_hBar->paint(context, scrollViewDirtyRect);
if (m_data->m_vBar)
context->restore();
}
+
+ m_data->m_dirtyRegion = QRegion(); //clear the cache...
+
}
void ScrollView::wheelEvent(PlatformWheelEvent& e)
struct WidgetPrivate
{
- WidgetPrivate() : m_client(0), m_widget(0), m_webFrame(0), m_parentScrollView(0) { }
+ WidgetPrivate()
+ : m_client(0)
+ , enabled(true)
+ , suppressInvalidation(false)
+ , m_widget(0)
+ , m_webFrame(0)
+ , m_parentScrollView(0) { }
~WidgetPrivate() { delete m_webFrame; }
- void setGeometry(const QRect &rect) {
- if (m_widget)
- m_widget->setGeometry(rect);
- m_geometry = rect;
- }
- QRect geometry() const {
- if (m_widget)
- m_widget->geometry();
- return m_geometry;
- }
-
WidgetClient* m_client;
bool enabled;
+ bool suppressInvalidation;
QRect m_geometry;
QWidget *m_widget; //for plugins
QWebFrame *m_webFrame;
IntRect Widget::frameGeometry() const
{
- return data->geometry();
+ if (data->m_widget)
+ data->m_widget->geometry();
+ return data->m_geometry;
+}
+
+void Widget::setFrameGeometry(const IntRect& r)
+{
+ if (data->m_widget)
+ data->m_widget->setGeometry(r);
+ data->m_geometry = r;
}
void Widget::setFocus()
void Widget::setCursor(const Cursor& cursor)
{
#ifndef QT_NO_CURSOR
- if (qwidget())
- qwidget()->setCursor(cursor.impl());
+ if (data->m_widget)
+ data->m_widget->setCursor(cursor.impl());
#endif
}
{
if (data->m_widget)
data->m_widget->show();
- else
- notImplemented();
}
void Widget::hide()
{
if (data->m_widget)
data->m_widget->hide();
- else
- notImplemented();
}
QWebFrame* Widget::qwebframe() const
data->m_webFrame = webFrame;
}
-QWidget* Widget::qwidget() const
+QWidget* Widget::nativeWidget() const
{
- if (data->m_widget)
- return data->m_widget;
-
- if (data->m_webFrame)
- return data->m_webFrame->page()->view();
-
- return 0;
+ return data->m_widget;
}
-void Widget::setQWidget(QWidget *widget)
+void Widget::setNativeWidget(QWidget *widget)
{
data->m_widget = widget;
}
-void Widget::setFrameGeometry(const IntRect& r)
-{
- data->setGeometry(r);
-}
-
void Widget::paint(GraphicsContext *, const IntRect &rect)
{
}
notImplemented();
}
+bool Widget::suppressInvalidation() const
+{
+ return data->suppressInvalidation;
+}
+
+void Widget::setSuppressInvalidation(bool suppress)
+{
+ data->suppressInvalidation = suppress;
+}
+
void Widget::invalidate()
{
invalidateRect(IntRect(0, 0, width(), height()));
void Widget::invalidateRect(const IntRect& r)
{
- if (data->m_widget) //plugins
- return data->m_widget->update(r);
+ if (data->suppressInvalidation)
+ return;
+
+ if (data->m_widget) { //plugins
+ data->m_widget->update(r);
+ return;
+ }
+
+ if (!parent()) {
+ if (isFrameView())
+ static_cast<FrameView*>(this)->addToDirtyRegion(r);
+ return;
+ }
+
+ // Get the root widget.
+ ScrollView* outermostView = topLevel();
+ if (!outermostView)
+ return;
IntRect windowRect = convertToContainingWindow(r);
IntRect clipRect = windowClipRect();
windowRect.intersect(clipRect);
- QWidget *canvas = qwidget(); //regular frameview
- if (!canvas && parent())
- canvas = parent()->qwidget(); //scrollbars
-
- if (!canvas) // not visible anymore
- return;
-
- bool shouldPaint = canvas->testAttribute(Qt::WA_WState_InPaintEvent);
- if (parent() && parent()->isFrameView() && static_cast<FrameView*>(parent())->needsLayout())
- shouldPaint = false;
-
-#if 0
- // ### QWebPage
- if (shouldPaint) {
- QWebPage* page = qobject_cast<QWebPage*>(canvas);
- QPainter p(page);
- page->mainFrame()->render(&p, windowRect);
- } else {
- canvas->update(windowRect);
- }
-#endif
+ outermostView->addToDirtyRegion(windowRect);
}
void Widget::removeFromParent()
return data->m_parentScrollView;
}
+ScrollView* Widget::topLevel() const
+{
+ if (!data->m_parentScrollView)
+ return isFrameView() ? const_cast<ScrollView*>(static_cast<const ScrollView*>(this)) : 0;
+ ScrollView* topLevel = data->m_parentScrollView;
+ while (topLevel->data->m_parentScrollView)
+ topLevel = topLevel->data->m_parentScrollView;
+ return topLevel;
+}
+
+QWidget *Widget::containingWindow() const
+{
+ ScrollView *topLevel = this->topLevel();
+ if (!topLevel)
+ return 0;
+ QWidget *view = 0;
+ if (topLevel->data->m_webFrame)
+ view = topLevel->data->m_webFrame->page()->view();
+ if (!view)
+ view = data->m_widget;
+ return view;
+}
+
+
void Widget::geometryChanged() const
{
}
return IntPoint(point.x() - child->x(), point.y() - child->y());
}
-QWidget *Widget::containingWindow() const
-{
- return qwidget();
-}
-
}
// vim: ts=4 sw=4 et
+2008-01-04 Lars Knoll <lars@trolltech.com>
+
+ Reviewed by Simon.
+
+ Remove most dependencies of Widget/ScrollView onto native QWidgets.
+
+ This also brings the code closer in line with the Windows code. Seems
+ to work nicely on first try :)
+
+
+ * WebCoreSupport/ChromeClientQt.cpp:
+ (WebCore::ChromeClientQt::updateBackingStore):
+ (WebCore::ChromeClientQt::mouseDidMoveOverElement):
+ (WebCore::ChromeClientQt::setToolTip):
+ * WebCoreSupport/FrameLoaderClientQt.cpp:
+ (WebCore::FrameLoaderClientQt::createPlugin):
+
2008-01-04 Holger Hans Peter Freyther <holger.freyther@trolltech.com>
Reviewed by Simon.
void ChromeClientQt::addToDirtyRegion(const IntRect& r)
{
+ QWidget* view = m_webPage->view();
+ if (view)
+ view->update(r);
}
void ChromeClientQt::scrollBackingStore(int dx, int dy, const IntRect& scrollViewRect, const IntRect& clipRect)
{
- // #### QWebPage
- //m_webPage->scroll(dx, dy, scrollViewRect);
+ QWidget* view = m_webPage->view();
+ if (view)
+ view->scroll(dx, dy, scrollViewRect);
}
void ChromeClientQt::updateBackingStore()
{
+// QWidget* view = m_webPage->view();
+// if (view)
+// view->update();
}
void ChromeClientQt::mouseDidMoveOverElement(const HitTestResult&, unsigned /*modifierFlags*/)
if (widget && view) {
widget->setParent(view);
Widget* w= new Widget();
- w->setQWidget(widget);
+ w->setNativeWidget(widget);
return w;
}
// FIXME: make things work for widgetless plugins as well