/src/mozilla-central/layout/svg/nsSVGUseFrame.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "nsSVGUseFrame.h" |
8 | | |
9 | | #include "mozilla/dom/SVGUseElement.h" |
10 | | #include "SVGObserverUtils.h" |
11 | | |
12 | | using namespace mozilla; |
13 | | using namespace mozilla::dom; |
14 | | |
15 | | //---------------------------------------------------------------------- |
16 | | // Implementation |
17 | | |
18 | | nsIFrame* |
19 | | NS_NewSVGUseFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle) |
20 | 0 | { |
21 | 0 | return new (aPresShell) nsSVGUseFrame(aStyle); |
22 | 0 | } |
23 | | |
24 | | NS_IMPL_FRAMEARENA_HELPERS(nsSVGUseFrame) |
25 | | |
26 | | //---------------------------------------------------------------------- |
27 | | // nsIFrame methods: |
28 | | |
29 | | void |
30 | | nsSVGUseFrame::Init(nsIContent* aContent, |
31 | | nsContainerFrame* aParent, |
32 | | nsIFrame* aPrevInFlow) |
33 | 0 | { |
34 | 0 | NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::use), |
35 | 0 | "Content is not an SVG use!"); |
36 | 0 |
|
37 | 0 | mHasValidDimensions = |
38 | 0 | static_cast<SVGUseElement*>(aContent)->HasValidDimensions(); |
39 | 0 |
|
40 | 0 | nsSVGGFrame::Init(aContent, aParent, aPrevInFlow); |
41 | 0 | } |
42 | | |
43 | | nsresult |
44 | | nsSVGUseFrame::AttributeChanged(int32_t aNameSpaceID, |
45 | | nsAtom* aAttribute, |
46 | | int32_t aModType) |
47 | 0 | { |
48 | 0 | auto* useElement = static_cast<SVGUseElement*>(GetContent()); |
49 | 0 |
|
50 | 0 | if (aNameSpaceID == kNameSpaceID_None) { |
51 | 0 | if (aAttribute == nsGkAtoms::x || aAttribute == nsGkAtoms::y) { |
52 | 0 | // make sure our cached transform matrix gets (lazily) updated |
53 | 0 | mCanvasTM = nullptr; |
54 | 0 | nsLayoutUtils::PostRestyleEvent( |
55 | 0 | useElement, nsRestyleHint(0), |
56 | 0 | nsChangeHint_InvalidateRenderingObservers); |
57 | 0 | nsSVGUtils::ScheduleReflowSVG(this); |
58 | 0 | nsSVGUtils::NotifyChildrenOfSVGChange(this, TRANSFORM_CHANGED); |
59 | 0 | } else if (aAttribute == nsGkAtoms::width || |
60 | 0 | aAttribute == nsGkAtoms::height) { |
61 | 0 | bool invalidate = false; |
62 | 0 | if (mHasValidDimensions != useElement->HasValidDimensions()) { |
63 | 0 | mHasValidDimensions = !mHasValidDimensions; |
64 | 0 | invalidate = true; |
65 | 0 | } |
66 | 0 |
|
67 | 0 | // FIXME(emilio): This shouldn't really belong to nsSVGUseFrame, but |
68 | 0 | // SVGUseElement. |
69 | 0 | if (useElement->OurWidthAndHeightAreUsed()) { |
70 | 0 | invalidate = true; |
71 | 0 | useElement->SyncWidthOrHeight(aAttribute); |
72 | 0 | } |
73 | 0 |
|
74 | 0 | if (invalidate) { |
75 | 0 | nsLayoutUtils::PostRestyleEvent( |
76 | 0 | useElement, nsRestyleHint(0), |
77 | 0 | nsChangeHint_InvalidateRenderingObservers); |
78 | 0 | nsSVGUtils::ScheduleReflowSVG(this); |
79 | 0 | } |
80 | 0 | } |
81 | 0 | } |
82 | 0 |
|
83 | 0 | if ((aNameSpaceID == kNameSpaceID_XLink || |
84 | 0 | aNameSpaceID == kNameSpaceID_None) && |
85 | 0 | aAttribute == nsGkAtoms::href) { |
86 | 0 | // we're changing our nature, clear out the clone information |
87 | 0 | nsLayoutUtils::PostRestyleEvent( |
88 | 0 | useElement, nsRestyleHint(0), |
89 | 0 | nsChangeHint_InvalidateRenderingObservers); |
90 | 0 | nsSVGUtils::ScheduleReflowSVG(this); |
91 | 0 | useElement->mOriginal = nullptr; |
92 | 0 | useElement->UnlinkSource(); |
93 | 0 | useElement->TriggerReclone(); |
94 | 0 | } |
95 | 0 |
|
96 | 0 | return nsSVGGFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType); |
97 | 0 | } |
98 | | |
99 | | //---------------------------------------------------------------------- |
100 | | // nsSVGDisplayableFrame methods |
101 | | |
102 | | void |
103 | | nsSVGUseFrame::ReflowSVG() |
104 | 0 | { |
105 | 0 | // We only handle x/y offset here, since any width/height that is in force is |
106 | 0 | // handled by the nsSVGOuterSVGFrame for the anonymous <svg> that will be |
107 | 0 | // created for that purpose. |
108 | 0 | float x, y; |
109 | 0 | static_cast<SVGUseElement*>(GetContent())-> |
110 | 0 | GetAnimatedLengthValues(&x, &y, nullptr); |
111 | 0 | mRect.MoveTo(nsLayoutUtils::RoundGfxRectToAppRect( |
112 | 0 | gfxRect(x, y, 0.0, 0.0), |
113 | 0 | AppUnitsPerCSSPixel()).TopLeft()); |
114 | 0 |
|
115 | 0 | // If we have a filter, we need to invalidate ourselves because filter |
116 | 0 | // output can change even if none of our descendants need repainting. |
117 | 0 | if (StyleEffects()->HasFilters()) { |
118 | 0 | InvalidateFrame(); |
119 | 0 | } |
120 | 0 |
|
121 | 0 | nsSVGGFrame::ReflowSVG(); |
122 | 0 | } |
123 | | |
124 | | void |
125 | | nsSVGUseFrame::NotifySVGChanged(uint32_t aFlags) |
126 | 0 | { |
127 | 0 | if (aFlags & COORD_CONTEXT_CHANGED && |
128 | 0 | !(aFlags & TRANSFORM_CHANGED)) { |
129 | 0 | // Coordinate context changes affect mCanvasTM if we have a |
130 | 0 | // percentage 'x' or 'y' |
131 | 0 | SVGUseElement *use = static_cast<SVGUseElement*>(GetContent()); |
132 | 0 | if (use->mLengthAttributes[SVGUseElement::ATTR_X].IsPercentage() || |
133 | 0 | use->mLengthAttributes[SVGUseElement::ATTR_Y].IsPercentage()) { |
134 | 0 | aFlags |= TRANSFORM_CHANGED; |
135 | 0 | // Ancestor changes can't affect how we render from the perspective of |
136 | 0 | // any rendering observers that we may have, so we don't need to |
137 | 0 | // invalidate them. We also don't need to invalidate ourself, since our |
138 | 0 | // changed ancestor will have invalidated its entire area, which includes |
139 | 0 | // our area. |
140 | 0 | // For perf reasons we call this before calling NotifySVGChanged() below. |
141 | 0 | nsSVGUtils::ScheduleReflowSVG(this); |
142 | 0 | } |
143 | 0 | } |
144 | 0 |
|
145 | 0 | // We don't remove the TRANSFORM_CHANGED flag here if we have a viewBox or |
146 | 0 | // non-percentage width/height, since if they're set then they are cloned to |
147 | 0 | // an anonymous child <svg>, and its nsSVGInnerSVGFrame will do that. |
148 | 0 |
|
149 | 0 | nsSVGGFrame::NotifySVGChanged(aFlags); |
150 | 0 | } |