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 {
mutable CollectionIndexCache<ChildNodeList, Node> collection_index_cache_;
};
DEFINE_TYPE_CASTS(ChildNodeList,
NodeList,
nodeList,
nodeList->IsChildNodeList(),
nodeList.IsChildNodeList());
template <>
struct DowncastTraits<ChildNodeList> {
static bool AllowFrom(const NodeList& nodeList) {
return nodeList.IsChildNodeList();
}
};
} // namespace blink
......
......@@ -50,11 +50,12 @@ class ClassCollection final : public HTMLCollection {
SpaceSplitString class_names_;
};
DEFINE_TYPE_CASTS(ClassCollection,
LiveNodeListBase,
collection,
collection->GetType() == kClassCollectionType,
collection.GetType() == kClassCollectionType);
template <>
struct DowncastTraits<ClassCollection> {
static bool AllowFrom(const LiveNodeListBase& collection) {
return collection.GetType() == kClassCollectionType;
}
};
inline bool ClassCollection::ElementMatches(const Element& test_element) const {
if (!test_element.HasClass())
......
......@@ -79,11 +79,12 @@ class CORE_EXPORT LiveNodeList : public NodeList, public LiveNodeListBase {
mutable CollectionItemsCache<LiveNodeList, Element> collection_items_cache_;
};
DEFINE_TYPE_CASTS(LiveNodeList,
LiveNodeListBase,
list,
IsLiveNodeListType(list->GetType()),
IsLiveNodeListType(list.GetType()));
template <>
struct DowncastTraits<LiveNodeList> {
static bool AllowFrom(const LiveNodeListBase& list) {
return IsLiveNodeListType(list.GetType());
}
};
inline void LiveNodeList::InvalidateCacheForAttribute(
const QualifiedName* attr_name) const {
......
......@@ -31,7 +31,7 @@ namespace blink {
void LiveNodeListBase::InvalidateCacheForAttribute(
const QualifiedName* attr_name) const {
if (IsLiveNodeListType(GetType()))
ToLiveNodeList(this)->InvalidateCacheForAttribute(attr_name);
To<LiveNodeList>(this)->InvalidateCacheForAttribute(attr_name);
else
ToHTMLCollection(this)->InvalidateCacheForAttribute(attr_name);
}
......
......@@ -39,13 +39,13 @@ class NodeListsNodeData final : public GarbageCollected<NodeListsNodeData> {
public:
ChildNodeList* GetChildNodeList(ContainerNode& node) {
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) {
DCHECK(ThreadState::Current()->IsGCForbidden());
if (child_node_list_)
return ToChildNodeList(child_node_list_);
return To<ChildNodeList>(child_node_list_.Get());
auto* list = MakeGarbageCollected<ChildNodeList>(node);
child_node_list_ = list;
return list;
......
......@@ -73,17 +73,19 @@ class TagCollectionNS : public HTMLCollection {
AtomicString local_name_;
};
DEFINE_TYPE_CASTS(TagCollection,
LiveNodeListBase,
collection,
collection->GetType() == kTagCollectionType,
collection.GetType() == kTagCollectionType);
template <>
struct DowncastTraits<TagCollection> {
static bool AllowFrom(const LiveNodeListBase& collection) {
return collection.GetType() == kTagCollectionType;
}
};
DEFINE_TYPE_CASTS(TagCollectionNS,
LiveNodeListBase,
collection,
collection->GetType() == kTagCollectionNSType,
collection.GetType() == kTagCollectionNSType);
template <>
struct DowncastTraits<TagCollectionNS> {
static bool AllowFrom(const LiveNodeListBase& collection) {
return collection.GetType() == kTagCollectionNSType;
}
};
} // namespace blink
......
......@@ -277,13 +277,13 @@ inline bool HTMLCollection::ElementMatches(const Element& element) const {
case kNodeChildren:
return true;
case kClassCollectionType:
return ToClassCollection(*this).ElementMatches(element);
return To<ClassCollection>(*this).ElementMatches(element);
case kTagCollectionType:
return ToTagCollection(*this).ElementMatches(element);
return To<TagCollection>(*this).ElementMatches(element);
case kHTMLTagCollectionType:
return ToHTMLTagCollection(*this).ElementMatches(element);
case kTagCollectionNSType:
return ToTagCollectionNS(*this).ElementMatches(element);
return To<TagCollectionNS>(*this).ElementMatches(element);
case kWindowNamedItems:
return ToWindowNameCollection(*this).ElementMatches(element);
case kDocumentAllNamedItems:
......@@ -355,7 +355,7 @@ Element* HTMLCollection::TraverseToFirst() const {
RootNode(), MakeIsMatch(ToHTMLTagCollection(*this)));
case kClassCollectionType:
return ElementTraversal::FirstWithin(
RootNode(), MakeIsMatch(ToClassCollection(*this)));
RootNode(), MakeIsMatch(To<ClassCollection>(*this)));
default:
if (OverridesItemAfter())
return VirtualItemAfter(nullptr);
......@@ -385,7 +385,7 @@ Element* HTMLCollection::TraverseForwardToOffset(
case kClassCollectionType:
return TraverseMatchingElementsForwardToOffset(
current_element, &RootNode(), offset, current_offset,
MakeIsMatch(ToClassCollection(*this)));
MakeIsMatch(To<ClassCollection>(*this)));
default:
if (OverridesItemAfter()) {
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