Upstream version 7.35.139.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
33 #include "core/rendering/svg/RenderSVGModelObject.h"
34
35 #include "SVGNames.h"
36 #include "core/rendering/svg/RenderSVGRoot.h"
37 #include "core/rendering/svg/SVGResourcesCache.h"
38 #include "core/svg/SVGGraphicsElement.h"
39
40 namespace WebCore {
41
42 RenderSVGModelObject::RenderSVGModelObject(SVGElement* node)
43     : RenderObject(node)
44 {
45 }
46
47 bool RenderSVGModelObject::isChildAllowed(RenderObject* child, RenderStyle*) const
48 {
49     return child->isSVG() && !(child->isSVGInline() || child->isSVGInlineText());
50 }
51
52 LayoutRect RenderSVGModelObject::clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const
53 {
54     return SVGRenderSupport::clippedOverflowRectForRepaint(this, repaintContainer);
55 }
56
57 void RenderSVGModelObject::computeFloatRectForRepaint(const RenderLayerModelObject* repaintContainer, FloatRect& repaintRect, bool fixed) const
58 {
59     SVGRenderSupport::computeFloatRectForRepaint(this, repaintContainer, repaintRect, fixed);
60 }
61
62 void RenderSVGModelObject::mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState& transformState, MapCoordinatesFlags, bool* wasFixed) const
63 {
64     SVGRenderSupport::mapLocalToContainer(this, repaintContainer, transformState, wasFixed);
65 }
66
67 const RenderObject* RenderSVGModelObject::pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap& geometryMap) const
68 {
69     return SVGRenderSupport::pushMappingToContainer(this, ancestorToStopAt, geometryMap);
70 }
71
72 // Copied from RenderBox, this method likely requires further refactoring to work easily for both SVG and CSS Box Model content.
73 // FIXME: This may also need to move into SVGRenderSupport as the RenderBox version depends
74 // on borderBoundingBox() which SVG RenderBox subclases (like SVGRenderBlock) do not implement.
75 LayoutRect RenderSVGModelObject::outlineBoundsForRepaint(const RenderLayerModelObject* repaintContainer, const RenderGeometryMap*) const
76 {
77     LayoutRect box = enclosingLayoutRect(repaintRectInLocalCoordinates());
78     adjustRectForOutline(box);
79
80     FloatQuad containerRelativeQuad = localToContainerQuad(FloatRect(box), repaintContainer);
81     return containerRelativeQuad.enclosingBoundingBox();
82 }
83
84 void RenderSVGModelObject::absoluteRects(Vector<IntRect>& rects, const LayoutPoint& accumulatedOffset) const
85 {
86     IntRect rect = enclosingIntRect(strokeBoundingBox());
87     rect.moveBy(roundedIntPoint(accumulatedOffset));
88     rects.append(rect);
89 }
90
91 void RenderSVGModelObject::absoluteQuads(Vector<FloatQuad>& quads, bool* wasFixed) const
92 {
93     quads.append(localToAbsoluteQuad(strokeBoundingBox(), 0 /* mode */, wasFixed));
94 }
95
96 void RenderSVGModelObject::willBeDestroyed()
97 {
98     SVGResourcesCache::clientDestroyed(this);
99     RenderObject::willBeDestroyed();
100 }
101
102 void RenderSVGModelObject::computeLayerHitTestRects(LayerHitTestRects& rects) const
103 {
104     // Using just the rect for the SVGRoot is good enough for now.
105     SVGRenderSupport::findTreeRootObject(this)->computeLayerHitTestRects(rects);
106 }
107
108 void RenderSVGModelObject::addLayerHitTestRects(LayerHitTestRects&, const RenderLayer* currentLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const
109 {
110     // We don't walk into SVG trees at all - just report their container.
111 }
112
113 void RenderSVGModelObject::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
114 {
115     if (diff == StyleDifferenceLayout) {
116         setNeedsBoundariesUpdate();
117         if (style()->hasTransform())
118             setNeedsTransformUpdate();
119     }
120
121     RenderObject::styleDidChange(diff, oldStyle);
122     SVGResourcesCache::clientStyleChanged(this, diff, style());
123 }
124
125 bool RenderSVGModelObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint&, HitTestAction)
126 {
127     ASSERT_NOT_REACHED();
128     return false;
129 }
130
131 // The SVG addFocusRingRects() method adds rects in local coordinates so the default absoluteFocusRingQuads
132 // returns incorrect values for SVG objects. Overriding this method provides access to the absolute bounds.
133 void RenderSVGModelObject::absoluteFocusRingQuads(Vector<FloatQuad>& quads)
134 {
135     quads.append(localToAbsoluteQuad(FloatQuad(repaintRectInLocalCoordinates())));
136 }
137
138 } // namespace WebCore