Skip to content

Commit

Permalink
Use new downcast helper for blink::HTMLSpanElement
Browse files Browse the repository at this point in the history
This CL has two goals,
1. Use To<HTMLSpanElement> and DynamicTo<HTMLSpanElement> as new
   downcast helper
2. Use IsA<HTMLSpanElement>(element) in place of
   IsHTMLSelectElement(element)

Bug: 891908
Change-Id: If2150ecebb45b7dd6dd78682ffac47eb60372c2f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1878269
Reviewed-by: Christian Biesinger <cbiesinger@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Abhijeet Kandalkar <abhijeet@igalia.com>
Cr-Commit-Position: refs/heads/master@{#709860}
  • Loading branch information
abhijeetk authored and Commit Bot committed Oct 28, 2019
1 parent 8c74983 commit 9d5550f
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ static void AdjustStyleForHTMLElement(ComputedStyle& style,
HTMLElement& element) {
// <div> and <span> are the most common elements on the web, we skip all the
// work for them.
if (IsHTMLDivElement(element) || IsHTMLSpanElement(element))
if (IsHTMLDivElement(element) || IsA<HTMLSpanElement>(element))
return;

if (IsHTMLTableCellElement(element)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static bool HasNoAttributeOrOnlyStyleAttribute(
}

bool IsStyleSpanOrSpanWithOnlyStyleAttribute(const Element* element) {
if (auto* span = ToHTMLSpanElementOrNull(element)) {
if (auto* span = DynamicTo<HTMLSpanElement>(element)) {
return HasNoAttributeOrOnlyStyleAttribute(span,
kAllowNonEmptyStyleAttribute);
}
Expand All @@ -89,7 +89,7 @@ bool IsStyleSpanOrSpanWithOnlyStyleAttribute(const Element* element) {

static inline bool IsSpanWithoutAttributesOrUnstyledStyleSpan(
const Node* node) {
if (auto* span = ToHTMLSpanElementOrNull(node)) {
if (auto* span = DynamicTo<HTMLSpanElement>(node)) {
return HasNoAttributeOrOnlyStyleAttribute(span,
kStyleAttributeShouldBeEmpty);
}
Expand Down Expand Up @@ -1905,10 +1905,10 @@ void ApplyStyleCommand::ApplyInlineStyleChange(
container = container->firstChild()) {
if (auto* font = DynamicTo<HTMLFontElement>(container))
font_container = font;
bool style_container_is_not_span = !IsHTMLSpanElement(style_container);
bool style_container_is_not_span = !IsA<HTMLSpanElement>(style_container);
auto* container_element = DynamicTo<HTMLElement>(container);
if (container_element) {
if (IsHTMLSpanElement(*container_element) ||
if (IsA<HTMLSpanElement>(*container_element) ||
(style_container_is_not_span && container_element->HasChildren()))
style_container = container_element;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ void InsertListCommand::ListifyParagraph(const VisiblePosition& original_start,
// | |-B
// | +-C (insertion point)
// | |-D (*)
if (IsHTMLSpanElement(insertion_pos.AnchorNode())) {
if (IsA<HTMLSpanElement>(insertion_pos.AnchorNode())) {
insertion_pos =
Position::InParentBeforeNode(*insertion_pos.ComputeContainerNode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ static bool FollowBlockElementStyle(const Node* node) {
static void HandleStyleSpansBeforeInsertion(ReplacementFragment& fragment,
const Position& insertion_pos) {
Node* top_node = fragment.FirstChild();
if (!IsHTMLSpanElement(top_node))
if (!IsA<HTMLSpanElement>(top_node))
return;

// Handling the case where we are doing Paste as Quotation or pasting into
Expand All @@ -907,7 +907,7 @@ static void HandleStyleSpansBeforeInsertion(ReplacementFragment& fragment,
// Remove style spans to follow the styles of parent block element when
// |fragment| becomes a part of it. See bugs http://crbug.com/226941 and
// http://crbug.com/335955.
HTMLSpanElement* wrapping_style_span = ToHTMLSpanElement(top_node);
auto* wrapping_style_span = To<HTMLSpanElement>(top_node);
const Node* node = insertion_pos.AnchorNode();
// |node| can be an inline element like <br> under <li>
// e.g.) editing/execCommand/switch-list-type.html
Expand Down
2 changes: 1 addition & 1 deletion third_party/blink/renderer/core/editing/editing_style.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ bool EditingStyle::ElementIsStyledSpanOrHTMLEquivalent(
const HTMLElement* element) {
DCHECK(element);
bool element_is_span_or_element_equivalent = false;
if (IsHTMLSpanElement(*element)) {
if (IsA<HTMLSpanElement>(*element)) {
element_is_span_or_element_equivalent = true;
} else {
const HeapVector<Member<HTMLElementEquivalent>>& html_element_equivalents =
Expand Down
4 changes: 2 additions & 2 deletions third_party/blink/renderer/core/editing/editing_utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ HTMLElement* CreateDefaultParagraphElement(Document& document) {
}

bool IsTabHTMLSpanElement(const Node* node) {
if (!IsHTMLSpanElement(node))
if (!IsA<HTMLSpanElement>(node))
return false;
const Node* const first_child = NodeTraversal::FirstChild(*node);
auto* first_child_text_node = DynamicTo<Text>(first_child);
Expand All @@ -1284,7 +1284,7 @@ bool IsTabHTMLSpanElementTextNode(const Node* node) {

HTMLSpanElement* TabSpanElement(const Node* node) {
return IsTabHTMLSpanElementTextNode(node)
? ToHTMLSpanElement(node->parentNode())
? To<HTMLSpanElement>(node->parentNode())
: nullptr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ static HTMLElement* HighestAncestorToWrapMarkup(
if (!special_common_ancestor &&
IsTabHTMLSpanElementTextNode(common_ancestor)) {
special_common_ancestor =
ToHTMLSpanElement(Strategy::Parent(*common_ancestor));
To<HTMLSpanElement>(Strategy::Parent(*common_ancestor));
}
if (!special_common_ancestor && IsTabHTMLSpanElement(common_ancestor))
special_common_ancestor = ToHTMLSpanElement(common_ancestor);
special_common_ancestor = To<HTMLSpanElement>(common_ancestor);

if (auto* enclosing_anchor = To<HTMLAnchorElement>(EnclosingElementWithTag(
Position::FirstPositionInNode(special_common_ancestor
Expand Down
2 changes: 1 addition & 1 deletion third_party/blink/renderer/core/frame/smart_clip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ Node* SmartClip::FindBestOverlappingNode(Node* root_node,
bool SmartClip::ShouldSkipBackgroundImage(Node* node) {
DCHECK(node);
// Apparently we're only interested in background images on spans and divs.
if (!IsHTMLSpanElement(*node) && !IsHTMLDivElement(*node))
if (!IsA<HTMLSpanElement>(*node) && !IsHTMLDivElement(*node))
return true;

// This check actually makes a bit of sense. If you're going to sprite an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ AXObjectInclusion AXNodeObject::ShouldIncludeBasedOnSemantics(
// <span> tags are inline tags and not meant to convey information if they
// have no other ARIA information on them. If we don't ignore them, they may
// emit signals expected to come from their parent.
if (node && IsHTMLSpanElement(node)) {
if (node && IsA<HTMLSpanElement>(node)) {
if (ignored_reasons)
ignored_reasons->push_back(IgnoredReason(kAXUninteresting));
return kIgnoreObject;
Expand Down Expand Up @@ -1025,8 +1025,9 @@ bool AXNodeObject::IsInPageLinkTarget() const {
return anchor->HasName() || anchor->HasID();
}

if (element->HasID() && (IsLandmarkRelated() || IsHTMLSpanElement(element) ||
IsHTMLDivElement(element))) {
if (element->HasID() &&
(IsLandmarkRelated() || IsA<HTMLSpanElement>(element) ||
IsHTMLDivElement(element))) {
return true;
}
return false;
Expand Down

0 comments on commit 9d5550f

Please sign in to comment.