Remove remaining uses of NODE_TYPE_CASTS() from html/
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Sep 2014 17:16:32 +0000 (17:16 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Sep 2014 17:16:32 +0000 (17:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137172

Reviewed by Darin Adler.

Remove remaining uses of NODE_TYPE_CASTS() from html/ and use the new
SPECIALIZE_TYPE_TRAITS_*() macro instead so that is<>() / downcast<>()
works for those types.

No new tests, no behavior change.

* css/SelectorCheckerTestFunctions.h:
(WebCore::matchesLangPseudoClass):
(WebCore::matchesFutureCuePseudoClass):
(WebCore::matchesPastCuePseudoClass):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::canShareStyleWithElement):
The new casting function found a bad cast from a StyledElement to VTTElement.
Those two types are unrelated as VTTElement inherits directly from Element.
Knowing that |element| in this method cannot be a VTTElement simplifies the
logic a bit.

* dom/NodeRenderingTraversal.cpp:
(WebCore::NodeRenderingTraversal::findFirstEnteringInsertionPoints):
(WebCore::NodeRenderingTraversal::findLastEnteringInsertionPoints):
(WebCore::NodeRenderingTraversal::traverseParent):
* html/HTMLLabelElement.cpp:
(WebCore::nodeAsSupportedLabelableElement):
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::innerTextElement):
* html/LabelableElement.h:
(WebCore::isLabelableElement):
* html/shadow/ContentDistributor.cpp:
(WebCore::ContentDistributor::ensureInsertionPointList):
* html/shadow/InsertionPoint.h:
(WebCore::isInsertionPoint):
(WebCore::isActiveInsertionPoint):
(WebCore::parentNodeForDistribution):
* html/shadow/TextControlInnerElements.h:
(WebCore::isTextControlInnerTextElement):
* html/track/VTTCue.cpp:
(WebCore::VTTCue::copyWebVTTNodeToDOMTree):
(WebCore::VTTCue::markFutureAndPastNodes):
* html/track/WebVTTElement.h:
(WebCore::isWebVTTElement):
* html/track/WebVTTParser.cpp:
(WebCore::WebVTTTreeBuilder::constructTreeFromToken):
* style/StyleResolveTree.cpp:
(WebCore::Style::attachRenderTree):
(WebCore::Style::detachChildren):

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

14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/css/SelectorCheckerTestFunctions.h
Source/WebCore/css/StyleResolver.cpp
Source/WebCore/dom/NodeRenderingTraversal.cpp
Source/WebCore/html/HTMLLabelElement.cpp
Source/WebCore/html/HTMLTextAreaElement.cpp
Source/WebCore/html/LabelableElement.h
Source/WebCore/html/shadow/ContentDistributor.cpp
Source/WebCore/html/shadow/InsertionPoint.h
Source/WebCore/html/shadow/TextControlInnerElements.h
Source/WebCore/html/track/VTTCue.cpp
Source/WebCore/html/track/WebVTTElement.h
Source/WebCore/html/track/WebVTTParser.cpp
Source/WebCore/style/StyleResolveTree.cpp

index 999e3c8..a68e6a4 100644 (file)
@@ -1,5 +1,58 @@
 2014-09-29  Christophe Dumez  <cdumez@apple.com>
 
+        Remove remaining uses of NODE_TYPE_CASTS() from html/
+        https://bugs.webkit.org/show_bug.cgi?id=137172
+
+        Reviewed by Darin Adler.
+
+        Remove remaining uses of NODE_TYPE_CASTS() from html/ and use the new
+        SPECIALIZE_TYPE_TRAITS_*() macro instead so that is<>() / downcast<>()
+        works for those types.
+
+        No new tests, no behavior change.
+
+        * css/SelectorCheckerTestFunctions.h:
+        (WebCore::matchesLangPseudoClass):
+        (WebCore::matchesFutureCuePseudoClass):
+        (WebCore::matchesPastCuePseudoClass):
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::canShareStyleWithElement):
+        The new casting function found a bad cast from a StyledElement to VTTElement.
+        Those two types are unrelated as VTTElement inherits directly from Element.
+        Knowing that |element| in this method cannot be a VTTElement simplifies the
+        logic a bit.
+
+        * dom/NodeRenderingTraversal.cpp:
+        (WebCore::NodeRenderingTraversal::findFirstEnteringInsertionPoints):
+        (WebCore::NodeRenderingTraversal::findLastEnteringInsertionPoints):
+        (WebCore::NodeRenderingTraversal::traverseParent):
+        * html/HTMLLabelElement.cpp:
+        (WebCore::nodeAsSupportedLabelableElement):
+        * html/HTMLTextAreaElement.cpp:
+        (WebCore::HTMLTextAreaElement::innerTextElement):
+        * html/LabelableElement.h:
+        (WebCore::isLabelableElement):
+        * html/shadow/ContentDistributor.cpp:
+        (WebCore::ContentDistributor::ensureInsertionPointList):
+        * html/shadow/InsertionPoint.h:
+        (WebCore::isInsertionPoint):
+        (WebCore::isActiveInsertionPoint):
+        (WebCore::parentNodeForDistribution):
+        * html/shadow/TextControlInnerElements.h:
+        (WebCore::isTextControlInnerTextElement):
+        * html/track/VTTCue.cpp:
+        (WebCore::VTTCue::copyWebVTTNodeToDOMTree):
+        (WebCore::VTTCue::markFutureAndPastNodes):
+        * html/track/WebVTTElement.h:
+        (WebCore::isWebVTTElement):
+        * html/track/WebVTTParser.cpp:
+        (WebCore::WebVTTTreeBuilder::constructTreeFromToken):
+        * style/StyleResolveTree.cpp:
+        (WebCore::Style::attachRenderTree):
+        (WebCore::Style::detachChildren):
+
+2014-09-29  Christophe Dumez  <cdumez@apple.com>
+
         Make is<>() / downcast<>() work for HTMLDocument and its subclasses
         https://bugs.webkit.org/show_bug.cgi?id=137169
 
index 1c64194..6f418c3 100644 (file)
@@ -127,8 +127,8 @@ inline bool matchesLangPseudoClass(const Element* element, AtomicStringImpl* fil
 {
     AtomicString value;
 #if ENABLE(VIDEO_TRACK)
-    if (element->isWebVTTElement())
-        value = toWebVTTElement(element)->language();
+    if (is<WebVTTElement>(element))
+        value = downcast<WebVTTElement>(*element).language();
     else
 #endif
         value = element->computeInheritedLanguage();
@@ -304,12 +304,12 @@ ALWAYS_INLINE bool matchesFullScreenDocumentPseudoClass(const Element* element)
 #if ENABLE(VIDEO_TRACK)
 ALWAYS_INLINE bool matchesFutureCuePseudoClass(const Element* element)
 {
-    return (element->isWebVTTElement() && !toWebVTTElement(element)->isPastNode());
+    return is<WebVTTElement>(element) && !downcast<WebVTTElement>(*element).isPastNode();
 }
 
 ALWAYS_INLINE bool matchesPastCuePseudoClass(const Element* element)
 {
-    return (element->isWebVTTElement() && toWebVTTElement(element)->isPastNode());
+    return is<WebVTTElement>(element) && downcast<WebVTTElement>(*element).isPastNode();
 }
 #endif
 
index 8fcb379..00fff0a 100644 (file)
@@ -650,10 +650,7 @@ bool StyleResolver::canShareStyleWithElement(StyledElement* element) const
 
 #if ENABLE(VIDEO_TRACK)
     // Deny sharing styles between WebVTT and non-WebVTT nodes.
-    if (element->isWebVTTElement() != state.element()->isWebVTTElement())
-        return false;
-
-    if (element->isWebVTTElement() && state.element()->isWebVTTElement() && toWebVTTElement(element)->isPastNode() != toWebVTTElement(state.element())->isPastNode())
+    if (is<WebVTTElement>(state.element()))
         return false;
 #endif
 
index 8a59782..86ef299 100644 (file)
@@ -72,8 +72,8 @@ static Node* findFirstEnteringInsertionPoints(const Node* node)
     ASSERT(node);
     if (!isActiveInsertionPoint(node))
         return const_cast<Node*>(node);
-    const InsertionPoint* insertionPoint = toInsertionPoint(node);
-    if (Node* found = findFirstFromDistributedNode(insertionPoint->firstDistributed(), insertionPoint))
+    const InsertionPoint& insertionPoint = downcast<InsertionPoint>(*node);
+    if (Node* found = findFirstFromDistributedNode(insertionPoint.firstDistributed(), &insertionPoint))
         return found;
     return findFirstSiblingEnteringInsertionPoints(node->firstChild());
 }
@@ -101,8 +101,8 @@ static Node* findLastEnteringInsertionPoints(const Node* node)
     ASSERT(node);
     if (!isActiveInsertionPoint(node))
         return const_cast<Node*>(node);
-    const InsertionPoint* insertionPoint = toInsertionPoint(node);
-    if (Node* found = findLastFromDistributedNode(insertionPoint->lastDistributed(), insertionPoint))
+    const InsertionPoint& insertionPoint = downcast<InsertionPoint>(*node);
+    if (Node* found = findLastFromDistributedNode(insertionPoint.lastDistributed(), &insertionPoint))
         return found;
     return findLastSiblingEnteringInsertionPoints(node->lastChild());
 }
@@ -135,11 +135,11 @@ static ContainerNode* traverseParent(const Node* node, ShadowRootCrossing shadow
     if (parent->isShadowRoot())
         return shadowRootCrossing == CrossShadowRoot ? toShadowRoot(parent)->hostElement() : parent;
 
-    if (parent->isInsertionPoint()) {
-        const InsertionPoint* insertionPoint = toInsertionPoint(parent);
-        if (insertionPoint->hasDistribution())
+    if (is<InsertionPoint>(parent)) {
+        const InsertionPoint& insertionPoint = downcast<InsertionPoint>(*parent);
+        if (insertionPoint.hasDistribution())
             return nullptr;
-        if (insertionPoint->isActive())
+        if (insertionPoint.isActive())
             return traverseParent(parent, shadowRootCrossing);
     }
     return parent;
index 4118985..125260f 100644 (file)
@@ -38,9 +38,9 @@ using namespace HTMLNames;
 
 static LabelableElement* nodeAsSupportedLabelableElement(Node* node)
 {
-    if (!node || !isLabelableElement(*node))
+    if (!node || !is<LabelableElement>(*node))
         return nullptr;
-    LabelableElement& element = toLabelableElement(*node);
+    LabelableElement& element = downcast<LabelableElement>(*node);
     return element.supportLabels() ? &element : nullptr;
 }
 
index ce3d8a9..2a4c5c5 100644 (file)
@@ -326,8 +326,7 @@ String HTMLTextAreaElement::sanitizeUserInputValue(const String& proposedValue,
 
 TextControlInnerTextElement* HTMLTextAreaElement::innerTextElement() const
 {
-    Node* node = userAgentShadowRoot()->firstChild();
-    return toTextControlInnerTextElement(node);
+    return downcast<TextControlInnerTextElement>(userAgentShadowRoot()->firstChild());
 }
 
 void HTMLTextAreaElement::rendererWillBeDestroyed()
index 40055c3..274c2ab 100644 (file)
@@ -50,16 +50,10 @@ private:
     virtual bool isLabelable() const override final { return true; }
 };
 
-void isLabelableElement(const LabelableElement&); // Catch unnecessary runtime check of type known at compile time.
-inline bool isLabelableElement(const HTMLElement& element) { return element.isLabelable(); }
-inline bool isLabelableElement(const Node& node) { return is<HTMLElement>(node) && downcast<HTMLElement>(node).isLabelable(); }
-
-template <typename ArgType>
-struct NodeTypeCastTraits<const LabelableElement, ArgType> {
-    static bool isType(ArgType& node) { return isLabelableElement(node); }
-};
-
-NODE_TYPE_CASTS(LabelableElement)
+SPECIALIZE_TYPE_TRAITS_BEGIN(LabelableElement)
+    static bool isLabelableElement(const HTMLElement& element) { return element.isLabelable(); }
+    static bool isLabelableElement(const Node& node) { return is<HTMLElement>(node) && isLabelableElement(downcast<HTMLElement>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 } // namespace WebCore
 
index c4c77a7..8e867e8 100644 (file)
@@ -56,10 +56,8 @@ const Vector<RefPtr<InsertionPoint>>& ContentDistributor::ensureInsertionPointLi
     m_insertionPointListIsValid = true;
     ASSERT(m_insertionPointList.isEmpty());
 
-    for (auto& element : descendantsOfType<Element>(*shadowRoot)) {
-        if (element.isInsertionPoint())
-            m_insertionPointList.append(toInsertionPoint(&element));
-    }
+    for (auto& element : descendantsOfType<InsertionPoint>(*shadowRoot))
+        m_insertionPointList.append(&element);
 
     return m_insertionPointList;
 }
index a4e6994..6e8b7cc 100644 (file)
@@ -75,13 +75,13 @@ private:
     bool m_hasDistribution;
 };
 
-inline bool isInsertionPoint(const Node& node) { return node.isInsertionPoint(); }
-
-NODE_TYPE_CASTS(InsertionPoint);
+SPECIALIZE_TYPE_TRAITS_BEGIN(InsertionPoint)
+    static bool isInsertionPoint(const Node& node) { return node.isInsertionPoint(); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 inline bool isActiveInsertionPoint(const Node* node)
 {
-    return node && node->isInsertionPoint() && toInsertionPoint(node)->isActive();
+    return node && is<InsertionPoint>(node) && downcast<InsertionPoint>(*node).isActive();
 }
 
 inline Node* parentNodeForDistribution(const Node* node)
@@ -89,12 +89,12 @@ inline Node* parentNodeForDistribution(const Node* node)
     ASSERT(node);
 
     if (Node* parent = node->parentNode()) {
-        if (parent->isInsertionPoint() && toInsertionPoint(parent)->shouldUseFallbackElements())
+        if (is<InsertionPoint>(parent) && downcast<InsertionPoint>(*parent).shouldUseFallbackElements())
             return parent->parentNode();
         return parent;
     }
 
-    return 0;
+    return nullptr;
 }
 
 inline Element* parentElementForDistribution(const Node* node)
index b2e8b39..bb7b032 100644 (file)
@@ -70,9 +70,10 @@ private:
     virtual bool isTextControlInnerTextElement() const override { return true; }
 };
 
-inline bool isTextControlInnerTextElement(const HTMLElement& element) { return element.isTextControlInnerTextElement(); }
-inline bool isTextControlInnerTextElement(const Node& node) { return is<HTMLElement>(node) && isTextControlInnerTextElement(downcast<HTMLElement>(node)); }
-NODE_TYPE_CASTS(TextControlInnerTextElement)
+SPECIALIZE_TYPE_TRAITS_BEGIN(TextControlInnerTextElement)
+    static bool isTextControlInnerTextElement(const HTMLElement& element) { return element.isTextControlInnerTextElement(); }
+    static bool isTextControlInnerTextElement(const Node& node) { return is<HTMLElement>(node) && isTextControlInnerTextElement(downcast<HTMLElement>(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 class SearchFieldResultsButtonElement final : public HTMLDivElement {
 public:
index 824c46e..ab1988f 100644 (file)
@@ -497,8 +497,8 @@ void VTTCue::copyWebVTTNodeToDOMTree(ContainerNode* webVTTNode, ContainerNode* p
 {
     for (Node* node = webVTTNode->firstChild(); node; node = node->nextSibling()) {
         RefPtr<Node> clonedNode;
-        if (node->isWebVTTElement())
-            clonedNode = toWebVTTElement(node)->createEquivalentHTMLElement(ownerDocument());
+        if (is<WebVTTElement>(node))
+            clonedNode = downcast<WebVTTElement>(*node).createEquivalentHTMLElement(ownerDocument());
         else
             clonedNode = node->cloneNode(false);
         parent->appendChild(clonedNode, ASSERT_NO_EXCEPTION);
@@ -766,8 +766,8 @@ void VTTCue::markFutureAndPastNodes(ContainerNode* root, const MediaTime& previo
                 isPastNode = false;
         }
         
-        if (child->isWebVTTElement()) {
-            toWebVTTElement(child)->setIsPastNode(isPastNode);
+        if (is<WebVTTElement>(child)) {
+            downcast<WebVTTElement>(*child).setIsPastNode(isPastNode);
             // Make an elemenet id match a cue id for style matching purposes.
             if (!id().isEmpty())
                 toElement(child)->setIdAttribute(id());
index 39406d9..3b3d911 100644 (file)
@@ -80,9 +80,9 @@ private:
     AtomicString m_language;
 };
 
-void isWebVTTElement(const WebVTTElement&); // Catch unnecessary runtime check of type known at compile time.
-inline bool isWebVTTElement(const Node& node) { return node.isWebVTTElement(); }
-NODE_TYPE_CASTS(WebVTTElement)
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebVTTElement)
+    static bool isWebVTTElement(const Node& node) { return node.isWebVTTElement(); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 } // namespace WebCore
 
index 7dbe8c3..7ff7565 100644 (file)
@@ -561,7 +561,7 @@ void WebVTTTreeBuilder::constructTreeFromToken(Document& document)
         if (nodeType == WebVTTNodeTypeNone)
             break;
 
-        WebVTTNodeType currentType = m_currentNode->isWebVTTElement() ? toWebVTTElement(m_currentNode.get())->webVTTNodeType() : WebVTTNodeTypeNone;
+        WebVTTNodeType currentType = is<WebVTTElement>(*m_currentNode) ? downcast<WebVTTElement>(*m_currentNode).webVTTNodeType() : WebVTTNodeTypeNone;
         // <rt> is only allowed if the current node is <ruby>.
         if (nodeType == WebVTTNodeTypeRubyText && currentType != WebVTTNodeTypeRuby)
             break;
@@ -589,10 +589,10 @@ void WebVTTTreeBuilder::constructTreeFromToken(Document& document)
         
         // The only non-VTTElement would be the DocumentFragment root. (Text
         // nodes and PIs will never appear as m_currentNode.)
-        if (!m_currentNode->isWebVTTElement())
+        if (!is<WebVTTElement>(*m_currentNode))
             break;
 
-        WebVTTNodeType currentType = toWebVTTElement(m_currentNode.get())->webVTTNodeType();
+        WebVTTNodeType currentType = downcast<WebVTTElement>(*m_currentNode).webVTTNodeType();
         bool matchesCurrent = nodeType == currentType;
         if (!matchesCurrent) {
             // </ruby> auto-closes <rt>
index 423b3cc..0889dfc 100644 (file)
@@ -352,7 +352,7 @@ static RenderObject* previousSiblingRenderer(const Text& textNode)
 
 static void invalidateWhitespaceOnlyTextSiblingsAfterAttachIfNeeded(Node& current)
 {
-    if (isInsertionPoint(current))
+    if (is<InsertionPoint>(current))
         return;
     // This function finds sibling text renderers where the results of textRendererIsNeeded may have changed as a result of
     // the current node gaining or losing the renderer. This can only affect white space text nodes.
@@ -606,8 +606,8 @@ static void attachRenderTree(Element& current, RenderStyle& inheritedStyle, Rend
     PostResolutionCallbackDisabler callbackDisabler(current.document());
     WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
 
-    if (isInsertionPoint(current)) {
-        attachDistributedChildren(toInsertionPoint(current), inheritedStyle, renderTreePosition);
+    if (is<InsertionPoint>(current)) {
+        attachDistributedChildren(downcast<InsertionPoint>(current), inheritedStyle, renderTreePosition);
         current.clearNeedsStyleRecalc();
         current.clearChildNeedsStyleRecalc();
         return;
@@ -662,8 +662,8 @@ static void detachDistributedChildren(InsertionPoint& insertionPoint)
 
 static void detachChildren(ContainerNode& current, DetachType detachType)
 {
-    if (isInsertionPoint(current))
-        detachDistributedChildren(toInsertionPoint(current));
+    if (is<InsertionPoint>(current))
+        detachDistributedChildren(downcast<InsertionPoint>(current));
 
     for (Node* child = current.firstChild(); child; child = child->nextSibling()) {
         if (child->isTextNode()) {
@@ -899,7 +899,7 @@ void resolveTree(Element& current, RenderStyle& inheritedStyle, RenderTreePositi
 {
     ASSERT(change != Detach);
 
-    if (isInsertionPoint(current)) {
+    if (is<InsertionPoint>(current)) {
         current.clearNeedsStyleRecalc();
         current.clearChildNeedsStyleRecalc();
         return;