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"
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
);
25 class SVGStopFrame
: public nsIFrame
{
26 friend nsIFrame
* ::NS_NewSVGStopFrame(mozilla::PresShell
* aPresShell
,
27 ComputedStyle
* aStyle
);
30 explicit SVGStopFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
)
31 : nsIFrame(aStyle
, aPresContext
, kClassID
) {
32 AddStateBits(NS_FRAME_SVG_LAYOUT
| NS_FRAME_IS_NONDISPLAY
);
36 NS_DECL_FRAMEARENA_HELPERS(SVGStopFrame
)
38 // nsIFrame interface:
40 virtual void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
41 nsIFrame
* aPrevInFlow
) override
;
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
) {
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
);
65 //----------------------------------------------------------------------
68 NS_IMPL_FRAMEARENA_HELPERS(SVGStopFrame
)
70 //----------------------------------------------------------------------
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
);
83 nsresult
SVGStopFrame::AttributeChanged(int32_t aNameSpaceID
,
84 nsAtom
* aAttribute
, int32_t aModType
) {
85 if (aNameSpaceID
== kNameSpaceID_None
&& aAttribute
== nsGkAtoms::offset
) {
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 // -------------------------------------------------------------------------
99 // -------------------------------------------------------------------------
101 nsIFrame
* NS_NewSVGStopFrame(mozilla::PresShell
* aPresShell
,
102 mozilla::ComputedStyle
* aStyle
) {
103 return new (aPresShell
)
104 mozilla::SVGStopFrame(aStyle
, aPresShell
->GetPresContext());