OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 double CSSCalcValue::clampToPermittedRange(double value) const | 171 double CSSCalcValue::clampToPermittedRange(double value) const |
172 { | 172 { |
173 return m_nonNegative && value < 0 ? 0 : value; | 173 return m_nonNegative && value < 0 ? 0 : value; |
174 } | 174 } |
175 | 175 |
176 double CSSCalcValue::doubleValue() const | 176 double CSSCalcValue::doubleValue() const |
177 { | 177 { |
178 return clampToPermittedRange(m_expression->doubleValue()); | 178 return clampToPermittedRange(m_expression->doubleValue()); |
179 } | 179 } |
180 | 180 |
181 double CSSCalcValue::computeLengthPx(const RenderStyle* currentStyle, const Rend
erStyle* rootStyle, double multiplier, bool computingFontSize) const | 181 double CSSCalcValue::computeLengthPx(const CSSToLengthConversionData& conversion
Data) const |
182 { | 182 { |
183 return clampToPermittedRange(m_expression->computeLengthPx(currentStyle, roo
tStyle, multiplier, computingFontSize)); | 183 return clampToPermittedRange(m_expression->computeLengthPx(conversionData)); |
184 } | 184 } |
185 | 185 |
186 CSSCalcExpressionNode::~CSSCalcExpressionNode() | 186 CSSCalcExpressionNode::~CSSCalcExpressionNode() |
187 { | 187 { |
188 } | 188 } |
189 | 189 |
190 class CSSCalcPrimitiveValue : public CSSCalcExpressionNode { | 190 class CSSCalcPrimitiveValue : public CSSCalcExpressionNode { |
191 WTF_MAKE_FAST_ALLOCATED; | 191 WTF_MAKE_FAST_ALLOCATED; |
192 public: | 192 public: |
193 | 193 |
(...skipping 22 matching lines...) Expand all Loading... |
216 virtual String serializeResolvingVariables(const HashMap<AtomicString, Strin
g>& variables) const | 216 virtual String serializeResolvingVariables(const HashMap<AtomicString, Strin
g>& variables) const |
217 { | 217 { |
218 return m_value->customSerializeResolvingVariables(variables); | 218 return m_value->customSerializeResolvingVariables(variables); |
219 } | 219 } |
220 | 220 |
221 virtual bool hasVariableReference() const | 221 virtual bool hasVariableReference() const |
222 { | 222 { |
223 return m_value->isVariableName(); | 223 return m_value->isVariableName(); |
224 } | 224 } |
225 | 225 |
226 virtual PassOwnPtr<CalcExpressionNode> toCalcValue(const RenderStyle* style,
const RenderStyle* rootStyle, double zoom) const | 226 virtual PassOwnPtr<CalcExpressionNode> toCalcValue(const CSSToLengthConversi
onData& conversionData) const |
227 { | 227 { |
228 switch (m_category) { | 228 switch (m_category) { |
229 case CalcNumber: | 229 case CalcNumber: |
230 return adoptPtr(new CalcExpressionNumber(m_value->getFloatValue())); | 230 return adoptPtr(new CalcExpressionNumber(m_value->getFloatValue())); |
231 case CalcLength: | 231 case CalcLength: |
232 return adoptPtr(new CalcExpressionLength(Length(m_value->computeLeng
th<float>(style, rootStyle, zoom), WebCore::Fixed))); | 232 return adoptPtr(new CalcExpressionLength(Length(m_value->computeLeng
th<float>(conversionData), WebCore::Fixed))); |
233 case CalcPercent: | 233 case CalcPercent: |
234 case CalcPercentLength: { | 234 case CalcPercentLength: { |
235 CSSPrimitiveValue* primitiveValue = m_value.get(); | 235 CSSPrimitiveValue* primitiveValue = m_value.get(); |
236 return adoptPtr(new CalcExpressionLength(primitiveValue | 236 return adoptPtr(new CalcExpressionLength(primitiveValue |
237 ? primitiveValue->convertToLength<FixedConversion | PercentConve
rsion>(style, rootStyle, zoom) | 237 ? primitiveValue->convertToLength<FixedConversion | PercentConve
rsion>(conversionData) |
238 : Length(Undefined))); | 238 : Length(Undefined))); |
239 } | 239 } |
240 // Only types that could be part of a Length expression can be converted | 240 // Only types that could be part of a Length expression can be converted |
241 // to a CalcExpressionNode. CalcPercentNumber makes no sense as a Length
. | 241 // to a CalcExpressionNode. CalcPercentNumber makes no sense as a Length
. |
242 case CalcPercentNumber: | 242 case CalcPercentNumber: |
243 case CalcVariable: | 243 case CalcVariable: |
244 case CalcOther: | 244 case CalcOther: |
245 ASSERT_NOT_REACHED(); | 245 ASSERT_NOT_REACHED(); |
246 } | 246 } |
247 return nullptr; | 247 return nullptr; |
248 } | 248 } |
249 | 249 |
250 virtual double doubleValue() const | 250 virtual double doubleValue() const |
251 { | 251 { |
252 if (hasDoubleValue(primitiveType())) | 252 if (hasDoubleValue(primitiveType())) |
253 return m_value->getDoubleValue(); | 253 return m_value->getDoubleValue(); |
254 ASSERT_NOT_REACHED(); | 254 ASSERT_NOT_REACHED(); |
255 return 0; | 255 return 0; |
256 } | 256 } |
257 | 257 |
258 virtual double computeLengthPx(const RenderStyle* currentStyle, const Render
Style* rootStyle, double multiplier, bool computingFontSize) const | 258 virtual double computeLengthPx(const CSSToLengthConversionData& conversionDa
ta) const |
259 { | 259 { |
260 switch (m_category) { | 260 switch (m_category) { |
261 case CalcLength: | 261 case CalcLength: |
262 return m_value->computeLength<double>(currentStyle, rootStyle, multi
plier, computingFontSize); | 262 return m_value->computeLength<double>(conversionData); |
263 case CalcPercent: | 263 case CalcPercent: |
264 case CalcNumber: | 264 case CalcNumber: |
265 return m_value->getDoubleValue(); | 265 return m_value->getDoubleValue(); |
266 case CalcPercentLength: | 266 case CalcPercentLength: |
267 case CalcPercentNumber: | 267 case CalcPercentNumber: |
268 case CalcVariable: | 268 case CalcVariable: |
269 case CalcOther: | 269 case CalcOther: |
270 ASSERT_NOT_REACHED(); | 270 ASSERT_NOT_REACHED(); |
271 break; | 271 break; |
272 } | 272 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 } | 413 } |
414 | 414 |
415 return create(leftSide, rightSide, op); | 415 return create(leftSide, rightSide, op); |
416 } | 416 } |
417 | 417 |
418 virtual bool isZero() const | 418 virtual bool isZero() const |
419 { | 419 { |
420 return !doubleValue(); | 420 return !doubleValue(); |
421 } | 421 } |
422 | 422 |
423 virtual PassOwnPtr<CalcExpressionNode> toCalcValue(const RenderStyle* style,
const RenderStyle* rootStyle, double zoom) const | 423 virtual PassOwnPtr<CalcExpressionNode> toCalcValue(const CSSToLengthConversi
onData& conversionData) const |
424 { | 424 { |
425 OwnPtr<CalcExpressionNode> left(m_leftSide->toCalcValue(style, rootStyle
, zoom)); | 425 OwnPtr<CalcExpressionNode> left(m_leftSide->toCalcValue(conversionData))
; |
426 if (!left) | 426 if (!left) |
427 return nullptr; | 427 return nullptr; |
428 OwnPtr<CalcExpressionNode> right(m_rightSide->toCalcValue(style, rootSty
le, zoom)); | 428 OwnPtr<CalcExpressionNode> right(m_rightSide->toCalcValue(conversionData
)); |
429 if (!right) | 429 if (!right) |
430 return nullptr; | 430 return nullptr; |
431 return adoptPtr(new CalcExpressionBinaryOperation(left.release(), right.
release(), m_operator)); | 431 return adoptPtr(new CalcExpressionBinaryOperation(left.release(), right.
release(), m_operator)); |
432 } | 432 } |
433 | 433 |
434 virtual double doubleValue() const | 434 virtual double doubleValue() const |
435 { | 435 { |
436 return evaluate(m_leftSide->doubleValue(), m_rightSide->doubleValue()); | 436 return evaluate(m_leftSide->doubleValue(), m_rightSide->doubleValue()); |
437 } | 437 } |
438 | 438 |
439 virtual double computeLengthPx(const RenderStyle* currentStyle, const Render
Style* rootStyle, double multiplier, bool computingFontSize) const | 439 virtual double computeLengthPx(const CSSToLengthConversionData& conversionDa
ta) const |
440 { | 440 { |
441 const double leftValue = m_leftSide->computeLengthPx(currentStyle, rootS
tyle, multiplier, computingFontSize); | 441 const double leftValue = m_leftSide->computeLengthPx(conversionData); |
442 const double rightValue = m_rightSide->computeLengthPx(currentStyle, roo
tStyle, multiplier, computingFontSize); | 442 const double rightValue = m_rightSide->computeLengthPx(conversionData); |
443 return evaluate(leftValue, rightValue); | 443 return evaluate(leftValue, rightValue); |
444 } | 444 } |
445 | 445 |
446 static String buildCSSText(const String& leftExpression, const String& right
Expression, CalcOperator op) | 446 static String buildCSSText(const String& leftExpression, const String& right
Expression, CalcOperator op) |
447 { | 447 { |
448 StringBuilder result; | 448 StringBuilder result; |
449 result.append('('); | 449 result.append('('); |
450 result.append(leftExpression); | 450 result.append(leftExpression); |
451 result.append(' '); | 451 result.append(' '); |
452 result.append(static_cast<char>(op)); | 452 result.append(static_cast<char>(op)); |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 | 781 |
782 return expression ? adoptRef(new CSSCalcValue(expression, range)) : 0; | 782 return expression ? adoptRef(new CSSCalcValue(expression, range)) : 0; |
783 } | 783 } |
784 | 784 |
785 PassRefPtr<CSSCalcValue> CSSCalcValue::create(PassRefPtr<CSSCalcExpressionNode>
expression, ValueRange range) | 785 PassRefPtr<CSSCalcValue> CSSCalcValue::create(PassRefPtr<CSSCalcExpressionNode>
expression, ValueRange range) |
786 { | 786 { |
787 return adoptRef(new CSSCalcValue(expression, range)); | 787 return adoptRef(new CSSCalcValue(expression, range)); |
788 } | 788 } |
789 | 789 |
790 } // namespace WebCore | 790 } // namespace WebCore |
OLD | NEW |