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

Use new downcast helper for blink::SVGTextContentElement

Bug: 891908
Change-Id: I6fdac09b795461c2f1de6be177b2ce141fcab529
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1715006
Commit-Queue: Abhijeet Kandalkar <abhijeet@igalia.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680459}
parent 7a85bf2d
...@@ -284,7 +284,7 @@ static bool ShouldAcceptNonElementNode(const Node& node) { ...@@ -284,7 +284,7 @@ static bool ShouldAcceptNonElementNode(const Node& node) {
// SVG text content elements has no background, and are thus not // SVG text content elements has no background, and are thus not
// hit during the background phase of hit-testing. Because of that // hit during the background phase of hit-testing. Because of that
// we need to allow any child (Text) node of these elements. // we need to allow any child (Text) node of these elements.
return IsSVGTextContentElement(*parent); return IsA<SVGTextContentElement>(parent);
} }
HeapVector<Member<Element>> TreeScope::ElementsFromHitTestResult( HeapVector<Member<Element>> TreeScope::ElementsFromHitTestResult(
......
...@@ -621,8 +621,7 @@ TEST_F(TextPaintTimingDetectorTest, CaptureSVGText) { ...@@ -621,8 +621,7 @@ TEST_F(TextPaintTimingDetectorTest, CaptureSVGText) {
</svg> </svg>
)HTML"); )HTML");
SVGTextContentElement* elem = auto* elem = To<SVGTextContentElement>(GetDocument().QuerySelector("text"));
ToSVGTextContentElement(GetDocument().QuerySelector("text"));
UpdateAllLifecyclePhasesAndSimulateSwapTime(); UpdateAllLifecyclePhasesAndSimulateSwapTime();
EXPECT_EQ(CountVisibleTexts(), 1u); EXPECT_EQ(CountVisibleTexts(), 1u);
......
...@@ -60,8 +60,7 @@ class SVGAnimatedTextLength final : public SVGAnimatedLength { ...@@ -60,8 +60,7 @@ class SVGAnimatedTextLength final : public SVGAnimatedLength {
SVGLength::Initial::kUnitlessZero) {} SVGLength::Initial::kUnitlessZero) {}
SVGLengthTearOff* baseVal() override { SVGLengthTearOff* baseVal() override {
SVGTextContentElement* text_content_element = auto* text_content_element = To<SVGTextContentElement>(ContextElement());
ToSVGTextContentElement(ContextElement());
if (!text_content_element->TextLengthIsSpecifiedByUser()) if (!text_content_element->TextLengthIsSpecifiedByUser())
BaseValue()->NewValueSpecifiedUnits( BaseValue()->NewValueSpecifiedUnits(
CSSPrimitiveValue::UnitType::kNumber, CSSPrimitiveValue::UnitType::kNumber,
...@@ -280,10 +279,8 @@ SVGTextContentElement* SVGTextContentElement::ElementFromLineLayoutItem( ...@@ -280,10 +279,8 @@ SVGTextContentElement* SVGTextContentElement::ElementFromLineLayoutItem(
(!line_layout_item.IsSVGText() && !line_layout_item.IsSVGInline())) (!line_layout_item.IsSVGText() && !line_layout_item.IsSVGInline()))
return nullptr; return nullptr;
auto* element = To<SVGElement>(line_layout_item.GetNode()); DCHECK(line_layout_item.GetNode());
DCHECK(element); return DynamicTo<SVGTextContentElement>(line_layout_item.GetNode());
return IsSVGTextContentElement(*element) ? ToSVGTextContentElement(element)
: nullptr;
} }
} // namespace blink } // namespace blink
...@@ -96,7 +96,13 @@ inline bool IsSVGTextContentElement(const SVGElement& element) { ...@@ -96,7 +96,13 @@ inline bool IsSVGTextContentElement(const SVGElement& element) {
return element.IsTextContent(); return element.IsTextContent();
} }
DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGTextContentElement); template <>
struct DowncastTraits<SVGTextContentElement> {
static bool AllowFrom(const Node& node) {
auto* svg_element = DynamicTo<SVGElement>(node);
return svg_element && IsSVGTextContentElement(*svg_element);
}
};
} // namespace blink } // namespace blink
......
...@@ -13,8 +13,7 @@ class SVGTextContentElementTest : public EditingTestBase {}; ...@@ -13,8 +13,7 @@ class SVGTextContentElementTest : public EditingTestBase {};
TEST_F(SVGTextContentElementTest, selectSubStringNotCrash) { TEST_F(SVGTextContentElementTest, selectSubStringNotCrash) {
SetBodyContent("<svg><text style='visibility:hidden;'>Text</text></svg>"); SetBodyContent("<svg><text style='visibility:hidden;'>Text</text></svg>");
SVGTextContentElement* elem = auto* elem = To<SVGTextContentElement>(GetDocument().QuerySelector("text"));
ToSVGTextContentElement(GetDocument().QuerySelector("text"));
VisiblePosition start = VisiblePosition::FirstPositionInNode( VisiblePosition start = VisiblePosition::FirstPositionInNode(
*const_cast<SVGTextContentElement*>(elem)); *const_cast<SVGTextContentElement*>(elem));
EXPECT_TRUE(start.IsNull()); EXPECT_TRUE(start.IsNull());
......
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