Commit 228af0a3 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1790167 - Simplify aspect-ratio code for outer svg. r=TYLin

Drive-by, but this should be more correct, since I'm not sure how this
code would handle mSVGView otherwise, which is in effect on the relevant
page.

Differential Revision: https://phabricator.services.mozilla.com/D157022
parent 751649fc
Loading
Loading
Loading
Loading
+6 −17
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@ void SVGOuterSVGFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
  // prevent them from painting by [ab]use NS_FRAME_IS_NONDISPLAY. The
  // frame will be recreated via an nsChangeHint_ReconstructFrame restyle if
  // the value returned by PassesConditionalProcessingTests changes.
  SVGSVGElement* svg = static_cast<SVGSVGElement*>(aContent);
  auto* svg = static_cast<SVGSVGElement*>(aContent);
  if (!svg->PassesConditionalProcessingTests()) {
    AddStateBits(NS_FRAME_IS_NONDISPLAY);
  }
@@ -243,11 +243,8 @@ AspectRatio SVGOuterSVGFrame::GetIntrinsicRatio() const {
  // We only have an intrinsic size/ratio if our width and height attributes
  // are both specified and set to non-percentage values, or we have a viewBox
  // rect: https://svgwg.org/svg2-draft/coords.html#SizingSVGInCSS
  // Unfortunately we have to return the ratio as two nscoords whereas what
  // we have are two floats. Using app units allows for some floating point
  // values to work but really small or large numbers will fail.

  SVGSVGElement* content = static_cast<SVGSVGElement*>(GetContent());
  auto* content = static_cast<SVGSVGElement*>(GetContent());
  const SVGAnimatedLength& width =
      content->mLengthAttributes[SVGSVGElement::ATTR_WIDTH];
  const SVGAnimatedLength& height =
@@ -265,18 +262,10 @@ AspectRatio SVGOuterSVGFrame::GetIntrinsicRatio() const {
    }
  }

  SVGViewElement* viewElement = content->GetCurrentViewElement();
  const SVGViewBox* viewbox = nullptr;

  // The logic here should match HasViewBox().
  if (viewElement && viewElement->mViewBox.HasRect()) {
    viewbox = &viewElement->mViewBox.GetAnimValue();
  } else if (content->mViewBox.HasRect()) {
    viewbox = &content->mViewBox.GetAnimValue();
  }

  if (viewbox) {
    return AspectRatio::FromSize(viewbox->width, viewbox->height);
  const auto& viewBox = content->GetViewBoxInternal();
  if (viewBox.HasRect()) {
    const auto& anim = viewBox.GetAnimValue();
    return AspectRatio::FromSize(anim.width, anim.height);
  }

  return SVGDisplayContainerFrame::GetIntrinsicRatio();