All pastes #1601363 Raw Edit

Anonymous

public cpp v1 · immutable
#1601363 ·published 2009-10-07 14:04 UTC
rendered paste body
From dbf1934a4b65a7d63d86837b8adf300e4108afd3 Mon Sep 17 00:00:00 2001From: Kenneth Rohde Christiansen <kenneth@webkit.org>Date: Wed, 7 Oct 2009 10:51:13 -0300Subject: [PATCH] Qt has very good theming support, so it is possible to paint our Qt Buttons, TextFields etc with the actual CSS background color.Patch by Kenneth Rohde Christiansen <kenneth@webkit.org> on 2009-10-07Reviewed by NOBODY (OOPS!).This patch changes isControlStyled to not fallback in caseswhere we can actually paint Qt Widgets with styling, by addinga few more cases and not taking the background color intoaccount when deciding to fallback or not.We still use the background comparison though, to find out whetherwe should apply the CSS color or not, and if that is the case, thecolor is stored in the style as a new styledControlBackgroundColor.This is also needed as we, in the case of the TextField, to actualset the actual CSS background color to Transparent, as our TextFieldQt widget has rounded corners, and we do not want those to betransparent.* platform/qt/RenderThemeQt.cpp:(WebCore::RenderThemeQt::isControlStyled):(WebCore::RenderThemeQt::paintButton):(WebCore::RenderThemeQt::paintTextField):* platform/qt/RenderThemeQt.h:* rendering/style/RenderStyle.h:(WebCore::):(WebCore::InheritedFlags::styledControlBackgroundColor):(WebCore::InheritedFlags::setStyledControlBackgroundColor):--- WebCore/ChangeLog                     |   31 ++++++++++++++++++++++++++++++ WebCore/platform/qt/RenderThemeQt.cpp |   34 +++++++++++++++++++++++++++++++++ WebCore/platform/qt/RenderThemeQt.h   |    3 ++ WebCore/rendering/style/RenderStyle.h |    6 +++++ 4 files changed, 74 insertions(+), 0 deletions(-)diff --git a/WebCore/ChangeLog b/WebCore/ChangeLogindex 408ae7e..87dfbfc 100644--- a/WebCore/ChangeLog+++ b/WebCore/ChangeLog@@ -1,5 +1,36 @@ 2009-10-07  Kenneth Rohde Christiansen  <kenneth@webkit.org> +        Reviewed by NOBODY (OOPS!).++        Qt has very good theming support, so it is possible to paint our+        Qt Buttons, TextFields etc with the actual CSS background color.++        This patch changes isControlStyled to not fallback in cases+        where we can actually paint Qt Widgets with styling, by adding+        a few more cases and not taking the background color into+        account when deciding to fallback or not.++        We still use the background comparison though, to find out whether+        we should apply the CSS color or not, and if that is the case, the+        color is stored in the style as a new styledControlBackgroundColor.++        This is also needed as we, in the case of the TextField, to actual+        set the actual CSS background color to Transparent, as our TextField+        Qt widget has rounded corners, and we do not want those to be+        transparent.++        * platform/qt/RenderThemeQt.cpp:+        (WebCore::RenderThemeQt::isControlStyled):+        (WebCore::RenderThemeQt::paintButton):+        (WebCore::RenderThemeQt::paintTextField):+        * platform/qt/RenderThemeQt.h:+        * rendering/style/RenderStyle.h:+        (WebCore::):+        (WebCore::InheritedFlags::styledControlBackgroundColor):+        (WebCore::InheritedFlags::setStyledControlBackgroundColor):++2009-10-07  Kenneth Rohde Christiansen  <kenneth@webkit.org>+         Reviewed by Simon Hausmann.          Do not create valid QColor's for invalid WebCore::Color's.diff --git a/WebCore/platform/qt/RenderThemeQt.cpp b/WebCore/platform/qt/RenderThemeQt.cppindex b61d356..b6e315d 100644--- a/WebCore/platform/qt/RenderThemeQt.cpp+++ b/WebCore/platform/qt/RenderThemeQt.cpp@@ -141,6 +141,33 @@ RenderThemeQt::~RenderThemeQt()     delete m_fallbackStyle; } +bool RenderThemeQt::isControlStyled(const RenderStyle* style, const BorderData& border, const FillLayer& background,+                                  const Color& backgroundColor) const+{+    switch (style->appearance()) {+        case PushButtonPart:+        case SquareButtonPart:+        case DefaultButtonPart:+        case ButtonPart:+        case RadioPart:+        case ListboxPart:+        case MenulistPart:+        case SearchFieldPart:+        case TextFieldPart:+        case TextAreaPart:+            if (style->backgroundColor() != backgroundColor) {+                RenderStyle* s = const_cast<RenderStyle*>(style);+                s->setStyledControlBackgroundColor(style->backgroundColor());+            }++            // Test the style to see if the UA border and background match.+            return (style->border() != border ||+                    *style->backgroundLayers() != background);+        default:+            return false;+    }+}+ // for some widget painting, we need to fallback to Windows style QStyle* RenderThemeQt::fallbackStyle() {@@ -476,6 +503,9 @@ bool RenderThemeQt::paintButton(RenderObject* o, const RenderObject::PaintInfo&     option.state |= QStyle::State_Small;      ControlPart appearance = applyTheme(option, o);+    QColor bgColor = o->style()->styledControlBackgroundColor();+    if (bgColor.isValid())+        option.palette.setBrush(QPalette::Button, bgColor);     if (appearance == PushButtonPart || appearance == ButtonPart) {         option.rect = inflateButtonRect(option.rect, qStyle());         p.drawControl(QStyle::CE_PushButton, option);@@ -518,6 +548,10 @@ bool RenderThemeQt::paintTextField(RenderObject* o, const RenderObject::PaintInf         && appearance != ListboxPart)         return true; +    QColor bgColor = o->style()->styledControlBackgroundColor();+    if (bgColor.isValid())+        panel.palette.setBrush(QPalette::Base, bgColor);+     // Now paint the text field.     p.drawPrimitive(QStyle::PE_PanelLineEdit, panel); diff --git a/WebCore/platform/qt/RenderThemeQt.h b/WebCore/platform/qt/RenderThemeQt.hindex 617c875..ef1cb76 100644--- a/WebCore/platform/qt/RenderThemeQt.h+++ b/WebCore/platform/qt/RenderThemeQt.h@@ -76,6 +76,9 @@ public: #endif  protected:+    // Whether or not the control has been styled enough by the author to disable the native appearance.+    virtual bool isControlStyled(const RenderStyle*, const BorderData&, const FillLayer&, const Color& backgroundColor) const;+     virtual bool paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r);     virtual void setCheckboxSize(RenderStyle*) const; diff --git a/WebCore/rendering/style/RenderStyle.h b/WebCore/rendering/style/RenderStyle.hindex c19b44f..e4d1b24 100644--- a/WebCore/rendering/style/RenderStyle.h+++ b/WebCore/rendering/style/RenderStyle.h@@ -118,6 +118,10 @@ protected:     bool m_affectedByEmpty : 1;     bool m_emptyState : 1; +    // Hook to store the color to apply to platform controls, still making+    // it possible to clear the actual CSSStyle background color in the RenderTheme.+    Color m_styledControlBackgroundColor;+     // We optimize for :first-child and :last-child.  The other positional child selectors like nth-child or     // *-child-of-type, we will just give up and re-evaluate whenever children change at all.     bool m_childrenAffectedByFirstChildRules : 1;@@ -520,6 +524,7 @@ public:     }      const Color& backgroundColor() const { return background->m_color; }+    const Color& styledControlBackgroundColor() const { return m_styledControlBackgroundColor; }     StyleImage* backgroundImage() const { return background->m_background.m_image.get(); }     EFillRepeat backgroundRepeatX() const { return static_cast<EFillRepeat>(background->m_background.m_repeatX); }     EFillRepeat backgroundRepeatY() const { return static_cast<EFillRepeat>(background->m_background.m_repeatY); }@@ -750,6 +755,7 @@ public:      void resetOutline() { SET_VAR(background, m_outline, OutlineValue()) } +    void setStyledControlBackgroundColor(const Color& v) { m_styledControlBackgroundColor = v; }     void setBackgroundColor(const Color& v) { SET_VAR(background, m_color, v) }      void setBackgroundXPosition(Length l) { SET_VAR(background, m_background.m_xPosition, l) }-- 1.6.0.4