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

Unified Diff: third_party/WebKit/Source/core/css/cssom/CSSSimpleLength.cpp

Issue 2373233002: Add fromCSSValue methods to LengthValue subclasses, remove extra method in CSSSimpleLength. (Closed)
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698