Commit 1f6684cc authored by Abhijeet Kandalkar's avatar Abhijeet Kandalkar Committed by Commit Bot

Use new downcast helpers for third_party/blink/renderer/core

This CL uses new downcast helpers for below classes
1. HTMLCollection
2. HTMLFormControlElementWithState
3. HTMLOptionsCollection
4. HTMLDataListOptionsCollection
5. HTMLTagCollection
6. HTMLImportTreeRoot

Bug: 891908
Change-Id: I082414d2765d3972c872bb5517ea81cd411883ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1999968
Commit-Queue: Abhijeet Kandalkar <abhijeet@igalia.com>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732347}
parent 6a314a4d
...@@ -33,7 +33,7 @@ void LiveNodeListBase::InvalidateCacheForAttribute( ...@@ -33,7 +33,7 @@ void LiveNodeListBase::InvalidateCacheForAttribute(
if (IsLiveNodeListType(GetType())) if (IsLiveNodeListType(GetType()))
To<LiveNodeList>(this)->InvalidateCacheForAttribute(attr_name); To<LiveNodeList>(this)->InvalidateCacheForAttribute(attr_name);
else else
ToHTMLCollection(this)->InvalidateCacheForAttribute(attr_name); To<HTMLCollection>(this)->InvalidateCacheForAttribute(attr_name);
} }
ContainerNode& LiveNodeListBase::RootNode() const { ContainerNode& LiveNodeListBase::RootNode() const {
......
...@@ -62,8 +62,9 @@ const AtomicString& ControlType(const ListedElement& control) { ...@@ -62,8 +62,9 @@ const AtomicString& ControlType(const ListedElement& control) {
} }
bool IsDirtyControl(const ListedElement& control) { bool IsDirtyControl(const ListedElement& control) {
if (control.IsFormControlElementWithState()) if (auto* form_control_element =
return ToHTMLFormControlElementWithState(control).UserHasEditedTheField(); DynamicTo<HTMLFormControlElementWithState>(control))
return form_control_element->UserHasEditedTheField();
if (control.IsElementInternals()) { if (control.IsElementInternals()) {
// We have no ways to know the dirtiness of a form-associated custom // We have no ways to know the dirtiness of a form-associated custom
// element. Assume it is dirty if it has focus. // element. Assume it is dirty if it has focus.
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "third_party/blink/renderer/core/html/forms/html_option_element.h" #include "third_party/blink/renderer/core/html/forms/html_option_element.h"
#include "third_party/blink/renderer/core/html/html_collection.h" #include "third_party/blink/renderer/core/html/html_collection.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace blink { namespace blink {
...@@ -28,11 +29,12 @@ class HTMLDataListOptionsCollection : public HTMLCollection { ...@@ -28,11 +29,12 @@ class HTMLDataListOptionsCollection : public HTMLCollection {
bool ElementMatches(const HTMLElement&) const; bool ElementMatches(const HTMLElement&) const;
}; };
DEFINE_TYPE_CASTS(HTMLDataListOptionsCollection, template <>
LiveNodeListBase, struct DowncastTraits<HTMLDataListOptionsCollection> {
collection, static bool AllowFrom(const LiveNodeListBase& collection) {
collection->GetType() == kDataListOptions, return collection.GetType() == kDataListOptions;
collection.GetType() == kDataListOptions); }
};
inline bool HTMLDataListOptionsCollection::ElementMatches( inline bool HTMLDataListOptionsCollection::ElementMatches(
const HTMLElement& element) const { const HTMLElement& element) const {
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/html/forms/html_form_control_element.h" #include "third_party/blink/renderer/core/html/forms/html_form_control_element.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace blink { namespace blink {
...@@ -68,11 +69,12 @@ class CORE_EXPORT HTMLFormControlElementWithState ...@@ -68,11 +69,12 @@ class CORE_EXPORT HTMLFormControlElementWithState
bool IsWearingAutofillAnchorMantle() const; bool IsWearingAutofillAnchorMantle() const;
}; };
DEFINE_TYPE_CASTS(HTMLFormControlElementWithState, template <>
ListedElement, struct DowncastTraits<HTMLFormControlElementWithState> {
control, static bool AllowFrom(const ListedElement& control) {
control->IsFormControlElementWithState(), return control.IsFormControlElementWithState();
control.IsFormControlElementWithState()); }
};
} // namespace blink } // namespace blink
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "third_party/blink/renderer/core/html/forms/html_option_element.h" #include "third_party/blink/renderer/core/html/forms/html_option_element.h"
#include "third_party/blink/renderer/core/html/html_collection.h" #include "third_party/blink/renderer/core/html/html_collection.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace blink { namespace blink {
...@@ -61,11 +62,12 @@ class HTMLOptionsCollection final : public HTMLCollection { ...@@ -61,11 +62,12 @@ class HTMLOptionsCollection final : public HTMLCollection {
void SupportedPropertyNames(Vector<String>& names) override; void SupportedPropertyNames(Vector<String>& names) override;
}; };
DEFINE_TYPE_CASTS(HTMLOptionsCollection, template <>
LiveNodeListBase, struct DowncastTraits<HTMLOptionsCollection> {
collection, static bool AllowFrom(const LiveNodeListBase& collection) {
collection->GetType() == kSelectOptions, return collection.GetType() == kSelectOptions;
collection.GetType() == kSelectOptions); }
};
inline bool HTMLOptionsCollection::ElementMatches( inline bool HTMLOptionsCollection::ElementMatches(
const HTMLElement& element) const { const HTMLElement& element) const {
......
...@@ -225,13 +225,13 @@ static inline bool IsMatchingHTMLElement(const HTMLCollection& html_collection, ...@@ -225,13 +225,13 @@ static inline bool IsMatchingHTMLElement(const HTMLCollection& html_collection,
case kTSectionRows: case kTSectionRows:
return element.HasTagName(html_names::kTrTag); return element.HasTagName(html_names::kTrTag);
case kSelectOptions: case kSelectOptions:
return ToHTMLOptionsCollection(html_collection).ElementMatches(element); return To<HTMLOptionsCollection>(html_collection).ElementMatches(element);
case kSelectedOptions: { case kSelectedOptions: {
auto* option_element = DynamicTo<HTMLOptionElement>(element); auto* option_element = DynamicTo<HTMLOptionElement>(element);
return option_element && option_element->Selected(); return option_element && option_element->Selected();
} }
case kDataListOptions: case kDataListOptions:
return ToHTMLDataListOptionsCollection(html_collection) return To<HTMLDataListOptionsCollection>(html_collection)
.ElementMatches(element); .ElementMatches(element);
case kMapAreas: case kMapAreas:
return element.HasTagName(html_names::kAreaTag); return element.HasTagName(html_names::kAreaTag);
...@@ -281,7 +281,7 @@ inline bool HTMLCollection::ElementMatches(const Element& element) const { ...@@ -281,7 +281,7 @@ inline bool HTMLCollection::ElementMatches(const Element& element) const {
case kTagCollectionType: case kTagCollectionType:
return To<TagCollection>(*this).ElementMatches(element); return To<TagCollection>(*this).ElementMatches(element);
case kHTMLTagCollectionType: case kHTMLTagCollectionType:
return ToHTMLTagCollection(*this).ElementMatches(element); return To<HTMLTagCollection>(*this).ElementMatches(element);
case kTagCollectionNSType: case kTagCollectionNSType:
return To<TagCollectionNS>(*this).ElementMatches(element); return To<TagCollectionNS>(*this).ElementMatches(element);
case kWindowNamedItems: case kWindowNamedItems:
...@@ -352,7 +352,7 @@ Element* HTMLCollection::TraverseToFirst() const { ...@@ -352,7 +352,7 @@ Element* HTMLCollection::TraverseToFirst() const {
switch (GetType()) { switch (GetType()) {
case kHTMLTagCollectionType: case kHTMLTagCollectionType:
return ElementTraversal::FirstWithin( return ElementTraversal::FirstWithin(
RootNode(), MakeIsMatch(ToHTMLTagCollection(*this))); RootNode(), MakeIsMatch(To<HTMLTagCollection>(*this)));
case kClassCollectionType: case kClassCollectionType:
return ElementTraversal::FirstWithin( return ElementTraversal::FirstWithin(
RootNode(), MakeIsMatch(To<ClassCollection>(*this))); RootNode(), MakeIsMatch(To<ClassCollection>(*this)));
...@@ -381,7 +381,7 @@ Element* HTMLCollection::TraverseForwardToOffset( ...@@ -381,7 +381,7 @@ Element* HTMLCollection::TraverseForwardToOffset(
case kHTMLTagCollectionType: case kHTMLTagCollectionType:
return TraverseMatchingElementsForwardToOffset( return TraverseMatchingElementsForwardToOffset(
current_element, &RootNode(), offset, current_offset, current_element, &RootNode(), offset, current_offset,
MakeIsMatch(ToHTMLTagCollection(*this))); MakeIsMatch(To<HTMLTagCollection>(*this)));
case kClassCollectionType: case kClassCollectionType:
return TraverseMatchingElementsForwardToOffset( return TraverseMatchingElementsForwardToOffset(
current_element, &RootNode(), offset, current_offset, current_element, &RootNode(), offset, current_offset,
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "third_party/blink/renderer/core/dom/live_node_list_base.h" #include "third_party/blink/renderer/core/dom/live_node_list_base.h"
#include "third_party/blink/renderer/core/html/collection_items_cache.h" #include "third_party/blink/renderer/core/html/collection_items_cache.h"
#include "third_party/blink/renderer/core/html/collection_type.h" #include "third_party/blink/renderer/core/html/collection_type.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
#include "third_party/blink/renderer/platform/wtf/forward.h" #include "third_party/blink/renderer/platform/wtf/forward.h"
namespace blink { namespace blink {
...@@ -212,11 +213,12 @@ class CORE_EXPORT HTMLCollection : public ScriptWrappable, ...@@ -212,11 +213,12 @@ class CORE_EXPORT HTMLCollection : public ScriptWrappable,
mutable CollectionItemsCache<HTMLCollection, Element> collection_items_cache_; mutable CollectionItemsCache<HTMLCollection, Element> collection_items_cache_;
}; };
DEFINE_TYPE_CASTS(HTMLCollection, template <>
LiveNodeListBase, struct DowncastTraits<HTMLCollection> {
collection, static bool AllowFrom(const LiveNodeListBase& collection) {
IsHTMLCollectionType(collection->GetType()), return IsHTMLCollectionType(collection.GetType());
IsHTMLCollectionType(collection.GetType())); }
};
DISABLE_CFI_PERF DISABLE_CFI_PERF
inline void HTMLCollection::InvalidateCacheForAttribute( inline void HTMLCollection::InvalidateCacheForAttribute(
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "third_party/blink/renderer/core/dom/element.h" #include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/tag_collection.h" #include "third_party/blink/renderer/core/dom/tag_collection.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace blink { namespace blink {
...@@ -46,11 +47,12 @@ class HTMLTagCollection final : public TagCollection { ...@@ -46,11 +47,12 @@ class HTMLTagCollection final : public TagCollection {
AtomicString lowered_qualified_name_; AtomicString lowered_qualified_name_;
}; };
DEFINE_TYPE_CASTS(HTMLTagCollection, template <>
LiveNodeListBase, struct DowncastTraits<HTMLTagCollection> {
collection, static bool AllowFrom(const LiveNodeListBase& collection) {
collection->GetType() == kHTMLTagCollectionType, return collection.GetType() == kHTMLTagCollectionType;
collection.GetType() == kHTMLTagCollectionType); }
};
inline bool HTMLTagCollection::ElementMatches( inline bool HTMLTagCollection::ElementMatches(
const Element& test_element) const { const Element& test_element) const {
......
...@@ -108,7 +108,7 @@ Document* HTMLImportChild::GetDocument() const { ...@@ -108,7 +108,7 @@ Document* HTMLImportChild::GetDocument() const {
} }
void HTMLImportChild::StateWillChange() { void HTMLImportChild::StateWillChange() {
ToHTMLImportTreeRoot(Root())->ScheduleRecalcState(); To<HTMLImportTreeRoot>(Root())->ScheduleRecalcState();
} }
void HTMLImportChild::StateDidChange() { void HTMLImportChild::StateDidChange() {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "third_party/blink/renderer/core/html/imports/html_import.h" #include "third_party/blink/renderer/core/html/imports/html_import.h"
#include "third_party/blink/renderer/platform/bindings/name_client.h" #include "third_party/blink/renderer/platform/bindings/name_client.h"
#include "third_party/blink/renderer/platform/timer.h" #include "third_party/blink/renderer/platform/timer.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace blink { namespace blink {
...@@ -48,11 +49,10 @@ class HTMLImportTreeRoot final : public HTMLImport, public NameClient { ...@@ -48,11 +49,10 @@ class HTMLImportTreeRoot final : public HTMLImport, public NameClient {
ImportList imports_; ImportList imports_;
}; };
DEFINE_TYPE_CASTS(HTMLImportTreeRoot, template <>
HTMLImport, struct DowncastTraits<HTMLImportTreeRoot> {
import, static bool AllowFrom(const HTMLImport& import) { return import.IsRoot(); }
import->IsRoot(), };
import.IsRoot());
} // namespace blink } // namespace blink
......
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