Backed out 2 changesets (bug 1733498) for causing perma Localised repacks build busta...
[gecko.git] / layout / svg / SVGViewFrame.cpp
blobfbef5d356964b76b591ebcf5099141d112a31dcc
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 // Keep in (case-insensitive) order:
8 #include "mozilla/PresShell.h"
9 #include "mozilla/SVGOuterSVGFrame.h"
10 #include "mozilla/SVGUtils.h"
11 #include "mozilla/dom/SVGSVGElement.h"
12 #include "mozilla/dom/SVGViewElement.h"
13 #include "nsIFrame.h"
14 #include "nsGkAtoms.h"
16 using namespace mozilla::dom;
18 nsIFrame* NS_NewSVGViewFrame(mozilla::PresShell* aPresShell,
19 mozilla::ComputedStyle* aStyle);
21 namespace mozilla {
23 /**
24 * While views are not directly rendered in SVG they can be linked to
25 * and thereby override attributes of an <svg> element via a fragment
26 * identifier. The SVGViewFrame class passes on any attribute changes
27 * the view receives to the overridden <svg> element (if there is one).
28 **/
29 class SVGViewFrame final : public nsIFrame {
30 friend nsIFrame* ::NS_NewSVGViewFrame(mozilla::PresShell* aPresShell,
31 ComputedStyle* aStyle);
33 protected:
34 explicit SVGViewFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
35 : nsIFrame(aStyle, aPresContext, kClassID) {
36 AddStateBits(NS_FRAME_SVG_LAYOUT | NS_FRAME_IS_NONDISPLAY);
39 public:
40 NS_DECL_FRAMEARENA_HELPERS(SVGViewFrame)
42 #ifdef DEBUG
43 void Init(nsIContent* aContent, nsContainerFrame* aParent,
44 nsIFrame* aPrevInFlow) override;
45 #endif
47 #ifdef DEBUG_FRAME_DUMP
48 nsresult GetFrameName(nsAString& aResult) const override {
49 return MakeFrameName(u"SVGView"_ns, aResult);
51 #endif
53 nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
54 int32_t aModType) override;
56 bool ComputeCustomOverflow(OverflowAreas& aOverflowAreas) override {
57 // We don't maintain a ink overflow rect
58 return false;
62 } // namespace mozilla
64 nsIFrame* NS_NewSVGViewFrame(mozilla::PresShell* aPresShell,
65 mozilla::ComputedStyle* aStyle) {
66 return new (aPresShell)
67 mozilla::SVGViewFrame(aStyle, aPresShell->GetPresContext());
70 namespace mozilla {
72 NS_IMPL_FRAMEARENA_HELPERS(SVGViewFrame)
74 #ifdef DEBUG
75 void SVGViewFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
76 nsIFrame* aPrevInFlow) {
77 NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::view),
78 "Content is not an SVG view");
80 nsIFrame::Init(aContent, aParent, aPrevInFlow);
82 #endif /* DEBUG */
84 nsresult SVGViewFrame::AttributeChanged(int32_t aNameSpaceID,
85 nsAtom* aAttribute, int32_t aModType) {
86 // Ignore zoomAndPan as it does not cause the <svg> element to re-render
88 if (aNameSpaceID == kNameSpaceID_None &&
89 (aAttribute == nsGkAtoms::preserveAspectRatio ||
90 aAttribute == nsGkAtoms::viewBox)) {
91 SVGOuterSVGFrame* outerSVGFrame = SVGUtils::GetOuterSVGFrame(this);
92 NS_ASSERTION(outerSVGFrame->GetContent()->IsSVGElement(nsGkAtoms::svg),
93 "Expecting an <svg> element");
95 SVGSVGElement* svgElement =
96 static_cast<SVGSVGElement*>(outerSVGFrame->GetContent());
98 nsAutoString viewID;
99 mContent->AsElement()->GetAttr(nsGkAtoms::id, viewID);
101 if (svgElement->IsOverriddenBy(viewID)) {
102 // We're the view that's providing overrides, so pretend that the frame
103 // we're overriding was updated.
104 outerSVGFrame->AttributeChanged(aNameSpaceID, aAttribute, aModType);
108 return nsIFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
111 } // namespace mozilla