initial import
[vuplus_webkit] / Source / WebCore / css / CSSWrapShapes.cpp
1 /*
2  * Copyright 2011 Adobe Systems Incorporated. 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
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above
9  *    copyright notice, this list of conditions and the following
10  *    disclaimer.
11  * 2. Redistributions in binary form must reproduce the above
12  *    copyright notice, this list of conditions and the following
13  *    disclaimer in the documentation and/or other materials
14  *    provided with the distribution.
15  * 
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
25  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
26  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 #include "config.h"
31
32 #include "CSSWrapShapes.h"
33
34 #include <wtf/text/StringBuilder.h>
35
36 using namespace WTF;
37
38 namespace WebCore {
39
40 String CSSWrapShapeRect::cssText() const
41 {
42     DEFINE_STATIC_LOCAL(const String, rectParen, ("rect("));
43     DEFINE_STATIC_LOCAL(const String, comma, (", "));
44     
45     StringBuilder result;
46     result.reserveCapacity(32);
47     result.append(rectParen);
48
49     result.append(m_left->cssText());
50     result.append(comma);
51
52     result.append(m_top->cssText());
53     result.append(comma);
54
55     result.append(m_width->cssText());
56     result.append(comma);
57
58     result.append(m_height->cssText());
59     
60     if (m_radiusX.get()) {
61         result.append(comma);
62         result.append(m_radiusX->cssText());
63
64         if (m_radiusY.get()) {
65             result.append(comma);
66             result.append(m_radiusY->cssText());
67         }
68     }
69     
70     result.append(')');
71             
72     return result.toString();
73 }
74
75 String CSSWrapShapeCircle::cssText() const
76 {
77     DEFINE_STATIC_LOCAL(const String, circleParen, ("circle("));
78     DEFINE_STATIC_LOCAL(const String, comma, (", "));
79     
80     StringBuilder result;
81     result.reserveCapacity(32);
82     result.append(circleParen);
83
84     result.append(m_left->cssText());
85     result.append(comma);
86
87     result.append(m_top->cssText());
88     result.append(comma);
89
90     result.append(m_radius->cssText());
91     result.append(')');
92             
93     return result.toString();
94 }
95
96 String CSSWrapShapeEllipse::cssText() const
97 {
98     DEFINE_STATIC_LOCAL(const String, ellipseParen, ("ellipse("));
99     DEFINE_STATIC_LOCAL(const String, comma, (", "));
100     
101     StringBuilder result;
102     result.reserveCapacity(32);
103     result.append(ellipseParen);
104
105     result.append(m_left->cssText());
106     result.append(comma);
107
108     result.append(m_top->cssText());
109     result.append(comma);
110
111     result.append(m_radiusX->cssText());
112     result.append(comma);
113
114     result.append(m_radiusY->cssText());
115     result.append(')');
116             
117     return result.toString();
118 }
119
120 String CSSWrapShapePolygon::cssText() const
121 {
122     DEFINE_STATIC_LOCAL(const String, polygonParenEvenOdd, ("polygon(evenodd, "));
123     DEFINE_STATIC_LOCAL(const String, polygonParenNonZero, ("polygon(nonzero, "));
124     DEFINE_STATIC_LOCAL(const String, comma, (", "));
125     
126     StringBuilder result;
127     result.reserveCapacity(32);
128     if (m_windRule == RULE_EVENODD)
129         result.append(polygonParenEvenOdd);
130     else
131         result.append(polygonParenNonZero);
132
133     ASSERT(!(m_values.size() % 2));
134
135     for (unsigned i = 0; i < m_values.size(); i += 2) {
136         if (i)
137             result.append(' ');
138         result.append(m_values.at(i)->cssText());
139         result.append(comma);
140         result.append(m_values.at(i + 1)->cssText());
141     }
142     
143     result.append(')');
144             
145     return result.toString();
146 }
147
148 } // namespace WebCore
149