OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> | |
3 * Copyright (C) 2004, 2005, 2007, 2008 Rob Buis <buis@kde.org> | |
4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> | |
5 * Copyright (C) 2009 Google, Inc. All rights reserved. | |
6 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | |
7 * | |
8 * This library is free software; you can redistribute it and/or | |
9 * modify it under the terms of the GNU Library General Public | |
10 * License as published by the Free Software Foundation; either | |
11 * version 2 of the License, or (at your option) any later version. | |
12 * | |
13 * This library is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Library General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Library General Public License | |
19 * along with this library; see the file COPYING.LIB. If not, write to | |
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
21 * Boston, MA 02110-1301, USA. | |
22 */ | |
23 | |
24 #include "config.h" | |
25 #include "core/rendering/svg/RenderSVGContainer.h" | |
26 | |
27 #include "core/layout/svg/SVGLayoutSupport.h" | |
28 #include "core/layout/svg/SVGResources.h" | |
29 #include "core/layout/svg/SVGResourcesCache.h" | |
30 #include "core/paint/SVGContainerPainter.h" | |
31 | |
32 namespace blink { | |
33 | |
34 RenderSVGContainer::RenderSVGContainer(SVGElement* node) | |
35 : RenderSVGModelObject(node) | |
36 , m_objectBoundingBoxValid(false) | |
37 , m_needsBoundariesUpdate(true) | |
38 , m_hasNonIsolatedBlendingDescendants(false) | |
39 , m_hasNonIsolatedBlendingDescendantsDirty(false) | |
40 { | |
41 } | |
42 | |
43 RenderSVGContainer::~RenderSVGContainer() | |
44 { | |
45 } | |
46 | |
47 void RenderSVGContainer::layout() | |
48 { | |
49 ASSERT(needsLayout()); | |
50 | |
51 // Allow RenderSVGViewportContainer to update its viewport. | |
52 calcViewport(); | |
53 | |
54 // Allow RenderSVGTransformableContainer to update its transform. | |
55 bool updatedTransform = calculateLocalTransform(); | |
56 | |
57 // RenderSVGViewportContainer needs to set the 'layout size changed' flag. | |
58 determineIfLayoutSizeChanged(); | |
59 | |
60 SVGLayoutSupport::layoutChildren(this, selfNeedsLayout() || SVGLayoutSupport
::filtersForceContainerLayout(this)); | |
61 | |
62 // Invalidate all resources of this client if our layout changed. | |
63 if (everHadLayout() && needsLayout()) | |
64 SVGResourcesCache::clientLayoutChanged(this); | |
65 | |
66 if (m_needsBoundariesUpdate || updatedTransform) { | |
67 updateCachedBoundaries(); | |
68 m_needsBoundariesUpdate = false; | |
69 | |
70 // If our bounds changed, notify the parents. | |
71 RenderSVGModelObject::setNeedsBoundariesUpdate(); | |
72 } | |
73 | |
74 clearNeedsLayout(); | |
75 } | |
76 | |
77 void RenderSVGContainer::addChild(LayoutObject* child, LayoutObject* beforeChild
) | |
78 { | |
79 RenderSVGModelObject::addChild(child, beforeChild); | |
80 SVGResourcesCache::clientWasAddedToTree(child, child->styleRef()); | |
81 | |
82 bool shouldIsolateDescendants = (child->isBlendingAllowed() && child->style(
)->hasBlendMode()) || child->hasNonIsolatedBlendingDescendants(); | |
83 if (shouldIsolateDescendants) | |
84 descendantIsolationRequirementsChanged(DescendantIsolationRequired); | |
85 } | |
86 | |
87 void RenderSVGContainer::removeChild(LayoutObject* child) | |
88 { | |
89 SVGResourcesCache::clientWillBeRemovedFromTree(child); | |
90 RenderSVGModelObject::removeChild(child); | |
91 | |
92 bool hadNonIsolatedDescendants = (child->isBlendingAllowed() && child->style
()->hasBlendMode()) || child->hasNonIsolatedBlendingDescendants(); | |
93 if (hadNonIsolatedDescendants) | |
94 descendantIsolationRequirementsChanged(DescendantIsolationNeedsUpdate); | |
95 } | |
96 | |
97 bool RenderSVGContainer::selfWillPaint() | |
98 { | |
99 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject(
this); | |
100 return resources && resources->filter(); | |
101 } | |
102 | |
103 void RenderSVGContainer::styleDidChange(StyleDifference diff, const LayoutStyle*
oldStyle) | |
104 { | |
105 RenderSVGModelObject::styleDidChange(diff, oldStyle); | |
106 | |
107 bool hadIsolation = oldStyle && !isSVGHiddenContainer() && SVGLayoutSupport:
:willIsolateBlendingDescendantsForStyle(*oldStyle); | |
108 bool isolationChanged = hadIsolation == !SVGLayoutSupport::willIsolateBlendi
ngDescendantsForObject(this); | |
109 | |
110 if (!parent() || !isolationChanged) | |
111 return; | |
112 | |
113 if (hasNonIsolatedBlendingDescendants()) | |
114 parent()->descendantIsolationRequirementsChanged(SVGLayoutSupport::willI
solateBlendingDescendantsForObject(this) ? DescendantIsolationNeedsUpdate : Desc
endantIsolationRequired); | |
115 } | |
116 | |
117 bool RenderSVGContainer::hasNonIsolatedBlendingDescendants() const | |
118 { | |
119 if (m_hasNonIsolatedBlendingDescendantsDirty) { | |
120 m_hasNonIsolatedBlendingDescendants = SVGLayoutSupport::computeHasNonIso
latedBlendingDescendants(this); | |
121 m_hasNonIsolatedBlendingDescendantsDirty = false; | |
122 } | |
123 return m_hasNonIsolatedBlendingDescendants; | |
124 } | |
125 | |
126 void RenderSVGContainer::descendantIsolationRequirementsChanged(DescendantIsolat
ionState state) | |
127 { | |
128 switch (state) { | |
129 case DescendantIsolationRequired: | |
130 m_hasNonIsolatedBlendingDescendants = true; | |
131 m_hasNonIsolatedBlendingDescendantsDirty = false; | |
132 break; | |
133 case DescendantIsolationNeedsUpdate: | |
134 if (m_hasNonIsolatedBlendingDescendantsDirty) | |
135 return; | |
136 m_hasNonIsolatedBlendingDescendantsDirty = true; | |
137 break; | |
138 } | |
139 if (SVGLayoutSupport::willIsolateBlendingDescendantsForObject(this)) | |
140 return; | |
141 if (parent()) | |
142 parent()->descendantIsolationRequirementsChanged(state); | |
143 } | |
144 | |
145 void RenderSVGContainer::paint(const PaintInfo& paintInfo, const LayoutPoint&) | |
146 { | |
147 SVGContainerPainter(*this).paint(paintInfo); | |
148 } | |
149 | |
150 void RenderSVGContainer::addFocusRingRects(Vector<LayoutRect>& rects, const Layo
utPoint&) const | |
151 { | |
152 LayoutRect contentRect = LayoutRect(paintInvalidationRectInLocalCoordinates(
)); | |
153 if (!contentRect.isEmpty()) | |
154 rects.append(contentRect); | |
155 } | |
156 | |
157 void RenderSVGContainer::updateCachedBoundaries() | |
158 { | |
159 SVGLayoutSupport::computeContainerBoundingBoxes(this, m_objectBoundingBox, m
_objectBoundingBoxValid, m_strokeBoundingBox, m_paintInvalidationBoundingBox); | |
160 SVGLayoutSupport::intersectPaintInvalidationRectWithResources(this, m_paintI
nvalidationBoundingBox); | |
161 } | |
162 | |
163 bool RenderSVGContainer::nodeAtFloatPoint(const HitTestRequest& request, HitTest
Result& result, const FloatPoint& pointInParent, HitTestAction hitTestAction) | |
164 { | |
165 // Give RenderSVGViewportContainer a chance to apply its viewport clip | |
166 if (!pointIsInsideViewportClip(pointInParent)) | |
167 return false; | |
168 | |
169 FloatPoint localPoint; | |
170 if (!SVGLayoutSupport::transformToUserSpaceAndCheckClipping(this, localToPar
entTransform(), pointInParent, localPoint)) | |
171 return false; | |
172 | |
173 for (LayoutObject* child = lastChild(); child; child = child->previousSiblin
g()) { | |
174 if (child->nodeAtFloatPoint(request, result, localPoint, hitTestAction))
{ | |
175 updateHitTestResult(result, roundedLayoutPoint(localPoint)); | |
176 return true; | |
177 } | |
178 } | |
179 | |
180 // pointer-events=boundingBox makes it possible for containers to be direct
targets | |
181 if (style()->pointerEvents() == PE_BOUNDINGBOX) { | |
182 ASSERT(isObjectBoundingBoxValid()); | |
183 if (objectBoundingBox().contains(localPoint)) { | |
184 updateHitTestResult(result, roundedLayoutPoint(localPoint)); | |
185 return true; | |
186 } | |
187 } | |
188 // 16.4: "If there are no graphics elements whose relevant graphics content
is under the pointer (i.e., there is no target element), the event is not dispat
ched." | |
189 return false; | |
190 } | |
191 | |
192 } | |
OLD | NEW |