Index: third_party/WebKit/Source/core/css/cssom/CSSSimpleLength.cpp |
diff --git a/third_party/WebKit/Source/core/css/cssom/CSSSimpleLength.cpp b/third_party/WebKit/Source/core/css/cssom/CSSSimpleLength.cpp |
index 1520beea20369b2a851b0ca45fb7fd5a6b58ce93..286446a87e2032af64fdd2ca8c986b0c96888c46 100644 |
--- a/third_party/WebKit/Source/core/css/cssom/CSSSimpleLength.cpp |
+++ b/third_party/WebKit/Source/core/css/cssom/CSSSimpleLength.cpp |
@@ -4,15 +4,27 @@ |
#include "core/css/cssom/CSSSimpleLength.h" |
+#include "bindings/core/v8/ExceptionState.h" |
#include "core/css/CSSPrimitiveValue.h" |
#include "core/css/cssom/CSSCalcLength.h" |
#include "wtf/text/StringBuilder.h" |
namespace blink { |
-CSSValue* CSSSimpleLength::toCSSValue() const |
+CSSSimpleLength* CSSSimpleLength::create(double value, const String& type, ExceptionState& exceptionState) |
{ |
- return CSSPrimitiveValue::create(m_value, m_unit); |
+ CSSPrimitiveValue::UnitType unit = CSSLengthValue::unitFromName(type); |
+ if (!CSSLengthValue::isSupportedLengthUnit(unit)) { |
+ exceptionState.throwTypeError("Invalid unit for CSSSimpleLength: " + type); |
+ return nullptr; |
+ } |
+ return new CSSSimpleLength(value, unit); |
+} |
+ |
+CSSSimpleLength* CSSSimpleLength::fromCSSValue(const CSSPrimitiveValue& value) |
+{ |
+ DCHECK(value.isLength()); |
+ return new CSSSimpleLength(value.getDoubleValue(), value.typeWithCalcResolved()); |
} |
bool CSSSimpleLength::containsPercent() const |
@@ -45,4 +57,9 @@ CSSLengthValue* CSSSimpleLength::divideInternal(double x) |
return create(m_value / x, m_unit); |
} |
+CSSValue* CSSSimpleLength::toCSSValue() const |
+{ |
+ return CSSPrimitiveValue::create(m_value, m_unit); |
+} |
+ |
} // namespace blink |