|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 // Keep in (case-insensitive) order: |
|
7 #include "nsContentUtils.h" |
|
8 #include "nsFrame.h" |
|
9 #include "nsGkAtoms.h" |
|
10 #include "nsLiteralString.h" |
|
11 #include "nsSVGEffects.h" |
|
12 #include "nsSVGFilters.h" |
|
13 #include "mozilla/dom/SVGFEImageElement.h" |
|
14 |
|
15 using namespace mozilla; |
|
16 using namespace mozilla::dom; |
|
17 |
|
18 typedef nsFrame SVGFEImageFrameBase; |
|
19 |
|
20 class SVGFEImageFrame : public SVGFEImageFrameBase |
|
21 { |
|
22 friend nsIFrame* |
|
23 NS_NewSVGFEImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
|
24 protected: |
|
25 SVGFEImageFrame(nsStyleContext* aContext) |
|
26 : SVGFEImageFrameBase(aContext) |
|
27 { |
|
28 AddStateBits(NS_FRAME_SVG_LAYOUT | NS_FRAME_IS_NONDISPLAY); |
|
29 } |
|
30 |
|
31 public: |
|
32 NS_DECL_FRAMEARENA_HELPERS |
|
33 |
|
34 virtual void Init(nsIContent* aContent, |
|
35 nsIFrame* aParent, |
|
36 nsIFrame* aPrevInFlow) MOZ_OVERRIDE; |
|
37 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; |
|
38 |
|
39 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE |
|
40 { |
|
41 return SVGFEImageFrameBase::IsFrameOfType(aFlags & ~(nsIFrame::eSVG)); |
|
42 } |
|
43 |
|
44 #ifdef DEBUG_FRAME_DUMP |
|
45 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE |
|
46 { |
|
47 return MakeFrameName(NS_LITERAL_STRING("SVGFEImage"), aResult); |
|
48 } |
|
49 #endif |
|
50 |
|
51 /** |
|
52 * Get the "type" of the frame |
|
53 * |
|
54 * @see nsGkAtoms::svgFEImageFrame |
|
55 */ |
|
56 virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
|
57 |
|
58 virtual nsresult AttributeChanged(int32_t aNameSpaceID, |
|
59 nsIAtom* aAttribute, |
|
60 int32_t aModType) MOZ_OVERRIDE; |
|
61 |
|
62 virtual bool UpdateOverflow() MOZ_OVERRIDE { |
|
63 // We don't maintain a visual overflow rect |
|
64 return false; |
|
65 } |
|
66 }; |
|
67 |
|
68 nsIFrame* |
|
69 NS_NewSVGFEImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) |
|
70 { |
|
71 return new (aPresShell) SVGFEImageFrame(aContext); |
|
72 } |
|
73 |
|
74 NS_IMPL_FRAMEARENA_HELPERS(SVGFEImageFrame) |
|
75 |
|
76 /* virtual */ void |
|
77 SVGFEImageFrame::DestroyFrom(nsIFrame* aDestructRoot) |
|
78 { |
|
79 nsCOMPtr<nsIImageLoadingContent> imageLoader = |
|
80 do_QueryInterface(SVGFEImageFrameBase::mContent); |
|
81 |
|
82 if (imageLoader) { |
|
83 imageLoader->FrameDestroyed(this); |
|
84 imageLoader->DecrementVisibleCount(); |
|
85 } |
|
86 |
|
87 SVGFEImageFrameBase::DestroyFrom(aDestructRoot); |
|
88 } |
|
89 |
|
90 void |
|
91 SVGFEImageFrame::Init(nsIContent* aContent, |
|
92 nsIFrame* aParent, |
|
93 nsIFrame* aPrevInFlow) |
|
94 { |
|
95 NS_ASSERTION(aContent->IsSVG(nsGkAtoms::feImage), |
|
96 "Trying to construct an SVGFEImageFrame for a " |
|
97 "content element that doesn't support the right interfaces"); |
|
98 |
|
99 SVGFEImageFrameBase::Init(aContent, aParent, aPrevInFlow); |
|
100 nsCOMPtr<nsIImageLoadingContent> imageLoader = |
|
101 do_QueryInterface(SVGFEImageFrameBase::mContent); |
|
102 |
|
103 if (imageLoader) { |
|
104 // We assume that feImage's are always visible. |
|
105 // Increment the visible count before calling FrameCreated so that |
|
106 // FrameCreated will actually track the image correctly. |
|
107 imageLoader->IncrementVisibleCount(); |
|
108 imageLoader->FrameCreated(this); |
|
109 } |
|
110 } |
|
111 |
|
112 nsIAtom * |
|
113 SVGFEImageFrame::GetType() const |
|
114 { |
|
115 return nsGkAtoms::svgFEImageFrame; |
|
116 } |
|
117 |
|
118 nsresult |
|
119 SVGFEImageFrame::AttributeChanged(int32_t aNameSpaceID, |
|
120 nsIAtom* aAttribute, |
|
121 int32_t aModType) |
|
122 { |
|
123 SVGFEImageElement *element = static_cast<SVGFEImageElement*>(mContent); |
|
124 if (element->AttributeAffectsRendering(aNameSpaceID, aAttribute)) { |
|
125 nsSVGEffects::InvalidateRenderingObservers(this); |
|
126 } |
|
127 if (aNameSpaceID == kNameSpaceID_XLink && |
|
128 aAttribute == nsGkAtoms::href) { |
|
129 |
|
130 // Prevent setting image.src by exiting early |
|
131 if (nsContentUtils::IsImageSrcSetDisabled()) { |
|
132 return NS_OK; |
|
133 } |
|
134 |
|
135 if (element->mStringAttributes[SVGFEImageElement::HREF].IsExplicitlySet()) { |
|
136 element->LoadSVGImage(true, true); |
|
137 } else { |
|
138 element->CancelImageRequests(true); |
|
139 } |
|
140 } |
|
141 |
|
142 return SVGFEImageFrameBase::AttributeChanged(aNameSpaceID, |
|
143 aAttribute, aModType); |
|
144 } |