OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. | 2 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above | 8 * 1. Redistributions of source code must retain the above |
9 * copyright notice, this list of conditions and the following | 9 * copyright notice, this list of conditions and the following |
10 * disclaimer. | 10 * disclaimer. |
(...skipping 12 matching lines...) Expand all Loading... |
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF | 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 | 26 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
27 * SUCH DAMAGE. | 27 * SUCH DAMAGE. |
28 */ | 28 */ |
29 | 29 |
30 #include "config.h" | 30 #include "config.h" |
31 #include "core/css/CSSBasicShapes.h" | 31 #include "core/css/CSSBasicShapes.h" |
32 | 32 |
| 33 #include "core/css/CSSValuePool.h" |
33 #include "core/css/Pair.h" | 34 #include "core/css/Pair.h" |
| 35 #include "platform/Length.h" |
34 #include "wtf/text/StringBuilder.h" | 36 #include "wtf/text/StringBuilder.h" |
35 | 37 |
36 using namespace WTF; | 38 using namespace WTF; |
37 | 39 |
38 namespace WebCore { | 40 namespace WebCore { |
39 | 41 |
40 static String buildRectangleString(const String& x, const String& y, const Strin
g& width, const String& height, const String& radiusX, const String& radiusY, co
nst String& layoutBox) | 42 static String buildRectangleString(const String& x, const String& y, const Strin
g& width, const String& height, const String& radiusX, const String& radiusY, co
nst String& layoutBox) |
41 { | 43 { |
42 const char opening[] = "rectangle("; | 44 const char opening[] = "rectangle("; |
43 const char separator[] = ", "; | 45 const char separator[] = ", "; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 result.append(centerY); | 126 result.append(centerY); |
125 } | 127 } |
126 result.append(")"); | 128 result.append(")"); |
127 if (layoutBox.length()) { | 129 if (layoutBox.length()) { |
128 result.appendLiteral(separator); | 130 result.appendLiteral(separator); |
129 result.append(layoutBox); | 131 result.append(layoutBox); |
130 } | 132 } |
131 return result.toString(); | 133 return result.toString(); |
132 } | 134 } |
133 | 135 |
| 136 static String serializePositionOffset(const Pair& offset, const Pair& other) |
| 137 { |
| 138 if ((offset.first()->getValueID() == CSSValueLeft && other.first()->getValue
ID() == CSSValueTop) |
| 139 || (offset.first()->getValueID() == CSSValueTop && other.first()->getVal
ueID() == CSSValueLeft)) |
| 140 return offset.second()->cssText(); |
| 141 return offset.cssText(); |
| 142 } |
| 143 |
| 144 static PassRefPtr<CSSPrimitiveValue> buildSerializablePositionOffset(PassRefPtr<
CSSPrimitiveValue> offset, CSSValueID defaultSide) |
| 145 { |
| 146 CSSValueID side = defaultSide; |
| 147 RefPtr<CSSPrimitiveValue> amount; |
| 148 |
| 149 if (!offset) { |
| 150 side = CSSValueCenter; |
| 151 } else if (offset->isValueID()) { |
| 152 side = offset->getValueID(); |
| 153 } else if (Pair* pair = offset->getPairValue()) { |
| 154 side = pair->first()->getValueID(); |
| 155 amount = pair->second(); |
| 156 } else { |
| 157 amount = offset; |
| 158 } |
| 159 |
| 160 if (side == CSSValueCenter) { |
| 161 side = defaultSide; |
| 162 amount = cssValuePool().createValue(Length(50, Percent)); |
| 163 } else if ((side == CSSValueRight || side == CSSValueBottom) |
| 164 && amount->isPercentage()) { |
| 165 side = defaultSide; |
| 166 amount = cssValuePool().createValue(Length(100 - amount->getFloatValue()
, Percent)); |
| 167 } else if (amount->isLength() && !amount->getFloatValue()) { |
| 168 if (side == CSSValueRight || side == CSSValueBottom) |
| 169 amount = cssValuePool().createValue(Length(100, Percent)); |
| 170 else |
| 171 amount = cssValuePool().createValue(Length(0, Percent)); |
| 172 side = defaultSide; |
| 173 } |
| 174 |
| 175 return cssValuePool().createValue(Pair::create(cssValuePool().createValue(si
de), amount.release(), Pair::KeepIdenticalValues)); |
| 176 } |
| 177 |
134 String CSSBasicShapeCircle::cssText() const | 178 String CSSBasicShapeCircle::cssText() const |
135 { | 179 { |
| 180 RefPtr<CSSPrimitiveValue> normalizedCX = buildSerializablePositionOffset(m_c
enterX, CSSValueLeft); |
| 181 RefPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositionOffset(m_c
enterY, CSSValueTop); |
| 182 |
136 return buildCircleString(m_radius ? m_radius->cssText() : String(), | 183 return buildCircleString(m_radius ? m_radius->cssText() : String(), |
137 m_centerX ? m_centerX->cssText() : String(), | 184 serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->ge
tPairValue()), |
138 m_centerY ? m_centerY->cssText() : String(), | 185 serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->ge
tPairValue()), |
139 m_layoutBox ? m_layoutBox->cssText() : String()); | 186 m_layoutBox ? m_layoutBox->cssText() : String()); |
140 } | 187 } |
141 | 188 |
142 bool CSSBasicShapeCircle::equals(const CSSBasicShape& shape) const | 189 bool CSSBasicShapeCircle::equals(const CSSBasicShape& shape) const |
143 { | 190 { |
144 if (shape.type() != CSSBasicShapeCircleType) | 191 if (shape.type() != CSSBasicShapeCircleType) |
145 return false; | 192 return false; |
146 | 193 |
147 const CSSBasicShapeCircle& other = static_cast<const CSSBasicShapeCircle&>(s
hape); | 194 const CSSBasicShapeCircle& other = static_cast<const CSSBasicShapeCircle&>(s
hape); |
148 return compareCSSValuePtr(m_centerX, other.m_centerX) | 195 return compareCSSValuePtr(m_centerX, other.m_centerX) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 result.append(")"); | 265 result.append(")"); |
219 if (box.length()) { | 266 if (box.length()) { |
220 result.appendLiteral(separator); | 267 result.appendLiteral(separator); |
221 result.append(box); | 268 result.append(box); |
222 } | 269 } |
223 return result.toString(); | 270 return result.toString(); |
224 } | 271 } |
225 | 272 |
226 String CSSBasicShapeEllipse::cssText() const | 273 String CSSBasicShapeEllipse::cssText() const |
227 { | 274 { |
| 275 RefPtr<CSSPrimitiveValue> normalizedCX = buildSerializablePositionOffset(m_c
enterX, CSSValueLeft); |
| 276 RefPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositionOffset(m_c
enterY, CSSValueTop); |
| 277 |
228 return buildEllipseString(m_radiusX ? m_radiusX->cssText() : String(), | 278 return buildEllipseString(m_radiusX ? m_radiusX->cssText() : String(), |
229 m_radiusY ? m_radiusY->cssText() : String(), | 279 m_radiusY ? m_radiusY->cssText() : String(), |
230 m_centerX ? m_centerX->cssText() : String(), | 280 serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->ge
tPairValue()), |
231 m_centerY ? m_centerY->cssText() : String(), | 281 serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->ge
tPairValue()), |
232 m_layoutBox ? m_layoutBox->cssText() : String()); | 282 m_layoutBox ? m_layoutBox->cssText() : String()); |
233 } | 283 } |
234 | 284 |
235 bool CSSBasicShapeEllipse::equals(const CSSBasicShape& shape) const | 285 bool CSSBasicShapeEllipse::equals(const CSSBasicShape& shape) const |
236 { | 286 { |
237 if (shape.type() != CSSBasicShapeEllipseType) | 287 if (shape.type() != CSSBasicShapeEllipseType) |
238 return false; | 288 return false; |
239 | 289 |
240 const CSSBasicShapeEllipse& other = static_cast<const CSSBasicShapeEllipse&>
(shape); | 290 const CSSBasicShapeEllipse& other = static_cast<const CSSBasicShapeEllipse&>
(shape); |
241 return compareCSSValuePtr(m_centerX, other.m_centerX) | 291 return compareCSSValuePtr(m_centerX, other.m_centerX) |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 visitor->trace(m_left); | 600 visitor->trace(m_left); |
551 visitor->trace(m_topLeftRadius); | 601 visitor->trace(m_topLeftRadius); |
552 visitor->trace(m_topRightRadius); | 602 visitor->trace(m_topRightRadius); |
553 visitor->trace(m_bottomRightRadius); | 603 visitor->trace(m_bottomRightRadius); |
554 visitor->trace(m_bottomLeftRadius); | 604 visitor->trace(m_bottomLeftRadius); |
555 CSSBasicShape::trace(visitor); | 605 CSSBasicShape::trace(visitor); |
556 } | 606 } |
557 | 607 |
558 } // namespace WebCore | 608 } // namespace WebCore |
559 | 609 |
OLD | NEW |