Commit 5a2e6afd authored by Fredrik Söderqvist's avatar Fredrik Söderqvist Committed by Commit Bot

Move HasValidViewBox() and HasEmptyViewBox() to SVGSVGElement

These need to take any potential view spec into account, so it makes
more sense to let them live in SVGSVGElement. Other users are trivial
and can be open-coded.

Bug: 427650
Change-Id: Ib0c9d3378cb08613356207ac3f062d66747ee14e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2510129Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#822670}
parent eceb8ae1
...@@ -64,15 +64,6 @@ SVGFitToViewBox::SVGFitToViewBox(SVGElement* element) ...@@ -64,15 +64,6 @@ SVGFitToViewBox::SVGFitToViewBox(SVGElement* element)
element->AddToPropertyMap(preserve_aspect_ratio_); element->AddToPropertyMap(preserve_aspect_ratio_);
} }
bool SVGFitToViewBox::HasValidViewBox() const {
return view_box_->CurrentValue()->IsValid();
}
bool SVGFitToViewBox::HasEmptyViewBox() const {
return view_box_->CurrentValue()->IsValid() &&
view_box_->CurrentValue()->Value().IsEmpty();
}
void SVGFitToViewBox::Trace(Visitor* visitor) const { void SVGFitToViewBox::Trace(Visitor* visitor) const {
visitor->Trace(view_box_); visitor->Trace(view_box_);
visitor->Trace(preserve_aspect_ratio_); visitor->Trace(preserve_aspect_ratio_);
......
...@@ -43,9 +43,6 @@ class SVGFitToViewBox : public GarbageCollectedMixin { ...@@ -43,9 +43,6 @@ class SVGFitToViewBox : public GarbageCollectedMixin {
static bool IsKnownAttribute(const QualifiedName&); static bool IsKnownAttribute(const QualifiedName&);
bool HasValidViewBox() const;
bool HasEmptyViewBox() const;
// JS API // JS API
SVGAnimatedRect* viewBox() const { return view_box_.Get(); } SVGAnimatedRect* viewBox() const { return view_box_.Get(); }
SVGAnimatedPreserveAspectRatio* preserveAspectRatio() const { SVGAnimatedPreserveAspectRatio* preserveAspectRatio() const {
......
...@@ -232,7 +232,7 @@ static void SetPatternAttributes(const SVGPatternElement& element, ...@@ -232,7 +232,7 @@ static void SetPatternAttributes(const SVGPatternElement& element,
if (!attributes.HasHeight() && element.height()->IsSpecified()) if (!attributes.HasHeight() && element.height()->IsSpecified())
attributes.SetHeight(element.height()->CurrentValue()); attributes.SetHeight(element.height()->CurrentValue());
if (!attributes.HasViewBox() && element.HasValidViewBox()) if (!attributes.HasViewBox() && element.viewBox()->CurrentValue()->IsValid())
attributes.SetViewBox(element.viewBox()->CurrentValue()->Value()); attributes.SetViewBox(element.viewBox()->CurrentValue()->Value());
if (!attributes.HasPreserveAspectRatio() && if (!attributes.HasPreserveAspectRatio() &&
......
...@@ -576,6 +576,15 @@ bool SVGSVGElement::SelfHasRelativeLengths() const { ...@@ -576,6 +576,15 @@ bool SVGSVGElement::SelfHasRelativeLengths() const {
height_->CurrentValue()->IsRelative(); height_->CurrentValue()->IsRelative();
} }
bool SVGSVGElement::HasValidViewBox() const {
return viewBox()->CurrentValue()->IsValid();
}
bool SVGSVGElement::HasEmptyViewBox() const {
const SVGRect* view_box = viewBox()->CurrentValue();
return view_box->IsValid() && view_box->Value().IsEmpty();
}
bool SVGSVGElement::ShouldSynthesizeViewBox() const { bool SVGSVGElement::ShouldSynthesizeViewBox() const {
return GetLayoutObject() && GetLayoutObject()->IsSVGRoot() && return GetLayoutObject() && GetLayoutObject()->IsSVGRoot() &&
ToLayoutSVGRoot(GetLayoutObject())->IsEmbeddedThroughSVGImage(); ToLayoutSVGRoot(GetLayoutObject())->IsEmbeddedThroughSVGImage();
......
...@@ -52,6 +52,7 @@ class SVGSVGElement final : public SVGGraphicsElement, ...@@ -52,6 +52,7 @@ class SVGSVGElement final : public SVGGraphicsElement,
base::Optional<float> IntrinsicHeight() const; base::Optional<float> IntrinsicHeight() const;
FloatSize CurrentViewportSize() const; FloatSize CurrentViewportSize() const;
FloatRect CurrentViewBoxRect() const; FloatRect CurrentViewBoxRect() const;
bool HasEmptyViewBox() const;
const SVGPreserveAspectRatio* CurrentPreserveAspectRatio() const; const SVGPreserveAspectRatio* CurrentPreserveAspectRatio() const;
float currentScale() const; float currentScale() const;
...@@ -131,6 +132,7 @@ class SVGSVGElement final : public SVGGraphicsElement, ...@@ -131,6 +132,7 @@ class SVGSVGElement final : public SVGGraphicsElement,
bool SelfHasRelativeLengths() const override; bool SelfHasRelativeLengths() const override;
bool HasValidViewBox() const;
bool ShouldSynthesizeViewBox() const; bool ShouldSynthesizeViewBox() const;
void UpdateUserTransform(); void UpdateUserTransform();
......
...@@ -49,7 +49,7 @@ SVGViewSpec* SVGViewSpec::CreateFromFragment(const String& fragment) { ...@@ -49,7 +49,7 @@ SVGViewSpec* SVGViewSpec::CreateFromFragment(const String& fragment) {
SVGViewSpec* SVGViewSpec::CreateForViewElement(const SVGViewElement& view) { SVGViewSpec* SVGViewSpec::CreateForViewElement(const SVGViewElement& view) {
SVGViewSpec* view_spec = MakeGarbageCollected<SVGViewSpec>(); SVGViewSpec* view_spec = MakeGarbageCollected<SVGViewSpec>();
if (view.HasValidViewBox()) if (view.viewBox()->CurrentValue()->IsValid())
view_spec->view_box_ = view.viewBox()->CurrentValue()->Clone(); view_spec->view_box_ = view.viewBox()->CurrentValue()->Clone();
if (view.preserveAspectRatio()->IsSpecified()) { if (view.preserveAspectRatio()->IsSpecified()) {
view_spec->preserve_aspect_ratio_ = view_spec->preserve_aspect_ratio_ =
......
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