Changeset 127220 in webkit for trunk/Source/WebCore/css/CSSCalculationValue.cpp
- Timestamp:
- Aug 30, 2012, 6:13:50 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/css/CSSCalculationValue.cpp
r124884 r127220 69 69 case CSSPrimitiveValue::CSS_REMS: 70 70 return CalcLength; 71 #if ENABLE(CSS_VARIABLES) 72 case CSSPrimitiveValue::CSS_VARIABLE_NAME: 73 return CalcVariable; 74 #endif 71 75 default: 72 76 return CalcOther; 73 77 } 74 78 } 75 76 String CSSCalcValue::customCssText() const 79 80 static String buildCssText(const String& expression) 77 81 { 78 82 StringBuilder result; 79 80 83 result.append("-webkit-calc"); 81 String expression = m_expression->customCssText();82 84 bool expressionHasSingleTerm = expression[0] != '('; 83 85 if (expressionHasSingleTerm) … … 89 91 } 90 92 93 String CSSCalcValue::customCssText() const 94 { 95 return buildCssText(m_expression->customCssText()); 96 } 97 98 #if ENABLE(CSS_VARIABLES) 99 String CSSCalcValue::customSerializeResolvingVariables(const HashMap<AtomicString, String>& variables) const 100 { 101 return buildCssText(m_expression->serializeResolvingVariables(variables)); 102 } 103 104 bool CSSCalcValue::hasVariableReference() const 105 { 106 return m_expression->hasVariableReference(); 107 } 108 #endif 109 91 110 void CSSCalcValue::reportDescendantMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const 92 111 { … … 130 149 return m_value->cssText(); 131 150 } 151 152 #if ENABLE(CSS_VARIABLES) 153 virtual String serializeResolvingVariables(const HashMap<AtomicString, String>& variables) const 154 { 155 return m_value->customSerializeResolvingVariables(variables); 156 } 157 158 virtual bool hasVariableReference() const 159 { 160 return m_value->isVariableName(); 161 } 162 #endif 132 163 133 164 virtual PassOwnPtr<CalcExpressionNode> toCalcValue(RenderStyle* style, RenderStyle* rootStyle, double zoom) const … … 144 175 // to a CalcExpressionNode. CalcPercentNumber makes no sense as a Length. 145 176 case CalcPercentNumber: 177 #if ENABLE(CSS_VARIABLES) 178 case CalcVariable: 179 #endif 146 180 case CalcOther: 147 181 ASSERT_NOT_REACHED(); … … 159 193 case CalcPercentLength: 160 194 case CalcPercentNumber: 195 #if ENABLE(CSS_VARIABLES) 196 case CalcVariable: 197 #endif 161 198 case CalcOther: 162 199 ASSERT_NOT_REACHED(); … … 176 213 case CalcPercentLength: 177 214 case CalcPercentNumber: 215 #if ENABLE(CSS_VARIABLES) 216 case CalcVariable: 217 #endif 178 218 case CalcOther: 179 219 ASSERT_NOT_REACHED(); … … 192 232 explicit CSSCalcPrimitiveValue(CSSPrimitiveValue* value, bool isInteger) 193 233 : CSSCalcExpressionNode(unitCategory((CSSPrimitiveValue::UnitTypes)value->primitiveType()), isInteger) 194 , m_value(value) 234 , m_value(value) 195 235 { 196 236 } … … 206 246 { CalcOther, CalcPercentLength, CalcPercentLength, CalcOther, CalcPercentLength }, 207 247 }; 208 248 249 static CalculationCategory determineCategory(const CSSCalcExpressionNode& leftSide, const CSSCalcExpressionNode& rightSide, CalcOperator op) 250 { 251 CalculationCategory leftCategory = leftSide.category(); 252 CalculationCategory rightCategory = rightSide.category(); 253 254 if (leftCategory == CalcOther || rightCategory == CalcOther) 255 return CalcOther; 256 257 #if ENABLE(CSS_VARIABLES) 258 if (leftCategory == CalcVariable || rightCategory == CalcVariable) 259 return CalcVariable; 260 #endif 261 262 switch (op) { 263 case CalcAdd: 264 case CalcSubtract: 265 return addSubtractResult[leftCategory][rightCategory]; 266 case CalcMultiply: 267 if (leftCategory != CalcNumber && rightCategory != CalcNumber) 268 return CalcOther; 269 return leftCategory == CalcNumber ? rightCategory : leftCategory; 270 case CalcDivide: 271 if (rightCategory != CalcNumber || rightSide.isZero()) 272 return CalcOther; 273 return leftCategory; 274 } 275 276 ASSERT_NOT_REACHED(); 277 return CalcOther; 278 } 279 209 280 class CSSCalcBinaryOperation : public CSSCalcExpressionNode { 281 210 282 public: 211 283 static PassRefPtr<CSSCalcBinaryOperation> create(PassRefPtr<CSSCalcExpressionNode> leftSide, PassRefPtr<CSSCalcExpressionNode> rightSide, CalcOperator op) 212 284 { 213 CalculationCategory leftCategory = leftSide->category(); 214 CalculationCategory rightCategory = rightSide->category(); 215 CalculationCategory newCategory = CalcOther; 285 ASSERT(leftSide->category() != CalcOther && rightSide->category() != CalcOther); 216 286 217 ASSERT(leftCategory != CalcOther && rightCategory != CalcOther); 218 219 switch (op) { 220 case CalcAdd: 221 case CalcSubtract: 222 if (leftCategory == CalcOther || rightCategory == CalcOther) 223 return 0; 224 newCategory = addSubtractResult[leftCategory][rightCategory]; 225 break; 226 227 case CalcMultiply: 228 if (leftCategory != CalcNumber && rightCategory != CalcNumber) 229 return 0; 230 231 newCategory = leftCategory == CalcNumber ? rightCategory : leftCategory; 232 break; 233 234 case CalcDivide: 235 if (rightCategory != CalcNumber || rightSide->isZero()) 236 return 0; 237 newCategory = leftCategory; 238 break; 239 } 240 287 CalculationCategory newCategory = determineCategory(*leftSide, *rightSide, op); 288 241 289 if (newCategory == CalcOther) 242 290 return 0; 243 291 244 292 return adoptRef(new CSSCalcBinaryOperation(leftSide, rightSide, op, newCategory)); 245 293 } … … 280 328 } 281 329 282 virtual String customCssText() const330 static String buildCssText(const String& leftExpression, const String& rightExpression, CalcOperator op) 283 331 { 284 332 StringBuilder result; 285 333 result.append('('); 286 result.append( m_leftSide->customCssText());334 result.append(leftExpression); 287 335 result.append(' '); 288 result.append(static_cast<char>( m_operator));336 result.append(static_cast<char>(op)); 289 337 result.append(' '); 290 result.append( m_rightSide->customCssText());338 result.append(rightExpression); 291 339 result.append(')'); 292 340 293 return result.toString(); 294 } 341 return result.toString(); 342 } 343 344 virtual String customCssText() const 345 { 346 return buildCssText(m_leftSide->customCssText(), m_rightSide->customCssText(), m_operator); 347 } 348 349 #if ENABLE(CSS_VARIABLES) 350 virtual String serializeResolvingVariables(const HashMap<AtomicString, String>& variables) const 351 { 352 return buildCssText(m_leftSide->serializeResolvingVariables(variables), m_rightSide->serializeResolvingVariables(variables), m_operator); 353 } 354 355 virtual bool hasVariableReference() const 356 { 357 return m_leftSide->hasVariableReference() || m_rightSide->hasVariableReference(); 358 } 359 #endif 295 360 296 361 private:
Note:
See TracChangeset
for help on using the changeset viewer.