Title: [88270] trunk/Source/WebCore
Revision
88270
Author
[email protected]
Date
2011-06-07 15:14:39 -0700 (Tue, 07 Jun 2011)

Log Message

2011-06-07  Simon Fraser  <[email protected]>

        Reviewed by Dave Hyatt.

        Clean up ContentData
        https://bugs.webkit.org/show_bug.cgi?id=62185

        ContentData did manual ref()/deref() and had a lot of awkward
        code from using a union to store data.

        Clean this up by adding ContentData subclasses for different
        content types, which are then able to use RefPtr and OwnPtr
        as appropriate.

        * css/CSSComputedStyleDeclaration.cpp:
        (WebCore::contentToCSSValue): Cast to different ContentData types as
        appropriate.

        * css/CSSStyleSelector.cpp:
        (WebCore::CSSStyleSelector::loadPendingImages): Cast to ImageContentData, and do some
        const gyrations.

        * html/HTMLBRElement.cpp:
        (WebCore::HTMLBRElement::createRenderer): Use hasContent().
        * html/HTMLFrameSetElement.cpp:
        (WebCore::HTMLFrameSetElement::createRenderer): Ditto
        * html/HTMLImageElement.cpp:
        (WebCore::HTMLImageElement::createRenderer): Ditto
        * rendering/RenderObject.cpp:
        (WebCore::RenderObject::createObject): Cast to ImageContentData.
        * rendering/RenderObjectChildList.cpp:
        (WebCore::RenderObjectChildList::updateBeforeAfterContent): Cast to different ContentData types as
        appropriate.

        * rendering/style/ContentData.h:
        (WebCore::ContentData::~ContentData):
        (WebCore::ContentData::isCounter):
        (WebCore::ContentData::isImage):
        (WebCore::ContentData::isQuote):
        (WebCore::ContentData::isText):
        (WebCore::ContentData::next):
        (WebCore::ContentData::setNext):
        (WebCore::ImageContentData::image):
        (WebCore::ImageContentData::setImage):
        (WebCore::ImageContentData::ImageContentData):
        (WebCore::ImageContentData::type):
        (WebCore::ImageContentData::isImage):
        (WebCore::TextContentData::text):
        (WebCore::TextContentData::setText):
        (WebCore::TextContentData::TextContentData):
        (WebCore::TextContentData::type):
        (WebCore::TextContentData::isText):
        (WebCore::CounterContentData::counter):
        (WebCore::CounterContentData::setCounter):
        (WebCore::CounterContentData::CounterContentData):
        (WebCore::CounterContentData::type):
        (WebCore::CounterContentData::isCounter):
        (WebCore::QuoteContentData::quote):
        (WebCore::QuoteContentData::setQuote):
        (WebCore::QuoteContentData::QuoteContentData):
        (WebCore::QuoteContentData::type):
        (WebCore::QuoteContentData::isQuote):
        Add subclasses for different content types, which are created
        via overloaded create() methods on the base class.

        * rendering/style/ContentData.cpp:
        (WebCore::ContentData::create):
        (WebCore::operator==): Test for type equality, followed by comparing data.
        (WebCore::operator!=):

        * rendering/style/RenderStyle.cpp:
        (WebCore::RenderStyle::clearContent):
        (WebCore::RenderStyle::appendContent):
        (WebCore::RenderStyle::setContent): Replace the overly complex prepareToSetContent()
        code with code that either appends, or replaces the content.
        This loses an optimization where the existing ContentData object could get reused,
        but this seems to be rarely hit in practice.
        * rendering/style/RenderStyle.h:
        (WebCore::InheritedFlags::hasContent): Convenience method.
        * rendering/style/StyleRareNonInheritedData.cpp:
        (WebCore::StyleRareNonInheritedData::contentDataEquivalent): Test
        that the pointers are non-null, then use the != operator.
        * rendering/style/StyleRareNonInheritedData.h: ContentData is a class now.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (88269 => 88270)


--- trunk/Source/WebCore/ChangeLog	2011-06-07 22:01:06 UTC (rev 88269)
+++ trunk/Source/WebCore/ChangeLog	2011-06-07 22:14:39 UTC (rev 88270)
@@ -1,3 +1,87 @@
+2011-06-07  Simon Fraser  <[email protected]>
+
+        Reviewed by Dave Hyatt.
+
+        Clean up ContentData
+        https://bugs.webkit.org/show_bug.cgi?id=62185
+
+        ContentData did manual ref()/deref() and had a lot of awkward
+        code from using a union to store data.
+        
+        Clean this up by adding ContentData subclasses for different
+        content types, which are then able to use RefPtr and OwnPtr
+        as appropriate.
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::contentToCSSValue): Cast to different ContentData types as
+        appropriate.
+
+        * css/CSSStyleSelector.cpp: 
+        (WebCore::CSSStyleSelector::loadPendingImages): Cast to ImageContentData, and do some
+        const gyrations.
+
+        * html/HTMLBRElement.cpp:
+        (WebCore::HTMLBRElement::createRenderer): Use hasContent().
+        * html/HTMLFrameSetElement.cpp:
+        (WebCore::HTMLFrameSetElement::createRenderer): Ditto
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::createRenderer): Ditto
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::createObject): Cast to ImageContentData.
+        * rendering/RenderObjectChildList.cpp:
+        (WebCore::RenderObjectChildList::updateBeforeAfterContent): Cast to different ContentData types as
+        appropriate.
+
+        * rendering/style/ContentData.h:
+        (WebCore::ContentData::~ContentData):
+        (WebCore::ContentData::isCounter):
+        (WebCore::ContentData::isImage):
+        (WebCore::ContentData::isQuote):
+        (WebCore::ContentData::isText):
+        (WebCore::ContentData::next):
+        (WebCore::ContentData::setNext):
+        (WebCore::ImageContentData::image):
+        (WebCore::ImageContentData::setImage):
+        (WebCore::ImageContentData::ImageContentData):
+        (WebCore::ImageContentData::type):
+        (WebCore::ImageContentData::isImage):
+        (WebCore::TextContentData::text):
+        (WebCore::TextContentData::setText):
+        (WebCore::TextContentData::TextContentData):
+        (WebCore::TextContentData::type):
+        (WebCore::TextContentData::isText):
+        (WebCore::CounterContentData::counter):
+        (WebCore::CounterContentData::setCounter):
+        (WebCore::CounterContentData::CounterContentData):
+        (WebCore::CounterContentData::type):
+        (WebCore::CounterContentData::isCounter):
+        (WebCore::QuoteContentData::quote):
+        (WebCore::QuoteContentData::setQuote):
+        (WebCore::QuoteContentData::QuoteContentData):
+        (WebCore::QuoteContentData::type):
+        (WebCore::QuoteContentData::isQuote):
+        Add subclasses for different content types, which are created
+        via overloaded create() methods on the base class.
+
+        * rendering/style/ContentData.cpp:
+        (WebCore::ContentData::create):
+        (WebCore::operator==): Test for type equality, followed by comparing data.
+        (WebCore::operator!=):
+
+        * rendering/style/RenderStyle.cpp:
+        (WebCore::RenderStyle::clearContent):
+        (WebCore::RenderStyle::appendContent): 
+        (WebCore::RenderStyle::setContent): Replace the overly complex prepareToSetContent()
+        code with code that either appends, or replaces the content.
+        This loses an optimization where the existing ContentData object could get reused,
+        but this seems to be rarely hit in practice.
+        * rendering/style/RenderStyle.h:
+        (WebCore::InheritedFlags::hasContent): Convenience method.
+        * rendering/style/StyleRareNonInheritedData.cpp:
+        (WebCore::StyleRareNonInheritedData::contentDataEquivalent): Test
+        that the pointers are non-null, then use the != operator.
+        * rendering/style/StyleRareNonInheritedData.h: ContentData is a class now.
+
 2011-06-07  Brian Weinstein  <[email protected]>
 
         Build fix after r88260.

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (88269 => 88270)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2011-06-07 22:01:06 UTC (rev 88269)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2011-06-07 22:14:39 UTC (rev 88270)
@@ -755,15 +755,15 @@
     RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
     for (const ContentData* contentData = style->contentData(); contentData; contentData = contentData->next()) {
         if (contentData->isCounter()) {
-            const CounterContent* counter = contentData->counter();
+            const CounterContent* counter = static_cast<const CounterContentData*>(contentData)->counter();
             ASSERT(counter);
             list->append(primitiveValueCache->createValue(counter->identifier(), CSSPrimitiveValue::CSS_COUNTER_NAME));
         } else if (contentData->isImage()) {
-            const StyleImage* image = contentData->image();
+            const StyleImage* image = static_cast<const ImageContentData*>(contentData)->image();
             ASSERT(image);
             list->append(image->cssValue());
         } else if (contentData->isText())
-            list->append(primitiveValueCache->createValue(contentData->text(), CSSPrimitiveValue::CSS_STRING));
+            list->append(primitiveValueCache->createValue(static_cast<const TextContentData*>(contentData)->text(), CSSPrimitiveValue::CSS_STRING));
     }
     return list.release();
 }

Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (88269 => 88270)


--- trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-06-07 22:01:06 UTC (rev 88269)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-06-07 22:14:39 UTC (rev 88270)
@@ -6775,10 +6775,13 @@
 
             case CSSPropertyContent: {
                 for (ContentData* contentData = const_cast<ContentData*>(m_style->contentData()); contentData; contentData = contentData->next()) {
-                    if (contentData->isImage() && contentData->image()->isPendingImage()) {
-                        CSSImageValue* imageValue = static_cast<StylePendingImage*>(contentData->image())->cssImageValue();
-                        if (StyleCachedImage* cachedImage = imageValue->cachedImage(cachedResourceLoader))
-                            contentData->setImage(cachedImage);
+                    if (contentData->isImage()) {
+                        const StyleImage* image = static_cast<ImageContentData*>(contentData)->image();
+                        if (image->isPendingImage()) {
+                            CSSImageValue* imageValue = static_cast<const StylePendingImage*>(image)->cssImageValue();
+                            if (StyleCachedImage* cachedImage = imageValue->cachedImage(cachedResourceLoader))
+                                static_cast<ImageContentData*>(contentData)->setImage(cachedImage);
+                        }
                     }
                 }
                 break;

Modified: trunk/Source/WebCore/html/HTMLBRElement.cpp (88269 => 88270)


--- trunk/Source/WebCore/html/HTMLBRElement.cpp	2011-06-07 22:01:06 UTC (rev 88269)
+++ trunk/Source/WebCore/html/HTMLBRElement.cpp	2011-06-07 22:14:39 UTC (rev 88270)
@@ -76,7 +76,7 @@
 
 RenderObject* HTMLBRElement::createRenderer(RenderArena* arena, RenderStyle* style)
 {
-     if (style->contentData())
+     if (style->hasContent())
         return RenderObject::createObject(this, style);
 
      return new (arena) RenderBR(this);

Modified: trunk/Source/WebCore/html/HTMLFrameSetElement.cpp (88269 => 88270)


--- trunk/Source/WebCore/html/HTMLFrameSetElement.cpp	2011-06-07 22:01:06 UTC (rev 88269)
+++ trunk/Source/WebCore/html/HTMLFrameSetElement.cpp	2011-06-07 22:14:39 UTC (rev 88270)
@@ -157,7 +157,7 @@
 
 RenderObject *HTMLFrameSetElement::createRenderer(RenderArena *arena, RenderStyle *style)
 {
-    if (style->contentData())
+    if (style->hasContent())
         return RenderObject::createObject(this, style);
     
     return new (arena) RenderFrameSet(this);

Modified: trunk/Source/WebCore/html/HTMLImageElement.cpp (88269 => 88270)


--- trunk/Source/WebCore/html/HTMLImageElement.cpp	2011-06-07 22:01:06 UTC (rev 88269)
+++ trunk/Source/WebCore/html/HTMLImageElement.cpp	2011-06-07 22:14:39 UTC (rev 88270)
@@ -180,7 +180,7 @@
 
 RenderObject* HTMLImageElement::createRenderer(RenderArena* arena, RenderStyle* style)
 {
-    if (style->contentData())
+    if (style->hasContent())
         return RenderObject::createObject(this, style);
 
     RenderImage* image = new (arena) RenderImage(this);

Modified: trunk/Source/WebCore/rendering/RenderObject.cpp (88269 => 88270)


--- trunk/Source/WebCore/rendering/RenderObject.cpp	2011-06-07 22:01:06 UTC (rev 88269)
+++ trunk/Source/WebCore/rendering/RenderObject.cpp	2011-06-07 22:14:39 UTC (rev 88270)
@@ -109,8 +109,8 @@
     if (contentData && !contentData->next() && contentData->isImage() && doc != node) {
         RenderImage* image = new (arena) RenderImage(node);
         image->setStyle(style);
-        if (StyleImage* styleImage = contentData->image())
-            image->setImageResource(RenderImageResourceStyleImage::create(styleImage));
+        if (const StyleImage* styleImage = static_cast<const ImageContentData*>(contentData)->image())
+            image->setImageResource(RenderImageResourceStyleImage::create(const_cast<StyleImage*>(styleImage)));
         else
             image->setImageResource(RenderImageResource::create());
         return image;

Modified: trunk/Source/WebCore/rendering/RenderObjectChildList.cpp (88269 => 88270)


--- trunk/Source/WebCore/rendering/RenderObjectChildList.cpp	2011-06-07 22:01:06 UTC (rev 88269)
+++ trunk/Source/WebCore/rendering/RenderObjectChildList.cpp	2011-06-07 22:14:39 UTC (rev 88270)
@@ -422,7 +422,7 @@
             case CONTENT_NONE:
                 break;
             case CONTENT_TEXT:
-                renderer = new (owner->renderArena()) RenderTextFragment(owner->document() /* anonymous object */, content->text());
+                renderer = new (owner->renderArena()) RenderTextFragment(owner->document() /* anonymous object */, static_cast<const TextContentData*>(content)->text().impl());
                 renderer->setStyle(pseudoElementStyle);
                 break;
             case CONTENT_OBJECT: {
@@ -430,19 +430,19 @@
                 RefPtr<RenderStyle> style = RenderStyle::create();
                 style->inheritFrom(pseudoElementStyle);
                 image->setStyle(style.release());
-                if (StyleImage* styleImage = content->image())
-                    image->setImageResource(RenderImageResourceStyleImage::create(styleImage));
+                if (const StyleImage* styleImage = static_cast<const ImageContentData*>(content)->image())
+                    image->setImageResource(RenderImageResourceStyleImage::create(const_cast<StyleImage*>(styleImage)));
                 else
                     image->setImageResource(RenderImageResource::create());
                 renderer = image;
                 break;
             }
         case CONTENT_COUNTER:
-            renderer = new (owner->renderArena()) RenderCounter(owner->document(), *content->counter());
+            renderer = new (owner->renderArena()) RenderCounter(owner->document(), *static_cast<const CounterContentData*>(content)->counter());
             renderer->setStyle(pseudoElementStyle);
             break;
         case CONTENT_QUOTE:
-            renderer = new (owner->renderArena()) RenderQuote(owner->document(), content->quote());
+            renderer = new (owner->renderArena()) RenderQuote(owner->document(), static_cast<const QuoteContentData*>(content)->quote());
             renderer->setStyle(pseudoElementStyle);
             break;
         }

Modified: trunk/Source/WebCore/rendering/style/ContentData.cpp (88269 => 88270)


--- trunk/Source/WebCore/rendering/style/ContentData.cpp	2011-06-07 22:01:06 UTC (rev 88269)
+++ trunk/Source/WebCore/rendering/style/ContentData.cpp	2011-06-07 22:14:39 UTC (rev 88270)
@@ -23,61 +23,53 @@
 #include "ContentData.h"
 
 #include "StyleImage.h"
-#include <wtf/text/StringImpl.h>
 
 namespace WebCore {
 
-void ContentData::clear()
+PassOwnPtr<ContentData> ContentData::create(PassRefPtr<StyleImage> image)
 {
-    deleteContent();
+    return adoptPtr(new ImageContentData(image));
+}
 
-    // Delete the singly-linked list without recursing.
-    for (OwnPtr<ContentData> next = m_next.release(); next; next = next->m_next.release()) { }
+PassOwnPtr<ContentData> ContentData::create(const String& text)
+{
+    return adoptPtr(new TextContentData(text));
 }
 
-// FIXME: Why isn't this just operator==?
-// FIXME: This is not a good name for a boolean-returning function.
-bool ContentData::dataEquivalent(const ContentData& other) const
+PassOwnPtr<ContentData> ContentData::create(PassOwnPtr<CounterContent> counter)
 {
-    if (type() != other.type())
+    return adoptPtr(new CounterContentData(counter));
+}
+
+PassOwnPtr<ContentData> ContentData::create(QuoteType quote)
+{
+    return adoptPtr(new QuoteContentData(quote));
+}
+
+bool operator==(const ContentData& a, const ContentData& b)
+{
+    if (a.type() != b.type())
         return false;
 
-    switch (type()) {
+    switch (a.type()) {
     case CONTENT_NONE:
         return true;
-    case CONTENT_TEXT:
-        return equal(text(), other.text());
     case CONTENT_OBJECT:
-        return StyleImage::imagesEquivalent(image(), other.image());
+        return static_cast<const ImageContentData*>(&a)->image() == static_cast<const ImageContentData*>(&b)->image();
+    case CONTENT_TEXT:
+        return static_cast<const TextContentData*>(&a)->text() == static_cast<const TextContentData*>(&b)->text();
     case CONTENT_COUNTER:
-        return *counter() == *other.counter();
+        return static_cast<const CounterContentData*>(&a)->counter() == static_cast<const CounterContentData*>(&b)->counter();
     case CONTENT_QUOTE:
-        return quote() == other.quote();
+        return static_cast<const QuoteContentData*>(&a)->quote() == static_cast<const QuoteContentData*>(&b)->quote();
     }
-
     ASSERT_NOT_REACHED();
     return false;
 }
 
-void ContentData::deleteContent()
+bool operator!=(const ContentData& a, const ContentData& b)
 {
-    switch (m_type) {
-    case CONTENT_NONE:
-        break;
-    case CONTENT_OBJECT:
-        m_content.m_image->deref();
-        break;
-    case CONTENT_TEXT:
-        m_content.m_text->deref();
-        break;
-    case CONTENT_COUNTER:
-        delete m_content.m_counter;
-        break;
-    case CONTENT_QUOTE:
-        break;
-    }
-
-    m_type = CONTENT_NONE;
+    return !(a == b);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/rendering/style/ContentData.h (88269 => 88270)


--- trunk/Source/WebCore/rendering/style/ContentData.h	2011-06-07 22:01:06 UTC (rev 88269)
+++ trunk/Source/WebCore/rendering/style/ContentData.h	2011-06-07 22:14:39 UTC (rev 88270)
@@ -33,93 +33,104 @@
 
 class StyleImage;
 
-struct ContentData {
-    WTF_MAKE_NONCOPYABLE(ContentData); WTF_MAKE_FAST_ALLOCATED;
+class ContentData {
+    WTF_MAKE_FAST_ALLOCATED;
 public:
-    ContentData()
-        : m_type(CONTENT_NONE)
-    {
-    }
+    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() { }
 
-    ~ContentData()
-    {
-        clear();
-    }
+    virtual bool isCounter() const { return false; }
+    virtual bool isImage() const { return false; }
+    virtual bool isQuote() const { return false; }
+    virtual bool isText() const { return false; }
 
-    void clear();
+    virtual StyleContentType type() const = 0;
 
-    bool isCounter() const { return m_type == CONTENT_COUNTER; }
-    bool isImage() const { return m_type == CONTENT_OBJECT; }
-    bool isNone() const { return m_type == CONTENT_NONE; }
-    bool isQuote() const { return m_type == CONTENT_QUOTE; }
-    bool isText() const { return m_type == CONTENT_TEXT; }
+    friend bool operator==(const ContentData&, const ContentData&);
+    friend bool operator!=(const ContentData&, const ContentData&);
 
-    StyleContentType type() const { return m_type; }
+    ContentData* next() const { return m_next.get(); }
+    void setNext(PassOwnPtr<ContentData> next) { m_next = next; }
 
-    bool dataEquivalent(const ContentData&) const;
+private:
+    OwnPtr<ContentData> m_next;
+};
 
-    StyleImage* image() const
+class ImageContentData : public ContentData {
+    friend class ContentData;
+public:
+    const StyleImage* image() const { return m_image.get(); }
+    StyleImage* image() { return m_image.get(); }
+    void setImage(PassRefPtr<StyleImage> image) { m_image = image; }
+
+private:
+    ImageContentData(PassRefPtr<StyleImage> image)
+        : m_image(image)
     {
-        ASSERT(isImage());
-        return m_content.m_image;
     }
-    void setImage(PassRefPtr<StyleImage> image)
-    {
-        deleteContent();
-        m_type = CONTENT_OBJECT;
-        m_content.m_image = image.leakRef();
-    }
 
-    StringImpl* text() const
+    virtual StyleContentType type() const { return CONTENT_OBJECT; }
+    virtual bool isImage() const { return true; }
+
+    RefPtr<StyleImage> m_image;
+};
+
+class TextContentData : public ContentData {
+    friend class ContentData;
+public:
+    const String& text() const { return m_text; }
+    void setText(const String& text) { m_text = text; }
+
+private:
+    TextContentData(const String& text)
+        : m_text(text)
     {
-        ASSERT(isText());
-        return m_content.m_text;
     }
-    void setText(PassRefPtr<StringImpl> text)
-    {
-        deleteContent();
-        m_type = CONTENT_TEXT;
-        m_content.m_text = text.leakRef();
-    }
 
-    CounterContent* counter() const
+    virtual StyleContentType type() const { return CONTENT_TEXT; }
+    virtual bool isText() const { return true; }
+
+    String m_text;
+};
+
+class CounterContentData : public ContentData {
+    friend class ContentData;
+public:
+    const CounterContent* counter() const { return m_counter.get(); }
+    void setCounter(PassOwnPtr<CounterContent> counter) { m_counter = counter; }
+
+private:
+    CounterContentData(PassOwnPtr<CounterContent> counter)
+        : m_counter(counter)
     {
-        ASSERT(isCounter());
-        return m_content.m_counter;
     }
-    void setCounter(PassOwnPtr<CounterContent> counter)
-    {
-        deleteContent();
-        m_type = CONTENT_COUNTER;
-        m_content.m_counter = counter.leakPtr();
-    }
 
-    QuoteType quote() const
+    virtual StyleContentType type() const { return CONTENT_COUNTER; }
+    virtual bool isCounter() const { return true; }
+
+    OwnPtr<CounterContent> m_counter;
+};
+
+class QuoteContentData : public ContentData {
+    friend class ContentData;
+public:
+    QuoteType quote() const { return m_quote; }
+    void setQuote(QuoteType quote) { m_quote = quote; }
+
+private:
+    QuoteContentData(QuoteType quote)
+        : m_quote(quote)
     {
-        ASSERT(isQuote());
-        return m_content.m_quote;
     }
-    void setQuote(QuoteType type)
-    {
-        deleteContent();
-        m_type = CONTENT_QUOTE;
-        m_content.m_quote = type;
-    }
 
-    ContentData* next() const { return m_next.get(); }
-    void setNext(PassOwnPtr<ContentData> next) { m_next = next; }
+    virtual StyleContentType type() const { return CONTENT_QUOTE; }
+    virtual bool isQuote() const { return true; }
 
-private:
-    void deleteContent();
-
-    StyleContentType m_type;
-    union {
-        StyleImage* m_image;
-        StringImpl* m_text;
-        CounterContent* m_counter;
-        QuoteType m_quote;
-    } m_content;
-    OwnPtr<ContentData> m_next;
+    QuoteType m_quote;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.cpp (88269 => 88270)


--- trunk/Source/WebCore/rendering/style/RenderStyle.cpp	2011-06-07 22:01:06 UTC (rev 88269)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.cpp	2011-06-07 22:14:39 UTC (rev 88270)
@@ -620,67 +620,81 @@
 void RenderStyle::clearContent()
 {
     if (rareNonInheritedData->m_content)
-        rareNonInheritedData->m_content->clear();
+        rareNonInheritedData.access()->m_content = nullptr;
 }
 
-ContentData* RenderStyle::prepareToSetContent(StringImpl* string, bool add)
+void RenderStyle::appendContent(PassOwnPtr<ContentData> contentData)
 {
     OwnPtr<ContentData>& content = rareNonInheritedData.access()->m_content;
     ContentData* lastContent = content.get();
     while (lastContent && lastContent->next())
         lastContent = lastContent->next();
 
-    if (string && add && lastContent && lastContent->isText()) {
-        // Augment the existing string and share the existing ContentData node.
-        String newText = lastContent->text();
-        newText.append(string);
-        lastContent->setText(newText.impl());
-        return 0;
-    }
-
-    bool reuseContent = !add;
-    OwnPtr<ContentData> newContentData;
-    if (reuseContent && content) {
-        content->clear();
-        newContentData = content.release();
-    } else
-        newContentData = adoptPtr(new ContentData);
-
-    ContentData* result = newContentData.get();
-
-    if (lastContent && !reuseContent)
-        lastContent->setNext(newContentData.release());
+    if (lastContent)
+        lastContent->setNext(contentData);
     else
-        content = newContentData.release();
-
-    return result;
+        content = contentData;
 }
 
 void RenderStyle::setContent(PassRefPtr<StyleImage> image, bool add)
 {
     if (!image)
         return;
-    prepareToSetContent(0, add)->setImage(image);
+        
+    if (add) {
+        appendContent(ContentData::create(image));
+        return;
+    }
+
+    rareNonInheritedData.access()->m_content = ContentData::create(image);
 }
 
-void RenderStyle::setContent(PassRefPtr<StringImpl> string, bool add)
+void RenderStyle::setContent(const String& string, bool add)
 {
-    if (!string)
-        return;
-    if (ContentData* data = "" add))
-        data->setText(string);
+    OwnPtr<ContentData>& content = rareNonInheritedData.access()->m_content;
+    if (add) {
+        ContentData* lastContent = content.get();
+        while (lastContent && lastContent->next())
+            lastContent = lastContent->next();
+
+        if (lastContent) {
+            // We attempt to merge with the last ContentData if possible.
+            if (lastContent->isText()) {
+                TextContentData* textContent = static_cast<TextContentData*>(lastContent);
+                String text = textContent->text();
+                text += string;
+                textContent->setText(text);
+            } else
+                lastContent->setNext(ContentData::create(string));
+
+            return;
+        }
+    }
+
+    content = ContentData::create(string);
 }
 
 void RenderStyle::setContent(PassOwnPtr<CounterContent> counter, bool add)
 {
     if (!counter)
         return;
-    prepareToSetContent(0, add)->setCounter(counter);
+
+    if (add) {
+        appendContent(ContentData::create(counter));
+        return;
+    }
+
+    rareNonInheritedData.access()->m_content = ContentData::create(counter);
 }
 
 void RenderStyle::setContent(QuoteType quote, bool add)
 {
-    prepareToSetContent(0, add)->setQuote(quote);
+    if (add) {
+        appendContent(ContentData::create(quote));
+        return;
+    }
+
+    rareNonInheritedData.access()->m_content = ContentData::create(quote);
 }
 
 void RenderStyle::applyTransform(TransformationMatrix& transform, const IntSize& borderBoxSize, ApplyTransformOrigin applyOrigin) const

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.h (88269 => 88270)


--- trunk/Source/WebCore/rendering/style/RenderStyle.h	2011-06-07 22:01:06 UTC (rev 88269)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.h	2011-06-07 22:14:39 UTC (rev 88270)
@@ -101,7 +101,7 @@
 class StyleImage;
 class TransformationMatrix;
 
-struct ContentData;
+class ContentData;
 
 typedef Vector<RefPtr<RenderStyle>, 4> PseudoStyleCache;
 
@@ -1145,10 +1145,11 @@
     void setFloodOpacity(float f) { accessSVGStyle()->setFloodOpacity(f); }
 #endif
 
+    bool hasContent() const { return contentData(); }
     const ContentData* contentData() const { return rareNonInheritedData->m_content.get(); }
     bool contentDataEquivalent(const RenderStyle* otherStyle) const { return const_cast<RenderStyle*>(this)->rareNonInheritedData->contentDataEquivalent(*const_cast<RenderStyle*>(otherStyle)->rareNonInheritedData); }
     void clearContent();
-    void setContent(PassRefPtr<StringImpl>, bool add = false);
+    void setContent(const String&, bool add = false);
     void setContent(PassRefPtr<StyleImage>, bool add = false);
     void setContent(PassOwnPtr<CounterContent>, bool add = false);
     void setContent(QuoteType, bool add = false);
@@ -1358,9 +1359,9 @@
     const Color& textFillColor() const { return rareInheritedData->textFillColor; }
     const Color& textStrokeColor() const { return rareInheritedData->textStrokeColor; }
     
-    const Color colorIncludingFallback(int colorProperty, EBorderStyle borderStyle) const;
+    const Color colorIncludingFallback(int colorProperty, EBorderStyle) const;
 
-    ContentData* prepareToSetContent(StringImpl*, bool add);
+    void appendContent(PassOwnPtr<ContentData>);
 };
 
 inline int adjustForAbsoluteZoom(int value, const RenderStyle* style)

Modified: trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp (88269 => 88270)


--- trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp	2011-06-07 22:01:06 UTC (rev 88269)
+++ trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp	2011-06-07 22:14:39 UTC (rev 88270)
@@ -143,17 +143,11 @@
 
 bool StyleRareNonInheritedData::contentDataEquivalent(const StyleRareNonInheritedData& o) const
 {
-    ContentData* c1 = m_content.get();
-    ContentData* c2 = o.m_content.get();
-
-    while (c1 && c2) {
-        if (!c1->dataEquivalent(*c2))
-            return false;
-        c1 = c1->next();
-        c2 = c2->next();
-    }
-
-    return !c1 && !c2;
+    if ((!m_content && o.m_content) || (m_content && !o.m_content))
+        return false;
+    if (m_content && o.m_content && (*m_content != *o.m_content))
+        return false;
+    return true;
 }
 
 bool StyleRareNonInheritedData::shadowDataEquivalent(const StyleRareNonInheritedData& o) const

Modified: trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.h (88269 => 88270)


--- trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.h	2011-06-07 22:01:06 UTC (rev 88269)
+++ trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.h	2011-06-07 22:14:39 UTC (rev 88270)
@@ -47,7 +47,7 @@
 class StyleReflection;
 class StyleTransformData;
 
-struct ContentData;
+class ContentData;
 struct LengthSize;
 
 #if ENABLE(DASHBOARD_SUPPORT)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to