Bug 1776056 - Switch to the tab an animation is running and make sure the animation...
[gecko.git] / layout / svg / SVGViewFrame.cpp
blobe7105ceb6c12d7a2abb6bba6c539834b3c19fc68
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 virtual void Init(nsIContent* aContent, nsContainerFrame* aParent,
44 nsIFrame* aPrevInFlow) override;
45 #endif
47 bool IsFrameOfType(uint32_t aFlags) const override {
48 if (aFlags & eSupportsContainLayoutAndPaint) {
49 return false;
52 return nsIFrame::IsFrameOfType(aFlags & ~(nsIFrame::eSVG));
55 #ifdef DEBUG_FRAME_DUMP
56 nsresult GetFrameName(nsAString& aResult) const override {
57 return MakeFrameName(u"SVGView"_ns, aResult);
59 #endif
61 virtual nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
62 int32_t aModType) override;
64 bool ComputeCustomOverflow(OverflowAreas& aOverflowAreas) override {
65 // We don't maintain a ink overflow rect
66 return false;
70 } // namespace mozilla
72 nsIFrame* NS_NewSVGViewFrame(mozilla::PresShell* aPresShell,
73 mozilla::ComputedStyle* aStyle) {
74 return new (aPresShell)
75 mozilla::SVGViewFrame(aStyle, aPresShell->GetPresContext());
78 namespace mozilla {
80 NS_IMPL_FRAMEARENA_HELPERS(SVGViewFrame)
82 #ifdef DEBUG
83 void SVGViewFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
84 nsIFrame* aPrevInFlow) {
85 NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::view),
86 "Content is not an SVG view");
88 nsIFrame::Init(aContent, aParent, aPrevInFlow);
90 #endif /* DEBUG */
92 nsresult SVGViewFrame::AttributeChanged(int32_t aNameSpaceID,
93 nsAtom* aAttribute, int32_t aModType) {
94 // Ignore zoomAndPan as it does not cause the <svg> element to re-render
96 if (aNameSpaceID == kNameSpaceID_None &&
97 (aAttribute == nsGkAtoms::preserveAspectRatio ||
98 aAttribute == nsGkAtoms::viewBox)) {
99 SVGOuterSVGFrame* outerSVGFrame = SVGUtils::GetOuterSVGFrame(this);
100 NS_ASSERTION(outerSVGFrame->GetContent()->IsSVGElement(nsGkAtoms::svg),
101 "Expecting an <svg> element");
103 SVGSVGElement* svgElement =
104 static_cast<SVGSVGElement*>(outerSVGFrame->GetContent());
106 nsAutoString viewID;
107 mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::id, viewID);
109 if (svgElement->IsOverriddenBy(viewID)) {
110 // We're the view that's providing overrides, so pretend that the frame
111 // we're overriding was updated.
112 outerSVGFrame->AttributeChanged(aNameSpaceID, aAttribute, aModType);
116 return nsIFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
119 } // namespace mozilla