Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: Source/core/css/CSSCalculationValue.cpp

Issue 64293008: Wrap CSS length conversion arguments in an object (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: bool for useEffectiveZoom instead of -1 magic number Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 double CSSCalcValue::clampToPermittedRange(double value) const 172 double CSSCalcValue::clampToPermittedRange(double value) const
173 { 173 {
174 return m_nonNegative && value < 0 ? 0 : value; 174 return m_nonNegative && value < 0 ? 0 : value;
175 } 175 }
176 176
177 double CSSCalcValue::doubleValue() const 177 double CSSCalcValue::doubleValue() const
178 { 178 {
179 return clampToPermittedRange(m_expression->doubleValue()); 179 return clampToPermittedRange(m_expression->doubleValue());
180 } 180 }
181 181
182 double CSSCalcValue::computeLengthPx(const RenderStyle* currentStyle, const Rend erStyle* rootStyle, double multiplier, bool computingFontSize) const 182 double CSSCalcValue::computeLengthPx(const CSSToLengthConversionData& conversion Data) const
183 { 183 {
184 return clampToPermittedRange(m_expression->computeLengthPx(currentStyle, roo tStyle, multiplier, computingFontSize)); 184 return clampToPermittedRange(m_expression->computeLengthPx(conversionData));
185 } 185 }
186 186
187 CSSCalcExpressionNode::~CSSCalcExpressionNode() 187 CSSCalcExpressionNode::~CSSCalcExpressionNode()
188 { 188 {
189 } 189 }
190 190
191 class CSSCalcPrimitiveValue : public CSSCalcExpressionNode { 191 class CSSCalcPrimitiveValue : public CSSCalcExpressionNode {
192 WTF_MAKE_FAST_ALLOCATED; 192 WTF_MAKE_FAST_ALLOCATED;
193 public: 193 public:
194 194
(...skipping 22 matching lines...) Expand all
217 virtual String serializeResolvingVariables(const HashMap<AtomicString, Strin g>& variables) const 217 virtual String serializeResolvingVariables(const HashMap<AtomicString, Strin g>& variables) const
218 { 218 {
219 return m_value->customSerializeResolvingVariables(variables); 219 return m_value->customSerializeResolvingVariables(variables);
220 } 220 }
221 221
222 virtual bool hasVariableReference() const 222 virtual bool hasVariableReference() const
223 { 223 {
224 return m_value->isVariableName(); 224 return m_value->isVariableName();
225 } 225 }
226 226
227 virtual PassOwnPtr<CalcExpressionNode> toCalcValue(const RenderStyle* style, const RenderStyle* rootStyle, double zoom) const 227 virtual PassOwnPtr<CalcExpressionNode> toCalcValue(const CSSToLengthConversi onData& conversionData) const
228 { 228 {
229 switch (m_category) { 229 switch (m_category) {
230 case CalcNumber: 230 case CalcNumber:
231 return adoptPtr(new CalcExpressionNumber(m_value->getFloatValue())); 231 return adoptPtr(new CalcExpressionNumber(m_value->getFloatValue()));
232 case CalcLength: 232 case CalcLength:
233 return adoptPtr(new CalcExpressionLength(Length(m_value->computeLeng th<float>(style, rootStyle, zoom), WebCore::Fixed))); 233 return adoptPtr(new CalcExpressionLength(Length(m_value->computeLeng th<float>(conversionData), WebCore::Fixed)));
234 case CalcPercent: 234 case CalcPercent:
235 case CalcPercentLength: { 235 case CalcPercentLength: {
236 CSSPrimitiveValue* primitiveValue = m_value.get(); 236 CSSPrimitiveValue* primitiveValue = m_value.get();
237 return adoptPtr(new CalcExpressionLength(primitiveValue 237 return adoptPtr(new CalcExpressionLength(primitiveValue
238 ? primitiveValue->convertToLength<FixedConversion | PercentConve rsion>(style, rootStyle, zoom) 238 ? primitiveValue->convertToLength<FixedConversion | PercentConve rsion>(conversionData)
239 : Length(Undefined))); 239 : Length(Undefined)));
240 } 240 }
241 // Only types that could be part of a Length expression can be converted 241 // Only types that could be part of a Length expression can be converted
242 // to a CalcExpressionNode. CalcPercentNumber makes no sense as a Length . 242 // to a CalcExpressionNode. CalcPercentNumber makes no sense as a Length .
243 case CalcPercentNumber: 243 case CalcPercentNumber:
244 case CalcVariable: 244 case CalcVariable:
245 case CalcOther: 245 case CalcOther:
246 ASSERT_NOT_REACHED(); 246 ASSERT_NOT_REACHED();
247 } 247 }
248 return nullptr; 248 return nullptr;
249 } 249 }
250 250
251 virtual double doubleValue() const 251 virtual double doubleValue() const
252 { 252 {
253 if (hasDoubleValue(primitiveType())) 253 if (hasDoubleValue(primitiveType()))
254 return m_value->getDoubleValue(); 254 return m_value->getDoubleValue();
255 ASSERT_NOT_REACHED(); 255 ASSERT_NOT_REACHED();
256 return 0; 256 return 0;
257 } 257 }
258 258
259 virtual double computeLengthPx(const RenderStyle* currentStyle, const Render Style* rootStyle, double multiplier, bool computingFontSize) const 259 virtual double computeLengthPx(const CSSToLengthConversionData& conversionDa ta) const
260 { 260 {
261 switch (m_category) { 261 switch (m_category) {
262 case CalcLength: 262 case CalcLength:
263 return m_value->computeLength<double>(currentStyle, rootStyle, multi plier, computingFontSize); 263 return m_value->computeLength<double>(conversionData);
264 case CalcPercent: 264 case CalcPercent:
265 case CalcNumber: 265 case CalcNumber:
266 return m_value->getDoubleValue(); 266 return m_value->getDoubleValue();
267 case CalcPercentLength: 267 case CalcPercentLength:
268 case CalcPercentNumber: 268 case CalcPercentNumber:
269 case CalcVariable: 269 case CalcVariable:
270 case CalcOther: 270 case CalcOther:
271 ASSERT_NOT_REACHED(); 271 ASSERT_NOT_REACHED();
272 break; 272 break;
273 } 273 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 414 }
415 415
416 return create(leftSide, rightSide, op); 416 return create(leftSide, rightSide, op);
417 } 417 }
418 418
419 virtual bool isZero() const 419 virtual bool isZero() const
420 { 420 {
421 return !doubleValue(); 421 return !doubleValue();
422 } 422 }
423 423
424 virtual PassOwnPtr<CalcExpressionNode> toCalcValue(const RenderStyle* style, const RenderStyle* rootStyle, double zoom) const 424 virtual PassOwnPtr<CalcExpressionNode> toCalcValue(const CSSToLengthConversi onData& conversionData) const
425 { 425 {
426 OwnPtr<CalcExpressionNode> left(m_leftSide->toCalcValue(style, rootStyle , zoom)); 426 OwnPtr<CalcExpressionNode> left(m_leftSide->toCalcValue(conversionData)) ;
427 if (!left) 427 if (!left)
428 return nullptr; 428 return nullptr;
429 OwnPtr<CalcExpressionNode> right(m_rightSide->toCalcValue(style, rootSty le, zoom)); 429 OwnPtr<CalcExpressionNode> right(m_rightSide->toCalcValue(conversionData ));
430 if (!right) 430 if (!right)
431 return nullptr; 431 return nullptr;
432 return adoptPtr(new CalcExpressionBinaryOperation(left.release(), right. release(), m_operator)); 432 return adoptPtr(new CalcExpressionBinaryOperation(left.release(), right. release(), m_operator));
433 } 433 }
434 434
435 virtual double doubleValue() const 435 virtual double doubleValue() const
436 { 436 {
437 return evaluate(m_leftSide->doubleValue(), m_rightSide->doubleValue()); 437 return evaluate(m_leftSide->doubleValue(), m_rightSide->doubleValue());
438 } 438 }
439 439
440 virtual double computeLengthPx(const RenderStyle* currentStyle, const Render Style* rootStyle, double multiplier, bool computingFontSize) const 440 virtual double computeLengthPx(const CSSToLengthConversionData& conversionDa ta) const
441 { 441 {
442 const double leftValue = m_leftSide->computeLengthPx(currentStyle, rootS tyle, multiplier, computingFontSize); 442 const double leftValue = m_leftSide->computeLengthPx(conversionData);
443 const double rightValue = m_rightSide->computeLengthPx(currentStyle, roo tStyle, multiplier, computingFontSize); 443 const double rightValue = m_rightSide->computeLengthPx(conversionData);
444 return evaluate(leftValue, rightValue); 444 return evaluate(leftValue, rightValue);
445 } 445 }
446 446
447 static String buildCSSText(const String& leftExpression, const String& right Expression, CalcOperator op) 447 static String buildCSSText(const String& leftExpression, const String& right Expression, CalcOperator op)
448 { 448 {
449 StringBuilder result; 449 StringBuilder result;
450 result.append('('); 450 result.append('(');
451 result.append(leftExpression); 451 result.append(leftExpression);
452 result.append(' '); 452 result.append(' ');
453 result.append(static_cast<char>(op)); 453 result.append(static_cast<char>(op));
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 782
783 return expression ? adoptRef(new CSSCalcValue(expression, range)) : 0; 783 return expression ? adoptRef(new CSSCalcValue(expression, range)) : 0;
784 } 784 }
785 785
786 PassRefPtr<CSSCalcValue> CSSCalcValue::create(PassRefPtr<CSSCalcExpressionNode> expression, ValueRange range) 786 PassRefPtr<CSSCalcValue> CSSCalcValue::create(PassRefPtr<CSSCalcExpressionNode> expression, ValueRange range)
787 { 787 {
788 return adoptRef(new CSSCalcValue(expression, range)); 788 return adoptRef(new CSSCalcValue(expression, range));
789 } 789 }
790 790
791 } // namespace WebCore 791 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698