Clean up ContentData
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 6 Oct 2013 20:11:38 +0000 (20:11 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 6 Oct 2013 20:11:38 +0000 (20:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122421

Reviewed by Andreas Kling.

Replace uses of OwnPtr with std::unique_ptr and get rid of the ContentData::create overloads.

* css/StyleResolver.cpp:
(WebCore::StyleResolver::applyProperty):
* rendering/style/ContentData.cpp:
(WebCore::ContentData::clone):
* rendering/style/ContentData.h:
(WebCore::ContentData::setNext):
* rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::appendContent):
(WebCore::RenderStyle::setContent):
* rendering/style/RenderStyle.h:
* rendering/style/StyleRareNonInheritedData.h:

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

Source/WebCore/ChangeLog
Source/WebCore/css/StyleResolver.cpp
Source/WebCore/rendering/style/ContentData.cpp
Source/WebCore/rendering/style/ContentData.h
Source/WebCore/rendering/style/RenderStyle.cpp
Source/WebCore/rendering/style/RenderStyle.h
Source/WebCore/rendering/style/StyleRareNonInheritedData.h

index 7569cbde21ccedefc5454cee57d42ff3de1124a2..8542346abe20ddf87de364a8012d37b6daa0d4f5 100644 (file)
@@ -1,3 +1,24 @@
+2013-10-06  Anders Carlsson  <andersca@apple.com>
+
+        Clean up ContentData
+        https://bugs.webkit.org/show_bug.cgi?id=122421
+
+        Reviewed by Andreas Kling.
+
+        Replace uses of OwnPtr with std::unique_ptr and get rid of the ContentData::create overloads.
+
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::applyProperty):
+        * rendering/style/ContentData.cpp:
+        (WebCore::ContentData::clone):
+        * rendering/style/ContentData.h:
+        (WebCore::ContentData::setNext):
+        * rendering/style/RenderStyle.cpp:
+        (WebCore::RenderStyle::appendContent):
+        (WebCore::RenderStyle::setContent):
+        * rendering/style/RenderStyle.h:
+        * rendering/style/StyleRareNonInheritedData.h:
+
 2013-10-06  Sam Weinig  <sam@webkit.org>
 
         Be a bit shouty about final classes while we look into why the bots don't like it.
index bd73ec1ce200f0301133688168347b19f2e1c998..88b1a07e9e5828197c9b8636f8c9f295512549cd 100644 (file)
@@ -2189,8 +2189,8 @@ void StyleResolver::applyProperty(CSSPropertyID id, CSSValue* value)
                     CSSValueID listStyleIdent = counterValue->listStyleIdent();
                     if (listStyleIdent != CSSValueNone)
                         listStyleType = static_cast<EListStyleType>(listStyleIdent - CSSValueDisc);
-                    OwnPtr<CounterContent> counter = adoptPtr(new CounterContent(counterValue->identifier(), listStyleType, counterValue->separator()));
-                    state.style()->setContent(counter.release(), didSet);
+                    auto counter = std::make_unique<CounterContent>(counterValue->identifier(), listStyleType, counterValue->separator());
+                    state.style()->setContent(std::move(counter), didSet);
                     didSet = true;
                 } else {
                     switch (contentValue->getValueID()) {
index 478f9a5bc2ea4577e7ad7e6de796293b131798c8..fb126f82239530364ffd5d7d3bcbd568ef49af4d 100644 (file)
 
 namespace WebCore {
 
-PassOwnPtr<ContentData> ContentData::create(PassRefPtr<StyleImage> image)
+std::unique_ptr<ContentData> ContentData::clone() const
 {
-    return adoptPtr(new ImageContentData(image));
-}
-
-PassOwnPtr<ContentData> ContentData::create(const String& text)
-{
-    return adoptPtr(new TextContentData(text));
-}
-
-PassOwnPtr<ContentData> ContentData::create(PassOwnPtr<CounterContent> counter)
-{
-    return adoptPtr(new CounterContentData(counter));
-}
-
-PassOwnPtr<ContentData> ContentData::create(QuoteType quote)
-{
-    return adoptPtr(new QuoteContentData(quote));
-}
-
-PassOwnPtr<ContentData> ContentData::clone() const
-{
-    OwnPtr<ContentData> result = cloneInternal();
+    auto result = cloneInternal();
     
     ContentData* lastNewData = result.get();
     for (const ContentData* contentData = next(); contentData; contentData = contentData->next()) {
-        OwnPtr<ContentData> newData = contentData->cloneInternal();
-        lastNewData->setNext(newData.release());
+        auto newData = contentData->cloneInternal();
+        lastNewData->setNext(std::move(newData));
         lastNewData = lastNewData->next();
     }
         
-    return result.release();
+    return result;
 }
 
 RenderObject* ImageContentData::createRenderer(Document& document, RenderStyle& pseudoStyle) const
index a601a8cd3608a1c2d788c46b527f4df684834eb1..af28248f95acc69c6154de1e4cf8480e325450bc 100644 (file)
@@ -28,7 +28,6 @@
 #include "CounterContent.h"
 #include "StyleImage.h"
 #include <wtf/OwnPtr.h>
-#include <wtf/PassOwnPtr.h>
 
 namespace WebCore {
 
@@ -39,11 +38,6 @@ class RenderStyle;
 class ContentData {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static PassOwnPtr<ContentData> create(PassRefPtr<StyleImage>);
-    static PassOwnPtr<ContentData> create(const String&);
-    static PassOwnPtr<ContentData> create(PassOwnPtr<CounterContent>);
-    static PassOwnPtr<ContentData> create(QuoteType);
-    
     virtual ~ContentData() { }
 
     virtual bool isCounter() const { return false; }
@@ -53,22 +47,26 @@ public:
 
     virtual RenderObject* createRenderer(Document&, RenderStyle&) const = 0;
 
-    virtual PassOwnPtr<ContentData> clone() const;
+    std::unique_ptr<ContentData> clone() const;
 
     ContentData* next() const { return m_next.get(); }
-    void setNext(PassOwnPtr<ContentData> next) { m_next = next; }
+    void setNext(std::unique_ptr<ContentData> next) { m_next = std::move(next); }
 
     virtual bool equals(const ContentData&) const = 0;
 
 private:
-    virtual PassOwnPtr<ContentData> cloneInternal() const = 0;
+    virtual std::unique_ptr<ContentData> cloneInternal() const = 0;
 
-    OwnPtr<ContentData> m_next;
+    std::unique_ptr<ContentData> m_next;
 };
 
 class ImageContentData FINAL : public ContentData {
-    friend class ContentData;
 public:
+    explicit ImageContentData(PassRefPtr<StyleImage> image)
+        : m_image(image)
+    {
+    }
+
     const StyleImage* image() const { return m_image.get(); }
     StyleImage* image() { return m_image.get(); }
     void setImage(PassRefPtr<StyleImage> image) { m_image = image; }
@@ -84,23 +82,23 @@ public:
     }
 
 private:
-    ImageContentData(PassRefPtr<StyleImage> image)
-        : m_image(image)
-    {
-    }
-
-    virtual PassOwnPtr<ContentData> cloneInternal() const
+    virtual std::unique_ptr<ContentData> cloneInternal() const OVERRIDE
     {
         RefPtr<StyleImage> image = const_cast<StyleImage*>(this->image());
-        return create(image.release());
+
+        return std::make_unique<ImageContentData>(image.release());
     }
 
     RefPtr<StyleImage> m_image;
 };
 
 class TextContentData FINAL : public ContentData {
-    friend class ContentData;
 public:
+    explicit TextContentData(const String& text)
+        : m_text(text)
+    {
+    }
+
     const String& text() const { return m_text; }
     void setText(const String& text) { m_text = text; }
 
@@ -115,35 +113,29 @@ public:
     }
 
 private:
-    TextContentData(const String& text)
-        : m_text(text)
-    {
-    }
-
-    virtual PassOwnPtr<ContentData> cloneInternal() const { return create(text()); }
+    virtual std::unique_ptr<ContentData> cloneInternal() const OVERRIDE { return std::make_unique<TextContentData>(text()); }
 
     String m_text;
 };
 
 class CounterContentData FINAL : public ContentData {
-    friend class ContentData;
 public:
+    explicit CounterContentData(std::unique_ptr<CounterContent> counter)
+        : m_counter(std::move(counter))
+    {
+    }
+
     const CounterContent* counter() const { return m_counter.get(); }
-    void setCounter(PassOwnPtr<CounterContent> counter) { m_counter = counter; }
+    void setCounter(std::unique_ptr<CounterContent> counter) { m_counter = std::move(counter); }
 
     virtual bool isCounter() const OVERRIDE { return true; }
     virtual RenderObject* createRenderer(Document&, RenderStyle&) const OVERRIDE;
 
 private:
-    CounterContentData(PassOwnPtr<CounterContent> counter)
-        : m_counter(counter)
+    virtual std::unique_ptr<ContentData> cloneInternal() const OVERRIDE
     {
-    }
-
-    virtual PassOwnPtr<ContentData> cloneInternal() const
-    {
-        OwnPtr<CounterContent> counterData = adoptPtr(new CounterContent(*counter()));
-        return create(counterData.release());
+        auto counterData = std::make_unique<CounterContent>(*counter());
+        return std::make_unique<CounterContentData>(std::move(counterData));
     }
 
     virtual bool equals(const ContentData& data) const OVERRIDE
@@ -153,12 +145,16 @@ private:
         return *static_cast<const CounterContentData&>(data).counter() == *counter();
     }
 
-    OwnPtr<CounterContent> m_counter;
+    std::unique_ptr<CounterContent> m_counter;
 };
 
 class QuoteContentData FINAL : public ContentData {
-    friend class ContentData;
 public:
+    explicit QuoteContentData(QuoteType quote)
+        : m_quote(quote)
+    {
+    }
+
     QuoteType quote() const { return m_quote; }
     void setQuote(QuoteType quote) { m_quote = quote; }
 
@@ -173,12 +169,7 @@ public:
     }
 
 private:
-    QuoteContentData(QuoteType quote)
-        : m_quote(quote)
-    {
-    }
-
-    virtual PassOwnPtr<ContentData> cloneInternal() const { return create(quote()); }
+    virtual std::unique_ptr<ContentData> cloneInternal() const OVERRIDE { return std::make_unique<QuoteContentData>(quote()); }
 
     QuoteType m_quote;
 };
index 31eb307c109fcb9715422771cb932269c7fd107e..5e1ff7e4787ee30340da626aecc6e60cd0683b17 100644 (file)
@@ -922,17 +922,17 @@ void RenderStyle::clearContent()
         rareNonInheritedData.access()->m_content = nullptr;
 }
 
-void RenderStyle::appendContent(PassOwnPtr<ContentData> contentData)
+void RenderStyle::appendContent(std::unique_ptr<ContentData> contentData)
 {
-    OwnPtr<ContentData>& content = rareNonInheritedData.access()->m_content;
+    auto& content = rareNonInheritedData.access()->m_content;
     ContentData* lastContent = content.get();
     while (lastContent && lastContent->next())
         lastContent = lastContent->next();
 
     if (lastContent)
-        lastContent->setNext(contentData);
+        lastContent->setNext(std::move(contentData));
     else
-        content = contentData;
+        content = std::move(contentData);
 }
 
 void RenderStyle::setContent(PassRefPtr<StyleImage> image, bool add)
@@ -941,16 +941,16 @@ void RenderStyle::setContent(PassRefPtr<StyleImage> image, bool add)
         return;
         
     if (add) {
-        appendContent(ContentData::create(image));
+        appendContent(std::make_unique<ImageContentData>(image));
         return;
     }
 
-    rareNonInheritedData.access()->m_content = ContentData::create(image);
+    rareNonInheritedData.access()->m_content = std::make_unique<ImageContentData>(image);
 }
 
 void RenderStyle::setContent(const String& string, bool add)
 {
-    OwnPtr<ContentData>& content = rareNonInheritedData.access()->m_content;
+    auto& content = rareNonInheritedData.access()->m_content;
     if (add) {
         ContentData* lastContent = content.get();
         while (lastContent && lastContent->next())
@@ -962,36 +962,36 @@ void RenderStyle::setContent(const String& string, bool add)
                 TextContentData* textContent = static_cast<TextContentData*>(lastContent);
                 textContent->setText(textContent->text() + string);
             } else
-                lastContent->setNext(ContentData::create(string));
+                lastContent->setNext(std::make_unique<TextContentData>(string));
 
             return;
         }
     }
 
-    content = ContentData::create(string);
+    content = std::make_unique<TextContentData>(string);
 }
 
-void RenderStyle::setContent(PassOwnPtr<CounterContent> counter, bool add)
+void RenderStyle::setContent(std::unique_ptr<CounterContent> counter, bool add)
 {
     if (!counter)
         return;
 
     if (add) {
-        appendContent(ContentData::create(counter));
+        appendContent(std::make_unique<CounterContentData>(std::move(counter)));
         return;
     }
 
-    rareNonInheritedData.access()->m_content = ContentData::create(counter);
+    rareNonInheritedData.access()->m_content = std::make_unique<CounterContentData>(std::move(counter));
 }
 
 void RenderStyle::setContent(QuoteType quote, bool add)
 {
     if (add) {
-        appendContent(ContentData::create(quote));
+        appendContent(std::make_unique<QuoteContentData>(quote));
         return;
     }
 
-    rareNonInheritedData.access()->m_content = ContentData::create(quote);
+    rareNonInheritedData.access()->m_content = std::make_unique<QuoteContentData>(quote);
 }
     
 inline bool requireTransformOrigin(const Vector<RefPtr<TransformOperation> >& transformOperations, RenderStyle::ApplyTransformOrigin applyOrigin)
index d1aa5a85761bc88e43a81fd94a18cfacf7c2dca4..22c5368e25f6a51084c9de57f0c959bbaad355e3 100644 (file)
@@ -1554,7 +1554,7 @@ public:
     void clearContent();
     void setContent(const String&, bool add = false);
     void setContent(PassRefPtr<StyleImage>, bool add = false);
-    void setContent(PassOwnPtr<CounterContent>, bool add = false);
+    void setContent(std::unique_ptr<CounterContent>, bool add = false);
     void setContent(QuoteType, bool add = false);
 
     const CounterDirectiveMap* counterDirectives() const;
@@ -1900,7 +1900,7 @@ private:
     Color lightingColor() const { return svgStyle()->lightingColor(); }
 #endif
 
-    void appendContent(PassOwnPtr<ContentData>);
+    void appendContent(std::unique_ptr<ContentData>);
 };
 
 inline int adjustForAbsoluteZoom(int value, const RenderStyle* style)
index f426e31d28666455945b0401bd3de1a8a0fed296..42475524e40026526c6e72e14f231d5bf1448f02 100644 (file)
@@ -123,7 +123,7 @@ public:
     DataRef<StyleGridData> m_grid;
     DataRef<StyleGridItemData> m_gridItem;
 
-    OwnPtr<ContentData> m_content;
+    std::unique_ptr<ContentData> m_content;
     OwnPtr<CounterDirectiveMap> m_counterDirectives;
 
     OwnPtr<ShadowData> m_boxShadow;  // For box-shadow decorations.