| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Andreas Kling (kling@webkit.org) | 2 * Copyright (C) 2011 Andreas Kling (kling@webkit.org) |
| 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #include "core/css/CSSSVGDocumentValue.h" | 51 #include "core/css/CSSSVGDocumentValue.h" |
| 52 #include "core/css/CSSShadowValue.h" | 52 #include "core/css/CSSShadowValue.h" |
| 53 #include "core/css/CSSTimingFunctionValue.h" | 53 #include "core/css/CSSTimingFunctionValue.h" |
| 54 #include "core/css/CSSTransformValue.h" | 54 #include "core/css/CSSTransformValue.h" |
| 55 #include "core/css/CSSUnicodeRangeValue.h" | 55 #include "core/css/CSSUnicodeRangeValue.h" |
| 56 #include "core/css/CSSValueList.h" | 56 #include "core/css/CSSValueList.h" |
| 57 | 57 |
| 58 namespace blink { | 58 namespace blink { |
| 59 | 59 |
| 60 struct SameSizeAsCSSValue : public RefCountedWillBeGarbageCollectedFinalized<Sam
eSizeAsCSSValue> | 60 struct SameSizeAsCSSValue : public RefCountedWillBeGarbageCollectedFinalized<Sam
eSizeAsCSSValue> |
| 61 // VC++ 2013 doesn't support EBCO (Empty Base Class Optimization), and having | |
| 62 // multiple empty base classes makes the size of CSSValue bloat (Note that both | |
| 63 // of GarbageCollectedFinalized and ScriptWrappableBase are empty classes). | |
| 64 // See the following article for details. | |
| 65 // http://social.msdn.microsoft.com/forums/vstudio/en-US/504c6598-6076-4acf-96b6
-e6acb475d302/vc-multiple-inheritance-empty-base-classes-bloats-object-size | |
| 66 // | |
| 67 // FIXME: Remove this #if directive once VC++'s issue gets fixed. | |
| 68 // Note that we're going to split CSSValue class into two classes; CSSOMValue | |
| 69 // (assumed name) which derives ScriptWrappable and CSSValue (new one) which | |
| 70 // doesn't derive ScriptWrappable or ScriptWrappableBase. Then, we can safely | |
| 71 // remove this #if directive. | |
| 72 #if ENABLE(OILPAN) && COMPILER(MSVC) | |
| 73 , public ScriptWrappableBase | |
| 74 #endif | |
| 75 { | 61 { |
| 76 uint32_t bitfields; | 62 uint32_t bitfields; |
| 77 }; | 63 }; |
| 78 | 64 |
| 79 COMPILE_ASSERT(sizeof(CSSValue) <= sizeof(SameSizeAsCSSValue), CSS_value_should_
stay_small); | 65 COMPILE_ASSERT(sizeof(CSSValue) <= sizeof(SameSizeAsCSSValue), CSS_value_should_
stay_small); |
| 80 | 66 |
| 81 class TextCloneCSSValue : public CSSValue { | |
| 82 public: | |
| 83 static PassRefPtrWillBeRawPtr<TextCloneCSSValue> create(ClassType classType,
const String& text) | |
| 84 { | |
| 85 return adoptRefWillBeNoop(new TextCloneCSSValue(classType, text)); | |
| 86 } | |
| 87 | |
| 88 String cssText() const { return m_cssText; } | |
| 89 | |
| 90 void traceAfterDispatch(Visitor* visitor) { CSSValue::traceAfterDispatch(vis
itor); } | |
| 91 | |
| 92 private: | |
| 93 TextCloneCSSValue(ClassType classType, const String& text) | |
| 94 : CSSValue(classType, /*isCSSOMSafe*/ true) | |
| 95 , m_cssText(text) | |
| 96 { | |
| 97 m_isTextClone = true; | |
| 98 } | |
| 99 | |
| 100 String m_cssText; | |
| 101 }; | |
| 102 | |
| 103 DEFINE_CSS_VALUE_TYPE_CASTS(TextCloneCSSValue, isTextCloneCSSValue()); | |
| 104 | |
| 105 bool CSSValue::isImplicitInitialValue() const | 67 bool CSSValue::isImplicitInitialValue() const |
| 106 { | 68 { |
| 107 return m_classType == InitialClass && toCSSInitialValue(this)->isImplicit(); | 69 return m_classType == InitialClass && toCSSInitialValue(this)->isImplicit(); |
| 108 } | 70 } |
| 109 | 71 |
| 110 CSSValue::Type CSSValue::cssValueType() const | 72 CSSValue::Type CSSValue::cssValueType() const |
| 111 { | 73 { |
| 112 if (isInheritedValue()) | 74 if (isInheritedValue()) |
| 113 return CSS_INHERIT; | 75 return CSS_INHERIT; |
| 114 if (isPrimitiveValue()) | 76 if (isPrimitiveValue()) |
| 115 return CSS_PRIMITIVE_VALUE; | 77 return CSS_PRIMITIVE_VALUE; |
| 116 if (isValueList()) | 78 if (isValueList()) |
| 117 return CSS_VALUE_LIST; | 79 return CSS_VALUE_LIST; |
| 118 if (isInitialValue()) | 80 if (isInitialValue()) |
| 119 return CSS_INITIAL; | 81 return CSS_INITIAL; |
| 120 return CSS_CUSTOM; | 82 return CSS_CUSTOM; |
| 121 } | 83 } |
| 122 | 84 |
| 123 bool CSSValue::hasFailedOrCanceledSubresources() const | 85 bool CSSValue::hasFailedOrCanceledSubresources() const |
| 124 { | 86 { |
| 125 // This should get called for internal instances only. | |
| 126 ASSERT(!isCSSOMSafe()); | |
| 127 | |
| 128 if (isValueList()) | 87 if (isValueList()) |
| 129 return toCSSValueList(this)->hasFailedOrCanceledSubresources(); | 88 return toCSSValueList(this)->hasFailedOrCanceledSubresources(); |
| 130 if (classType() == FontFaceSrcClass) | 89 if (classType() == FontFaceSrcClass) |
| 131 return toCSSFontFaceSrcValue(this)->hasFailedOrCanceledSubresources(); | 90 return toCSSFontFaceSrcValue(this)->hasFailedOrCanceledSubresources(); |
| 132 if (classType() == ImageClass) | 91 if (classType() == ImageClass) |
| 133 return toCSSImageValue(this)->hasFailedOrCanceledSubresources(); | 92 return toCSSImageValue(this)->hasFailedOrCanceledSubresources(); |
| 134 if (classType() == CrossfadeClass) | 93 if (classType() == CrossfadeClass) |
| 135 return toCSSCrossfadeValue(this)->hasFailedOrCanceledSubresources(); | 94 return toCSSCrossfadeValue(this)->hasFailedOrCanceledSubresources(); |
| 136 if (classType() == ImageSetClass) | 95 if (classType() == ImageSetClass) |
| 137 return toCSSImageSetValue(this)->hasFailedOrCanceledSubresources(); | 96 return toCSSImageSetValue(this)->hasFailedOrCanceledSubresources(); |
| 138 | 97 |
| 139 return false; | 98 return false; |
| 140 } | 99 } |
| 141 | 100 |
| 142 template<class ChildClassType> | 101 template<class ChildClassType> |
| 143 inline static bool compareCSSValues(const CSSValue& first, const CSSValue& secon
d) | 102 inline static bool compareCSSValues(const CSSValue& first, const CSSValue& secon
d) |
| 144 { | 103 { |
| 145 return static_cast<const ChildClassType&>(first).equals(static_cast<const Ch
ildClassType&>(second)); | 104 return static_cast<const ChildClassType&>(first).equals(static_cast<const Ch
ildClassType&>(second)); |
| 146 } | 105 } |
| 147 | 106 |
| 148 bool CSSValue::equals(const CSSValue& other) const | 107 bool CSSValue::equals(const CSSValue& other) const |
| 149 { | 108 { |
| 150 if (m_isTextClone) { | |
| 151 ASSERT(isCSSOMSafe()); | |
| 152 return toTextCloneCSSValue(this)->cssText() == other.cssText(); | |
| 153 } | |
| 154 | |
| 155 if (m_classType == other.m_classType) { | 109 if (m_classType == other.m_classType) { |
| 156 switch (m_classType) { | 110 switch (m_classType) { |
| 157 case BorderImageSliceClass: | 111 case BorderImageSliceClass: |
| 158 return compareCSSValues<CSSBorderImageSliceValue>(*this, other); | 112 return compareCSSValues<CSSBorderImageSliceValue>(*this, other); |
| 159 case CanvasClass: | 113 case CanvasClass: |
| 160 return compareCSSValues<CSSCanvasValue>(*this, other); | 114 return compareCSSValues<CSSCanvasValue>(*this, other); |
| 161 case CursorImageClass: | 115 case CursorImageClass: |
| 162 return compareCSSValues<CSSCursorImageValue>(*this, other); | 116 return compareCSSValues<CSSCursorImageValue>(*this, other); |
| 163 case FontClass: | 117 case FontClass: |
| 164 return compareCSSValues<CSSFontValue>(*this, other); | 118 return compareCSSValues<CSSFontValue>(*this, other); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 172 } |
| 219 } else if (m_classType == ValueListClass && other.m_classType != ValueListCl
ass) | 173 } else if (m_classType == ValueListClass && other.m_classType != ValueListCl
ass) |
| 220 return toCSSValueList(this)->equals(other); | 174 return toCSSValueList(this)->equals(other); |
| 221 else if (m_classType != ValueListClass && other.m_classType == ValueListClas
s) | 175 else if (m_classType != ValueListClass && other.m_classType == ValueListClas
s) |
| 222 return static_cast<const CSSValueList&>(other).equals(*this); | 176 return static_cast<const CSSValueList&>(other).equals(*this); |
| 223 return false; | 177 return false; |
| 224 } | 178 } |
| 225 | 179 |
| 226 String CSSValue::cssText() const | 180 String CSSValue::cssText() const |
| 227 { | 181 { |
| 228 if (m_isTextClone) { | |
| 229 ASSERT(isCSSOMSafe()); | |
| 230 return toTextCloneCSSValue(this)->cssText(); | |
| 231 } | |
| 232 ASSERT(!isCSSOMSafe() || isSubtypeExposedToCSSOM()); | |
| 233 | |
| 234 switch (classType()) { | 182 switch (classType()) { |
| 235 case BorderImageSliceClass: | 183 case BorderImageSliceClass: |
| 236 return toCSSBorderImageSliceValue(this)->customCSSText(); | 184 return toCSSBorderImageSliceValue(this)->customCSSText(); |
| 237 case CanvasClass: | 185 case CanvasClass: |
| 238 return toCSSCanvasValue(this)->customCSSText(); | 186 return toCSSCanvasValue(this)->customCSSText(); |
| 239 case CursorImageClass: | 187 case CursorImageClass: |
| 240 return toCSSCursorImageValue(this)->customCSSText(); | 188 return toCSSCursorImageValue(this)->customCSSText(); |
| 241 case FontClass: | 189 case FontClass: |
| 242 return toCSSFontValue(this)->customCSSText(); | 190 return toCSSFontValue(this)->customCSSText(); |
| 243 case FontFaceSrcClass: | 191 case FontFaceSrcClass: |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 return toCSSSVGDocumentValue(this)->customCSSText(); | 238 return toCSSSVGDocumentValue(this)->customCSSText(); |
| 291 case CSSContentDistributionClass: | 239 case CSSContentDistributionClass: |
| 292 return toCSSContentDistributionValue(this)->customCSSText(); | 240 return toCSSContentDistributionValue(this)->customCSSText(); |
| 293 } | 241 } |
| 294 ASSERT_NOT_REACHED(); | 242 ASSERT_NOT_REACHED(); |
| 295 return String(); | 243 return String(); |
| 296 } | 244 } |
| 297 | 245 |
| 298 void CSSValue::destroy() | 246 void CSSValue::destroy() |
| 299 { | 247 { |
| 300 if (m_isTextClone) { | |
| 301 ASSERT(isCSSOMSafe()); | |
| 302 delete toTextCloneCSSValue(this); | |
| 303 return; | |
| 304 } | |
| 305 ASSERT(!isCSSOMSafe() || isSubtypeExposedToCSSOM()); | |
| 306 | |
| 307 switch (classType()) { | 248 switch (classType()) { |
| 308 case BorderImageSliceClass: | 249 case BorderImageSliceClass: |
| 309 delete toCSSBorderImageSliceValue(this); | 250 delete toCSSBorderImageSliceValue(this); |
| 310 return; | 251 return; |
| 311 case CanvasClass: | 252 case CanvasClass: |
| 312 delete toCSSCanvasValue(this); | 253 delete toCSSCanvasValue(this); |
| 313 return; | 254 return; |
| 314 case CursorImageClass: | 255 case CursorImageClass: |
| 315 delete toCSSCursorImageValue(this); | 256 delete toCSSCursorImageValue(this); |
| 316 return; | 257 return; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 return; | 332 return; |
| 392 case CSSContentDistributionClass: | 333 case CSSContentDistributionClass: |
| 393 delete toCSSContentDistributionValue(this); | 334 delete toCSSContentDistributionValue(this); |
| 394 return; | 335 return; |
| 395 } | 336 } |
| 396 ASSERT_NOT_REACHED(); | 337 ASSERT_NOT_REACHED(); |
| 397 } | 338 } |
| 398 | 339 |
| 399 void CSSValue::finalizeGarbageCollectedObject() | 340 void CSSValue::finalizeGarbageCollectedObject() |
| 400 { | 341 { |
| 401 if (m_isTextClone) { | |
| 402 ASSERT(isCSSOMSafe()); | |
| 403 toTextCloneCSSValue(this)->~TextCloneCSSValue(); | |
| 404 return; | |
| 405 } | |
| 406 ASSERT(!isCSSOMSafe() || isSubtypeExposedToCSSOM()); | |
| 407 | |
| 408 switch (classType()) { | 342 switch (classType()) { |
| 409 case BorderImageSliceClass: | 343 case BorderImageSliceClass: |
| 410 toCSSBorderImageSliceValue(this)->~CSSBorderImageSliceValue(); | 344 toCSSBorderImageSliceValue(this)->~CSSBorderImageSliceValue(); |
| 411 return; | 345 return; |
| 412 case CanvasClass: | 346 case CanvasClass: |
| 413 toCSSCanvasValue(this)->~CSSCanvasValue(); | 347 toCSSCanvasValue(this)->~CSSCanvasValue(); |
| 414 return; | 348 return; |
| 415 case CursorImageClass: | 349 case CursorImageClass: |
| 416 toCSSCursorImageValue(this)->~CSSCursorImageValue(); | 350 toCSSCursorImageValue(this)->~CSSCursorImageValue(); |
| 417 return; | 351 return; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 return; | 426 return; |
| 493 case CSSContentDistributionClass: | 427 case CSSContentDistributionClass: |
| 494 toCSSContentDistributionValue(this)->~CSSContentDistributionValue(); | 428 toCSSContentDistributionValue(this)->~CSSContentDistributionValue(); |
| 495 return; | 429 return; |
| 496 } | 430 } |
| 497 ASSERT_NOT_REACHED(); | 431 ASSERT_NOT_REACHED(); |
| 498 } | 432 } |
| 499 | 433 |
| 500 void CSSValue::trace(Visitor* visitor) | 434 void CSSValue::trace(Visitor* visitor) |
| 501 { | 435 { |
| 502 if (m_isTextClone) { | |
| 503 ASSERT(isCSSOMSafe()); | |
| 504 toTextCloneCSSValue(this)->traceAfterDispatch(visitor); | |
| 505 return; | |
| 506 } | |
| 507 ASSERT(!isCSSOMSafe() || isSubtypeExposedToCSSOM()); | |
| 508 | |
| 509 switch (classType()) { | 436 switch (classType()) { |
| 510 case BorderImageSliceClass: | 437 case BorderImageSliceClass: |
| 511 toCSSBorderImageSliceValue(this)->traceAfterDispatch(visitor); | 438 toCSSBorderImageSliceValue(this)->traceAfterDispatch(visitor); |
| 512 return; | 439 return; |
| 513 case CanvasClass: | 440 case CanvasClass: |
| 514 toCSSCanvasValue(this)->traceAfterDispatch(visitor); | 441 toCSSCanvasValue(this)->traceAfterDispatch(visitor); |
| 515 return; | 442 return; |
| 516 case CursorImageClass: | 443 case CursorImageClass: |
| 517 toCSSCursorImageValue(this)->traceAfterDispatch(visitor); | 444 toCSSCursorImageValue(this)->traceAfterDispatch(visitor); |
| 518 return; | 445 return; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 case CSSSVGDocumentClass: | 518 case CSSSVGDocumentClass: |
| 592 toCSSSVGDocumentValue(this)->traceAfterDispatch(visitor); | 519 toCSSSVGDocumentValue(this)->traceAfterDispatch(visitor); |
| 593 return; | 520 return; |
| 594 case CSSContentDistributionClass: | 521 case CSSContentDistributionClass: |
| 595 toCSSContentDistributionValue(this)->traceAfterDispatch(visitor); | 522 toCSSContentDistributionValue(this)->traceAfterDispatch(visitor); |
| 596 return; | 523 return; |
| 597 } | 524 } |
| 598 ASSERT_NOT_REACHED(); | 525 ASSERT_NOT_REACHED(); |
| 599 } | 526 } |
| 600 | 527 |
| 601 PassRefPtrWillBeRawPtr<CSSValue> CSSValue::cloneForCSSOM() const | |
| 602 { | |
| 603 switch (classType()) { | |
| 604 case PrimitiveClass: | |
| 605 return toCSSPrimitiveValue(this)->cloneForCSSOM(); | |
| 606 case ValueListClass: | |
| 607 return toCSSValueList(this)->cloneForCSSOM(); | |
| 608 case ImageClass: | |
| 609 case CursorImageClass: | |
| 610 return toCSSImageValue(this)->cloneForCSSOM(); | |
| 611 case CSSFilterClass: | |
| 612 return toCSSFilterValue(this)->cloneForCSSOM(); | |
| 613 case CSSTransformClass: | |
| 614 return toCSSTransformValue(this)->cloneForCSSOM(); | |
| 615 case ImageSetClass: | |
| 616 return toCSSImageSetValue(this)->cloneForCSSOM(); | |
| 617 default: | |
| 618 ASSERT(!isSubtypeExposedToCSSOM()); | |
| 619 return TextCloneCSSValue::create(classType(), cssText()); | |
| 620 } | |
| 621 } | 528 } |
| 622 | |
| 623 } | |
| OLD | NEW |