Commit 7e7c58f3 authored by Abhijeet Kandalkar's avatar Abhijeet Kandalkar Committed by Commit Bot

Switch blink::SVGElement to use new downcast helpers (3/n)

Bug: 891908
Change-Id: I43fae34afee2c5b278cd652908eb6ff666e0020e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1608871Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Commit-Queue: Abhijeet Kandalkar <abhijeet@igalia.com>
Cr-Commit-Position: refs/heads/master@{#659141}
parent 6af5d756
......@@ -217,11 +217,11 @@ QualifiedName SvgAttributeName(const String& property) {
const QualifiedName* AnimationInputHelpers::KeyframeAttributeToSVGAttribute(
const String& property,
Element* element) {
if (!RuntimeEnabledFeatures::WebAnimationsSVGEnabled() || !element ||
!element->IsSVGElement() || !IsSVGPrefixed(property))
auto* svg_element = DynamicTo<SVGElement>(element);
if (!RuntimeEnabledFeatures::WebAnimationsSVGEnabled() || !svg_element ||
!IsSVGPrefixed(property))
return nullptr;
SVGElement* svg_element = ToSVGElement(element);
if (IsSVGSMILElement(svg_element))
return nullptr;
......
......@@ -379,9 +379,9 @@ void KeyframeEffect::ApplyEffects() {
if (changed) {
target_->SetNeedsAnimationStyleRecalc();
if (RuntimeEnabledFeatures::WebAnimationsSVGEnabled() &&
target_->IsSVGElement())
ToSVGElement(*target_).SetWebAnimationsPending();
auto* svg_element = DynamicTo<SVGElement>(target_.Get());
if (RuntimeEnabledFeatures::WebAnimationsSVGEnabled() && svg_element)
svg_element->SetWebAnimationsPending();
}
}
......@@ -393,9 +393,9 @@ void KeyframeEffect::ClearEffects() {
if (GetAnimation())
GetAnimation()->RestartAnimationOnCompositor();
target_->SetNeedsAnimationStyleRecalc();
if (RuntimeEnabledFeatures::WebAnimationsSVGEnabled() &&
target_->IsSVGElement())
ToSVGElement(*target_).ClearWebAnimatedAttributes();
auto* svg_element = DynamicTo<SVGElement>(target_.Get());
if (RuntimeEnabledFeatures::WebAnimationsSVGEnabled() && svg_element)
svg_element->ClearWebAnimatedAttributes();
Invalidate();
}
......@@ -424,9 +424,9 @@ void KeyframeEffect::AttachTarget(Animation* animation) {
return;
target_->EnsureElementAnimations().Animations().insert(animation);
target_->SetNeedsAnimationStyleRecalc();
if (RuntimeEnabledFeatures::WebAnimationsSVGEnabled() &&
target_->IsSVGElement())
ToSVGElement(target_)->SetWebAnimationsPending();
auto* svg_element = DynamicTo<SVGElement>(target_.Get());
if (RuntimeEnabledFeatures::WebAnimationsSVGEnabled() && svg_element)
svg_element->SetWebAnimationsPending();
}
void KeyframeEffect::DetachTarget(Animation* animation) {
......
......@@ -122,8 +122,8 @@ static EDisplay EquivalentBlockDisplay(EDisplay display) {
}
static bool IsOutermostSVGElement(const Element* element) {
return element && element->IsSVGElement() &&
ToSVGElement(*element).IsOutermostSVGSVGElement();
auto* svg_element = DynamicTo<SVGElement>(element);
return svg_element && svg_element->IsOutermostSVGSVGElement();
}
static bool IsAtUAShadowBoundary(const Element* element) {
......@@ -589,10 +589,10 @@ void StyleAdjuster::AdjustComputedStyle(StyleResolverState& state,
AdjustStyleForEditing(style);
bool is_svg_root = false;
bool is_svg_element = element && element->IsSVGElement();
auto* svg_element = DynamicTo<SVGElement>(element);
if (is_svg_element) {
is_svg_root = ToSVGElement(element)->IsOutermostSVGSVGElement();
if (svg_element) {
is_svg_root = svg_element->IsOutermostSVGSVGElement();
if (!is_svg_root) {
// Only the root <svg> element in an SVG document fragment tree honors css
// position.
......
......@@ -595,10 +595,11 @@ void StyleResolver::MatchAllRules(StyleResolverState& state,
}
// Now check SMIL animation override style.
if (include_smil_properties && state.GetElement()->IsSVGElement())
auto* svg_element = DynamicTo<SVGElement>(state.GetElement());
if (include_smil_properties && svg_element) {
collector.AddElementStyleProperties(
ToSVGElement(state.GetElement())->AnimatedSMILStyleProperties(),
false /* isCacheable */);
svg_element->AnimatedSMILStyleProperties(), false /* isCacheable */);
}
}
collector.FinishAddingAuthorRulesForTreeScope();
......
......@@ -554,7 +554,7 @@ void Element::SynchronizeAllAttributes() const {
SynchronizeStyleAttributeInternal();
}
if (GetElementData()->animated_svg_attributes_are_dirty_)
ToSVGElement(this)->SynchronizeAnimatedSVGAttribute(AnyQName());
To<SVGElement>(this)->SynchronizeAnimatedSVGAttribute(AnyQName());
}
inline void Element::SynchronizeAttribute(const QualifiedName& name) const {
......@@ -569,7 +569,7 @@ inline void Element::SynchronizeAttribute(const QualifiedName& name) const {
if (UNLIKELY(GetElementData()->animated_svg_attributes_are_dirty_)) {
// See comment in the AtomicString version of SynchronizeAttribute()
// also.
ToSVGElement(this)->SynchronizeAnimatedSVGAttribute(name);
To<SVGElement>(this)->SynchronizeAnimatedSVGAttribute(name);
}
}
......@@ -597,7 +597,7 @@ void Element::SynchronizeAttribute(const AtomicString& local_name) const {
// AnyQName(). This means that even if Element::SynchronizeAttribute()
// is called on all attributes, animated_svg_attributes_are_dirty_ remains
// true.
ToSVGElement(this)->SynchronizeAnimatedSVGAttribute(
To<SVGElement>(this)->SynchronizeAnimatedSVGAttribute(
QualifiedName(g_null_atom, local_name, g_null_atom));
}
}
......@@ -1223,11 +1223,12 @@ IntRect Element::BoundsInViewport() const {
// cannot use LocalToAbsoluteQuad directly with ObjectBoundingBox which is
// SVG coordinates and not HTML coordinates. Instead, use the AbsoluteQuads
// codepath below.
if (IsSVGElement() && GetLayoutObject() &&
auto* svg_element = DynamicTo<SVGElement>(this);
if (svg_element && GetLayoutObject() &&
!GetLayoutObject()->IsSVGForeignObject()) {
// Get the bounding rectangle from the SVG model.
// TODO(pdr): This should include stroke.
if (ToSVGElement(this)->IsSVGGraphicsElement())
if (svg_element->IsSVGGraphicsElement())
quads.push_back(GetLayoutObject()->LocalToAbsoluteQuad(
GetLayoutObject()->ObjectBoundingBox()));
} else {
......@@ -1293,13 +1294,14 @@ void Element::ClientQuads(Vector<FloatQuad>& quads) {
// cannot use LocalToAbsoluteQuad directly with ObjectBoundingBox which is
// SVG coordinates and not HTML coordinates. Instead, use the AbsoluteQuads
// codepath below.
if (IsSVGElement() && !element_layout_object->IsSVGRoot() &&
auto* svg_element = DynamicTo<SVGElement>(this);
if (svg_element && !element_layout_object->IsSVGRoot() &&
!element_layout_object->IsSVGForeignObject()) {
// Get the bounding rectangle from the SVG model.
// TODO(pdr): ObjectBoundingBox does not include stroke and the spec is not
// clear (see: https://github.com/w3c/svgwg/issues/339, crbug.com/529734).
// If stroke is desired, we can update this to use AbsoluteQuads, below.
if (ToSVGElement(this)->IsSVGGraphicsElement())
if (svg_element->IsSVGGraphicsElement())
quads.push_back(element_layout_object->LocalToAbsoluteQuad(
element_layout_object->ObjectBoundingBox()));
return;
......@@ -4148,8 +4150,8 @@ bool Element::HasDisplayContentsStyle() const {
bool Element::ShouldStoreComputedStyle(const ComputedStyle& style) const {
if (LayoutObjectIsNeeded(style))
return true;
if (IsSVGElement()) {
if (!ToSVGElement(*this).HasSVGParent())
if (auto* svg_element = DynamicTo<SVGElement>(this)) {
if (!svg_element->HasSVGParent())
return false;
if (IsSVGStopElement(*this))
return true;
......@@ -4677,8 +4679,8 @@ bool Element::FastAttributeLookupAllowed(const QualifiedName& name) const {
if (name == html_names::kStyleAttr)
return false;
if (IsSVGElement())
return !ToSVGElement(this)->IsAnimatableAttribute(name);
if (auto* svg_element = DynamicTo<SVGElement>(this))
return !svg_element->IsAnimatableAttribute(name);
return true;
}
......
......@@ -359,9 +359,9 @@ HeapVector<Member<EventTarget>> Event::PathInternal(ScriptState* script_state,
EventTarget* Event::currentTarget() const {
if (!current_target_)
return nullptr;
Node* node = current_target_->ToNode();
if (node && node->IsSVGElement()) {
if (SVGElement* svg_element = ToSVGElement(node)->CorrespondingElement())
if (auto* curr_svg_element =
DynamicTo<SVGElement>(current_target_->ToNode())) {
if (SVGElement* svg_element = curr_svg_element->CorrespondingElement())
return svg_element;
}
return current_target_.Get();
......
......@@ -1213,8 +1213,8 @@ void Node::SetNeedsStyleRecalc(StyleChangeType change_type,
if (IsElementNode() && HasRareData())
ToElement(*this).SetAnimationStyleChange(false);
if (IsSVGElement())
ToSVGElement(this)->SetNeedsStyleRecalcForInstances(change_type, reason);
if (auto* svg_element = DynamicTo<SVGElement>(this))
svg_element->SetNeedsStyleRecalcForInstances(change_type, reason);
}
void Node::ClearNeedsStyleRecalc() {
......
......@@ -45,7 +45,7 @@ static inline const AtomicString& LinkAttribute(const Element& element) {
if (element.IsHTMLElement())
return element.FastGetAttribute(html_names::kHrefAttr);
DCHECK(element.IsSVGElement());
return SVGURIReference::LegacyHrefString(ToSVGElement(element));
return SVGURIReference::LegacyHrefString(To<SVGElement>(element));
}
static inline LinkHash LinkHashForElement(
......
......@@ -1698,7 +1698,7 @@ AtomicString GetUrlStringFromNode(const Node& node) {
if (IsHTMLImageElement(node) || IsHTMLInputElement(node))
return To<HTMLElement>(node).getAttribute(kSrcAttr);
if (IsSVGImageElement(node))
return ToSVGElement(node).ImageSourceURL();
return To<SVGElement>(node).ImageSourceURL();
if (IsHTMLEmbedElement(node) || IsHTMLObjectElement(node) ||
IsHTMLCanvasElement(node))
return To<HTMLElement>(node).ImageSourceURL();
......
......@@ -81,9 +81,9 @@ const LayoutObject* FindTargetLayoutObject(Node*& target_node) {
layout_object = layout_object->Parent();
// Update the target node to point to the SVG root.
target_node = layout_object->GetNode();
auto* svg_element = DynamicTo<SVGElement>(target_node);
DCHECK(!target_node ||
(target_node->IsSVGElement() &&
ToSVGElement(*target_node).IsOutermostSVGSVGElement()));
(svg_element && svg_element->IsOutermostSVGSVGElement()));
return layout_object;
}
......
......@@ -30,6 +30,7 @@
#include "third_party/blink/renderer/core/svg_names.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
namespace blink {
......@@ -334,6 +335,11 @@ FloatRect ComputeSVGTransformReferenceBox(const LayoutObject&);
DEFINE_ELEMENT_TYPE_CASTS(SVGElement, IsSVGElement());
template <>
struct DowncastTraits<SVGElement> {
static bool AllowFrom(const Node& node) { return node.IsSVGElement(); }
};
template <typename T>
bool IsElementOfType(const SVGElement&);
template <>
......@@ -342,7 +348,8 @@ inline bool IsElementOfType<const SVGElement>(const SVGElement&) {
}
inline bool Node::HasTagName(const SVGQualifiedName& name) const {
return IsSVGElement() && ToSVGElement(*this).HasTagName(name);
auto* svg_element = DynamicTo<SVGElement>(this);
return svg_element && svg_element->HasTagName(name);
}
// This requires IsSVG*Element(const SVGElement&).
......@@ -353,7 +360,8 @@ inline bool Node::HasTagName(const SVGQualifiedName& name) const {
return element && Is##thisType(*element); \
} \
inline bool Is##thisType(const Node& node) { \
return node.IsSVGElement() && Is##thisType(ToSVGElement(node)); \
auto* svg_element = DynamicTo<SVGElement>(node); \
return svg_element && Is##thisType(svg_element); \
} \
inline bool Is##thisType(const Node* node) { \
return node && Is##thisType(*node); \
......
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