2011-04-27 James Robinson <jamesr@chromium.org>
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Apr 2011 07:04:28 +0000 (07:04 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Apr 2011 07:04:28 +0000 (07:04 +0000)
        Reviewed by Eric Seidel.

        Fix OwnPtr strict errors in RenderStyle and make StyleRareInheritedData::textShadow an OwnPtr
        https://bugs.webkit.org/show_bug.cgi?id=59377

        This cleans up some strict OwnPtr<> violations around text and box shadow data.  ShadowData's linked list data
        structure now uses OwnPtr<>s to manage memory - each entry in the list has ownership of the next ShadowData.

        * css/CSSStyleSelector.cpp:
        (WebCore::CSSStyleSelector::applyProperty):
        * page/animation/AnimationBase.cpp:
        (WebCore::blendFunc):
        (WebCore::PropertyWrapperShadow::PropertyWrapperShadow):
        (WebCore::PropertyWrapperShadow::blend):
        * rendering/style/RenderStyle.cpp:
        (WebCore::RenderStyle::setTextShadow):
        (WebCore::RenderStyle::setBoxShadow):
        * rendering/style/RenderStyle.h:
        (WebCore::InheritedFlags::textShadow):
        * rendering/style/ShadowData.cpp:
        (WebCore::ShadowData::ShadowData):
        * rendering/style/ShadowData.h:
        (WebCore::ShadowData::ShadowData):
        (WebCore::ShadowData::next):
        (WebCore::ShadowData::setNext):
        * rendering/style/StyleRareInheritedData.cpp:
        (WebCore::StyleRareInheritedData::StyleRareInheritedData):
        (WebCore::StyleRareInheritedData::~StyleRareInheritedData):
        * rendering/style/StyleRareInheritedData.h:
        * rendering/style/StyleRareNonInheritedData.cpp:
        (WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData):

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

Source/WebCore/ChangeLog
Source/WebCore/css/CSSStyleSelector.cpp
Source/WebCore/page/animation/AnimationBase.cpp
Source/WebCore/rendering/style/RenderStyle.cpp
Source/WebCore/rendering/style/RenderStyle.h
Source/WebCore/rendering/style/ShadowData.cpp
Source/WebCore/rendering/style/ShadowData.h
Source/WebCore/rendering/style/StyleRareInheritedData.cpp
Source/WebCore/rendering/style/StyleRareInheritedData.h
Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp

index 40eeb85..7c2496c 100644 (file)
@@ -1,3 +1,37 @@
+2011-04-27  James Robinson  <jamesr@chromium.org>
+
+        Reviewed by Eric Seidel.
+
+        Fix OwnPtr strict errors in RenderStyle and make StyleRareInheritedData::textShadow an OwnPtr
+        https://bugs.webkit.org/show_bug.cgi?id=59377
+
+        This cleans up some strict OwnPtr<> violations around text and box shadow data.  ShadowData's linked list data
+        structure now uses OwnPtr<>s to manage memory - each entry in the list has ownership of the next ShadowData.
+
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::applyProperty):
+        * page/animation/AnimationBase.cpp:
+        (WebCore::blendFunc):
+        (WebCore::PropertyWrapperShadow::PropertyWrapperShadow):
+        (WebCore::PropertyWrapperShadow::blend):
+        * rendering/style/RenderStyle.cpp:
+        (WebCore::RenderStyle::setTextShadow):
+        (WebCore::RenderStyle::setBoxShadow):
+        * rendering/style/RenderStyle.h:
+        (WebCore::InheritedFlags::textShadow):
+        * rendering/style/ShadowData.cpp:
+        (WebCore::ShadowData::ShadowData):
+        * rendering/style/ShadowData.h:
+        (WebCore::ShadowData::ShadowData):
+        (WebCore::ShadowData::next):
+        (WebCore::ShadowData::setNext):
+        * rendering/style/StyleRareInheritedData.cpp:
+        (WebCore::StyleRareInheritedData::StyleRareInheritedData):
+        (WebCore::StyleRareInheritedData::~StyleRareInheritedData):
+        * rendering/style/StyleRareInheritedData.h:
+        * rendering/style/StyleRareNonInheritedData.cpp:
+        (WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData):
+
 2011-04-26  David Levin  <levin@chromium.org>
 
         Reviewed by Eric Seidel.
index 4f653f7..fac02ca 100644 (file)
@@ -5128,11 +5128,11 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
     case CSSPropertyWebkitBoxShadow: {
         if (isInherit) {
             if (id == CSSPropertyTextShadow)
-                return m_style->setTextShadow(m_parentStyle->textShadow() ? new ShadowData(*m_parentStyle->textShadow()) : 0);
-            return m_style->setBoxShadow(m_parentStyle->boxShadow() ? new ShadowData(*m_parentStyle->boxShadow()) : 0);
+                return m_style->setTextShadow(m_parentStyle->textShadow() ? adoptPtr(new ShadowData(*m_parentStyle->textShadow())) : PassOwnPtr<ShadowData>());
+            return m_style->setBoxShadow(m_parentStyle->boxShadow() ? adoptPtr(new ShadowData(*m_parentStyle->boxShadow())) : PassOwnPtr<ShadowData>());
         }
         if (isInitial || primitiveValue) // initial | none
-            return id == CSSPropertyTextShadow ? m_style->setTextShadow(0) : m_style->setBoxShadow(0);
+            return id == CSSPropertyTextShadow ? m_style->setTextShadow(PassOwnPtr<ShadowData>()) : m_style->setBoxShadow(PassOwnPtr<ShadowData>());
 
         if (!value->isValueList())
             return;
@@ -5152,11 +5152,11 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
             Color color;
             if (item->color)
                 color = getColorFromPrimitiveValue(item->color.get());
-            ShadowData* shadowData = new ShadowData(x, y, blur, spread, shadowStyle, id == CSSPropertyWebkitBoxShadow, color.isValid() ? color : Color::transparent);
+            OwnPtr<ShadowData> shadowData = adoptPtr(new ShadowData(x, y, blur, spread, shadowStyle, id == CSSPropertyWebkitBoxShadow, color.isValid() ? color : Color::transparent));
             if (id == CSSPropertyTextShadow)
-                m_style->setTextShadow(shadowData, i != 0);
+                m_style->setTextShadow(shadowData.release(), i /* add to the list if this is not the firsty entry */);
             else
-                m_style->setBoxShadow(shadowData, i != 0);
+                m_style->setBoxShadow(shadowData.release(), i /* add to the list if this is not the firsty entry */);
         }
         return;
     }
index 7d8f218..00a15e8 100644 (file)
@@ -139,19 +139,19 @@ static inline ShadowStyle blendFunc(const AnimationBase* anim, ShadowStyle from,
     return result > 0 ? Normal : Inset;
 }
 
-static inline ShadowData* blendFunc(const AnimationBase* anim, const ShadowData* from, const ShadowData* to, double progress)
+static inline PassOwnPtr<ShadowData> blendFunc(const AnimationBase* anim, const ShadowData* from, const ShadowData* to, double progress)
 {  
     ASSERT(from && to);
     if (from->style() != to->style())
-        return new ShadowData(*to);
-
-    return new ShadowData(blendFunc(anim, from->x(), to->x(), progress),
-                          blendFunc(anim, from->y(), to->y(), progress), 
-                          blendFunc(anim, from->blur(), to->blur(), progress),
-                          blendFunc(anim, from->spread(), to->spread(), progress),
-                          blendFunc(anim, from->style(), to->style(), progress),
-                          from->isWebkitBoxShadow(),
-                          blendFunc(anim, from->color(), to->color(), progress));
+        return adoptPtr(new ShadowData(*to));
+
+    return adoptPtr(new ShadowData(blendFunc(anim, from->x(), to->x(), progress),
+                                   blendFunc(anim, from->y(), to->y(), progress), 
+                                   blendFunc(anim, from->blur(), to->blur(), progress),
+                                   blendFunc(anim, from->spread(), to->spread(), progress),
+                                   blendFunc(anim, from->style(), to->style(), progress),
+                                   from->isWebkitBoxShadow(),
+                                   blendFunc(anim, from->color(), to->color(), progress)));
 }
 
 static inline TransformOperations blendFunc(const AnimationBase* anim, const TransformOperations& from, const TransformOperations& to, double progress)
@@ -329,7 +329,7 @@ public:
 
 class PropertyWrapperShadow : public PropertyWrapperBase {
 public:
-    PropertyWrapperShadow(int prop, const ShadowData* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(ShadowData*, bool))
+    PropertyWrapperShadow(int prop, const ShadowData* (RenderStyle::*getter)() const, void (RenderStyle::*setter)(PassOwnPtr<ShadowData>, bool))
         : PropertyWrapperBase(prop)
         , m_getter(getter)
         , m_setter(setter)
@@ -365,31 +365,33 @@ public:
         ShadowData defaultShadowData(0, 0, 0, 0, Normal, property() == CSSPropertyWebkitBoxShadow, Color::transparent);
         ShadowData defaultInsetShadowData(0, 0, 0, 0, Inset, property() == CSSPropertyWebkitBoxShadow, Color::transparent);
 
-        ShadowData* newShadowData = 0;
+        OwnPtr<ShadowData> newShadowData;
         ShadowData* lastShadow = 0;
         
         while (shadowA || shadowB) {
             const ShadowData* srcShadow = shadowA ? shadowA : (shadowB->style() == Inset ? &defaultInsetShadowData : &defaultShadowData);
             const ShadowData* dstShadow = shadowB ? shadowB : (shadowA->style() == Inset ? &defaultInsetShadowData : &defaultShadowData);
 
-            ShadowData* blendedShadow = blendFunc(anim, srcShadow, dstShadow, progress);
+            OwnPtr<ShadowData> blendedShadow = blendFunc(anim, srcShadow, dstShadow, progress);
+            ShadowData* blendedShadowPtr = blendedShadow.get();
+
             if (!lastShadow)
-                newShadowData = blendedShadow;
+                newShadowData = blendedShadow.release();
             else
-                lastShadow->setNext(blendedShadow);
-
-            lastShadow = blendedShadow;
+                lastShadow->setNext(blendedShadow.release());
+            
+            lastShadow = blendedShadowPtr;
 
             shadowA = shadowA ? shadowA->next() : 0;
             shadowB = shadowB ? shadowB->next() : 0;
         }
         
-        (dst->*m_setter)(newShadowData, false);
+        (dst->*m_setter)(newShadowData.release(), false);
     }
 
 private:
     const ShadowData* (RenderStyle::*m_getter)() const;
-    void (RenderStyle::*m_setter)(ShadowData*, bool);
+    void (RenderStyle::*m_setter)(PassOwnPtr<ShadowData>, bool);
 };
 
 class PropertyWrapperMaybeInvalidColor : public PropertyWrapperBase {
index 6e4c788..7d8663a 100644 (file)
@@ -728,31 +728,30 @@ void RenderStyle::setPageScaleTransform(float scale)
     setTransformOriginY(Length(0, Fixed));
 }
 
-void RenderStyle::setTextShadow(ShadowData* val, bool add)
+void RenderStyle::setTextShadow(PassOwnPtr<ShadowData> shadowData, bool add)
 {
-    ASSERT(!val || (!val->spread() && val->style() == Normal));
+    ASSERT(!shadowData || (!shadowData->spread() && shadowData->style() == Normal));
 
     StyleRareInheritedData* rareData = rareInheritedData.access();
     if (!add) {
-        delete rareData->textShadow;
-        rareData->textShadow = val;
+        rareData->textShadow = shadowData;
         return;
     }
 
-    val->setNext(rareData->textShadow);
-    rareData->textShadow = val;
+    shadowData->setNext(rareData->textShadow.release());
+    rareData->textShadow = shadowData;
 }
 
-void RenderStyle::setBoxShadow(ShadowData* shadowData, bool add)
+void RenderStyle::setBoxShadow(PassOwnPtr<ShadowData> shadowData, bool add)
 {
     StyleRareNonInheritedData* rareData = rareNonInheritedData.access();
     if (!add) {
-        rareData->m_boxShadow.set(shadowData);
+        rareData->m_boxShadow = shadowData;
         return;
     }
 
-    shadowData->setNext(rareData->m_boxShadow.leakPtr());
-    rareData->m_boxShadow.set(shadowData);
+    shadowData->setNext(rareData->m_boxShadow.release());
+    rareData->m_boxShadow = shadowData;
 }
 
 static RoundedIntRect::Radii calcRadiiFor(const BorderData& border, int width, int height)
index 32e41bc..f6cc07c 100644 (file)
@@ -650,7 +650,7 @@ public:
         return m_background->outline().offset();
     }
 
-    const ShadowData* textShadow() const { return rareInheritedData->textShadow; }
+    const ShadowData* textShadow() const { return rareInheritedData->textShadow.get(); }
     void getTextShadowExtent(int& top, int& right, int& bottom, int& left) const { getShadowExtent(textShadow(), top, right, bottom, left); }
     void getTextShadowHorizontalExtent(int& left, int& right) const { getShadowHorizontalExtent(textShadow(), left, right); }
     void getTextShadowVerticalExtent(int& top, int& bottom) const { getShadowVerticalExtent(textShadow(), top, bottom); }
@@ -1019,7 +1019,7 @@ public:
 
     // CSS3 Setters
     void setOutlineOffset(int v) { SET_VAR(m_background, m_outline.m_offset, v) }
-    void setTextShadow(ShadowData* val, bool add=false);
+    void setTextShadow(PassOwnPtr<ShadowData>, bool add = false);
     void setTextStrokeColor(const Color& c) { SET_VAR(rareInheritedData, textStrokeColor, c) }
     void setTextStrokeWidth(float w) { SET_VAR(rareInheritedData, textStrokeWidth, w) }
     void setTextFillColor(const Color& c) { SET_VAR(rareInheritedData, textFillColor, c) }
@@ -1034,7 +1034,7 @@ public:
     void setBoxOrdinalGroup(unsigned int og) { SET_VAR(rareNonInheritedData.access()->flexibleBox, ordinal_group, og); }
     void setBoxOrient(EBoxOrient o) { SET_VAR(rareNonInheritedData.access()->flexibleBox, orient, o); }
     void setBoxPack(EBoxAlignment p) { SET_VAR(rareNonInheritedData.access()->flexibleBox, pack, p); }
-    void setBoxShadow(ShadowData* val, bool add=false);
+    void setBoxShadow(PassOwnPtr<ShadowData>, bool add = false);
     void setBoxReflect(PassRefPtr<StyleReflection> reflect) { if (rareNonInheritedData->m_boxReflect != reflect) rareNonInheritedData.access()->m_boxReflect = reflect; }
     void setBoxSizing(EBoxSizing s) { SET_VAR(m_box, m_boxSizing, s); }
     void setMarqueeIncrement(const Length& f) { SET_VAR(rareNonInheritedData.access()->marquee, increment, f); }
index e8d381c..9efa842 100644 (file)
@@ -37,8 +37,8 @@ ShadowData::ShadowData(const ShadowData& o)
     , m_color(o.m_color)
     , m_style(o.m_style)
     , m_isWebkitBoxShadow(o.m_isWebkitBoxShadow)
+    , m_next(o.m_next ? adoptPtr(new ShadowData(*o.m_next)) : PassOwnPtr<ShadowData>())
 {
-    m_next = o.m_next ? new ShadowData(*o.m_next) : 0;
 }
 
 bool ShadowData::operator==(const ShadowData& o) const
index 0be3fc1..6d629fa 100644 (file)
@@ -26,6 +26,8 @@
 #define ShadowData_h
 
 #include "Color.h"
+#include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
 
 namespace WebCore {
 
@@ -34,7 +36,7 @@ class IntRect;
 
 enum ShadowStyle { Normal, Inset };
 
-// This struct holds information about shadows for the text-shadow and box-shadow properties.
+// This class holds information about shadows for the text-shadow and box-shadow properties.
 
 class ShadowData {
     WTF_MAKE_FAST_ALLOCATED;
@@ -46,7 +48,6 @@ public:
         , m_spread(0)
         , m_style(Normal)
         , m_isWebkitBoxShadow(false)
-        , m_next(0)
     {
     }
 
@@ -58,12 +59,10 @@ public:
         , m_color(color)
         , m_style(style)
         , m_isWebkitBoxShadow(isWebkitBoxShadow)
-        , m_next(0)
     {
     }
 
     ShadowData(const ShadowData& o);
-    ~ShadowData() { delete m_next; }
 
     bool operator==(const ShadowData& o) const;
     bool operator!=(const ShadowData& o) const
@@ -79,8 +78,8 @@ public:
     const Color& color() const { return m_color; }
     bool isWebkitBoxShadow() const { return m_isWebkitBoxShadow; }
 
-    const ShadowData* next() const { return m_next; }
-    void setNext(ShadowData* shadow) { m_next = shadow; }
+    const ShadowData* next() const { return m_next.get(); }
+    void setNext(PassOwnPtr<ShadowData> shadow) { m_next = shadow; }
 
     void adjustRectForShadow(IntRect&, int additionalOutlineSize = 0) const;
     void adjustRectForShadow(FloatRect&, int additionalOutlineSize = 0) const;
@@ -93,7 +92,7 @@ private:
     Color m_color;
     ShadowStyle m_style;
     bool m_isWebkitBoxShadow;
-    ShadowData* m_next;
+    OwnPtr<ShadowData> m_next;
 };
 
 } // namespace WebCore
index a6a19ea..2a8c502 100644 (file)
@@ -32,7 +32,6 @@ namespace WebCore {
 
 StyleRareInheritedData::StyleRareInheritedData()
     : textStrokeWidth(RenderStyle::initialTextStrokeWidth())
-    , textShadow(0)
     , indent(RenderStyle::initialTextIndent())
     , m_effectiveZoom(RenderStyle::initialZoom())
     , widows(RenderStyle::initialWidows())
@@ -64,7 +63,7 @@ StyleRareInheritedData::StyleRareInheritedData(const StyleRareInheritedData& o)
     , textStrokeWidth(o.textStrokeWidth)
     , textFillColor(o.textFillColor)
     , textEmphasisColor(o.textEmphasisColor)
-    , textShadow(o.textShadow ? new ShadowData(*o.textShadow) : 0)
+    , textShadow(o.textShadow ? adoptPtr(new ShadowData(*o.textShadow)) : PassOwnPtr<ShadowData>())
     , highlight(o.highlight)
     , cursorData(o.cursorData)
     , indent(o.indent)
@@ -97,7 +96,6 @@ StyleRareInheritedData::StyleRareInheritedData(const StyleRareInheritedData& o)
 
 StyleRareInheritedData::~StyleRareInheritedData()
 {
-    delete textShadow;
 }
 
 static bool cursorDataEquivalent(const CursorList* c1, const CursorList* c2)
index bf28f29..da410f1 100644 (file)
@@ -58,7 +58,7 @@ public:
     Color textFillColor;
     Color textEmphasisColor;
 
-    ShadowData* textShadow; // Our text shadow information for shadowed text drawing.
+    OwnPtr<ShadowData> textShadow; // Our text shadow information for shadowed text drawing.
     AtomicString highlight; // Apple-specific extension for custom highlight rendering.
     
     RefPtr<CursorList> cursorData;
index 3771f13..d85235c 100644 (file)
@@ -34,8 +34,6 @@ namespace WebCore {
 StyleRareNonInheritedData::StyleRareNonInheritedData()
     : lineClamp(RenderStyle::initialLineClamp())
     , opacity(RenderStyle::initialOpacity())
-    , m_content(0)
-    , m_counterDirectives(0)
     , userDrag(RenderStyle::initialUserDrag())
     , textOverflow(RenderStyle::initialTextOverflow())
     , marginBeforeCollapse(MCOLLAPSE)
@@ -49,9 +47,6 @@ StyleRareNonInheritedData::StyleRareNonInheritedData()
 #if USE(ACCELERATED_COMPOSITING)
     , m_runningAcceleratedAnimation(false)
 #endif
-    , m_boxShadow(0)
-    , m_animations(0)
-    , m_transitions(0)
     , m_mask(FillLayer(MaskFillLayer))
     , m_transformStyle3D(RenderStyle::initialTransformStyle3D())
     , m_backfaceVisibility(RenderStyle::initialBackfaceVisibility())
@@ -71,8 +66,6 @@ StyleRareNonInheritedData::StyleRareNonInheritedData(const StyleRareNonInherited
     , marquee(o.marquee)
     , m_multiCol(o.m_multiCol)
     , m_transform(o.m_transform)
-    , m_content(0)
-    , m_counterDirectives(0)
     , userDrag(o.userDrag)
     , textOverflow(o.textOverflow)
     , marginBeforeCollapse(o.marginBeforeCollapse)
@@ -86,10 +79,10 @@ StyleRareNonInheritedData::StyleRareNonInheritedData(const StyleRareNonInherited
 #if USE(ACCELERATED_COMPOSITING)
     , m_runningAcceleratedAnimation(o.m_runningAcceleratedAnimation)
 #endif
-    , m_boxShadow(o.m_boxShadow ? new ShadowData(*o.m_boxShadow) : 0)
+    , m_boxShadow(o.m_boxShadow ? adoptPtr(new ShadowData(*o.m_boxShadow)) : PassOwnPtr<ShadowData>())
     , m_boxReflect(o.m_boxReflect)
-    , m_animations(o.m_animations ? new AnimationList(*o.m_animations) : 0)
-    , m_transitions(o.m_transitions ? new AnimationList(*o.m_transitions) : 0)
+    , m_animations(o.m_animations ? adoptPtr(new AnimationList(*o.m_animations)) : PassOwnPtr<AnimationList>())
+    , m_transitions(o.m_transitions ? adoptPtr(new AnimationList(*o.m_transitions)) : PassOwnPtr<AnimationList>())
     , m_mask(o.m_mask)
     , m_maskBoxImage(o.m_maskBoxImage)
     , m_transformStyle3D(o.m_transformStyle3D)