Title: [174801] trunk/Source/WebCore
Revision
174801
Author
[email protected]
Date
2014-10-16 17:35:59 -0700 (Thu, 16 Oct 2014)

Log Message

Use is<>() / downcast<>() for ContentData subclasses
https://bugs.webkit.org/show_bug.cgi?id=137768

Reviewed by Andreas Kling.

Use is<>() / downcast<>() for ContentData subclasses.

No new tests, no behavior change.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::contentToCSSValue):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::loadPendingImages):
* rendering/RenderElement.cpp:
(WebCore::RenderElement::createFor):
* rendering/style/ContentData.h:
(WebCore::operator==):
* rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::setContent):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (174800 => 174801)


--- trunk/Source/WebCore/ChangeLog	2014-10-16 23:55:59 UTC (rev 174800)
+++ trunk/Source/WebCore/ChangeLog	2014-10-17 00:35:59 UTC (rev 174801)
@@ -1,3 +1,25 @@
+2014-10-16  Chris Dumez  <[email protected]>
+
+        Use is<>() / downcast<>() for ContentData subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=137768
+
+        Reviewed by Andreas Kling.
+
+        Use is<>() / downcast<>() for ContentData subclasses.
+
+        No new tests, no behavior change.
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::contentToCSSValue):
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::loadPendingImages):
+        * rendering/RenderElement.cpp:
+        (WebCore::RenderElement::createFor):
+        * rendering/style/ContentData.h:
+        (WebCore::operator==):
+        * rendering/style/RenderStyle.cpp:
+        (WebCore::RenderStyle::setContent):
+
 2014-10-16  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r174744.

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (174800 => 174801)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2014-10-16 23:55:59 UTC (rev 174800)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2014-10-17 00:35:59 UTC (rev 174801)
@@ -1462,12 +1462,12 @@
 {
     auto list = CSSValueList::createSpaceSeparated();
     for (const ContentData* contentData = style->contentData(); contentData; contentData = contentData->next()) {
-        if (contentData->isCounter())
-            list.get().append(cssValuePool().createValue(toCounterContentData(contentData)->counter().identifier(), CSSPrimitiveValue::CSS_COUNTER_NAME));
-        else if (contentData->isImage())
-            list.get().append(*toImageContentData(contentData)->image().cssValue());
-        else if (contentData->isText())
-            list.get().append(cssValuePool().createValue(toTextContentData(contentData)->text(), CSSPrimitiveValue::CSS_STRING));
+        if (is<CounterContentData>(*contentData))
+            list.get().append(cssValuePool().createValue(downcast<CounterContentData>(*contentData).counter().identifier(), CSSPrimitiveValue::CSS_COUNTER_NAME));
+        else if (is<ImageContentData>(*contentData))
+            list.get().append(*downcast<ImageContentData>(*contentData).image().cssValue());
+        else if (is<TextContentData>(*contentData))
+            list.get().append(cssValuePool().createValue(downcast<TextContentData>(*contentData).text(), CSSPrimitiveValue::CSS_STRING));
     }
     if (style->hasFlowFrom())
         list.get().append(cssValuePool().createValue(style->regionThread(), CSSPrimitiveValue::CSS_STRING));

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (174800 => 174801)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2014-10-16 23:55:59 UTC (rev 174800)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2014-10-17 00:35:59 UTC (rev 174801)
@@ -3713,12 +3713,12 @@
         }
         case CSSPropertyContent: {
             for (ContentData* contentData = const_cast<ContentData*>(m_state.style()->contentData()); contentData; contentData = contentData->next()) {
-                if (contentData->isImage()) {
-                    auto& styleImage = toImageContentData(contentData)->image();
+                if (is<ImageContentData>(*contentData)) {
+                    auto& styleImage = downcast<ImageContentData>(*contentData).image();
                     if (styleImage.isPendingImage()) {
                         RefPtr<StyleImage> loadedImage = loadPendingImage(toStylePendingImage(styleImage));
                         if (loadedImage)
-                            toImageContentData(contentData)->setImage(loadedImage.release());
+                            downcast<ImageContentData>(*contentData).setImage(loadedImage.release());
                     }
                 }
             }

Modified: trunk/Source/WebCore/rendering/RenderElement.cpp (174800 => 174801)


--- trunk/Source/WebCore/rendering/RenderElement.cpp	2014-10-16 23:55:59 UTC (rev 174800)
+++ trunk/Source/WebCore/rendering/RenderElement.cpp	2014-10-17 00:35:59 UTC (rev 174801)
@@ -139,8 +139,8 @@
     // Works only if we have exactly one piece of content and it's a URL.
     // Otherwise acts as if we didn't support this feature.
     const ContentData* contentData = style.get().contentData();
-    if (contentData && !contentData->next() && contentData->isImage() && !element.isPseudoElement()) {
-        auto& styleImage = toImageContentData(contentData)->image();
+    if (contentData && !contentData->next() && is<ImageContentData>(*contentData) && !element.isPseudoElement()) {
+        auto& styleImage = downcast<ImageContentData>(*contentData).image();
         auto image = createRenderer<RenderImage>(element, WTF::move(style), const_cast<StyleImage*>(&styleImage));
         image->setIsGeneratedContent();
         return WTF::move(image);

Modified: trunk/Source/WebCore/rendering/style/ContentData.h (174800 => 174801)


--- trunk/Source/WebCore/rendering/style/ContentData.h	2014-10-16 23:55:59 UTC (rev 174800)
+++ trunk/Source/WebCore/rendering/style/ContentData.h	2014-10-17 00:35:59 UTC (rev 174801)
@@ -28,6 +28,7 @@
 #include "CounterContent.h"
 #include "StyleImage.h"
 #include "RenderPtr.h"
+#include <wtf/TypeCasts.h>
 
 namespace WebCore {
 
@@ -77,9 +78,6 @@
     Type m_type;
 };
 
-#define CONTENT_DATA_TYPE_CASTS(ToClassName, FromClassName, ContentDataName) \
-    TYPE_CASTS_BASE(ToClassName, FromClassName, resource, resource->is##ContentDataName(), resource.is##ContentDataName())
-
 class ImageContentData final : public ContentData {
 public:
     explicit ImageContentData(PassRefPtr<StyleImage> image)
@@ -107,8 +105,6 @@
     RefPtr<StyleImage> m_image;
 };
 
-CONTENT_DATA_TYPE_CASTS(ImageContentData, ContentData, Image)
-
 inline bool operator==(const ImageContentData& a, const ImageContentData& b)
 {
     return a.image() == b.image();
@@ -138,8 +134,6 @@
     String m_text;
 };
 
-CONTENT_DATA_TYPE_CASTS(TextContentData, ContentData, Text)
-
 inline bool operator==(const TextContentData& a, const TextContentData& b)
 {
     return a.text() == b.text();
@@ -178,8 +172,6 @@
     std::unique_ptr<CounterContent> m_counter;
 };
 
-CONTENT_DATA_TYPE_CASTS(CounterContentData, ContentData, Counter)
-
 inline bool operator==(const CounterContentData& a, const CounterContentData& b)
 {
     return a.counter() == b.counter();
@@ -209,8 +201,6 @@
     QuoteType m_quote;
 };
 
-CONTENT_DATA_TYPE_CASTS(QuoteContentData, ContentData, Quote)
-
 inline bool operator==(const QuoteContentData& a, const QuoteContentData& b)
 {
     return a.quote() == b.quote();
@@ -228,13 +218,13 @@
 
     switch (a.type()) {
     case ContentData::CounterDataType:
-        return toCounterContentData(a) == toCounterContentData(b);
+        return downcast<CounterContentData>(a) == downcast<CounterContentData>(b);
     case ContentData::ImageDataType:
-        return toImageContentData(a) == toImageContentData(b);
+        return downcast<ImageContentData>(a) == downcast<ImageContentData>(b);
     case ContentData::QuoteDataType:
-        return toQuoteContentData(a) == toQuoteContentData(b);
+        return downcast<QuoteContentData>(a) == downcast<QuoteContentData>(b);
     case ContentData::TextDataType:
-        return toTextContentData(a) == toTextContentData(b);
+        return downcast<TextContentData>(a) == downcast<TextContentData>(b);
     }
 
     ASSERT_NOT_REACHED();
@@ -248,4 +238,14 @@
 
 } // namespace WebCore
 
+#define SPECIALIZE_TYPE_TRAITS_CONTENT_DATA(ToClassName, ContentDataName) \
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToClassName) \
+    static bool isType(const WebCore::ContentData& contentData) { return contentData.is##ContentDataName(); } \
+SPECIALIZE_TYPE_TRAITS_END()
+
+SPECIALIZE_TYPE_TRAITS_CONTENT_DATA(ImageContentData, Image)
+SPECIALIZE_TYPE_TRAITS_CONTENT_DATA(TextContentData, Text)
+SPECIALIZE_TYPE_TRAITS_CONTENT_DATA(CounterContentData, Counter)
+SPECIALIZE_TYPE_TRAITS_CONTENT_DATA(QuoteContentData, Quote)
+
 #endif // ContentData_h

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.cpp (174800 => 174801)


--- trunk/Source/WebCore/rendering/style/RenderStyle.cpp	2014-10-16 23:55:59 UTC (rev 174800)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.cpp	2014-10-17 00:35:59 UTC (rev 174801)
@@ -904,9 +904,9 @@
 
         if (lastContent) {
             // We attempt to merge with the last ContentData if possible.
-            if (lastContent->isText()) {
-                TextContentData* textContent = toTextContentData(lastContent);
-                textContent->setText(textContent->text() + string);
+            if (is<TextContentData>(*lastContent)) {
+                TextContentData& textContent = downcast<TextContentData>(*lastContent);
+                textContent.setText(textContent.text() + string);
             } else
                 lastContent->setNext(std::make_unique<TextContentData>(string));
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to