Bug 1814091 - Move CanvasContext.getPreferredFormat to GPU.getPreferredCanvasFormat...
[gecko.git] / layout / svg / SVGStopFrame.cpp
blobb6a3ab69a619f16abcca99b455f2269e4a1a1901
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 "nsContainerFrame.h"
9 #include "nsIFrame.h"
10 #include "nsGkAtoms.h"
11 #include "mozilla/ComputedStyle.h"
12 #include "mozilla/PresShell.h"
13 #include "mozilla/SVGGradientFrame.h"
14 #include "mozilla/SVGObserverUtils.h"
16 // This is a very simple frame whose only purpose is to capture style change
17 // events and propagate them to the parent. Most of the heavy lifting is done
18 // within the SVGGradientFrame, which is the parent for this frame
20 nsIFrame* NS_NewSVGStopFrame(mozilla::PresShell* aPresShell,
21 mozilla::ComputedStyle* aStyle);
23 namespace mozilla {
25 class SVGStopFrame : public nsIFrame {
26 friend nsIFrame* ::NS_NewSVGStopFrame(mozilla::PresShell* aPresShell,
27 ComputedStyle* aStyle);
29 protected:
30 explicit SVGStopFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
31 : nsIFrame(aStyle, aPresContext, kClassID) {
32 AddStateBits(NS_FRAME_SVG_LAYOUT | NS_FRAME_IS_NONDISPLAY);
35 public:
36 NS_DECL_FRAMEARENA_HELPERS(SVGStopFrame)
38 // nsIFrame interface:
39 #ifdef DEBUG
40 virtual void Init(nsIContent* aContent, nsContainerFrame* aParent,
41 nsIFrame* aPrevInFlow) override;
42 #endif
44 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
45 const nsDisplayListSet& aLists) override {}
47 virtual nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
48 int32_t aModType) override;
50 bool IsFrameOfType(uint32_t aFlags) const override {
51 if (aFlags & eSupportsContainLayoutAndPaint) {
52 return false;
55 return nsIFrame::IsFrameOfType(aFlags & ~(nsIFrame::eSVG));
58 #ifdef DEBUG_FRAME_DUMP
59 nsresult GetFrameName(nsAString& aResult) const override {
60 return MakeFrameName(u"SVGStop"_ns, aResult);
62 #endif
65 //----------------------------------------------------------------------
66 // Implementation
68 NS_IMPL_FRAMEARENA_HELPERS(SVGStopFrame)
70 //----------------------------------------------------------------------
71 // nsIFrame methods:
73 #ifdef DEBUG
74 void SVGStopFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
75 nsIFrame* aPrevInFlow) {
76 NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::stop),
77 "Content is not a stop element");
79 nsIFrame::Init(aContent, aParent, aPrevInFlow);
81 #endif /* DEBUG */
83 nsresult SVGStopFrame::AttributeChanged(int32_t aNameSpaceID,
84 nsAtom* aAttribute, int32_t aModType) {
85 if (aNameSpaceID == kNameSpaceID_None && aAttribute == nsGkAtoms::offset) {
86 MOZ_ASSERT(
87 static_cast<SVGGradientFrame*>(do_QueryFrame(GetParent())),
88 "Observers observe the gradient, so that's what we must invalidate");
89 SVGObserverUtils::InvalidateDirectRenderingObservers(GetParent());
92 return nsIFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
95 } // namespace mozilla
97 // -------------------------------------------------------------------------
98 // Public functions
99 // -------------------------------------------------------------------------
101 nsIFrame* NS_NewSVGStopFrame(mozilla::PresShell* aPresShell,
102 mozilla::ComputedStyle* aStyle) {
103 return new (aPresShell)
104 mozilla::SVGStopFrame(aStyle, aPresShell->GetPresContext());