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

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

Issue 1252683002: CSSValue Immediates: Change RefPtr<CSSValue> to store tagged pointers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 5 years, 4 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
« no previous file with comments | « Source/core/css/CSSPrimitiveValue.h ('k') | Source/core/css/CSSPrimitiveValueMappings.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 161
162 typedef HashMap<const CSSPrimitiveValue*, String> CSSTextCache; 162 typedef HashMap<const CSSPrimitiveValue*, String> CSSTextCache;
163 static CSSTextCache& cssTextCache() 163 static CSSTextCache& cssTextCache()
164 { 164 {
165 AtomicallyInitializedStaticReference(ThreadSpecific<CSSTextCache>, cache, ne w ThreadSpecific<CSSTextCache>()); 165 AtomicallyInitializedStaticReference(ThreadSpecific<CSSTextCache>, cache, ne w ThreadSpecific<CSSTextCache>());
166 return *cache; 166 return *cache;
167 } 167 }
168 168
169 CSSPrimitiveValue::UnitType CSSPrimitiveValue::primitiveType() const 169 CSSPrimitiveValue::UnitType CSSPrimitiveValue::primitiveType() const
170 { 170 {
171 if (m_primitiveUnitType == CSS_PROPERTY_ID || m_primitiveUnitType == CSS_VAL UE_ID) 171 if (type() == CSS_PROPERTY_ID || type() == CSS_VALUE_ID)
172 return CSS_IDENT; 172 return CSS_IDENT;
173 173
174 if (m_primitiveUnitType != CSS_CALC) 174 if (type() != CSS_CALC)
175 return static_cast<UnitType>(m_primitiveUnitType); 175 return type();
176 176
177 switch (m_value.calc->category()) { 177 switch (value().calc->category()) {
178 case CalcAngle: 178 case CalcAngle:
179 return CSS_DEG; 179 return CSS_DEG;
180 case CalcFrequency: 180 case CalcFrequency:
181 return CSS_HZ; 181 return CSS_HZ;
182 case CalcNumber: 182 case CalcNumber:
183 return CSS_NUMBER; 183 return CSS_NUMBER;
184 case CalcPercent: 184 case CalcPercent:
185 return CSS_PERCENTAGE; 185 return CSS_PERCENTAGE;
186 case CalcLength: 186 case CalcLength:
187 return CSS_PX; 187 return CSS_PX;
(...skipping 25 matching lines...) Expand all
213 static AtomicString* keywordStrings = new AtomicString[numCSSValueKeywords]; // Leaked intentionally. 213 static AtomicString* keywordStrings = new AtomicString[numCSSValueKeywords]; // Leaked intentionally.
214 AtomicString& keywordString = keywordStrings[valueID]; 214 AtomicString& keywordString = keywordStrings[valueID];
215 if (keywordString.isNull()) 215 if (keywordString.isNull())
216 keywordString = getValueName(valueID); 216 keywordString = getValueName(valueID);
217 return keywordString; 217 return keywordString;
218 } 218 }
219 219
220 CSSPrimitiveValue::CSSPrimitiveValue(CSSValueID valueID) 220 CSSPrimitiveValue::CSSPrimitiveValue(CSSValueID valueID)
221 : CSSValue(PrimitiveClass) 221 : CSSValue(PrimitiveClass)
222 { 222 {
223 ASSERT(!isTaggedPtr());
223 m_primitiveUnitType = CSS_VALUE_ID; 224 m_primitiveUnitType = CSS_VALUE_ID;
224 m_value.valueID = valueID; 225 m_value.valueID = valueID;
225 } 226 }
226 227
227 CSSPrimitiveValue::CSSPrimitiveValue(CSSPropertyID propertyID) 228 CSSPrimitiveValue::CSSPrimitiveValue(CSSPropertyID propertyID)
228 : CSSValue(PrimitiveClass) 229 : CSSValue(PrimitiveClass)
229 { 230 {
231 ASSERT(!isTaggedPtr());
230 m_primitiveUnitType = CSS_PROPERTY_ID; 232 m_primitiveUnitType = CSS_PROPERTY_ID;
231 m_value.propertyID = propertyID; 233 m_value.propertyID = propertyID;
232 } 234 }
233 235
234 CSSPrimitiveValue::CSSPrimitiveValue(double num, UnitType type) 236 CSSPrimitiveValue::CSSPrimitiveValue(double num, UnitType type)
235 : CSSValue(PrimitiveClass) 237 : CSSValue(PrimitiveClass)
236 { 238 {
239 ASSERT(!isTaggedPtr());
237 m_primitiveUnitType = type; 240 m_primitiveUnitType = type;
238 ASSERT(std::isfinite(num)); 241 ASSERT(std::isfinite(num));
239 m_value.num = num; 242 m_value.num = num;
240 } 243 }
241 244
242 CSSPrimitiveValue::CSSPrimitiveValue(const String& str, UnitType type) 245 CSSPrimitiveValue::CSSPrimitiveValue(const String& str, UnitType type)
243 : CSSValue(PrimitiveClass) 246 : CSSValue(PrimitiveClass)
244 { 247 {
248 ASSERT(!isTaggedPtr());
245 m_primitiveUnitType = type; 249 m_primitiveUnitType = type;
246 m_value.string = str.impl(); 250 m_value.string = str.impl();
247 if (m_value.string) 251 if (m_value.string)
248 m_value.string->ref(); 252 m_value.string->ref();
249 } 253 }
250 254
251 CSSPrimitiveValue::CSSPrimitiveValue(const LengthSize& lengthSize, const Compute dStyle& style) 255 CSSPrimitiveValue::CSSPrimitiveValue(const LengthSize& lengthSize, const Compute dStyle& style)
252 : CSSValue(PrimitiveClass) 256 : CSSValue(PrimitiveClass)
253 { 257 {
258 ASSERT(!isTaggedPtr());
254 init(lengthSize, style); 259 init(lengthSize, style);
255 } 260 }
256 261
257 CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color) 262 CSSPrimitiveValue::CSSPrimitiveValue(RGBA32 color)
258 : CSSValue(PrimitiveClass) 263 : CSSValue(PrimitiveClass)
259 { 264 {
265 ASSERT(!isTaggedPtr());
260 m_primitiveUnitType = CSS_RGBCOLOR; 266 m_primitiveUnitType = CSS_RGBCOLOR;
261 m_value.rgbcolor = color; 267 m_value.rgbcolor = color;
262 } 268 }
263 269
264 CSSPrimitiveValue::CSSPrimitiveValue(const Length& length, float zoom) 270 CSSPrimitiveValue::CSSPrimitiveValue(const Length& length, float zoom)
265 : CSSValue(PrimitiveClass) 271 : CSSValue(PrimitiveClass)
266 { 272 {
273 ASSERT(!isTaggedPtr());
267 switch (length.type()) { 274 switch (length.type()) {
268 case Auto: 275 case Auto:
269 m_primitiveUnitType = CSS_VALUE_ID; 276 m_primitiveUnitType = CSS_VALUE_ID;
270 m_value.valueID = CSSValueAuto; 277 m_value.valueID = CSSValueAuto;
271 break; 278 break;
272 case Intrinsic: 279 case Intrinsic:
273 m_primitiveUnitType = CSS_VALUE_ID; 280 m_primitiveUnitType = CSS_VALUE_ID;
274 m_value.valueID = CSSValueIntrinsic; 281 m_value.valueID = CSSValueIntrinsic;
275 break; 282 break;
276 case MinIntrinsic: 283 case MinIntrinsic:
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 case DeviceWidth: 335 case DeviceWidth:
329 case DeviceHeight: 336 case DeviceHeight:
330 case MaxSizeNone: 337 case MaxSizeNone:
331 ASSERT_NOT_REACHED(); 338 ASSERT_NOT_REACHED();
332 break; 339 break;
333 } 340 }
334 } 341 }
335 342
336 void CSSPrimitiveValue::init(const LengthSize& lengthSize, const ComputedStyle& style) 343 void CSSPrimitiveValue::init(const LengthSize& lengthSize, const ComputedStyle& style)
337 { 344 {
345 ASSERT(!isTaggedPtr());
338 m_primitiveUnitType = CSS_PAIR; 346 m_primitiveUnitType = CSS_PAIR;
339 m_hasCachedCSSText = false; 347 m_hasCachedCSSText = false;
340 m_value.pair = Pair::create(create(lengthSize.width(), style.effectiveZoom() ), create(lengthSize.height(), style.effectiveZoom()), Pair::KeepIdenticalValues ).leakRef(); 348 m_value.pair = Pair::create(create(lengthSize.width(), style.effectiveZoom() ), create(lengthSize.height(), style.effectiveZoom()), Pair::KeepIdenticalValues ).leakRef();
341 } 349 }
342 350
343 void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<Counter> c) 351 void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<Counter> c)
344 { 352 {
353 ASSERT(!isTaggedPtr());
345 m_primitiveUnitType = CSS_COUNTER; 354 m_primitiveUnitType = CSS_COUNTER;
346 m_hasCachedCSSText = false; 355 m_hasCachedCSSText = false;
347 m_value.counter = c.leakRef(); 356 m_value.counter = c.leakRef();
348 } 357 }
349 358
350 void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<Rect> r) 359 void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<Rect> r)
351 { 360 {
361 ASSERT(!isTaggedPtr());
352 m_primitiveUnitType = CSS_RECT; 362 m_primitiveUnitType = CSS_RECT;
353 m_hasCachedCSSText = false; 363 m_hasCachedCSSText = false;
354 m_value.rect = r.leakRef(); 364 m_value.rect = r.leakRef();
355 } 365 }
356 366
357 void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<Quad> quad) 367 void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<Quad> quad)
358 { 368 {
369 ASSERT(!isTaggedPtr());
359 m_primitiveUnitType = CSS_QUAD; 370 m_primitiveUnitType = CSS_QUAD;
360 m_hasCachedCSSText = false; 371 m_hasCachedCSSText = false;
361 m_value.quad = quad.leakRef(); 372 m_value.quad = quad.leakRef();
362 } 373 }
363 374
364 void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<Pair> p) 375 void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<Pair> p)
365 { 376 {
377 ASSERT(!isTaggedPtr());
366 m_primitiveUnitType = CSS_PAIR; 378 m_primitiveUnitType = CSS_PAIR;
367 m_hasCachedCSSText = false; 379 m_hasCachedCSSText = false;
368 m_value.pair = p.leakRef(); 380 m_value.pair = p.leakRef();
369 } 381 }
370 382
371 void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<CSSCalcValue> c) 383 void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<CSSCalcValue> c)
372 { 384 {
385 ASSERT(!isTaggedPtr());
373 m_primitiveUnitType = CSS_CALC; 386 m_primitiveUnitType = CSS_CALC;
374 m_hasCachedCSSText = false; 387 m_hasCachedCSSText = false;
375 m_value.calc = c.leakRef(); 388 m_value.calc = c.leakRef();
376 } 389 }
377 390
378 void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<CSSBasicShape> shape) 391 void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<CSSBasicShape> shape)
379 { 392 {
393 ASSERT(!isTaggedPtr());
380 m_primitiveUnitType = CSS_SHAPE; 394 m_primitiveUnitType = CSS_SHAPE;
381 m_hasCachedCSSText = false; 395 m_hasCachedCSSText = false;
382 m_value.shape = shape.leakRef(); 396 m_value.shape = shape.leakRef();
383 } 397 }
384 398
385 CSSPrimitiveValue::~CSSPrimitiveValue() 399 CSSPrimitiveValue::~CSSPrimitiveValue()
386 { 400 {
387 cleanup(); 401 cleanup();
388 } 402 }
389 403
390 void CSSPrimitiveValue::cleanup() 404 void CSSPrimitiveValue::cleanup()
391 { 405 {
392 switch (static_cast<UnitType>(m_primitiveUnitType)) { 406 if (isTaggedPtr())
407 return;
408
409 switch (type()) {
393 case CSS_CUSTOM_IDENT: 410 case CSS_CUSTOM_IDENT:
394 case CSS_STRING: 411 case CSS_STRING:
395 case CSS_URI: 412 case CSS_URI:
396 case CSS_ATTR: 413 case CSS_ATTR:
397 if (m_value.string) 414 if (m_value.string)
398 m_value.string->deref(); 415 m_value.string->deref();
399 break; 416 break;
400 case CSS_COUNTER: 417 case CSS_COUNTER:
401 // We must not call deref() when oilpan is enabled because m_value.count er is traced. 418 // We must not call deref() when oilpan is enabled because m_value.count er is traced.
402 #if !ENABLE(OILPAN) 419 #if !ENABLE(OILPAN)
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 m_primitiveUnitType = 0; 494 m_primitiveUnitType = 0;
478 if (m_hasCachedCSSText) { 495 if (m_hasCachedCSSText) {
479 cssTextCache().remove(this); 496 cssTextCache().remove(this);
480 m_hasCachedCSSText = false; 497 m_hasCachedCSSText = false;
481 } 498 }
482 } 499 }
483 500
484 double CSSPrimitiveValue::computeSeconds() 501 double CSSPrimitiveValue::computeSeconds()
485 { 502 {
486 ASSERT(isTime() || (isCalculated() && cssCalcValue()->category() == CalcTime )); 503 ASSERT(isTime() || (isCalculated() && cssCalcValue()->category() == CalcTime ));
487 UnitType currentType = isCalculated() ? cssCalcValue()->expressionNode()->pr imitiveType() : static_cast<UnitType>(m_primitiveUnitType); 504 UnitType currentType = isCalculated() ? cssCalcValue()->expressionNode()->pr imitiveType() : type();
488 if (currentType == CSS_S) 505 if (currentType == CSS_S)
489 return getDoubleValue(); 506 return getDoubleValue();
490 if (currentType == CSS_MS) 507 if (currentType == CSS_MS)
491 return getDoubleValue() / 1000; 508 return getDoubleValue() / 1000;
492 ASSERT_NOT_REACHED(); 509 ASSERT_NOT_REACHED();
493 return 0; 510 return 0;
494 } 511 }
495 512
496 double CSSPrimitiveValue::computeDegrees() const 513 double CSSPrimitiveValue::computeDegrees() const
497 { 514 {
498 ASSERT(isAngle() || (isCalculated() && cssCalcValue()->category() == CalcAng le)); 515 ASSERT(isAngle() || (isCalculated() && cssCalcValue()->category() == CalcAng le));
499 UnitType currentType = isCalculated() ? cssCalcValue()->expressionNode()->pr imitiveType() : static_cast<UnitType>(m_primitiveUnitType); 516 UnitType currentType = isCalculated() ? cssCalcValue()->expressionNode()->pr imitiveType() : type();
500 switch (currentType) { 517 switch (currentType) {
501 case CSS_DEG: 518 case CSS_DEG:
502 return getDoubleValue(); 519 return getDoubleValue();
503 case CSS_RAD: 520 case CSS_RAD:
504 return rad2deg(getDoubleValue()); 521 return rad2deg(getDoubleValue());
505 case CSS_GRAD: 522 case CSS_GRAD:
506 return grad2deg(getDoubleValue()); 523 return grad2deg(getDoubleValue());
507 case CSS_TURN: 524 case CSS_TURN:
508 return turn2deg(getDoubleValue()); 525 return turn2deg(getDoubleValue());
509 default: 526 default:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 template<> double CSSPrimitiveValue::computeLength(const CSSToLengthConversionDa ta& conversionData) 562 template<> double CSSPrimitiveValue::computeLength(const CSSToLengthConversionDa ta& conversionData)
546 { 563 {
547 return computeLengthDouble(conversionData); 564 return computeLengthDouble(conversionData);
548 } 565 }
549 566
550 double CSSPrimitiveValue::computeLengthDouble(const CSSToLengthConversionData& c onversionData) 567 double CSSPrimitiveValue::computeLengthDouble(const CSSToLengthConversionData& c onversionData)
551 { 568 {
552 // The logic in this function is duplicated in MediaValues::computeLength 569 // The logic in this function is duplicated in MediaValues::computeLength
553 // because MediaValues::computeLength needs nearly identical logic, but we h aven't found a way to make 570 // because MediaValues::computeLength needs nearly identical logic, but we h aven't found a way to make
554 // CSSPrimitiveValue::computeLengthDouble more generic (to solve both cases) without hurting performance. 571 // CSSPrimitiveValue::computeLengthDouble more generic (to solve both cases) without hurting performance.
555 if (m_primitiveUnitType == CSS_CALC) 572 if (type() == CSS_CALC)
556 return m_value.calc->computeLengthPx(conversionData); 573 return value().calc->computeLengthPx(conversionData);
557 574
558 double factor; 575 double factor;
559 576
560 switch (primitiveType()) { 577 switch (primitiveType()) {
561 case CSS_EMS: 578 case CSS_EMS:
562 factor = conversionData.emFontSize(); 579 factor = conversionData.emFontSize();
563 break; 580 break;
564 case CSS_EXS: 581 case CSS_EXS:
565 factor = conversionData.exFontSize(); 582 factor = conversionData.exFontSize();
566 break; 583 break;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 if (isFontRelativeLength()) 633 if (isFontRelativeLength())
617 return result; 634 return result;
618 635
619 return result * conversionData.zoom(); 636 return result * conversionData.zoom();
620 } 637 }
621 638
622 void CSSPrimitiveValue::accumulateLengthArray(CSSLengthArray& lengthArray, CSSLe ngthTypeArray& lengthTypeArray, double multiplier) const 639 void CSSPrimitiveValue::accumulateLengthArray(CSSLengthArray& lengthArray, CSSLe ngthTypeArray& lengthTypeArray, double multiplier) const
623 { 640 {
624 ASSERT(lengthArray.size() == LengthUnitTypeCount); 641 ASSERT(lengthArray.size() == LengthUnitTypeCount);
625 642
626 if (m_primitiveUnitType == CSS_CALC) { 643 if (type() == CSS_CALC) {
627 cssCalcValue()->accumulateLengthArray(lengthArray, lengthTypeArray, mult iplier); 644 cssCalcValue()->accumulateLengthArray(lengthArray, lengthTypeArray, mult iplier);
628 return; 645 return;
629 } 646 }
630 647
631 LengthUnitType lengthType; 648 LengthUnitType lengthType;
632 if (unitTypeToLengthUnitType(static_cast<UnitType>(m_primitiveUnitType), len gthType)) { 649 if (unitTypeToLengthUnitType(type(), lengthType)) {
633 lengthArray.at(lengthType) += m_value.num * conversionToCanonicalUnitsSc aleFactor(static_cast<UnitType>(m_primitiveUnitType)) * multiplier; 650 lengthArray.at(lengthType) += value().num * conversionToCanonicalUnitsSc aleFactor(type()) * multiplier;
634 lengthTypeArray.set(lengthType); 651 lengthTypeArray.set(lengthType);
635 } 652 }
636 } 653 }
637 654
638 void CSSPrimitiveValue::accumulateLengthArray(CSSLengthArray& lengthArray, doubl e multiplier) const 655 void CSSPrimitiveValue::accumulateLengthArray(CSSLengthArray& lengthArray, doubl e multiplier) const
639 { 656 {
640 CSSLengthTypeArray lengthTypeArray; 657 CSSLengthTypeArray lengthTypeArray;
641 lengthTypeArray.resize(CSSPrimitiveValue::LengthUnitTypeCount); 658 lengthTypeArray.resize(CSSPrimitiveValue::LengthUnitTypeCount);
642 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i) 659 for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; ++i)
643 lengthTypeArray.clear(i); 660 lengthTypeArray.clear(i);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 Length CSSPrimitiveValue::convertToLength(const CSSToLengthConversionData& conve rsionData) 716 Length CSSPrimitiveValue::convertToLength(const CSSToLengthConversionData& conve rsionData)
700 { 717 {
701 if (isLength()) 718 if (isLength())
702 return computeLength<Length>(conversionData); 719 return computeLength<Length>(conversionData);
703 if (isPercentage()) 720 if (isPercentage())
704 return Length(getDoubleValue(), Percent); 721 return Length(getDoubleValue(), Percent);
705 ASSERT(isCalculated()); 722 ASSERT(isCalculated());
706 return Length(cssCalcValue()->toCalcValue(conversionData)); 723 return Length(cssCalcValue()->toCalcValue(conversionData));
707 } 724 }
708 725
709 double CSSPrimitiveValue::getDoubleValue() const 726 double CSSPrimitiveValue::getCalcDoubleValue() const
710 { 727 {
711 return m_primitiveUnitType != CSS_CALC ? m_value.num : m_value.calc->doubleV alue(); 728 ASSERT(!isTaggedPtr());
729 ASSERT(m_primitiveUnitType == CSS_CALC);
730 return value().calc->doubleValue();
712 } 731 }
713 732
714 CSSPrimitiveValue::UnitType CSSPrimitiveValue::canonicalUnitTypeForCategory(Unit Category category) 733 CSSPrimitiveValue::UnitType CSSPrimitiveValue::canonicalUnitTypeForCategory(Unit Category category)
715 { 734 {
716 // The canonical unit type is chosen according to the way CSSPropertyParser: :validUnit() chooses the default unit 735 // The canonical unit type is chosen according to the way CSSPropertyParser: :validUnit() chooses the default unit
717 // in each category (based on unitflags). 736 // in each category (based on unitflags).
718 switch (category) { 737 switch (category) {
719 case UNumber: 738 case UNumber:
720 return CSS_NUMBER; 739 return CSS_NUMBER;
721 case ULength: 740 case ULength:
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 return CSSPrimitiveValue::CSS_VMAX; 822 return CSSPrimitiveValue::CSS_VMAX;
804 case LengthUnitTypeCount: 823 case LengthUnitTypeCount:
805 break; 824 break;
806 } 825 }
807 ASSERT_NOT_REACHED(); 826 ASSERT_NOT_REACHED();
808 return CSSPrimitiveValue::CSS_UNKNOWN; 827 return CSSPrimitiveValue::CSS_UNKNOWN;
809 } 828 }
810 829
811 String CSSPrimitiveValue::getStringValue() const 830 String CSSPrimitiveValue::getStringValue() const
812 { 831 {
813 switch (m_primitiveUnitType) { 832 switch (type()) {
814 case CSS_CUSTOM_IDENT: 833 case CSS_CUSTOM_IDENT:
815 case CSS_STRING: 834 case CSS_STRING:
816 case CSS_ATTR: 835 case CSS_ATTR:
817 case CSS_URI: 836 case CSS_URI:
818 return m_value.string; 837 return value().string;
819 case CSS_VALUE_ID: 838 case CSS_VALUE_ID:
820 return valueName(m_value.valueID); 839 return valueName(value().valueID);
821 case CSS_PROPERTY_ID: 840 case CSS_PROPERTY_ID:
822 return propertyName(m_value.propertyID); 841 return propertyName(value().propertyID);
823 default: 842 default:
824 break; 843 break;
825 } 844 }
826 845
827 return String(); 846 return String();
828 } 847 }
829 848
830 static String formatNumber(double number, const char* suffix, unsigned suffixLen gth) 849 static String formatNumber(double number, const char* suffix, unsigned suffixLen gth)
831 { 850 {
832 #if OS(WIN) && _MSC_VER < 1900 851 #if OS(WIN) && _MSC_VER < 1900
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 case CSS_CALC_PERCENTAGE_WITH_LENGTH: 949 case CSS_CALC_PERCENTAGE_WITH_LENGTH:
931 case CSS_QEM: 950 case CSS_QEM:
932 break; 951 break;
933 }; 952 };
934 ASSERT_NOT_REACHED(); 953 ASSERT_NOT_REACHED();
935 return ""; 954 return "";
936 } 955 }
937 956
938 String CSSPrimitiveValue::customCSSText() const 957 String CSSPrimitiveValue::customCSSText() const
939 { 958 {
940 if (m_hasCachedCSSText) { 959 if (isTaggedPtr() && cssTextCache().contains(this))
960 return cssTextCache().get(this);
961
962 if (!isTaggedPtr() && m_hasCachedCSSText) {
941 ASSERT(cssTextCache().contains(this)); 963 ASSERT(cssTextCache().contains(this));
942 return cssTextCache().get(this); 964 return cssTextCache().get(this);
943 } 965 }
944 966
945 String text; 967 String text;
946 switch (m_primitiveUnitType) { 968 switch (type()) {
947 case CSS_UNKNOWN: 969 case CSS_UNKNOWN:
948 // FIXME 970 // FIXME
949 break; 971 break;
950 case CSS_INTEGER: 972 case CSS_INTEGER:
951 text = String::format("%d", getIntValue()); 973 text = String::format("%d", getIntValue());
952 break; 974 break;
953 case CSS_NUMBER: 975 case CSS_NUMBER:
954 case CSS_PERCENTAGE: 976 case CSS_PERCENTAGE:
955 case CSS_EMS: 977 case CSS_EMS:
956 case CSS_EXS: 978 case CSS_EXS:
(...skipping 14 matching lines...) Expand all
971 case CSS_MS: 993 case CSS_MS:
972 case CSS_S: 994 case CSS_S:
973 case CSS_HZ: 995 case CSS_HZ:
974 case CSS_KHZ: 996 case CSS_KHZ:
975 case CSS_TURN: 997 case CSS_TURN:
976 case CSS_FR: 998 case CSS_FR:
977 case CSS_VW: 999 case CSS_VW:
978 case CSS_VH: 1000 case CSS_VH:
979 case CSS_VMIN: 1001 case CSS_VMIN:
980 case CSS_VMAX: 1002 case CSS_VMAX:
981 text = formatNumber(m_value.num, unitTypeToString((UnitType)m_primit iveUnitType)); 1003 text = formatNumber(value().num, unitTypeToString(type()));
982 break; 1004 break;
983 case CSS_CUSTOM_IDENT: 1005 case CSS_CUSTOM_IDENT:
984 text = quoteCSSStringIfNeeded(m_value.string); 1006 text = quoteCSSStringIfNeeded(value().string);
985 break; 1007 break;
986 case CSS_STRING: { 1008 case CSS_STRING: {
987 text = serializeString(m_value.string); 1009 text = serializeString(value().string);
988 break; 1010 break;
989 } 1011 }
990 case CSS_URI: 1012 case CSS_URI:
991 text = "url(" + quoteCSSURLIfNeeded(m_value.string) + ")"; 1013 text = "url(" + quoteCSSURLIfNeeded(value().string) + ")";
992 break; 1014 break;
993 case CSS_VALUE_ID: 1015 case CSS_VALUE_ID:
994 text = valueName(m_value.valueID); 1016 text = valueName(value().valueID);
995 break; 1017 break;
996 case CSS_PROPERTY_ID: 1018 case CSS_PROPERTY_ID:
997 text = propertyName(m_value.propertyID); 1019 text = propertyName(value().propertyID);
998 break; 1020 break;
999 case CSS_ATTR: { 1021 case CSS_ATTR: {
1000 StringBuilder result; 1022 StringBuilder result;
1001 result.reserveCapacity(6 + m_value.string->length()); 1023 result.reserveCapacity(6 + value().string->length());
1002 result.appendLiteral("attr("); 1024 result.appendLiteral("attr(");
1003 result.append(m_value.string); 1025 result.append(value().string);
1004 result.append(')'); 1026 result.append(')');
1005 1027
1006 text = result.toString(); 1028 text = result.toString();
1007 break; 1029 break;
1008 } 1030 }
1009 case CSS_COUNTER: { 1031 case CSS_COUNTER: {
1010 StringBuilder result; 1032 StringBuilder result;
1011 String separator = m_value.counter->separator(); 1033 String separator = value().counter->separator();
1012 if (separator.isEmpty()) 1034 if (separator.isEmpty())
1013 result.appendLiteral("counter("); 1035 result.appendLiteral("counter(");
1014 else 1036 else
1015 result.appendLiteral("counters("); 1037 result.appendLiteral("counters(");
1016 1038
1017 result.append(m_value.counter->identifier()); 1039 result.append(value().counter->identifier());
1018 if (!separator.isEmpty()) { 1040 if (!separator.isEmpty()) {
1019 result.appendLiteral(", "); 1041 result.appendLiteral(", ");
1020 result.append(serializeString(separator)); 1042 result.append(serializeString(separator));
1021 } 1043 }
1022 String listStyle = m_value.counter->listStyle(); 1044 String listStyle = value().counter->listStyle();
1023 bool isDefaultListStyle = m_value.counter->listStyleIdent() == CSSVa lueDecimal; 1045 bool isDefaultListStyle = value().counter->listStyleIdent() == CSSVa lueDecimal;
1024 if (!listStyle.isEmpty() && !isDefaultListStyle) { 1046 if (!listStyle.isEmpty() && !isDefaultListStyle) {
1025 result.appendLiteral(", "); 1047 result.appendLiteral(", ");
1026 result.append(listStyle); 1048 result.append(listStyle);
1027 } 1049 }
1028 result.append(')'); 1050 result.append(')');
1029 1051
1030 text = result.toString(); 1052 text = result.toString();
1031 break; 1053 break;
1032 } 1054 }
1033 case CSS_RECT: 1055 case CSS_RECT:
1034 text = getRectValue()->cssText(); 1056 text = getRectValue()->cssText();
1035 break; 1057 break;
1036 case CSS_QUAD: 1058 case CSS_QUAD:
1037 text = getQuadValue()->cssText(); 1059 text = getQuadValue()->cssText();
1038 break; 1060 break;
1039 case CSS_RGBCOLOR: { 1061 case CSS_RGBCOLOR: {
1040 text = Color(m_value.rgbcolor).serializedAsCSSComponentValue(); 1062 text = Color(value().rgbcolor).serializedAsCSSComponentValue();
1041 break; 1063 break;
1042 } 1064 }
1043 case CSS_PAIR: 1065 case CSS_PAIR:
1044 text = getPairValue()->cssText(); 1066 text = getPairValue()->cssText();
1045 break; 1067 break;
1046 case CSS_CALC: 1068 case CSS_CALC:
1047 text = m_value.calc->cssText(); 1069 text = value().calc->cssText();
1048 break; 1070 break;
1049 case CSS_SHAPE: 1071 case CSS_SHAPE:
1050 text = m_value.shape->cssText(); 1072 text = value().shape->cssText();
1073 break;
1074 case CSS_IDENT:
1075 case CSS_CALC_PERCENTAGE_WITH_NUMBER:
1076 case CSS_CALC_PERCENTAGE_WITH_LENGTH:
1077 case CSS_QEM:
1051 break; 1078 break;
1052 } 1079 }
1053 1080
1054 ASSERT(!cssTextCache().contains(this)); 1081 ASSERT(!cssTextCache().contains(this));
1055 cssTextCache().set(this, text); 1082 cssTextCache().set(this, text);
1056 m_hasCachedCSSText = true; 1083 if (!isTaggedPtr())
1084 m_hasCachedCSSText = true;
1057 return text; 1085 return text;
1058 } 1086 }
1059 1087
1060 bool CSSPrimitiveValue::equals(const CSSPrimitiveValue& other) const 1088 bool CSSPrimitiveValue::equals(const CSSPrimitiveValue& other) const
1061 { 1089 {
1062 if (m_primitiveUnitType != other.m_primitiveUnitType) 1090 if (type() != other.type())
1063 return false; 1091 return false;
1064 1092
1065 switch (m_primitiveUnitType) { 1093 switch (type()) {
1066 case CSS_UNKNOWN: 1094 case CSS_UNKNOWN:
1067 return false; 1095 return false;
1068 case CSS_NUMBER: 1096 case CSS_NUMBER:
1069 case CSS_PERCENTAGE: 1097 case CSS_PERCENTAGE:
1070 case CSS_EMS: 1098 case CSS_EMS:
1071 case CSS_EXS: 1099 case CSS_EXS:
1072 case CSS_REMS: 1100 case CSS_REMS:
1073 case CSS_PX: 1101 case CSS_PX:
1074 case CSS_CM: 1102 case CSS_CM:
1075 case CSS_DPPX: 1103 case CSS_DPPX:
1076 case CSS_DPI: 1104 case CSS_DPI:
1077 case CSS_DPCM: 1105 case CSS_DPCM:
1078 case CSS_MM: 1106 case CSS_MM:
1079 case CSS_IN: 1107 case CSS_IN:
1080 case CSS_PT: 1108 case CSS_PT:
1081 case CSS_PC: 1109 case CSS_PC:
1082 case CSS_DEG: 1110 case CSS_DEG:
1083 case CSS_RAD: 1111 case CSS_RAD:
1084 case CSS_GRAD: 1112 case CSS_GRAD:
1085 case CSS_MS: 1113 case CSS_MS:
1086 case CSS_S: 1114 case CSS_S:
1087 case CSS_HZ: 1115 case CSS_HZ:
1088 case CSS_KHZ: 1116 case CSS_KHZ:
1089 case CSS_TURN: 1117 case CSS_TURN:
1090 case CSS_VW: 1118 case CSS_VW:
1091 case CSS_VH: 1119 case CSS_VH:
1092 case CSS_VMIN: 1120 case CSS_VMIN:
1093 case CSS_VMAX: 1121 case CSS_VMAX:
1094 case CSS_FR: 1122 case CSS_FR:
1095 return m_value.num == other.m_value.num; 1123 return value().num == other.value().num;
1096 case CSS_PROPERTY_ID: 1124 case CSS_PROPERTY_ID:
1097 return m_value.propertyID == other.m_value.propertyID; 1125 return value().propertyID == other.value().propertyID;
1098 case CSS_VALUE_ID: 1126 case CSS_VALUE_ID:
1099 return m_value.valueID == other.m_value.valueID; 1127 return value().valueID == other.value().valueID;
1100 case CSS_CUSTOM_IDENT: 1128 case CSS_CUSTOM_IDENT:
1101 case CSS_STRING: 1129 case CSS_STRING:
1102 case CSS_URI: 1130 case CSS_URI:
1103 case CSS_ATTR: 1131 case CSS_ATTR:
1104 return equal(m_value.string, other.m_value.string); 1132 return equal(value().string, other.value().string);
1105 case CSS_COUNTER: 1133 case CSS_COUNTER:
1106 return m_value.counter && other.m_value.counter && m_value.counter->equa ls(*other.m_value.counter); 1134 return value().counter && other.value().counter && value().counter->equa ls(*other.value().counter);
1107 case CSS_RECT: 1135 case CSS_RECT:
1108 return m_value.rect && other.m_value.rect && m_value.rect->equals(*other .m_value.rect); 1136 return value().rect && other.value().rect && value().rect->equals(*other .value().rect);
1109 case CSS_QUAD: 1137 case CSS_QUAD:
1110 return m_value.quad && other.m_value.quad && m_value.quad->equals(*other .m_value.quad); 1138 return value().quad && other.value().quad && value().quad->equals(*other .value().quad);
1111 case CSS_RGBCOLOR: 1139 case CSS_RGBCOLOR:
1112 return m_value.rgbcolor == other.m_value.rgbcolor; 1140 return value().rgbcolor == other.value().rgbcolor;
1113 case CSS_PAIR: 1141 case CSS_PAIR:
1114 return m_value.pair && other.m_value.pair && m_value.pair->equals(*other .m_value.pair); 1142 return value().pair && other.value().pair && value().pair->equals(*other .value().pair);
1115 case CSS_CALC: 1143 case CSS_CALC:
1116 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other .m_value.calc); 1144 return value().calc && other.value().calc && value().calc->equals(*other .value().calc);
1117 case CSS_SHAPE: 1145 case CSS_SHAPE:
1118 return m_value.shape && other.m_value.shape && m_value.shape->equals(*ot her.m_value.shape); 1146 return value().shape && other.value().shape && value().shape->equals(*ot her.value().shape);
1147 case CSS_IDENT:
1148 case CSS_INTEGER:
1149 case CSS_CHS:
1150 case CSS_CALC_PERCENTAGE_WITH_NUMBER:
1151 case CSS_CALC_PERCENTAGE_WITH_LENGTH:
1152 case CSS_QEM:
1153 return false;
1119 } 1154 }
1120 return false; 1155 return false;
1121 } 1156 }
1122 1157
1123 DEFINE_TRACE_AFTER_DISPATCH(CSSPrimitiveValue) 1158 DEFINE_TRACE_AFTER_DISPATCH(CSSPrimitiveValue)
1124 { 1159 {
1125 #if ENABLE(OILPAN) 1160 #if ENABLE(OILPAN)
1126 switch (m_primitiveUnitType) { 1161 switch (type()) {
1127 case CSS_COUNTER: 1162 case CSS_COUNTER:
1128 visitor->trace(m_value.counter); 1163 visitor->trace(value().counter);
1129 break; 1164 break;
1130 case CSS_RECT: 1165 case CSS_RECT:
1131 visitor->trace(m_value.rect); 1166 visitor->trace(value().rect);
1132 break; 1167 break;
1133 case CSS_QUAD: 1168 case CSS_QUAD:
1134 visitor->trace(m_value.quad); 1169 visitor->trace(value().quad);
1135 break; 1170 break;
1136 case CSS_PAIR: 1171 case CSS_PAIR:
1137 visitor->trace(m_value.pair); 1172 visitor->trace(value().pair);
1138 break; 1173 break;
1139 case CSS_CALC: 1174 case CSS_CALC:
1140 visitor->trace(m_value.calc); 1175 visitor->trace(value().calc);
1141 break; 1176 break;
1142 case CSS_SHAPE: 1177 case CSS_SHAPE:
1143 visitor->trace(m_value.shape); 1178 visitor->trace(value().shape);
1144 break; 1179 break;
1145 default: 1180 default:
1146 break; 1181 break;
1147 } 1182 }
1148 #endif 1183 #endif
1149 CSSValue::traceAfterDispatch(visitor); 1184 CSSValue::traceAfterDispatch(visitor);
1150 } 1185 }
1151 1186
1152 } // namespace blink 1187 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/CSSPrimitiveValue.h ('k') | Source/core/css/CSSPrimitiveValueMappings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698