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/SVGObserverUtils.h"
10 #include "mozilla/dom/SVGFEImageElement.h"
11 #include "mozilla/dom/MutationEventBinding.h"
12 #include "nsContainerFrame.h"
14 #include "nsGkAtoms.h"
15 #include "nsLiteralString.h"
17 using namespace mozilla::dom
;
19 nsIFrame
* NS_NewSVGFEImageFrame(mozilla::PresShell
* aPresShell
,
20 mozilla::ComputedStyle
* aStyle
);
24 class SVGFEImageFrame final
: public nsIFrame
{
25 friend nsIFrame
* ::NS_NewSVGFEImageFrame(mozilla::PresShell
* aPresShell
,
26 ComputedStyle
* aStyle
);
29 explicit SVGFEImageFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
)
30 : nsIFrame(aStyle
, aPresContext
, kClassID
) {
31 AddStateBits(NS_FRAME_SVG_LAYOUT
| NS_FRAME_IS_NONDISPLAY
);
33 // This frame isn't actually displayed, but it contains an image and we want
34 // to use the nsImageLoadingContent machinery for managing images, which
35 // requires visibility tracking, so we enable visibility tracking and
36 // forcibly mark it visible below.
37 EnableVisibilityTracking();
41 NS_DECL_FRAMEARENA_HELPERS(SVGFEImageFrame
)
43 void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
44 nsIFrame
* aPrevInFlow
) override
;
45 void Destroy(DestroyContext
&) override
;
47 #ifdef DEBUG_FRAME_DUMP
48 nsresult
GetFrameName(nsAString
& aResult
) const override
{
49 return MakeFrameName(u
"SVGFEImage"_ns
, aResult
);
53 nsresult
AttributeChanged(int32_t aNameSpaceID
, nsAtom
* aAttribute
,
54 int32_t aModType
) override
;
56 void OnVisibilityChange(
57 Visibility aNewVisibility
,
58 const Maybe
<OnNonvisible
>& aNonvisibleAction
= Nothing()) override
;
60 bool ComputeCustomOverflow(OverflowAreas
& aOverflowAreas
) override
{
61 // We don't maintain a ink overflow rect
66 } // namespace mozilla
68 nsIFrame
* NS_NewSVGFEImageFrame(mozilla::PresShell
* aPresShell
,
69 mozilla::ComputedStyle
* aStyle
) {
70 return new (aPresShell
)
71 mozilla::SVGFEImageFrame(aStyle
, aPresShell
->GetPresContext());
76 NS_IMPL_FRAMEARENA_HELPERS(SVGFEImageFrame
)
79 void SVGFEImageFrame::Destroy(DestroyContext
& aContext
) {
80 DecApproximateVisibleCount();
82 nsCOMPtr
<nsIImageLoadingContent
> imageLoader
= do_QueryInterface(mContent
);
84 imageLoader
->FrameDestroyed(this);
87 nsIFrame::Destroy(aContext
);
90 void SVGFEImageFrame::Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
91 nsIFrame
* aPrevInFlow
) {
92 NS_ASSERTION(aContent
->IsSVGElement(nsGkAtoms::feImage
),
93 "Trying to construct an SVGFEImageFrame for a "
94 "content element that doesn't support the right interfaces");
96 nsIFrame::Init(aContent
, aParent
, aPrevInFlow
);
98 // We assume that feImage's are always visible.
99 // This call must happen before the FrameCreated. This is because the
100 // primary frame pointer on our content node isn't set until after this
101 // function ends, so there is no way for the resulting OnVisibilityChange
102 // notification to get a frame. FrameCreated has a workaround for this in
103 // that it passes our frame around so it can be accessed. OnVisibilityChange
104 // doesn't have that workaround.
105 IncApproximateVisibleCount();
107 nsCOMPtr
<nsIImageLoadingContent
> imageLoader
= do_QueryInterface(mContent
);
109 imageLoader
->FrameCreated(this);
113 nsresult
SVGFEImageFrame::AttributeChanged(int32_t aNameSpaceID
,
116 SVGFEImageElement
* element
= static_cast<SVGFEImageElement
*>(GetContent());
117 if (element
->AttributeAffectsRendering(aNameSpaceID
, aAttribute
)) {
119 GetParent()->IsSVGFilterFrame(),
120 "Observers observe the filter, so that's what we must invalidate");
121 SVGObserverUtils::InvalidateRenderingObservers(GetParent());
124 // Currently our SMIL implementation does not modify the DOM attributes. Once
125 // we implement the SVG 2 SMIL behaviour this can be removed
126 // SVGFEImageElement::AfterSetAttr's implementation will be sufficient.
127 if (aModType
== MutationEvent_Binding::SMIL
&&
128 aAttribute
== nsGkAtoms::href
&&
129 (aNameSpaceID
== kNameSpaceID_XLink
||
130 aNameSpaceID
== kNameSpaceID_None
)) {
132 element
->mStringAttributes
[SVGFEImageElement::HREF
].IsExplicitlySet() ||
133 element
->mStringAttributes
[SVGFEImageElement::XLINK_HREF
]
136 element
->LoadSVGImage(true, true);
138 element
->CancelImageRequests(true);
142 return nsIFrame::AttributeChanged(aNameSpaceID
, aAttribute
, aModType
);
145 void SVGFEImageFrame::OnVisibilityChange(
146 Visibility aNewVisibility
, const Maybe
<OnNonvisible
>& aNonvisibleAction
) {
147 nsCOMPtr
<nsIImageLoadingContent
> imageLoader
= do_QueryInterface(mContent
);
149 imageLoader
->OnVisibilityChange(aNewVisibility
, aNonvisibleAction
);
152 nsIFrame::OnVisibilityChange(aNewVisibility
, aNonvisibleAction
);
155 } // namespace mozilla