Commit 3cf5fda4 authored by Abhijeet Kandalkar's avatar Abhijeet Kandalkar Committed by Commit Bot

Remove DEFINE_TYPE_CASTS from t_p/blink/renderer/core/dom (1/n)

The goal of this CL is to use new downcast helper and remove
DEFINE_TYPE_CASTS to adopt new downcast helpers.

This CL removes DEFINE_TYPE_CASTS for below element.
- ChildNodeList,
- ClassCollection,
- LiveNodeList,
- TagCollection,
- TagCollectionNS

Bug: 891908
Change-Id: I97faab9ef623ee5bcfff6f39eb70c8ebb048605d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1969294Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Commit-Queue: Abhijeet Kandalkar <abhijeet@igalia.com>
Cr-Commit-Position: refs/heads/master@{#725415}
parent bf00f152
...@@ -70,11 +70,12 @@ class ChildNodeList final : public NodeList { ...@@ -70,11 +70,12 @@ class ChildNodeList final : public NodeList {
mutable CollectionIndexCache<ChildNodeList, Node> collection_index_cache_; mutable CollectionIndexCache<ChildNodeList, Node> collection_index_cache_;
}; };
DEFINE_TYPE_CASTS(ChildNodeList, template <>
NodeList, struct DowncastTraits<ChildNodeList> {
nodeList, static bool AllowFrom(const NodeList& nodeList) {
nodeList->IsChildNodeList(), return nodeList.IsChildNodeList();
nodeList.IsChildNodeList()); }
};
} // namespace blink } // namespace blink
......
...@@ -50,11 +50,12 @@ class ClassCollection final : public HTMLCollection { ...@@ -50,11 +50,12 @@ class ClassCollection final : public HTMLCollection {
SpaceSplitString class_names_; SpaceSplitString class_names_;
}; };
DEFINE_TYPE_CASTS(ClassCollection, template <>
LiveNodeListBase, struct DowncastTraits<ClassCollection> {
collection, static bool AllowFrom(const LiveNodeListBase& collection) {
collection->GetType() == kClassCollectionType, return collection.GetType() == kClassCollectionType;
collection.GetType() == kClassCollectionType); }
};
inline bool ClassCollection::ElementMatches(const Element& test_element) const { inline bool ClassCollection::ElementMatches(const Element& test_element) const {
if (!test_element.HasClass()) if (!test_element.HasClass())
......
...@@ -79,11 +79,12 @@ class CORE_EXPORT LiveNodeList : public NodeList, public LiveNodeListBase { ...@@ -79,11 +79,12 @@ class CORE_EXPORT LiveNodeList : public NodeList, public LiveNodeListBase {
mutable CollectionItemsCache<LiveNodeList, Element> collection_items_cache_; mutable CollectionItemsCache<LiveNodeList, Element> collection_items_cache_;
}; };
DEFINE_TYPE_CASTS(LiveNodeList, template <>
LiveNodeListBase, struct DowncastTraits<LiveNodeList> {
list, static bool AllowFrom(const LiveNodeListBase& list) {
IsLiveNodeListType(list->GetType()), return IsLiveNodeListType(list.GetType());
IsLiveNodeListType(list.GetType())); }
};
inline void LiveNodeList::InvalidateCacheForAttribute( inline void LiveNodeList::InvalidateCacheForAttribute(
const QualifiedName* attr_name) const { const QualifiedName* attr_name) const {
......
...@@ -31,7 +31,7 @@ namespace blink { ...@@ -31,7 +31,7 @@ namespace blink {
void LiveNodeListBase::InvalidateCacheForAttribute( void LiveNodeListBase::InvalidateCacheForAttribute(
const QualifiedName* attr_name) const { const QualifiedName* attr_name) const {
if (IsLiveNodeListType(GetType())) if (IsLiveNodeListType(GetType()))
ToLiveNodeList(this)->InvalidateCacheForAttribute(attr_name); To<LiveNodeList>(this)->InvalidateCacheForAttribute(attr_name);
else else
ToHTMLCollection(this)->InvalidateCacheForAttribute(attr_name); ToHTMLCollection(this)->InvalidateCacheForAttribute(attr_name);
} }
......
...@@ -39,13 +39,13 @@ class NodeListsNodeData final : public GarbageCollected<NodeListsNodeData> { ...@@ -39,13 +39,13 @@ class NodeListsNodeData final : public GarbageCollected<NodeListsNodeData> {
public: public:
ChildNodeList* GetChildNodeList(ContainerNode& node) { ChildNodeList* GetChildNodeList(ContainerNode& node) {
DCHECK(!child_node_list_ || node == child_node_list_->VirtualOwnerNode()); DCHECK(!child_node_list_ || node == child_node_list_->VirtualOwnerNode());
return ToChildNodeList(child_node_list_); return To<ChildNodeList>(child_node_list_.Get());
} }
ChildNodeList* EnsureChildNodeList(ContainerNode& node) { ChildNodeList* EnsureChildNodeList(ContainerNode& node) {
DCHECK(ThreadState::Current()->IsGCForbidden()); DCHECK(ThreadState::Current()->IsGCForbidden());
if (child_node_list_) if (child_node_list_)
return ToChildNodeList(child_node_list_); return To<ChildNodeList>(child_node_list_.Get());
auto* list = MakeGarbageCollected<ChildNodeList>(node); auto* list = MakeGarbageCollected<ChildNodeList>(node);
child_node_list_ = list; child_node_list_ = list;
return list; return list;
......
...@@ -73,17 +73,19 @@ class TagCollectionNS : public HTMLCollection { ...@@ -73,17 +73,19 @@ class TagCollectionNS : public HTMLCollection {
AtomicString local_name_; AtomicString local_name_;
}; };
DEFINE_TYPE_CASTS(TagCollection, template <>
LiveNodeListBase, struct DowncastTraits<TagCollection> {
collection, static bool AllowFrom(const LiveNodeListBase& collection) {
collection->GetType() == kTagCollectionType, return collection.GetType() == kTagCollectionType;
collection.GetType() == kTagCollectionType); }
};
DEFINE_TYPE_CASTS(TagCollectionNS, template <>
LiveNodeListBase, struct DowncastTraits<TagCollectionNS> {
collection, static bool AllowFrom(const LiveNodeListBase& collection) {
collection->GetType() == kTagCollectionNSType, return collection.GetType() == kTagCollectionNSType;
collection.GetType() == kTagCollectionNSType); }
};
} // namespace blink } // namespace blink
......
...@@ -277,13 +277,13 @@ inline bool HTMLCollection::ElementMatches(const Element& element) const { ...@@ -277,13 +277,13 @@ inline bool HTMLCollection::ElementMatches(const Element& element) const {
case kNodeChildren: case kNodeChildren:
return true; return true;
case kClassCollectionType: case kClassCollectionType:
return ToClassCollection(*this).ElementMatches(element); return To<ClassCollection>(*this).ElementMatches(element);
case kTagCollectionType: case kTagCollectionType:
return ToTagCollection(*this).ElementMatches(element); return To<TagCollection>(*this).ElementMatches(element);
case kHTMLTagCollectionType: case kHTMLTagCollectionType:
return ToHTMLTagCollection(*this).ElementMatches(element); return ToHTMLTagCollection(*this).ElementMatches(element);
case kTagCollectionNSType: case kTagCollectionNSType:
return ToTagCollectionNS(*this).ElementMatches(element); return To<TagCollectionNS>(*this).ElementMatches(element);
case kWindowNamedItems: case kWindowNamedItems:
return ToWindowNameCollection(*this).ElementMatches(element); return ToWindowNameCollection(*this).ElementMatches(element);
case kDocumentAllNamedItems: case kDocumentAllNamedItems:
...@@ -355,7 +355,7 @@ Element* HTMLCollection::TraverseToFirst() const { ...@@ -355,7 +355,7 @@ Element* HTMLCollection::TraverseToFirst() const {
RootNode(), MakeIsMatch(ToHTMLTagCollection(*this))); RootNode(), MakeIsMatch(ToHTMLTagCollection(*this)));
case kClassCollectionType: case kClassCollectionType:
return ElementTraversal::FirstWithin( return ElementTraversal::FirstWithin(
RootNode(), MakeIsMatch(ToClassCollection(*this))); RootNode(), MakeIsMatch(To<ClassCollection>(*this)));
default: default:
if (OverridesItemAfter()) if (OverridesItemAfter())
return VirtualItemAfter(nullptr); return VirtualItemAfter(nullptr);
...@@ -385,7 +385,7 @@ Element* HTMLCollection::TraverseForwardToOffset( ...@@ -385,7 +385,7 @@ Element* HTMLCollection::TraverseForwardToOffset(
case kClassCollectionType: case kClassCollectionType:
return TraverseMatchingElementsForwardToOffset( return TraverseMatchingElementsForwardToOffset(
current_element, &RootNode(), offset, current_offset, current_element, &RootNode(), offset, current_offset,
MakeIsMatch(ToClassCollection(*this))); MakeIsMatch(To<ClassCollection>(*this)));
default: default:
if (OverridesItemAfter()) { if (OverridesItemAfter()) {
for (Element* next = VirtualItemAfter(&current_element); next; for (Element* next = VirtualItemAfter(&current_element); next;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment