Fixed crash when rendering form elements with Qt 4.4
authorhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Dec 2007 12:04:31 +0000 (12:04 +0000)
committerhausmann@webkit.org <hausmann@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Dec 2007 12:04:31 +0000 (12:04 +0000)
QPainter::device() is not guaranteed to return a QWidget, so do the safe "cast" with the
help of QPaintDevice::devType().
Also fall back to the QApplication::style() if we don't have a widget.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28344 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/platform/qt/RenderThemeQt.cpp

index 7347433eef182daa20925242a957d9cec3f050f6..cd1afa1aeb3b5114cf647eaaff2051fbdfff468e 100644 (file)
@@ -1,3 +1,19 @@
+2007-12-03  Simon Hausmann  <hausmann@webkit.org>
+
+        Reviewed by Lars.
+
+        Fixed crash when rendering form elements with Qt 4.4
+
+        QPainter::device() is not guaranteed to return a QWidget, so do the safe "cast" with the
+        help of QPaintDevice::devType().
+        Also fall back to the QApplication::style() if we don't have a widget.
+
+        * platform/qt/RenderThemeQt.cpp:
+        (WebCore::RenderThemeQt::paintButton):
+        (WebCore::RenderThemeQt::paintTextField):
+        (WebCore::RenderThemeQt::paintMenuList):
+        (WebCore::RenderThemeQt::getStylePainterAndWidgetFromPaintInfo):
+
 2007-12-02  Holger Hans Peter Freyther  <holger.freyther@trolltech.com>
 
         Reviewed by Sam Weinig.
index 37c39d1e478f16353dc1c0051f8c535b48eac12e..44a418eed2f9266b012b3ab041486a4d43fa96a5 100644 (file)
@@ -227,7 +227,8 @@ bool RenderThemeQt::paintButton(RenderObject* o, const RenderObject::PaintInfo&
         return true;
 
     QStyleOptionButton option;
-    option.initFrom(widget);
+    if (widget)
+        option.initFrom(widget);
     option.rect = r;
 
     // Get the correct theme data for a button
@@ -258,8 +259,8 @@ bool RenderThemeQt::paintTextField(RenderObject* o, const RenderObject::PaintInf
         return true;
 
     QStyleOptionFrameV2 panel;
-    
-    panel.initFrom(widget);
+    if (widget)
+        panel.initFrom(widget);
     panel.rect = r;
     panel.state |= QStyle::State_Sunken;
     panel.features = QStyleOptionFrameV2::None;
@@ -310,7 +311,8 @@ bool RenderThemeQt::paintMenuList(RenderObject* o, const RenderObject::PaintInfo
         return true;
 
     QStyleOptionComboBox opt;
-    opt.initFrom(widget);
+    if (widget)
+        opt.initFrom(widget);
     EAppearance appearance = applyTheme(opt, o);
     const QPoint topLeft = r.topLeft();
     painter->translate(topLeft);
@@ -416,10 +418,15 @@ bool RenderThemeQt::getStylePainterAndWidgetFromPaintInfo(const RenderObject::Pa
                                                           QPainter*& painter, QWidget*& widget) const
 {
     painter = (i.context ? static_cast<QPainter*>(i.context->platformContext()) : 0);
-    widget = (painter ? static_cast<QWidget*>(painter->device()) : 0);
-    style = (widget ? widget->style() : 0);
-
-    return (painter && widget && style);
+    widget = 0;
+    QPaintDevice* dev = 0;
+    if (painter)
+        dev = painter->device();
+    if (dev && dev->devType() == QInternal::Widget)
+        widget = static_cast<QWidget*>(dev);
+    style = (widget ? widget->style() : QApplication::style());
+
+    return (painter && style);
 }
 
 EAppearance RenderThemeQt::applyTheme(QStyleOption& option, RenderObject* o) const