Title: [110886] trunk/Source/WebCore
Revision
110886
Author
[email protected]
Date
2012-03-15 14:24:32 -0700 (Thu, 15 Mar 2012)

Log Message

RenderStyle: Return Color objects by value instead of as const references.
<http://webkit.org/b/81180>

Reviewed by Antti Koivisto.

Make RenderStyle getters return "Color" rather than "const Color&". This is preparation
for storing some color values in a more space-efficient fashion.

* css/CSSStyleApplyProperty.cpp:
(WebCore::ApplyPropertyColor::applyInheritValue):
* page/animation/AnimationBase.cpp:
(PropertyWrapperColor):
(WebCore::PropertyWrapperColor::PropertyWrapperColor):
(WebCore::PropertyWrapperColor::blend):
(WebCore::PropertyWrapperMaybeInvalidColor::PropertyWrapperMaybeInvalidColor):
(PropertyWrapperMaybeInvalidColor):
(WebCore::PropertyWrapperVisitedAffectedColor::PropertyWrapperVisitedAffectedColor):
(WebCore::PropertyWrapperSVGPaint::PropertyWrapperSVGPaint):
(PropertyWrapperSVGPaint):
* platform/graphics/Color.h:
(WebCore::Color::Color):
* rendering/style/RenderStyle.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (110885 => 110886)


--- trunk/Source/WebCore/ChangeLog	2012-03-15 21:16:05 UTC (rev 110885)
+++ trunk/Source/WebCore/ChangeLog	2012-03-15 21:24:32 UTC (rev 110886)
@@ -1,3 +1,28 @@
+2012-03-15  Andreas Kling  <[email protected]>
+
+        RenderStyle: Return Color objects by value instead of as const references.
+        <http://webkit.org/b/81180>
+
+        Reviewed by Antti Koivisto.
+
+        Make RenderStyle getters return "Color" rather than "const Color&". This is preparation
+        for storing some color values in a more space-efficient fashion.
+
+        * css/CSSStyleApplyProperty.cpp:
+        (WebCore::ApplyPropertyColor::applyInheritValue):
+        * page/animation/AnimationBase.cpp:
+        (PropertyWrapperColor):
+        (WebCore::PropertyWrapperColor::PropertyWrapperColor):
+        (WebCore::PropertyWrapperColor::blend):
+        (WebCore::PropertyWrapperMaybeInvalidColor::PropertyWrapperMaybeInvalidColor):
+        (PropertyWrapperMaybeInvalidColor):
+        (WebCore::PropertyWrapperVisitedAffectedColor::PropertyWrapperVisitedAffectedColor):
+        (WebCore::PropertyWrapperSVGPaint::PropertyWrapperSVGPaint):
+        (PropertyWrapperSVGPaint):
+        * platform/graphics/Color.h:
+        (WebCore::Color::Color):
+        * rendering/style/RenderStyle.h:
+
 2012-03-15  Jessie Berlin  <[email protected]>
 
         Assertion failures in WebCore::Page::goBackOrForward causing multiple "crashes" on Lion Intel

Modified: trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp (110885 => 110886)


--- trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp	2012-03-15 21:16:05 UTC (rev 110885)
+++ trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp	2012-03-15 21:24:32 UTC (rev 110886)
@@ -266,17 +266,17 @@
 Color defaultInitialColor();
 Color defaultInitialColor() { return Color(); }
 template <ColorInherit inheritColorFromParent,
-          const Color& (RenderStyle::*getterFunction)() const,
+          Color (RenderStyle::*getterFunction)() const,
           void (RenderStyle::*setterFunction)(const Color&),
           void (RenderStyle::*visitedLinkSetterFunction)(const Color&),
-          const Color& (RenderStyle::*defaultFunction)() const,
+          Color (RenderStyle::*defaultFunction)() const,
           Color (*initialFunction)() = &defaultInitialColor>
 class ApplyPropertyColor {
 public:
     static void applyInheritValue(CSSStyleSelector* selector)
     {
         // Visited link style can never explicitly inherit from parent visited link style so no separate getters are needed.
-        const Color& color = (selector->parentStyle()->*getterFunction)();
+        Color color = (selector->parentStyle()->*getterFunction)();
         applyColorValue(selector, color.isValid() ? color : (selector->parentStyle()->*defaultFunction)());
     }
 

Modified: trunk/Source/WebCore/page/animation/AnimationBase.cpp (110885 => 110886)


--- trunk/Source/WebCore/page/animation/AnimationBase.cpp	2012-03-15 21:16:05 UTC (rev 110885)
+++ trunk/Source/WebCore/page/animation/AnimationBase.cpp	2012-03-15 21:24:32 UTC (rev 110886)
@@ -418,6 +418,23 @@
     }
 };
 
+class PropertyWrapperColor : public PropertyWrapperGetter<Color> {
+public:
+    PropertyWrapperColor(int prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
+        : PropertyWrapperGetter<Color>(prop, getter)
+        , m_setter(setter)
+    {
+    }
+
+    virtual void blend(const AnimationBase* anim, RenderStyle* dst, const RenderStyle* a, const RenderStyle* b, double progress) const
+    {
+        (dst->*m_setter)(blendFunc(anim, (a->*PropertyWrapperGetter<Color>::m_getter)(), (b->*PropertyWrapperGetter<Color>::m_getter)(), progress));
+    }
+
+protected:
+    void (RenderStyle::*m_setter)(const Color&);
+};
+
 #if USE(ACCELERATED_COMPOSITING)
 class PropertyWrapperAcceleratedOpacity : public PropertyWrapper<float> {
 public:
@@ -610,7 +627,7 @@
 
 class PropertyWrapperMaybeInvalidColor : public PropertyWrapperBase {
 public:
-    PropertyWrapperMaybeInvalidColor(int prop, const Color& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
+    PropertyWrapperMaybeInvalidColor(int prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
         : PropertyWrapperBase(prop)
         , m_getter(getter)
         , m_setter(setter)
@@ -649,22 +666,22 @@
     }
 
 private:
-    const Color& (RenderStyle::*m_getter)() const;
+    Color (RenderStyle::*m_getter)() const;
     void (RenderStyle::*m_setter)(const Color&);
 };
 
 enum MaybeInvalidColorTag { MaybeInvalidColor };
 class PropertyWrapperVisitedAffectedColor : public PropertyWrapperBase {
 public:
-    PropertyWrapperVisitedAffectedColor(int prop, const Color& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&), 
-                                        const Color& (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Color&))
+    PropertyWrapperVisitedAffectedColor(int prop, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&), 
+                                        Color (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Color&))
         : PropertyWrapperBase(prop)
-        , m_wrapper(adoptPtr(new PropertyWrapper<const Color&>(prop, getter, setter)))
-        , m_visitedWrapper(adoptPtr(new PropertyWrapper<const Color&>(prop, visitedGetter, visitedSetter)))
+        , m_wrapper(adoptPtr(new PropertyWrapperColor(prop, getter, setter)))
+        , m_visitedWrapper(adoptPtr(new PropertyWrapperColor(prop, visitedGetter, visitedSetter)))
     {
     }
-    PropertyWrapperVisitedAffectedColor(int prop, MaybeInvalidColorTag, const Color& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&), 
-                                        const Color& (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Color&))
+    PropertyWrapperVisitedAffectedColor(int prop, MaybeInvalidColorTag, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&), 
+                                        Color (RenderStyle::*visitedGetter)() const, void (RenderStyle::*visitedSetter)(const Color&))
         : PropertyWrapperBase(prop)
         , m_wrapper(adoptPtr(new PropertyWrapperMaybeInvalidColor(prop, getter, setter)))
         , m_visitedWrapper(adoptPtr(new PropertyWrapperMaybeInvalidColor(prop, visitedGetter, visitedSetter)))
@@ -887,7 +904,7 @@
 #if ENABLE(SVG)
 class PropertyWrapperSVGPaint : public PropertyWrapperBase {
 public:
-    PropertyWrapperSVGPaint(int prop, const SVGPaint::SVGPaintType& (RenderStyle::*paintTypeGetter)() const, const Color& (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
+    PropertyWrapperSVGPaint(int prop, const SVGPaint::SVGPaintType& (RenderStyle::*paintTypeGetter)() const, Color (RenderStyle::*getter)() const, void (RenderStyle::*setter)(const Color&))
         : PropertyWrapperBase(prop)
         , m_paintTypeGetter(paintTypeGetter)
         , m_getter(getter)
@@ -941,7 +958,7 @@
 
 private:
     const SVGPaint::SVGPaintType& (RenderStyle::*m_paintTypeGetter)() const;
-    const Color& (RenderStyle::*m_getter)() const;
+    Color (RenderStyle::*m_getter)() const;
     void (RenderStyle::*m_setter)(const Color&);
 };
 #endif

Modified: trunk/Source/WebCore/platform/graphics/Color.h (110885 => 110886)


--- trunk/Source/WebCore/platform/graphics/Color.h	2012-03-15 21:16:05 UTC (rev 110885)
+++ trunk/Source/WebCore/platform/graphics/Color.h	2012-03-15 21:24:32 UTC (rev 110886)
@@ -79,7 +79,7 @@
     WTF_MAKE_FAST_ALLOCATED;
 public:
     Color() : m_color(0), m_valid(false) { }
-    Color(RGBA32 col) : m_color(col), m_valid(true) { }
+    Color(RGBA32 color, bool valid = true) : m_color(color), m_valid(valid) { ASSERT(!m_color || m_valid); }
     Color(int r, int g, int b) : m_color(makeRGB(r, g, b)), m_valid(true) { }
     Color(int r, int g, int b, int a) : m_color(makeRGBA(r, g, b, a)), m_valid(true) { }
     // Color is currently limited to 32bit RGBA, perhaps some day we'll support better colors

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.h (110885 => 110886)


--- trunk/Source/WebCore/rendering/style/RenderStyle.h	2012-03-15 21:16:05 UTC (rev 110885)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.h	2012-03-15 21:24:32 UTC (rev 110886)
@@ -1377,13 +1377,13 @@
     SVGRenderStyle* accessSVGStyle() { return m_svgStyle.access(); }
 
     const SVGPaint::SVGPaintType& fillPaintType() const { return svgStyle()->fillPaintType(); }
-    const Color& fillPaintColor() const { return svgStyle()->fillPaintColor(); }
+    Color fillPaintColor() const { return svgStyle()->fillPaintColor(); }
     void setFillPaintColor(const Color& c) { accessSVGStyle()->setFillPaint(SVGPaint::SVG_PAINTTYPE_RGBCOLOR, c, ""); }
     float fillOpacity() const { return svgStyle()->fillOpacity(); }
     void setFillOpacity(float f) { accessSVGStyle()->setFillOpacity(f); }
 
     const SVGPaint::SVGPaintType& strokePaintType() const { return svgStyle()->strokePaintType(); }
-    const Color& strokePaintColor() const { return svgStyle()->strokePaintColor(); }
+    Color strokePaintColor() const { return svgStyle()->strokePaintColor(); }
     void setStrokePaintColor(const Color& c) { accessSVGStyle()->setStrokePaint(SVGPaint::SVG_PAINTTYPE_RGBCOLOR, c, ""); }
     float strokeOpacity() const { return svgStyle()->strokeOpacity(); }
     void setStrokeOpacity(float f) { accessSVGStyle()->setStrokeOpacity(f); }
@@ -1717,36 +1717,36 @@
     bool isDisplayInlineType(EDisplay display) const { return display == INLINE || isDisplayReplacedType(display); }
 
     // Color accessors are all private to make sure callers use visitedDependentColor instead to access them.
-    const Color& invalidColor() const { static Color invalid; return invalid; }
-    const Color& borderLeftColor() const { return surround->border.left().color(); }
-    const Color& borderRightColor() const { return surround->border.right().color(); }
-    const Color& borderTopColor() const { return surround->border.top().color(); }
-    const Color& borderBottomColor() const { return surround->border.bottom().color(); }
-    const Color& backgroundColor() const { return m_background->color(); }
-    const Color& color() const { return inherited->color; }
-    const Color& columnRuleColor() const { return rareNonInheritedData->m_multiCol->m_rule.color(); }
-    const Color& outlineColor() const { return m_background->outline().color(); }
-    const Color& textEmphasisColor() const { return rareInheritedData->textEmphasisColor; }
-    const Color& textFillColor() const { return rareInheritedData->textFillColor; }
-    const Color& textStrokeColor() const { return rareInheritedData->textStrokeColor; }
-    const Color& visitedLinkColor() const { return inherited->visitedLinkColor; }
-    const Color& visitedLinkBackgroundColor() const { return rareNonInheritedData->m_visitedLinkBackgroundColor; }
-    const Color& visitedLinkBorderLeftColor() const { return rareNonInheritedData->m_visitedLinkBorderLeftColor; }
-    const Color& visitedLinkBorderRightColor() const { return rareNonInheritedData->m_visitedLinkBorderRightColor; }
-    const Color& visitedLinkBorderBottomColor() const { return rareNonInheritedData->m_visitedLinkBorderBottomColor; }
-    const Color& visitedLinkBorderTopColor() const { return rareNonInheritedData->m_visitedLinkBorderTopColor; }
-    const Color& visitedLinkOutlineColor() const { return rareNonInheritedData->m_visitedLinkOutlineColor; }
-    const Color& visitedLinkColumnRuleColor() const { return rareNonInheritedData->m_multiCol->m_visitedLinkColumnRuleColor; }
-    const Color& visitedLinkTextEmphasisColor() const { return rareInheritedData->visitedLinkTextEmphasisColor; }
-    const Color& visitedLinkTextFillColor() const { return rareInheritedData->visitedLinkTextFillColor; }
-    const Color& visitedLinkTextStrokeColor() const { return rareInheritedData->visitedLinkTextStrokeColor; }
+    Color invalidColor() const { static Color invalid; return invalid; }
+    Color borderLeftColor() const { return surround->border.left().color(); }
+    Color borderRightColor() const { return surround->border.right().color(); }
+    Color borderTopColor() const { return surround->border.top().color(); }
+    Color borderBottomColor() const { return surround->border.bottom().color(); }
+    Color backgroundColor() const { return m_background->color(); }
+    Color color() const { return inherited->color; }
+    Color columnRuleColor() const { return rareNonInheritedData->m_multiCol->m_rule.color(); }
+    Color outlineColor() const { return m_background->outline().color(); }
+    Color textEmphasisColor() const { return rareInheritedData->textEmphasisColor; }
+    Color textFillColor() const { return rareInheritedData->textFillColor; }
+    Color textStrokeColor() const { return rareInheritedData->textStrokeColor; }
+    Color visitedLinkColor() const { return inherited->visitedLinkColor; }
+    Color visitedLinkBackgroundColor() const { return rareNonInheritedData->m_visitedLinkBackgroundColor; }
+    Color visitedLinkBorderLeftColor() const { return rareNonInheritedData->m_visitedLinkBorderLeftColor; }
+    Color visitedLinkBorderRightColor() const { return rareNonInheritedData->m_visitedLinkBorderRightColor; }
+    Color visitedLinkBorderBottomColor() const { return rareNonInheritedData->m_visitedLinkBorderBottomColor; }
+    Color visitedLinkBorderTopColor() const { return rareNonInheritedData->m_visitedLinkBorderTopColor; }
+    Color visitedLinkOutlineColor() const { return rareNonInheritedData->m_visitedLinkOutlineColor; }
+    Color visitedLinkColumnRuleColor() const { return rareNonInheritedData->m_multiCol->m_visitedLinkColumnRuleColor; }
+    Color visitedLinkTextEmphasisColor() const { return rareInheritedData->visitedLinkTextEmphasisColor; }
+    Color visitedLinkTextFillColor() const { return rareInheritedData->visitedLinkTextFillColor; }
+    Color visitedLinkTextStrokeColor() const { return rareInheritedData->visitedLinkTextStrokeColor; }
 
     Color colorIncludingFallback(int colorProperty, bool visitedLink) const;
 
 #if ENABLE(SVG)
-    const Color& stopColor() const { return svgStyle()->stopColor(); }
-    const Color& floodColor() const { return svgStyle()->floodColor(); }
-    const Color& lightingColor() const { return svgStyle()->lightingColor(); }
+    Color stopColor() const { return svgStyle()->stopColor(); }
+    Color floodColor() const { return svgStyle()->floodColor(); }
+    Color lightingColor() const { return svgStyle()->lightingColor(); }
 #endif
 
     void appendContent(PassOwnPtr<ContentData>);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to