initial import
[vuplus_webkit] / Source / WebCore / rendering / svg / RenderSVGBlock.cpp
1 /*
2  * Copyright (C) 2006 Apple Computer, Inc.
3  * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
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 #if ENABLE(SVG)
25 #include "RenderSVGBlock.h"
26
27 #include "RenderSVGResource.h"
28 #include "SVGElement.h"
29
30 namespace WebCore {
31
32 RenderSVGBlock::RenderSVGBlock(SVGElement* node) 
33     : RenderBlock(node)
34 {
35 }
36
37 LayoutRect RenderSVGBlock::visualOverflowRect() const
38 {
39     LayoutRect borderRect = borderBoxRect();
40
41     if (const ShadowData* textShadow = style()->textShadow())
42         textShadow->adjustRectForShadow(borderRect);
43
44     return borderRect;
45 }
46
47 void RenderSVGBlock::setStyle(PassRefPtr<RenderStyle> style) 
48 {
49     RefPtr<RenderStyle> useStyle = style;
50
51     // SVG text layout code expects us to be a block-level style element.   
52     if (useStyle->isDisplayInlineType()) {
53         RefPtr<RenderStyle> newStyle = RenderStyle::create();
54         newStyle->inheritFrom(useStyle.get());
55         newStyle->setDisplay(BLOCK);
56         useStyle = newStyle.release();
57     }
58
59     RenderBlock::setStyle(useStyle.release());
60 }
61
62 void RenderSVGBlock::updateBoxModelInfoFromStyle()
63 {
64     RenderBlock::updateBoxModelInfoFromStyle();
65
66     // RenderSVGlock, used by Render(SVGText|ForeignObject), is not allowed to call setHasOverflowClip(true).
67     // RenderBlock assumes a layer to be present when the overflow clip functionality is requested. Both
68     // Render(SVGText|ForeignObject) return 'false' on 'requiresLayer'. Fine for RenderSVGText.
69     //
70     // If we want to support overflow rules for <foreignObject> we can choose between two solutions:
71     // a) make RenderSVGForeignObject require layers and SVG layer aware
72     // b) reactor overflow logic out of RenderLayer (as suggested by dhyatt), which is a large task
73     //
74     // Until this is resolved, disable overflow support. Opera/FF don't support it as well at the moment (Feb 2010).
75     //
76     // Note: This does NOT affect overflow handling on outer/inner <svg> elements - this is handled
77     // manually by RenderSVGRoot - which owns the documents enclosing root layer and thus works fine.
78     setHasOverflowClip(false);
79 }
80
81 void RenderSVGBlock::absoluteRects(Vector<LayoutRect>&, const LayoutPoint&)
82 {
83     // This code path should never be taken for SVG, as we're assuming useTransforms=true everywhere, absoluteQuads should be used.
84     ASSERT_NOT_REACHED();
85 }
86
87 void RenderSVGBlock::willBeDestroyed()
88 {
89     SVGResourcesCache::clientDestroyed(this);
90     RenderBlock::willBeDestroyed();
91 }
92
93 void RenderSVGBlock::styleWillChange(StyleDifference diff, const RenderStyle* newStyle)
94 {
95     if (diff == StyleDifferenceLayout)
96         setNeedsBoundariesUpdate();
97     RenderBlock::styleWillChange(diff, newStyle);
98 }
99
100 void RenderSVGBlock::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
101 {
102     RenderBlock::styleDidChange(diff, oldStyle);
103     SVGResourcesCache::clientStyleChanged(this, diff, style());
104 }
105
106 void RenderSVGBlock::updateFromElement()
107 {
108     RenderBlock::updateFromElement();
109     SVGResourcesCache::clientUpdatedFromElement(this, style());
110 }
111
112 }
113
114 #endif