Commit f2ed958b authored by Abhijeet Kandalkar's avatar Abhijeet Kandalkar Committed by Commit Bot

Use new downcast helper for blink::HTMLQuoteElement

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

Bug: 891908
Change-Id: Ie3908bdfd769857c8bc6332a5fbd794bc13b6884
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1930544Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Commit-Queue: Abhijeet | Igalia <abhijeet@igalia.com>
Cr-Commit-Position: refs/heads/master@{#719504}
parent 53fae989
......@@ -83,7 +83,7 @@ static HTMLQuoteElement* TopBlockquoteOf(const Position& start) {
// |position| will be in the first node that we need to move (there are a few
// exceptions to this, see |doApply|).
const Position& position = MostForwardCaretPosition(start);
return ToHTMLQuoteElement(
return To<HTMLQuoteElement>(
HighestEnclosingNodeOfType(position, IsMailHTMLBlockquoteElement));
}
......@@ -172,7 +172,7 @@ void BreakBlockquoteCommand::DoApply(EditingState* editing_state) {
// Adjust the position so we don't split at the beginning of a quote.
while (IsFirstVisiblePositionInNode(CreateVisiblePosition(pos),
ToHTMLQuoteElement(EnclosingNodeOfType(
To<HTMLQuoteElement>(EnclosingNodeOfType(
pos, IsMailHTMLBlockquoteElement)))) {
pos = PreviousPositionOf(pos, PositionMoveType::kGraphemeCluster);
}
......
......@@ -1772,9 +1772,8 @@ bool CompositeEditCommand::BreakOutOfEmptyMailBlockquotedParagraph(
GetDocument().UpdateStyleAndLayout();
VisiblePosition caret = EndingVisibleSelection().VisibleStart();
HTMLQuoteElement* highest_blockquote =
ToHTMLQuoteElement(HighestEnclosingNodeOfType(
caret.DeepEquivalent(), &IsMailHTMLBlockquoteElement));
auto* highest_blockquote = To<HTMLQuoteElement>(HighestEnclosingNodeOfType(
caret.DeepEquivalent(), &IsMailHTMLBlockquoteElement));
if (!highest_blockquote)
return false;
......
......@@ -305,8 +305,8 @@ void InsertParagraphSeparatorCommand::DoApply(EditingState* editing_state) {
// then don't want the newline within the blockquote or else it will also
// be quoted.
if (paste_blockquote_into_unquoted_area_) {
if (HTMLQuoteElement* highest_blockquote =
ToHTMLQuoteElement(HighestEnclosingNodeOfType(
if (auto* highest_blockquote =
To<HTMLQuoteElement>(HighestEnclosingNodeOfType(
canonical_pos, &IsMailHTMLBlockquoteElement)))
start_block = highest_blockquote;
}
......
......@@ -598,10 +598,10 @@ void ReplaceSelectionCommand::RemoveRedundantStylesAndKeepStyleSpanInline(
// you're pasting into a quoted region, styles from blockquoteNode are
// allowed to override those from the source document, see
// <rdar://problem/4930986> and <rdar://problem/5089327>.
HTMLQuoteElement* blockquote_element =
auto* blockquote_element =
!context
? ToHTMLQuoteElement(context)
: ToHTMLQuoteElement(EnclosingNodeOfType(
? To<HTMLQuoteElement>(context)
: To<HTMLQuoteElement>(EnclosingNodeOfType(
Position::FirstPositionInNode(*context),
IsMailHTMLBlockquoteElement, kCanCrossEditingBoundary));
......
......@@ -207,8 +207,8 @@ static HTMLElement* HighestAncestorToWrapMarkup(
// Retain the Mail quote level by including all ancestor mail block
// quotes.
if (HTMLQuoteElement* highest_mail_blockquote =
ToHTMLQuoteElement(HighestEnclosingNodeOfType(
if (auto* highest_mail_blockquote =
To<HTMLQuoteElement>(HighestEnclosingNodeOfType(
first_node_position, IsMailHTMLBlockquoteElement,
kCanCrossEditingBoundary))) {
special_common_ancestor = highest_mail_blockquote;
......
......@@ -46,7 +46,25 @@ inline bool IsHTMLQuoteElement(const HTMLElement& element) {
element.HasTagName(html_names::kBlockquoteTag);
}
DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLQuoteElement);
template <>
struct DowncastTraits<HTMLQuoteElement> {
static bool AllowFrom(const HTMLElement& element) {
return IsHTMLQuoteElement(element);
}
static bool AllowFrom(const HTMLElement* element) {
return element && IsHTMLQuoteElement(*element);
}
static bool AllowFrom(const Node& node) {
auto* html_element = DynamicTo<HTMLElement>(node);
return html_element ? IsHTMLQuoteElement(*html_element) : false;
}
static bool AllowFrom(const Node* node) {
return node && IsA<HTMLQuoteElement>(*node);
}
static bool AllowFrom(const Element* element) {
return element && IsA<HTMLQuoteElement>(*element);
}
};
} // 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