Index: third_party/WebKit/Source/core/css/cssom/CSSRotation.cpp |
diff --git a/third_party/WebKit/Source/core/css/cssom/CSSRotation.cpp b/third_party/WebKit/Source/core/css/cssom/CSSRotation.cpp |
index 8e5e1a1a8b3caee3d8c49834814378c130295093..bc7210b31784bc4a7b3498beafb9827129027b34 100644 |
--- a/third_party/WebKit/Source/core/css/cssom/CSSRotation.cpp |
+++ b/third_party/WebKit/Source/core/css/cssom/CSSRotation.cpp |
@@ -4,10 +4,77 @@ |
#include "core/css/cssom/CSSRotation.h" |
+#include "core/css/CSSFunctionValue.h" |
#include "core/css/CSSPrimitiveValue.h" |
namespace blink { |
+namespace { |
+ |
+bool isNumberValue(const CSSValue& value) |
+{ |
+ if (!value.isPrimitiveValue()) |
Timothy Loh
2016/06/27 05:10:04
fwiw I think it'd clearer if this is just
return
meade_UTC10
2016/06/27 17:19:41
Done.
|
+ return false; |
+ return toCSSPrimitiveValue(value).isNumber(); |
+} |
+ |
+CSSRotation* fromCSSRotate(const CSSFunctionValue& value) |
+{ |
+ DCHECK_EQ(value.length(), 1UL); |
+ return CSSRotation::create(toCSSPrimitiveValue(value.item(0)).computeDegrees()); |
+} |
+ |
+CSSRotation* fromCSSRotate3d(const CSSFunctionValue& value) |
+{ |
+ DCHECK_EQ(value.length(), 4UL); |
+ if (!isNumberValue(value.item(0)) |
Timothy Loh
2016/06/27 05:10:04
DCHECKs for these too. I think none of these conve
meade_UTC10
2016/06/27 17:19:41
Done.
|
+ || !isNumberValue(value.item(1)) |
+ || !isNumberValue(value.item(2))) { |
+ // computeDegrees asserts that value.item(3) is an angle. |
+ return nullptr; |
+ } |
+ double x = toCSSPrimitiveValue(value.item(0)).getDoubleValue(); |
+ double y = toCSSPrimitiveValue(value.item(1)).getDoubleValue(); |
+ double z = toCSSPrimitiveValue(value.item(2)).getDoubleValue(); |
+ double angle = toCSSPrimitiveValue(value.item(3)).computeDegrees(); |
+ return CSSRotation::create(x, y, z, angle); |
+} |
+ |
+CSSRotation* fromCSSRotateXYZ(const CSSFunctionValue& value) |
+{ |
+ DCHECK_EQ(value.length(), 1UL); |
+ double angle = toCSSPrimitiveValue(value.item(0)).computeDegrees(); |
+ |
+ switch (value.functionType()) { |
+ case CSSValueRotateX: |
+ return CSSRotation::create(1, 0, 0, angle); |
+ case CSSValueRotateY: |
+ return CSSRotation::create(0, 1, 0, angle); |
+ case CSSValueRotateZ: |
+ return CSSRotation::create(0, 0, 1, angle); |
+ default: |
Timothy Loh
2016/06/27 05:10:04
NOT_REACHED()
meade_UTC10
2016/06/27 17:19:41
Done.
|
+ return nullptr; |
+ } |
+} |
+ |
+} // namespace |
+ |
+CSSRotation* CSSRotation::fromCSSValue(const CSSFunctionValue& value) |
+{ |
+ switch (value.functionType()) { |
+ case CSSValueRotate: |
+ return fromCSSRotate(value); |
+ case CSSValueRotate3d: |
+ return fromCSSRotate3d(value); |
+ case CSSValueRotateX: |
+ case CSSValueRotateY: |
+ case CSSValueRotateZ: |
+ return fromCSSRotateXYZ(value); |
+ default: |
+ return nullptr; |
Timothy Loh
2016/06/27 05:10:04
NOT_REACHED()
meade_UTC10
2016/06/27 17:19:41
Done.
|
+ } |
+} |
+ |
CSSFunctionValue* CSSRotation::toCSSValue() const |
{ |
CSSFunctionValue* result = CSSFunctionValue::create(m_is2D ? CSSValueRotate : CSSValueRotate3d); |