Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / svg / RenderSVGInline.cpp
1 /*
2  * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>
3  * Copyright (C) 2006 Apple Inc. All rights reserved.
4  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #include "config.h"
23
24 #include "core/rendering/svg/RenderSVGInline.h"
25
26 #include "SVGNames.h"
27 #include "core/rendering/svg/RenderSVGText.h"
28 #include "core/rendering/svg/SVGInlineFlowBox.h"
29 #include "core/rendering/svg/SVGRenderSupport.h"
30 #include "core/rendering/svg/SVGResourcesCache.h"
31 #include "core/svg/SVGAElement.h"
32
33 namespace WebCore {
34
35 bool RenderSVGInline::isChildAllowed(RenderObject* child, RenderStyle* style) const
36 {
37     if (child->isText())
38         return SVGRenderSupport::isRenderableTextNode(child);
39
40     if (isSVGAElement(*node())) {
41         // Disallow direct descendant 'a'.
42         if (isSVGAElement(*child->node()))
43             return false;
44     }
45
46     if (!child->isSVGInline() && !child->isSVGInlineText())
47         return false;
48
49     return RenderInline::isChildAllowed(child, style);
50 }
51
52 RenderSVGInline::RenderSVGInline(Element* element)
53     : RenderInline(element)
54 {
55     setAlwaysCreateLineBoxes();
56 }
57
58 InlineFlowBox* RenderSVGInline::createInlineFlowBox()
59 {
60     InlineFlowBox* box = new SVGInlineFlowBox(*this);
61     box->setHasVirtualLogicalHeight();
62     return box;
63 }
64
65 FloatRect RenderSVGInline::objectBoundingBox() const
66 {
67     if (const RenderObject* object = RenderSVGText::locateRenderSVGTextAncestor(this))
68         return object->objectBoundingBox();
69
70     return FloatRect();
71 }
72
73 FloatRect RenderSVGInline::strokeBoundingBox() const
74 {
75     if (const RenderObject* object = RenderSVGText::locateRenderSVGTextAncestor(this))
76         return object->strokeBoundingBox();
77
78     return FloatRect();
79 }
80
81 FloatRect RenderSVGInline::repaintRectInLocalCoordinates() const
82 {
83     if (const RenderObject* object = RenderSVGText::locateRenderSVGTextAncestor(this))
84         return object->repaintRectInLocalCoordinates();
85
86     return FloatRect();
87 }
88
89 LayoutRect RenderSVGInline::clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const
90 {
91     return SVGRenderSupport::clippedOverflowRectForRepaint(this, repaintContainer);
92 }
93
94 void RenderSVGInline::computeFloatRectForRepaint(const RenderLayerModelObject* repaintContainer, FloatRect& repaintRect, bool fixed) const
95 {
96     SVGRenderSupport::computeFloatRectForRepaint(this, repaintContainer, repaintRect, fixed);
97 }
98
99 void RenderSVGInline::mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState& transformState, MapCoordinatesFlags, bool* wasFixed) const
100 {
101     SVGRenderSupport::mapLocalToContainer(this, repaintContainer, transformState, wasFixed);
102 }
103
104 const RenderObject* RenderSVGInline::pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap& geometryMap) const
105 {
106     return SVGRenderSupport::pushMappingToContainer(this, ancestorToStopAt, geometryMap);
107 }
108
109 void RenderSVGInline::absoluteQuads(Vector<FloatQuad>& quads, bool* wasFixed) const
110 {
111     const RenderObject* object = RenderSVGText::locateRenderSVGTextAncestor(this);
112     if (!object)
113         return;
114
115     FloatRect textBoundingBox = object->strokeBoundingBox();
116     for (InlineFlowBox* box = firstLineBox(); box; box = box->nextLineBox())
117         quads.append(localToAbsoluteQuad(FloatRect(textBoundingBox.x() + box->x(), textBoundingBox.y() + box->y(), box->logicalWidth(), box->logicalHeight()), false, wasFixed));
118 }
119
120 void RenderSVGInline::willBeDestroyed()
121 {
122     SVGResourcesCache::clientDestroyed(this);
123     RenderInline::willBeDestroyed();
124 }
125
126 void RenderSVGInline::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
127 {
128     if (diff.needsFullLayout())
129         setNeedsBoundariesUpdate();
130
131     RenderInline::styleDidChange(diff, oldStyle);
132     SVGResourcesCache::clientStyleChanged(this, diff, style());
133 }
134
135 void RenderSVGInline::addChild(RenderObject* child, RenderObject* beforeChild)
136 {
137     RenderInline::addChild(child, beforeChild);
138     SVGResourcesCache::clientWasAddedToTree(child, child->style());
139
140     if (RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(this))
141         textRenderer->subtreeChildWasAdded(child);
142 }
143
144 void RenderSVGInline::removeChild(RenderObject* child)
145 {
146     SVGResourcesCache::clientWillBeRemovedFromTree(child);
147
148     RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(this);
149     if (!textRenderer) {
150         RenderInline::removeChild(child);
151         return;
152     }
153     Vector<SVGTextLayoutAttributes*, 2> affectedAttributes;
154     textRenderer->subtreeChildWillBeRemoved(child, affectedAttributes);
155     RenderInline::removeChild(child);
156     textRenderer->subtreeChildWasRemoved(affectedAttributes);
157 }
158
159 }