Bug 1859059 - increase chunk number for windows debug mochitest-browser-chrome jobs...
[gecko.git] / layout / svg / SVGFEImageFrame.cpp
blob1cfe788d89bf3f7e7edc01c34427f2b7cb005f38
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 virtual 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 virtual 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 =
91 do_QueryInterface(nsIFrame::mContent);
92 if (imageLoader) {
93 imageLoader->FrameDestroyed(this);
96 nsIFrame::Destroy(aContext);
99 void SVGFEImageFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
100 nsIFrame* aPrevInFlow) {
101 NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::feImage),
102 "Trying to construct an SVGFEImageFrame for a "
103 "content element that doesn't support the right interfaces");
105 nsIFrame::Init(aContent, aParent, aPrevInFlow);
107 // We assume that feImage's are always visible.
108 // This call must happen before the FrameCreated. This is because the
109 // primary frame pointer on our content node isn't set until after this
110 // function ends, so there is no way for the resulting OnVisibilityChange
111 // notification to get a frame. FrameCreated has a workaround for this in
112 // that it passes our frame around so it can be accessed. OnVisibilityChange
113 // doesn't have that workaround.
114 IncApproximateVisibleCount();
116 nsCOMPtr<nsIImageLoadingContent> imageLoader =
117 do_QueryInterface(nsIFrame::mContent);
118 if (imageLoader) {
119 imageLoader->FrameCreated(this);
123 nsresult SVGFEImageFrame::AttributeChanged(int32_t aNameSpaceID,
124 nsAtom* aAttribute,
125 int32_t aModType) {
126 SVGFEImageElement* element = static_cast<SVGFEImageElement*>(GetContent());
127 if (element->AttributeAffectsRendering(aNameSpaceID, aAttribute)) {
128 MOZ_ASSERT(
129 GetParent()->IsSVGFilterFrame(),
130 "Observers observe the filter, so that's what we must invalidate");
131 SVGObserverUtils::InvalidateRenderingObservers(GetParent());
134 // Currently our SMIL implementation does not modify the DOM attributes. Once
135 // we implement the SVG 2 SMIL behaviour this can be removed
136 // SVGFEImageElement::AfterSetAttr's implementation will be sufficient.
137 if (aModType == MutationEvent_Binding::SMIL &&
138 aAttribute == nsGkAtoms::href &&
139 (aNameSpaceID == kNameSpaceID_XLink ||
140 aNameSpaceID == kNameSpaceID_None)) {
141 bool hrefIsSet =
142 element->mStringAttributes[SVGFEImageElement::HREF].IsExplicitlySet() ||
143 element->mStringAttributes[SVGFEImageElement::XLINK_HREF]
144 .IsExplicitlySet();
145 if (hrefIsSet) {
146 element->LoadSVGImage(true, true);
147 } else {
148 element->CancelImageRequests(true);
152 return nsIFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
155 void SVGFEImageFrame::OnVisibilityChange(
156 Visibility aNewVisibility, const Maybe<OnNonvisible>& aNonvisibleAction) {
157 nsCOMPtr<nsIImageLoadingContent> imageLoader =
158 do_QueryInterface(nsIFrame::mContent);
159 if (!imageLoader) {
160 MOZ_ASSERT_UNREACHABLE("Should have an nsIImageLoadingContent");
161 nsIFrame::OnVisibilityChange(aNewVisibility, aNonvisibleAction);
162 return;
165 imageLoader->OnVisibilityChange(aNewVisibility, aNonvisibleAction);
167 nsIFrame::OnVisibilityChange(aNewVisibility, aNonvisibleAction);
170 } // namespace mozilla