Chromium Code Reviews| Index: third_party/WebKit/Source/core/css/CSSIdentifierValue.cpp |
| diff --git a/third_party/WebKit/Source/core/css/CSSIdentifierValue.cpp b/third_party/WebKit/Source/core/css/CSSIdentifierValue.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d2325b479c342c0c53fdc3273af55e61b45bba1a |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/css/CSSIdentifierValue.cpp |
| @@ -0,0 +1,87 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/css/CSSIdentifierValue.h" |
| + |
| +#include "core/css/CSSMarkup.h" |
| +#include "core/css/CSSValuePool.h" |
| +#include "platform/Length.h" |
| +#include "wtf/text/StringBuilder.h" |
| +#include "wtf/text/WTFString.h" |
| + |
| +namespace blink { |
| + |
| +static const AtomicString& valueName(CSSValueID valueID) |
| +{ |
| + DCHECK_GE(valueID, 0); |
| + DCHECK_LT(valueID, numCSSValueKeywords); |
| + |
| + if (valueID < 0) |
| + return nullAtom; |
| + |
| + static AtomicString* keywordStrings = new AtomicString[numCSSValueKeywords]; // Leaked intentionally. |
| + AtomicString& keywordString = keywordStrings[valueID]; |
| + if (keywordString.isNull()) |
| + keywordString = getValueName(valueID); |
| + return keywordString; |
| +} |
| + |
| +CSSIdentifierValue* CSSIdentifierValue::createIdentifier(CSSValueID valueID) |
| +{ |
| + CSSIdentifierValue* cssValue = cssValuePool().identifierCacheValue(valueID); |
| + if (!cssValue) |
| + cssValue = cssValuePool().setIdentifierCacheValue(valueID, new CSSIdentifierValue(valueID)); |
| + return cssValue; |
| +} |
| + |
| +String CSSIdentifierValue::customCSSText() const |
| +{ |
| + return valueName(m_valueID); |
| +} |
| + |
| +CSSIdentifierValue::CSSIdentifierValue(CSSValueID valueID) |
| + : CSSValue(IdentifierClass) |
| + , m_valueID(valueID) |
| +{ |
| + // TODO(sashab): Add a DCHECK_NE(valueID, CSSValueInvalid). |
|
rjwright
2016/09/22 06:12:50
Want to add this now?
sashab
2016/09/23 01:01:10
It makes some tests fail :( clarified the todo :)
|
| +} |
| + |
| +CSSIdentifierValue::CSSIdentifierValue(const Length& length) |
| + : CSSValue(IdentifierClass) |
| +{ |
| + switch (length.type()) { |
| + case Auto: |
| + m_valueID = CSSValueAuto; |
| + break; |
| + case MinContent: |
| + m_valueID = CSSValueMinContent; |
| + break; |
| + case MaxContent: |
| + m_valueID = CSSValueMaxContent; |
| + break; |
| + case FillAvailable: |
| + m_valueID = CSSValueWebkitFillAvailable; |
| + break; |
| + case FitContent: |
| + m_valueID = CSSValueFitContent; |
| + break; |
| + case ExtendToZoom: |
| + m_valueID = CSSValueInternalExtendToZoom; |
| + case Percent: |
| + case Fixed: |
| + case Calculated: |
| + case DeviceWidth: |
| + case DeviceHeight: |
| + case MaxSizeNone: |
| + NOTREACHED(); |
| + break; |
| + } |
| +} |
| + |
| +DEFINE_TRACE_AFTER_DISPATCH(CSSIdentifierValue) |
| +{ |
| + CSSValue::traceAfterDispatch(visitor); |
| +} |
| + |
| +} // namespace blink |