Bug 1858915 [wpt PR 42525] - Use taskcluster-run in infra tests, a=testonly
[gecko.git] / layout / svg / SVGFEImageFrame.cpp
blob5ee4f8558deb0b4ccd3d92a0b8df2acfbb69db5d
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"
13 #include "nsIFrame.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);
22 namespace mozilla {
24 class SVGFEImageFrame final : public nsIFrame {
25 friend nsIFrame* ::NS_NewSVGFEImageFrame(mozilla::PresShell* aPresShell,
26 ComputedStyle* aStyle);
28 protected:
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();
40 public:
41 NS_DECL_FRAMEARENA_HELPERS(SVGFEImageFrame)
43 void Init(nsIContent* aContent, nsContainerFrame* aParent,
44 nsIFrame* aPrevInFlow) override;
45 void Destroy(DestroyContext&) override;
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"SVGFEImage"_ns, aResult);
59 #endif
61 nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
62 int32_t aModType) override;
64 void OnVisibilityChange(
65 Visibility aNewVisibility,
66 const Maybe<OnNonvisible>& aNonvisibleAction = Nothing()) override;
68 bool ComputeCustomOverflow(OverflowAreas& aOverflowAreas) override {
69 // We don't maintain a ink overflow rect
70 return false;
74 } // namespace mozilla
76 nsIFrame* NS_NewSVGFEImageFrame(mozilla::PresShell* aPresShell,
77 mozilla::ComputedStyle* aStyle) {
78 return new (aPresShell)
79 mozilla::SVGFEImageFrame(aStyle, aPresShell->GetPresContext());
82 namespace mozilla {
84 NS_IMPL_FRAMEARENA_HELPERS(SVGFEImageFrame)
86 /* virtual */
87 void SVGFEImageFrame::Destroy(DestroyContext& aContext) {
88 DecApproximateVisibleCount();
90 nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
91 if (imageLoader) {
92 imageLoader->FrameDestroyed(this);
95 nsIFrame::Destroy(aContext);
98 void SVGFEImageFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
99 nsIFrame* aPrevInFlow) {
100 NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::feImage),
101 "Trying to construct an SVGFEImageFrame for a "
102 "content element that doesn't support the right interfaces");
104 nsIFrame::Init(aContent, aParent, aPrevInFlow);
106 // We assume that feImage's are always visible.
107 // This call must happen before the FrameCreated. This is because the
108 // primary frame pointer on our content node isn't set until after this
109 // function ends, so there is no way for the resulting OnVisibilityChange
110 // notification to get a frame. FrameCreated has a workaround for this in
111 // that it passes our frame around so it can be accessed. OnVisibilityChange
112 // doesn't have that workaround.
113 IncApproximateVisibleCount();
115 nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
116 if (imageLoader) {
117 imageLoader->FrameCreated(this);
121 nsresult SVGFEImageFrame::AttributeChanged(int32_t aNameSpaceID,
122 nsAtom* aAttribute,
123 int32_t aModType) {
124 SVGFEImageElement* element = static_cast<SVGFEImageElement*>(GetContent());
125 if (element->AttributeAffectsRendering(aNameSpaceID, aAttribute)) {
126 MOZ_ASSERT(
127 GetParent()->IsSVGFilterFrame(),
128 "Observers observe the filter, so that's what we must invalidate");
129 SVGObserverUtils::InvalidateRenderingObservers(GetParent());
132 // Currently our SMIL implementation does not modify the DOM attributes. Once
133 // we implement the SVG 2 SMIL behaviour this can be removed
134 // SVGFEImageElement::AfterSetAttr's implementation will be sufficient.
135 if (aModType == MutationEvent_Binding::SMIL &&
136 aAttribute == nsGkAtoms::href &&
137 (aNameSpaceID == kNameSpaceID_XLink ||
138 aNameSpaceID == kNameSpaceID_None)) {
139 bool hrefIsSet =
140 element->mStringAttributes[SVGFEImageElement::HREF].IsExplicitlySet() ||
141 element->mStringAttributes[SVGFEImageElement::XLINK_HREF]
142 .IsExplicitlySet();
143 if (hrefIsSet) {
144 element->LoadSVGImage(true, true);
145 } else {
146 element->CancelImageRequests(true);
150 return nsIFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
153 void SVGFEImageFrame::OnVisibilityChange(
154 Visibility aNewVisibility, const Maybe<OnNonvisible>& aNonvisibleAction) {
155 nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
156 if (imageLoader) {
157 imageLoader->OnVisibilityChange(aNewVisibility, aNonvisibleAction);
160 nsIFrame::OnVisibilityChange(aNewVisibility, aNonvisibleAction);
163 } // namespace mozilla