Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / svg / RenderSVGModelObject.cpp
1 /*
2  * Copyright (c) 2009, Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include "config.h"
32 #include "core/rendering/svg/RenderSVGModelObject.h"
33
34 #include "core/rendering/RenderLayer.h"
35 #include "core/rendering/RenderView.h"
36 #include "core/rendering/svg/RenderSVGContainer.h"
37 #include "core/rendering/svg/RenderSVGRoot.h"
38 #include "core/rendering/svg/SVGRenderSupport.h"
39 #include "core/rendering/svg/SVGResourcesCache.h"
40 #include "core/svg/SVGGraphicsElement.h"
41
42 namespace blink {
43
44 RenderSVGModelObject::RenderSVGModelObject(SVGElement* node)
45     : RenderObject(node)
46 {
47 }
48
49 bool RenderSVGModelObject::isChildAllowed(RenderObject* child, RenderStyle*) const
50 {
51     return child->isSVG() && !(child->isSVGInline() || child->isSVGInlineText());
52 }
53
54 LayoutRect RenderSVGModelObject::clippedOverflowRectForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer, const PaintInvalidationState* paintInvalidationState) const
55 {
56     return SVGRenderSupport::clippedOverflowRectForPaintInvalidation(this, paintInvalidationContainer, paintInvalidationState);
57 }
58
59 void RenderSVGModelObject::computeFloatRectForPaintInvalidation(const RenderLayerModelObject* paintInvalidationContainer, FloatRect& paintInvalidationRect, const PaintInvalidationState* paintInvalidationState) const
60 {
61     SVGRenderSupport::computeFloatRectForPaintInvalidation(this, paintInvalidationContainer, paintInvalidationRect, paintInvalidationState);
62 }
63
64 void RenderSVGModelObject::mapLocalToContainer(const RenderLayerModelObject* paintInvalidationContainer, TransformState& transformState, MapCoordinatesFlags, bool* wasFixed, const PaintInvalidationState* paintInvalidationState) const
65 {
66     SVGRenderSupport::mapLocalToContainer(this, paintInvalidationContainer, transformState, wasFixed, paintInvalidationState);
67 }
68
69 const RenderObject* RenderSVGModelObject::pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap& geometryMap) const
70 {
71     return SVGRenderSupport::pushMappingToContainer(this, ancestorToStopAt, geometryMap);
72 }
73
74 void RenderSVGModelObject::absoluteRects(Vector<IntRect>& rects, const LayoutPoint& accumulatedOffset) const
75 {
76     IntRect rect = enclosingIntRect(strokeBoundingBox());
77     rect.moveBy(roundedIntPoint(accumulatedOffset));
78     rects.append(rect);
79 }
80
81 void RenderSVGModelObject::absoluteQuads(Vector<FloatQuad>& quads, bool* wasFixed) const
82 {
83     quads.append(localToAbsoluteQuad(strokeBoundingBox(), 0 /* mode */, wasFixed));
84 }
85
86 void RenderSVGModelObject::willBeDestroyed()
87 {
88     SVGResourcesCache::clientDestroyed(this);
89     RenderObject::willBeDestroyed();
90 }
91
92 void RenderSVGModelObject::computeLayerHitTestRects(LayerHitTestRects& rects) const
93 {
94     // Using just the rect for the SVGRoot is good enough for now.
95     SVGRenderSupport::findTreeRootObject(this)->computeLayerHitTestRects(rects);
96 }
97
98 void RenderSVGModelObject::addLayerHitTestRects(LayerHitTestRects&, const RenderLayer* currentLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const
99 {
100     // We don't walk into SVG trees at all - just report their container.
101 }
102
103 void RenderSVGModelObject::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
104 {
105     if (diff.needsFullLayout()) {
106         setNeedsBoundariesUpdate();
107         if (style()->hasTransform())
108             setNeedsTransformUpdate();
109     }
110
111     RenderObject::styleDidChange(diff, oldStyle);
112     SVGResourcesCache::clientStyleChanged(this, diff, style());
113 }
114
115 bool RenderSVGModelObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint&, HitTestAction)
116 {
117     ASSERT_NOT_REACHED();
118     return false;
119 }
120
121 // The SVG addFocusRingRects() method adds rects in local coordinates so the default absoluteFocusRingQuads
122 // returns incorrect values for SVG objects. Overriding this method provides access to the absolute bounds.
123 void RenderSVGModelObject::absoluteFocusRingQuads(Vector<FloatQuad>& quads)
124 {
125     quads.append(localToAbsoluteQuad(FloatQuad(paintInvalidationRectInLocalCoordinates())));
126 }
127
128 InvalidationReason RenderSVGModelObject::invalidatePaintIfNeeded(const PaintInvalidationState& paintInvalidationState, const RenderLayerModelObject& paintInvalidationContainer)
129 {
130     ForceHorriblySlowRectMapping slowRectMapping(&paintInvalidationState);
131
132     return RenderObject::invalidatePaintIfNeeded(paintInvalidationState, paintInvalidationContainer);
133 }
134
135 } // namespace blink