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