f9290c819cdfaf606b30252e134b83d7c5b03fc7
[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 void RenderSVGModelObject::absoluteRects(Vector<IntRect>& rects, const LayoutPoint& accumulatedOffset) const
73 {
74     IntRect rect = enclosingIntRect(strokeBoundingBox());
75     rect.moveBy(roundedIntPoint(accumulatedOffset));
76     rects.append(rect);
77 }
78
79 void RenderSVGModelObject::absoluteQuads(Vector<FloatQuad>& quads, bool* wasFixed) const
80 {
81     quads.append(localToAbsoluteQuad(strokeBoundingBox(), 0 /* mode */, wasFixed));
82 }
83
84 void RenderSVGModelObject::willBeDestroyed()
85 {
86     SVGResourcesCache::clientDestroyed(this);
87     RenderObject::willBeDestroyed();
88 }
89
90 void RenderSVGModelObject::computeLayerHitTestRects(LayerHitTestRects& rects) const
91 {
92     // Using just the rect for the SVGRoot is good enough for now.
93     SVGRenderSupport::findTreeRootObject(this)->computeLayerHitTestRects(rects);
94 }
95
96 void RenderSVGModelObject::addLayerHitTestRects(LayerHitTestRects&, const RenderLayer* currentLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const
97 {
98     // We don't walk into SVG trees at all - just report their container.
99 }
100
101 void RenderSVGModelObject::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
102 {
103     if (diff == StyleDifferenceLayout) {
104         setNeedsBoundariesUpdate();
105         if (style()->hasTransform())
106             setNeedsTransformUpdate();
107     }
108
109     RenderObject::styleDidChange(diff, oldStyle);
110     SVGResourcesCache::clientStyleChanged(this, diff, style());
111 }
112
113 bool RenderSVGModelObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint&, HitTestAction)
114 {
115     ASSERT_NOT_REACHED();
116     return false;
117 }
118
119 // The SVG addFocusRingRects() method adds rects in local coordinates so the default absoluteFocusRingQuads
120 // returns incorrect values for SVG objects. Overriding this method provides access to the absolute bounds.
121 void RenderSVGModelObject::absoluteFocusRingQuads(Vector<FloatQuad>& quads)
122 {
123     quads.append(localToAbsoluteQuad(FloatQuad(repaintRectInLocalCoordinates())));
124 }
125
126 } // namespace WebCore