Remove DEFINE_CONTENT_DATA_TYPE_CASTS use from content_data.h

The primary motivation of this CL is to replace
ToCounterContentData with To<CounterContentData>,
ToQuoteContentData with To<QuoteContentData>,
ToImageContentData with To<ImageContentData>,
ToTextContentData with To<TextContentData>.

This CL also ports other dependent files to refer to a new template
function name.

Bug: 891908
Change-Id: I0ace9d668a090a2d4ef9f90b57aa73b65227f15f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1533677
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Abhijeet Kandalkar <abhijeet@igalia.com>
Cr-Commit-Position: refs/heads/master@{#642904}
diff --git a/third_party/blink/renderer/core/css/properties/computed_style_utils.cc b/third_party/blink/renderer/core/css/properties/computed_style_utils.cc
index bc4cff1..160c1da 100644
--- a/third_party/blink/renderer/core/css/properties/computed_style_utils.cc
+++ b/third_party/blink/renderer/core/css/properties/computed_style_utils.cc
@@ -1728,7 +1728,7 @@
        content_data = content_data->Next()) {
     if (content_data->IsCounter()) {
       const CounterContent* counter =
-          ToCounterContentData(content_data)->Counter();
+          To<CounterContentData>(content_data)->Counter();
       DCHECK(counter);
       CSSCustomIdentValue* identifier =
           CSSCustomIdentValue::Create(counter->Identifier());
@@ -1744,14 +1744,14 @@
           CSSIdentifierValue::Create(list_style_ident);
       list->Append(*CSSCounterValue::Create(identifier, list_style, separator));
     } else if (content_data->IsImage()) {
-      const StyleImage* image = ToImageContentData(content_data)->GetImage();
+      const StyleImage* image = To<ImageContentData>(content_data)->GetImage();
       DCHECK(image);
       list->Append(*image->ComputedCSSValue());
     } else if (content_data->IsText()) {
-      list->Append(
-          *CSSStringValue::Create(ToTextContentData(content_data)->GetText()));
+      list->Append(*CSSStringValue::Create(
+          To<TextContentData>(content_data)->GetText()));
     } else if (content_data->IsQuote()) {
-      const QuoteType quote_type = ToQuoteContentData(content_data)->Quote();
+      const QuoteType quote_type = To<QuoteContentData>(content_data)->Quote();
       list->Append(*CSSIdentifierValue::Create(ValueForQuoteType(quote_type)));
     } else {
       NOTREACHED();
diff --git a/third_party/blink/renderer/core/css/properties/longhands/content_custom.cc b/third_party/blink/renderer/core/css/properties/longhands/content_custom.cc
index 0da8b1d..20e1d57 100644
--- a/third_party/blink/renderer/core/css/properties/longhands/content_custom.cc
+++ b/third_party/blink/renderer/core/css/properties/longhands/content_custom.cc
@@ -195,7 +195,7 @@
         string = To<CSSStringValue>(*item).Value();
       }
       if (prev_content && prev_content->IsText()) {
-        TextContentData* text_content = ToTextContentData(prev_content);
+        TextContentData* text_content = To<TextContentData>(prev_content);
         text_content->SetText(text_content->GetText() + string);
         continue;
       }
diff --git a/third_party/blink/renderer/core/css/resolver/element_style_resources.cc b/third_party/blink/renderer/core/css/resolver/element_style_resources.cc
index 5b3cb0b..270e9c7 100644
--- a/third_party/blink/renderer/core/css/resolver/element_style_resources.cc
+++ b/third_party/blink/renderer/core/css/resolver/element_style_resources.cc
@@ -230,9 +230,9 @@
                  const_cast<ContentData*>(style->GetContentData());
              content_data; content_data = content_data->Next()) {
           if (content_data->IsImage()) {
-            StyleImage* image = ToImageContentData(content_data)->GetImage();
+            StyleImage* image = To<ImageContentData>(content_data)->GetImage();
             if (image->IsPendingImage()) {
-              ToImageContentData(content_data)
+              To<ImageContentData>(content_data)
                   ->SetImage(
                       LoadPendingImage(style, To<StylePendingImage>(image),
                                        FetchParameters::kAllowPlaceholder));
diff --git a/third_party/blink/renderer/core/html/html_image_element.cc b/third_party/blink/renderer/core/html/html_image_element.cc
index af20ff6..15c1a9b 100644
--- a/third_party/blink/renderer/core/html/html_image_element.cc
+++ b/third_party/blink/renderer/core/html/html_image_element.cc
@@ -396,7 +396,7 @@
   const ContentData* content_data = style.GetContentData();
   if (content_data && content_data->IsImage()) {
     const StyleImage* content_image =
-        ToImageContentData(content_data)->GetImage();
+        To<ImageContentData>(content_data)->GetImage();
     bool error_occurred = content_image && content_image->CachedImage() &&
                           content_image->CachedImage()->ErrorOccurred();
     if (!error_occurred)
diff --git a/third_party/blink/renderer/core/layout/layout_object.cc b/third_party/blink/renderer/core/layout/layout_object.cc
index 3d88e8a..9d4a5de 100644
--- a/third_party/blink/renderer/core/layout/layout_object.cc
+++ b/third_party/blink/renderer/core/layout/layout_object.cc
@@ -225,7 +225,7 @@
     // should be run once at layoutObject creation.
     image->SetStyleInternal(const_cast<ComputedStyle*>(&style));
     if (const StyleImage* style_image =
-            ToImageContentData(content_data)->GetImage()) {
+            To<ImageContentData>(content_data)->GetImage()) {
       image->SetImageResource(LayoutImageResourceStyleImage::Create(
           const_cast<StyleImage*>(style_image)));
       image->SetIsGeneratedContent();
@@ -2210,12 +2210,12 @@
   StyleImage* old_content_image =
       old_style && old_style->GetContentData() &&
               old_style->GetContentData()->IsImage()
-          ? ToImageContentData(old_style->GetContentData())->GetImage()
+          ? To<ImageContentData>(old_style->GetContentData())->GetImage()
           : nullptr;
   StyleImage* new_content_image =
       new_style && new_style->GetContentData() &&
               new_style->GetContentData()->IsImage()
-          ? ToImageContentData(new_style->GetContentData())->GetImage()
+          ? To<ImageContentData>(new_style->GetContentData())->GetImage()
           : nullptr;
   UpdateImage(old_content_image, new_content_image);
 
diff --git a/third_party/blink/renderer/core/style/content_data.h b/third_party/blink/renderer/core/style/content_data.h
index b4e8924..1d113d2 100644
--- a/third_party/blink/renderer/core/style/content_data.h
+++ b/third_party/blink/renderer/core/style/content_data.h
@@ -31,6 +31,7 @@
 
 #include "third_party/blink/renderer/core/style/counter_content.h"
 #include "third_party/blink/renderer/core/style/style_image.h"
+#include "third_party/blink/renderer/platform/wtf/casting.h"
 
 namespace blink {
 
@@ -70,10 +71,6 @@
   Member<ContentData> next_;
 };
 
-#define DEFINE_CONTENT_DATA_TYPE_CASTS(typeName)                 \
-  DEFINE_TYPE_CASTS(typeName##ContentData, ContentData, content, \
-                    content->Is##typeName(), content.Is##typeName())
-
 class ImageContentData final : public ContentData {
   friend class ContentData;
 
@@ -109,7 +106,12 @@
   Member<StyleImage> image_;
 };
 
-DEFINE_CONTENT_DATA_TYPE_CASTS(Image);
+template <>
+struct DowncastTraits<ImageContentData> {
+  static bool AllowFrom(const ContentData& content) {
+    return content.IsImage();
+  }
+};
 
 class TextContentData final : public ContentData {
   friend class ContentData;
@@ -136,7 +138,10 @@
   String text_;
 };
 
-DEFINE_CONTENT_DATA_TYPE_CASTS(Text);
+template <>
+struct DowncastTraits<TextContentData> {
+  static bool AllowFrom(const ContentData& content) { return content.IsText(); }
+};
 
 class CounterContentData final : public ContentData {
   friend class ContentData;
@@ -171,7 +176,12 @@
   std::unique_ptr<CounterContent> counter_;
 };
 
-DEFINE_CONTENT_DATA_TYPE_CASTS(Counter);
+template <>
+struct DowncastTraits<CounterContentData> {
+  static bool AllowFrom(const ContentData& content) {
+    return content.IsCounter();
+  }
+};
 
 class QuoteContentData final : public ContentData {
   friend class ContentData;
@@ -198,7 +208,12 @@
   QuoteType quote_;
 };
 
-DEFINE_CONTENT_DATA_TYPE_CASTS(Quote);
+template <>
+struct DowncastTraits<QuoteContentData> {
+  static bool AllowFrom(const ContentData& content) {
+    return content.IsQuote();
+  }
+};
 
 inline bool operator==(const ContentData& a, const ContentData& b) {
   const ContentData* ptr_a = &a;