Commit 051116fa authored by Abhijeet Kandalkar's avatar Abhijeet Kandalkar Committed by Commit Bot

Use new downcast helper for blink::HTMLDivElement

This CL has two goals,
  1. Use To<HTMLDivElement> and DynamicTo<HTMLDivElement> as new
   downcast helper
  2. Use IsA<HTMLDivElement>(element) in place of
   IsHTMLDivElement(element)

Bug: 891908
Change-Id: Icf2b04b39e87af309a7fc5d66fbd402ae8ed8b0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1930765Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Commit-Queue: Abhijeet | Igalia <abhijeet@igalia.com>
Cr-Commit-Position: refs/heads/master@{#719062}
parent 6738562f
...@@ -201,7 +201,7 @@ static void AdjustStyleForHTMLElement(ComputedStyle& style, ...@@ -201,7 +201,7 @@ static void AdjustStyleForHTMLElement(ComputedStyle& style,
HTMLElement& element) { HTMLElement& element) {
// <div> and <span> are the most common elements on the web, we skip all the // <div> and <span> are the most common elements on the web, we skip all the
// work for them. // work for them.
if (IsHTMLDivElement(element) || IsA<HTMLSpanElement>(element)) if (IsA<HTMLDivElement>(element) || IsA<HTMLSpanElement>(element))
return; return;
if (IsHTMLTableCellElement(element)) { if (IsHTMLTableCellElement(element)) {
......
...@@ -265,15 +265,15 @@ void CompositeEditCommand::InsertParagraphSeparator( ...@@ -265,15 +265,15 @@ void CompositeEditCommand::InsertParagraphSeparator(
bool CompositeEditCommand::IsRemovableBlock(const Node* node) { bool CompositeEditCommand::IsRemovableBlock(const Node* node) {
DCHECK(node); DCHECK(node);
if (!IsHTMLDivElement(*node)) const auto* element = DynamicTo<HTMLDivElement>(node);
if (!element)
return false; return false;
const HTMLDivElement& element = ToHTMLDivElement(*node); ContainerNode* parent_node = element->parentNode();
ContainerNode* parent_node = element.parentNode();
if (parent_node && parent_node->firstChild() != parent_node->lastChild()) if (parent_node && parent_node->firstChild() != parent_node->lastChild())
return false; return false;
if (!element.hasAttributes()) if (!element->hasAttributes())
return true; return true;
return false; return false;
......
...@@ -56,7 +56,7 @@ static Element* HighestVisuallyEquivalentDivBelowRoot(Element* start_block) { ...@@ -56,7 +56,7 @@ static Element* HighestVisuallyEquivalentDivBelowRoot(Element* start_block) {
// We don't want to return a root node (if it happens to be a div, e.g., in a // We don't want to return a root node (if it happens to be a div, e.g., in a
// document fragment) because there are no siblings for us to append to. // document fragment) because there are no siblings for us to append to.
while (!cur_block->nextSibling() && while (!cur_block->nextSibling() &&
IsHTMLDivElement(*cur_block->parentElement()) && IsA<HTMLDivElement>(*cur_block->parentElement()) &&
cur_block->parentElement()->parentElement()) { cur_block->parentElement()->parentElement()) {
if (cur_block->parentElement()->hasAttributes()) if (cur_block->parentElement()->hasAttributes())
break; break;
...@@ -322,7 +322,7 @@ void InsertParagraphSeparatorCommand::DoApply(EditingState* editing_state) { ...@@ -322,7 +322,7 @@ void InsertParagraphSeparatorCommand::DoApply(EditingState* editing_state) {
// startBlock (e.g., when nesting within lists). However, for div nodes, // startBlock (e.g., when nesting within lists). However, for div nodes,
// this can result in nested div tags that are hard to break out of. // this can result in nested div tags that are hard to break out of.
Element* sibling_element = start_block; Element* sibling_element = start_block;
if (IsHTMLDivElement(*block_to_insert)) if (IsA<HTMLDivElement>(*block_to_insert))
sibling_element = HighestVisuallyEquivalentDivBelowRoot(start_block); sibling_element = HighestVisuallyEquivalentDivBelowRoot(start_block);
InsertNodeAfter(block_to_insert, sibling_element, editing_state); InsertNodeAfter(block_to_insert, sibling_element, editing_state);
} }
......
...@@ -500,20 +500,21 @@ static void FillContainerFromString(ContainerNode* paragraph, ...@@ -500,20 +500,21 @@ static void FillContainerFromString(ContainerNode* paragraph,
bool IsPlainTextMarkup(Node* node) { bool IsPlainTextMarkup(Node* node) {
DCHECK(node); DCHECK(node);
if (!IsHTMLDivElement(*node)) auto* element = DynamicTo<HTMLDivElement>(*node);
if (!element)
return false; return false;
HTMLDivElement& element = ToHTMLDivElement(*node); if (!element->hasAttributes())
if (!element.hasAttributes())
return false; return false;
if (element.HasOneChild()) if (element->HasOneChild()) {
return element.firstChild()->IsTextNode() || return element->firstChild()->IsTextNode() ||
element.firstChild()->hasChildren(); element->firstChild()->hasChildren();
}
return element.HasChildCount(2) && return element->HasChildCount(2) &&
IsTabHTMLSpanElementTextNode(element.firstChild()->firstChild()) && IsTabHTMLSpanElementTextNode(element->firstChild()->firstChild()) &&
element.lastChild()->IsTextNode(); element->lastChild()->IsTextNode();
} }
static bool ShouldPreserveNewline(const EphemeralRange& range) { static bool ShouldPreserveNewline(const EphemeralRange& range) {
......
...@@ -195,7 +195,7 @@ Node* SmartClip::FindBestOverlappingNode(Node* root_node, ...@@ -195,7 +195,7 @@ Node* SmartClip::FindBestOverlappingNode(Node* root_node,
bool SmartClip::ShouldSkipBackgroundImage(Node* node) { bool SmartClip::ShouldSkipBackgroundImage(Node* node) {
DCHECK(node); DCHECK(node);
// Apparently we're only interested in background images on spans and divs. // Apparently we're only interested in background images on spans and divs.
if (!IsA<HTMLSpanElement>(*node) && !IsHTMLDivElement(*node)) if (!IsA<HTMLSpanElement>(*node) && !IsA<HTMLDivElement>(*node))
return true; return true;
// This check actually makes a bit of sense. If you're going to sprite an // This check actually makes a bit of sense. If you're going to sprite an
......
...@@ -50,7 +50,7 @@ class HTMLVideoElementPersistentTest : public PageTestBase { ...@@ -50,7 +50,7 @@ class HTMLVideoElementPersistentTest : public PageTestBase {
} }
HTMLDivElement* DivElement() { HTMLDivElement* DivElement() {
return ToHTMLDivElement(GetDocument().QuerySelector("div")); return To<HTMLDivElement>(GetDocument().QuerySelector("div"));
} }
Element* FullscreenElement() { Element* FullscreenElement() {
......
...@@ -720,7 +720,7 @@ ax::mojom::Role AXNodeObject::NativeRoleIgnoringAria() const { ...@@ -720,7 +720,7 @@ ax::mojom::Role AXNodeObject::NativeRoleIgnoringAria() const {
if (HeadingLevel()) if (HeadingLevel())
return ax::mojom::Role::kHeading; return ax::mojom::Role::kHeading;
if (IsHTMLDivElement(*GetNode())) if (IsA<HTMLDivElement>(*GetNode()))
return ax::mojom::Role::kGenericContainer; return ax::mojom::Role::kGenericContainer;
if (IsA<HTMLMeterElement>(*GetNode())) if (IsA<HTMLMeterElement>(*GetNode()))
...@@ -1169,7 +1169,7 @@ bool AXNodeObject::IsInPageLinkTarget() const { ...@@ -1169,7 +1169,7 @@ bool AXNodeObject::IsInPageLinkTarget() const {
if (element->HasID() && if (element->HasID() &&
(IsLandmarkRelated() || IsA<HTMLSpanElement>(element) || (IsLandmarkRelated() || IsA<HTMLSpanElement>(element) ||
IsHTMLDivElement(element))) { IsA<HTMLDivElement>(element))) {
return true; return true;
} }
return false; return false;
......
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