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

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

Issue 345903005: calc expressions should support time, angle and frequency values. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix build warrning. Created 6 years, 5 months 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 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 table.set(String("dpi"), CSSPrimitiveValue::CSS_DPI); 136 table.set(String("dpi"), CSSPrimitiveValue::CSS_DPI);
137 table.set(String("dpcm"), CSSPrimitiveValue::CSS_DPCM); 137 table.set(String("dpcm"), CSSPrimitiveValue::CSS_DPCM);
138 table.set(String("dppx"), CSSPrimitiveValue::CSS_DPPX); 138 table.set(String("dppx"), CSSPrimitiveValue::CSS_DPPX);
139 table.set(String("vw"), CSSPrimitiveValue::CSS_VW); 139 table.set(String("vw"), CSSPrimitiveValue::CSS_VW);
140 table.set(String("vh"), CSSPrimitiveValue::CSS_VH); 140 table.set(String("vh"), CSSPrimitiveValue::CSS_VH);
141 table.set(String("vmax"), CSSPrimitiveValue::CSS_VMIN); 141 table.set(String("vmax"), CSSPrimitiveValue::CSS_VMIN);
142 table.set(String("vmin"), CSSPrimitiveValue::CSS_VMAX); 142 table.set(String("vmin"), CSSPrimitiveValue::CSS_VMAX);
143 return table; 143 return table;
144 } 144 }
145 145
146 CSSPrimitiveValue::UnitType CSSPrimitiveValue::calcUnitType() const
147 {
148 CSSCalcExpressionNode* calcExpressionNode = cssCalcValue()->expressionNode() ;
149 if (calcExpressionNode)
150 return calcExpressionNode->primitiveType();
151 return CSS_UNKNOWN;
alancutter (OOO until 2018) 2014/07/21 14:03:47 This function should only get called if we are a c
152 }
146 153
147 CSSPrimitiveValue::UnitType CSSPrimitiveValue::fromName(const String& unit) 154 CSSPrimitiveValue::UnitType CSSPrimitiveValue::fromName(const String& unit)
148 { 155 {
149 DEFINE_STATIC_LOCAL(StringToUnitTable, unitTable, (createStringToUnitTable() )); 156 DEFINE_STATIC_LOCAL(StringToUnitTable, unitTable, (createStringToUnitTable() ));
150 return unitTable.get(unit.lower()); 157 return unitTable.get(unit.lower());
151 } 158 }
152 159
153 CSSPrimitiveValue::UnitCategory CSSPrimitiveValue::unitCategory(UnitType type) 160 CSSPrimitiveValue::UnitCategory CSSPrimitiveValue::unitCategory(UnitType type)
154 { 161 {
155 // Here we violate the spec (http://www.w3.org/TR/DOM-Level-2-Style/css.html #CSS-CSSPrimitiveValue) and allow conversions 162 // Here we violate the spec (http://www.w3.org/TR/DOM-Level-2-Style/css.html #CSS-CSSPrimitiveValue) and allow conversions
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 216
210 CSSPrimitiveValue::UnitType CSSPrimitiveValue::primitiveType() const 217 CSSPrimitiveValue::UnitType CSSPrimitiveValue::primitiveType() const
211 { 218 {
212 if (m_primitiveUnitType == CSS_PROPERTY_ID || m_primitiveUnitType == CSS_VAL UE_ID) 219 if (m_primitiveUnitType == CSS_PROPERTY_ID || m_primitiveUnitType == CSS_VAL UE_ID)
213 return CSS_IDENT; 220 return CSS_IDENT;
214 221
215 if (m_primitiveUnitType != CSS_CALC) 222 if (m_primitiveUnitType != CSS_CALC)
216 return static_cast<UnitType>(m_primitiveUnitType); 223 return static_cast<UnitType>(m_primitiveUnitType);
217 224
218 switch (m_value.calc->category()) { 225 switch (m_value.calc->category()) {
226 case CalcAngle:
227 return CSS_DEG;
228 case CalcFrequency:
229 return CSS_HZ;
219 case CalcNumber: 230 case CalcNumber:
220 return CSS_NUMBER; 231 return CSS_NUMBER;
221 case CalcPercent: 232 case CalcPercent:
222 return CSS_PERCENTAGE; 233 return CSS_PERCENTAGE;
223 case CalcLength: 234 case CalcLength:
224 return CSS_PX; 235 return CSS_PX;
225 case CalcPercentNumber: 236 case CalcPercentNumber:
226 return CSS_CALC_PERCENTAGE_WITH_NUMBER; 237 return CSS_CALC_PERCENTAGE_WITH_NUMBER;
227 case CalcPercentLength: 238 case CalcPercentLength:
228 return CSS_CALC_PERCENTAGE_WITH_LENGTH; 239 return CSS_CALC_PERCENTAGE_WITH_LENGTH;
240 case CalcTime:
241 return CSS_MS;
229 case CalcOther: 242 case CalcOther:
230 return CSS_UNKNOWN; 243 return CSS_UNKNOWN;
231 } 244 }
232 return CSS_UNKNOWN; 245 return CSS_UNKNOWN;
233 } 246 }
234 247
235 static const AtomicString& propertyName(CSSPropertyID propertyID) 248 static const AtomicString& propertyName(CSSPropertyID propertyID)
236 { 249 {
237 ASSERT_ARG(propertyID, propertyID >= 0); 250 ASSERT_ARG(propertyID, propertyID >= 0);
238 ASSERT_ARG(propertyID, (propertyID >= firstCSSProperty && propertyID < first CSSProperty + numCSSProperties)); 251 ASSERT_ARG(propertyID, (propertyID >= firstCSSProperty && propertyID < first CSSProperty + numCSSProperties));
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 case CSS_VALUE_ID: 540 case CSS_VALUE_ID:
528 break; 541 break;
529 } 542 }
530 m_primitiveUnitType = 0; 543 m_primitiveUnitType = 0;
531 if (m_hasCachedCSSText) { 544 if (m_hasCachedCSSText) {
532 cssTextCache().remove(this); 545 cssTextCache().remove(this);
533 m_hasCachedCSSText = false; 546 m_hasCachedCSSText = false;
534 } 547 }
535 } 548 }
536 549
550 double CSSPrimitiveValue::computeSeconds()
551 {
552 ASSERT(isTime() || (isCalculated() && cssCalcValue()->category() == CalcTime ));
553 UnitType currentType = isCalculated() ? calcUnitType() : static_cast<UnitTyp e>(m_primitiveUnitType);
554 if (currentType == CSS_S)
555 return getDoubleValue();
556 if (currentType == CSS_MS)
557 return getDoubleValue() / 1000;
558 ASSERT_NOT_REACHED();
559 return 0;
560 }
561
537 double CSSPrimitiveValue::computeDegrees() 562 double CSSPrimitiveValue::computeDegrees()
538 { 563 {
539 switch (m_primitiveUnitType) { 564 ASSERT(isAngle() || (isCalculated() && cssCalcValue()->category() == CalcAng le));
565 UnitType currentType = isCalculated() ? calcUnitType() : static_cast<UnitTyp e>(m_primitiveUnitType);
566 switch (currentType) {
540 case CSS_DEG: 567 case CSS_DEG:
541 return getDoubleValue(); 568 return getDoubleValue();
542 case CSS_RAD: 569 case CSS_RAD:
543 return rad2deg(getDoubleValue()); 570 return rad2deg(getDoubleValue());
544 case CSS_GRAD: 571 case CSS_GRAD:
545 return grad2deg(getDoubleValue()); 572 return grad2deg(getDoubleValue());
546 case CSS_TURN: 573 case CSS_TURN:
547 return turn2deg(getDoubleValue()); 574 return turn2deg(getDoubleValue());
548 default: 575 default:
549 ASSERT_NOT_REACHED(); 576 ASSERT_NOT_REACHED();
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 case CSS_SHAPE: 1459 case CSS_SHAPE:
1433 visitor->trace(m_value.shape); 1460 visitor->trace(m_value.shape);
1434 break; 1461 break;
1435 default: 1462 default:
1436 break; 1463 break;
1437 } 1464 }
1438 CSSValue::traceAfterDispatch(visitor); 1465 CSSValue::traceAfterDispatch(visitor);
1439 } 1466 }
1440 1467
1441 } // namespace WebCore 1468 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698