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

Use new downcast helper for blink::SVGGraphicsElement

Bug: 891908
Change-Id: Id65e5d833e4ccf16df6fa5c15f321b7bd38becb7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1710599
Commit-Queue: Abhijeet Kandalkar <abhijeet@igalia.com>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#679949}
parent afe319c7
...@@ -60,7 +60,7 @@ void LayoutSVGPath::UpdateMarkers() { ...@@ -60,7 +60,7 @@ void LayoutSVGPath::UpdateMarkers() {
marker_positions_.clear(); marker_positions_.clear();
if (!StyleRef().SvgStyle().HasMarkers() || if (!StyleRef().SvgStyle().HasMarkers() ||
!SVGResources::SupportsMarkers(*ToSVGGraphicsElement(GetElement()))) !SVGResources::SupportsMarkers(*To<SVGGraphicsElement>(GetElement())))
return; return;
SVGResources* resources = SVGResources* resources =
......
...@@ -84,9 +84,10 @@ ClipStrategy DetermineClipStrategy(const SVGElement& element) { ...@@ -84,9 +84,10 @@ ClipStrategy DetermineClipStrategy(const SVGElement& element) {
return ModifyStrategyForClipPath(use_layout_object->StyleRef(), return ModifyStrategyForClipPath(use_layout_object->StyleRef(),
shape_strategy); shape_strategy);
} }
if (!element.IsSVGGraphicsElement()) auto* svg_graphics_element = DynamicTo<SVGGraphicsElement>(element);
if (!svg_graphics_element)
return ClipStrategy::kNone; return ClipStrategy::kNone;
return DetermineClipStrategy(ToSVGGraphicsElement(element)); return DetermineClipStrategy(*svg_graphics_element);
} }
bool ContributesToClip(const SVGElement& element) { bool ContributesToClip(const SVGElement& element) {
......
...@@ -235,7 +235,7 @@ static inline bool TransformDependsOnReferenceBox(const ComputedStyle& style) { ...@@ -235,7 +235,7 @@ static inline bool TransformDependsOnReferenceBox(const ComputedStyle& style) {
} }
bool LayoutSVGShape::UpdateLocalTransform() { bool LayoutSVGShape::UpdateLocalTransform() {
SVGGraphicsElement* graphics_element = ToSVGGraphicsElement(GetElement()); auto* graphics_element = To<SVGGraphicsElement>(GetElement());
if (graphics_element->HasTransform(SVGElement::kIncludeMotionTransform)) { if (graphics_element->HasTransform(SVGElement::kIncludeMotionTransform)) {
local_transform_.SetTransform(graphics_element->CalculateTransform( local_transform_.SetTransform(graphics_element->CalculateTransform(
SVGElement::kIncludeMotionTransform)); SVGElement::kIncludeMotionTransform));
......
...@@ -39,10 +39,9 @@ size_t ResizeObservation::TargetDepth() { ...@@ -39,10 +39,9 @@ size_t ResizeObservation::TargetDepth() {
LayoutSize ResizeObservation::ComputeTargetSize() const { LayoutSize ResizeObservation::ComputeTargetSize() const {
if (target_) { if (target_) {
if (LayoutObject* layout_object = target_->GetLayoutObject()) { if (LayoutObject* layout_object = target_->GetLayoutObject()) {
auto* svg_element = DynamicTo<SVGElement>(target_.Get()); if (auto* svg_graphics_element =
if (svg_element && svg_element->IsSVGGraphicsElement()) { DynamicTo<SVGGraphicsElement>(target_.Get())) {
SVGGraphicsElement& svg = ToSVGGraphicsElement(*target_); return LayoutSize(svg_graphics_element->GetBBox().Size());
return LayoutSize(svg.GetBBox().Size());
} }
if (layout_object->IsBox()) if (layout_object->IsBox())
return ToLayoutBox(layout_object)->ContentSize(); return ToLayoutBox(layout_object)->ContentSize();
......
...@@ -91,6 +91,14 @@ inline bool IsSVGGraphicsElement(const SVGElement& element) { ...@@ -91,6 +91,14 @@ inline bool IsSVGGraphicsElement(const SVGElement& element) {
return element.IsSVGGraphicsElement(); return element.IsSVGGraphicsElement();
} }
template <>
struct DowncastTraits<SVGGraphicsElement> {
static bool AllowFrom(const Node& node) {
auto* svg_element = DynamicTo<SVGElement>(node);
return svg_element && IsSVGGraphicsElement(*svg_element);
}
};
DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGGraphicsElement); DEFINE_SVGELEMENT_TYPE_CASTS_WITH_FUNCTION(SVGGraphicsElement);
} // namespace blink } // namespace blink
......
...@@ -323,7 +323,7 @@ bool SVGSVGElement::CheckIntersectionOrEnclosure( ...@@ -323,7 +323,7 @@ bool SVGSVGElement::CheckIntersectionOrEnclosure(
return false; return false;
AffineTransform ctm = AffineTransform ctm =
ToSVGGraphicsElement(element).ComputeCTM(kAncestorScope, this); To<SVGGraphicsElement>(element).ComputeCTM(kAncestorScope, this);
FloatRect mapped_repaint_rect = FloatRect mapped_repaint_rect =
ctm.MapRect(layout_object->VisualRectInLocalSVGCoordinates()); ctm.MapRect(layout_object->VisualRectInLocalSVGCoordinates());
......
...@@ -499,23 +499,21 @@ Path SVGUseElement::ToClipPath() const { ...@@ -499,23 +499,21 @@ Path SVGUseElement::ToClipPath() const {
SVGGraphicsElement* SVGUseElement::VisibleTargetGraphicsElementForClipping() SVGGraphicsElement* SVGUseElement::VisibleTargetGraphicsElementForClipping()
const { const {
auto* element = DynamicTo<SVGElement>(UseShadowRoot().firstChild()); auto* svg_graphics_element =
if (!element) DynamicTo<SVGGraphicsElement>(UseShadowRoot().firstChild());
return nullptr; if (!svg_graphics_element)
if (!element->IsSVGGraphicsElement())
return nullptr; return nullptr;
// Spec: "If a <use> element is a child of a clipPath element, it must // Spec: "If a <use> element is a child of a clipPath element, it must
// directly reference <path>, <text> or basic shapes elements. Indirect // directly reference <path>, <text> or basic shapes elements. Indirect
// references are an error and the clipPath element must be ignored." // references are an error and the clipPath element must be ignored."
// https://drafts.fxtf.org/css-masking/#the-clip-path // https://drafts.fxtf.org/css-masking/#the-clip-path
if (!IsDirectReference(*element)) { if (!IsDirectReference(*svg_graphics_element)) {
// Spec: Indirect references are an error (14.3.5) // Spec: Indirect references are an error (14.3.5)
return nullptr; return nullptr;
} }
return &ToSVGGraphicsElement(*element); return svg_graphics_element;
} }
void SVGUseElement::AddReferencesToFirstDegreeNestedUseElements( void SVGUseElement::AddReferencesToFirstDegreeNestedUseElements(
......
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