Commit 45edc5f2 authored by George Steel's avatar George Steel Committed by Commit Bot

[refactor] move ValueForTransformOperation to ComputedStyleUtils

Move computed_style_property_map.cc::ComputedTransformComponent()
to ComputedStylePropertyMap::ValueForTransformOperation() in preparation
for its upcoming use by animations code.  It has been moved verbatim
except for renaming it according to current conventions.

Add ValueForMatrixTransform to COmputedStyleUtils class. It previously
had no declaration in the header.

This causes no behavioral change.

Change-Id: I94faea6fac02a2ee37b88d32fed326142c0ec01e
Bug: 933761
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2106497Reviewed-by: default avatarRobert Flack <flackr@chromium.org>
Commit-Queue: George Steel <gtsteel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751178}
parent 692512f9
...@@ -15,160 +15,19 @@ ...@@ -15,160 +15,19 @@
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/pseudo_element.h" #include "third_party/blink/renderer/core/dom/pseudo_element.h"
#include "third_party/blink/renderer/core/style/computed_style.h" #include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/platform/transforms/matrix_3d_transform_operation.h"
#include "third_party/blink/renderer/platform/transforms/matrix_transform_operation.h"
#include "third_party/blink/renderer/platform/transforms/perspective_transform_operation.h"
#include "third_party/blink/renderer/platform/transforms/skew_transform_operation.h"
namespace blink { namespace blink {
namespace { namespace {
// We collapse functions like translateX into translate, since we will reify
// them as a translate anyway.
const CSSValue* ComputedTransformComponent(const TransformOperation& operation,
float zoom) {
switch (operation.GetType()) {
case TransformOperation::kScaleX:
case TransformOperation::kScaleY:
case TransformOperation::kScaleZ:
case TransformOperation::kScale:
case TransformOperation::kScale3D: {
const auto& scale = To<ScaleTransformOperation>(operation);
CSSFunctionValue* result = MakeGarbageCollected<CSSFunctionValue>(
operation.Is3DOperation() ? CSSValueID::kScale3d
: CSSValueID::kScale);
result->Append(*CSSNumericLiteralValue::Create(
scale.X(), CSSPrimitiveValue::UnitType::kNumber));
result->Append(*CSSNumericLiteralValue::Create(
scale.Y(), CSSPrimitiveValue::UnitType::kNumber));
if (operation.Is3DOperation()) {
result->Append(*CSSNumericLiteralValue::Create(
scale.Z(), CSSPrimitiveValue::UnitType::kNumber));
}
return result;
}
case TransformOperation::kTranslateX:
case TransformOperation::kTranslateY:
case TransformOperation::kTranslateZ:
case TransformOperation::kTranslate:
case TransformOperation::kTranslate3D: {
const auto& translate = To<TranslateTransformOperation>(operation);
CSSFunctionValue* result = MakeGarbageCollected<CSSFunctionValue>(
operation.Is3DOperation() ? CSSValueID::kTranslate3d
: CSSValueID::kTranslate);
result->Append(*CSSPrimitiveValue::CreateFromLength(translate.X(), zoom));
result->Append(*CSSPrimitiveValue::CreateFromLength(translate.Y(), zoom));
if (operation.Is3DOperation()) {
result->Append(*CSSNumericLiteralValue::Create(
translate.Z(), CSSPrimitiveValue::UnitType::kPixels));
}
return result;
}
case TransformOperation::kRotateX:
case TransformOperation::kRotateY:
case TransformOperation::kRotate3D: {
const auto& rotate = To<RotateTransformOperation>(operation);
CSSFunctionValue* result =
MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kRotate3d);
result->Append(*CSSNumericLiteralValue::Create(
rotate.X(), CSSPrimitiveValue::UnitType::kNumber));
result->Append(*CSSNumericLiteralValue::Create(
rotate.Y(), CSSPrimitiveValue::UnitType::kNumber));
result->Append(*CSSNumericLiteralValue::Create(
rotate.Z(), CSSPrimitiveValue::UnitType::kNumber));
result->Append(*CSSNumericLiteralValue::Create(
rotate.Angle(), CSSPrimitiveValue::UnitType::kDegrees));
return result;
}
case TransformOperation::kRotate: {
const auto& rotate = To<RotateTransformOperation>(operation);
auto* result =
MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kRotate);
result->Append(*CSSNumericLiteralValue::Create(
rotate.Angle(), CSSPrimitiveValue::UnitType::kDegrees));
return result;
}
case TransformOperation::kSkewX: {
const auto& skew = To<SkewTransformOperation>(operation);
auto* result = MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kSkewX);
result->Append(*CSSNumericLiteralValue::Create(
skew.AngleX(), CSSPrimitiveValue::UnitType::kDegrees));
return result;
}
case TransformOperation::kSkewY: {
const auto& skew = To<SkewTransformOperation>(operation);
auto* result = MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kSkewY);
result->Append(*CSSNumericLiteralValue::Create(
skew.AngleY(), CSSPrimitiveValue::UnitType::kDegrees));
return result;
}
case TransformOperation::kSkew: {
const auto& skew = To<SkewTransformOperation>(operation);
auto* result = MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kSkew);
result->Append(*CSSNumericLiteralValue::Create(
skew.AngleX(), CSSPrimitiveValue::UnitType::kDegrees));
result->Append(*CSSNumericLiteralValue::Create(
skew.AngleY(), CSSPrimitiveValue::UnitType::kDegrees));
return result;
}
case TransformOperation::kPerspective: {
const auto& perspective = To<PerspectiveTransformOperation>(operation);
auto* result =
MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kPerspective);
result->Append(*CSSNumericLiteralValue::Create(
perspective.Perspective() / zoom,
CSSPrimitiveValue::UnitType::kPixels));
return result;
}
case TransformOperation::kMatrix: {
const auto& matrix = To<MatrixTransformOperation>(operation).Matrix();
auto* result =
MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kMatrix);
double values[6] = {matrix.A(), matrix.B(), matrix.C(),
matrix.D(), matrix.E() / zoom, matrix.F() / zoom};
for (double value : values) {
result->Append(*CSSNumericLiteralValue::Create(
value, CSSPrimitiveValue::UnitType::kNumber));
}
return result;
}
case TransformOperation::kMatrix3D: {
const auto& matrix = To<Matrix3DTransformOperation>(operation).Matrix();
CSSFunctionValue* result =
MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kMatrix3d);
double values[16] = {
matrix.M11(), matrix.M12(), matrix.M13(),
matrix.M14(), matrix.M21(), matrix.M22(),
matrix.M23(), matrix.M24(), matrix.M31(),
matrix.M32(), matrix.M33(), matrix.M34(),
matrix.M41() / zoom, matrix.M42() / zoom, matrix.M43() / zoom,
matrix.M44()};
for (double value : values) {
result->Append(*CSSNumericLiteralValue::Create(
value, CSSPrimitiveValue::UnitType::kNumber));
}
return result;
}
case TransformOperation::kInterpolated:
// TODO(816803): The computed value in this case is not fully spec'd
// See https://github.com/w3c/css-houdini-drafts/issues/425
return CSSIdentifierValue::Create(CSSValueID::kNone);
default:
// The remaining operations are unsupported.
NOTREACHED();
return CSSIdentifierValue::Create(CSSValueID::kNone);
}
}
const CSSValue* ComputedTransform(const ComputedStyle& style) { const CSSValue* ComputedTransform(const ComputedStyle& style) {
if (style.Transform().Operations().size() == 0) if (style.Transform().Operations().size() == 0)
return CSSIdentifierValue::Create(CSSValueID::kNone); return CSSIdentifierValue::Create(CSSValueID::kNone);
CSSValueList* components = CSSValueList::CreateSpaceSeparated(); CSSValueList* components = CSSValueList::CreateSpaceSeparated();
for (const auto& operation : style.Transform().Operations()) { for (const auto& operation : style.Transform().Operations()) {
components->Append( components->Append(*ComputedStyleUtils::ValueForTransformOperation(
*ComputedTransformComponent(*operation, style.EffectiveZoom())); *operation, style.EffectiveZoom()));
} }
return components; return components;
} }
......
...@@ -45,6 +45,10 @@ ...@@ -45,6 +45,10 @@
#include "third_party/blink/renderer/core/style/style_svg_resource.h" #include "third_party/blink/renderer/core/style/style_svg_resource.h"
#include "third_party/blink/renderer/core/style_property_shorthand.h" #include "third_party/blink/renderer/core/style_property_shorthand.h"
#include "third_party/blink/renderer/core/svg_element_type_helpers.h" #include "third_party/blink/renderer/core/svg_element_type_helpers.h"
#include "third_party/blink/renderer/platform/transforms/matrix_3d_transform_operation.h"
#include "third_party/blink/renderer/platform/transforms/matrix_transform_operation.h"
#include "third_party/blink/renderer/platform/transforms/perspective_transform_operation.h"
#include "third_party/blink/renderer/platform/transforms/skew_transform_operation.h"
namespace blink { namespace blink {
...@@ -1711,7 +1715,7 @@ CSSValue* ComputedStyleUtils::ValueForBorderRadiusCorner( ...@@ -1711,7 +1715,7 @@ CSSValue* ComputedStyleUtils::ValueForBorderRadiusCorner(
CSSValuePair::kDropIdenticalValues); CSSValuePair::kDropIdenticalValues);
} }
CSSFunctionValue* ValueForMatrixTransform( CSSValue* ComputedStyleUtils::ValueForMatrixTransform(
const TransformationMatrix& transform_param, const TransformationMatrix& transform_param,
const ComputedStyle& style) { const ComputedStyle& style) {
// Take TransformationMatrix by reference and then copy it because VC++ // Take TransformationMatrix by reference and then copy it because VC++
...@@ -1779,6 +1783,144 @@ CSSFunctionValue* ValueForMatrixTransform( ...@@ -1779,6 +1783,144 @@ CSSFunctionValue* ValueForMatrixTransform(
return transform_value; return transform_value;
} }
// We collapse functions like translateX into translate, since we will reify
// them as a translate anyway.
CSSValue* ComputedStyleUtils::ValueForTransformOperation(
const TransformOperation& operation,
float zoom) {
switch (operation.GetType()) {
case TransformOperation::kScaleX:
case TransformOperation::kScaleY:
case TransformOperation::kScaleZ:
case TransformOperation::kScale:
case TransformOperation::kScale3D: {
const auto& scale = To<ScaleTransformOperation>(operation);
CSSFunctionValue* result = MakeGarbageCollected<CSSFunctionValue>(
operation.Is3DOperation() ? CSSValueID::kScale3d
: CSSValueID::kScale);
result->Append(*CSSNumericLiteralValue::Create(
scale.X(), CSSPrimitiveValue::UnitType::kNumber));
result->Append(*CSSNumericLiteralValue::Create(
scale.Y(), CSSPrimitiveValue::UnitType::kNumber));
if (operation.Is3DOperation()) {
result->Append(*CSSNumericLiteralValue::Create(
scale.Z(), CSSPrimitiveValue::UnitType::kNumber));
}
return result;
}
case TransformOperation::kTranslateX:
case TransformOperation::kTranslateY:
case TransformOperation::kTranslateZ:
case TransformOperation::kTranslate:
case TransformOperation::kTranslate3D: {
const auto& translate = To<TranslateTransformOperation>(operation);
CSSFunctionValue* result = MakeGarbageCollected<CSSFunctionValue>(
operation.Is3DOperation() ? CSSValueID::kTranslate3d
: CSSValueID::kTranslate);
result->Append(*CSSPrimitiveValue::CreateFromLength(translate.X(), zoom));
result->Append(*CSSPrimitiveValue::CreateFromLength(translate.Y(), zoom));
if (operation.Is3DOperation()) {
result->Append(*CSSNumericLiteralValue::Create(
translate.Z(), CSSPrimitiveValue::UnitType::kPixels));
}
return result;
}
case TransformOperation::kRotateX:
case TransformOperation::kRotateY:
case TransformOperation::kRotate3D: {
const auto& rotate = To<RotateTransformOperation>(operation);
CSSFunctionValue* result =
MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kRotate3d);
result->Append(*CSSNumericLiteralValue::Create(
rotate.X(), CSSPrimitiveValue::UnitType::kNumber));
result->Append(*CSSNumericLiteralValue::Create(
rotate.Y(), CSSPrimitiveValue::UnitType::kNumber));
result->Append(*CSSNumericLiteralValue::Create(
rotate.Z(), CSSPrimitiveValue::UnitType::kNumber));
result->Append(*CSSNumericLiteralValue::Create(
rotate.Angle(), CSSPrimitiveValue::UnitType::kDegrees));
return result;
}
case TransformOperation::kRotate: {
const auto& rotate = To<RotateTransformOperation>(operation);
auto* result =
MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kRotate);
result->Append(*CSSNumericLiteralValue::Create(
rotate.Angle(), CSSPrimitiveValue::UnitType::kDegrees));
return result;
}
case TransformOperation::kSkewX: {
const auto& skew = To<SkewTransformOperation>(operation);
auto* result = MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kSkewX);
result->Append(*CSSNumericLiteralValue::Create(
skew.AngleX(), CSSPrimitiveValue::UnitType::kDegrees));
return result;
}
case TransformOperation::kSkewY: {
const auto& skew = To<SkewTransformOperation>(operation);
auto* result = MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kSkewY);
result->Append(*CSSNumericLiteralValue::Create(
skew.AngleY(), CSSPrimitiveValue::UnitType::kDegrees));
return result;
}
case TransformOperation::kSkew: {
const auto& skew = To<SkewTransformOperation>(operation);
auto* result = MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kSkew);
result->Append(*CSSNumericLiteralValue::Create(
skew.AngleX(), CSSPrimitiveValue::UnitType::kDegrees));
result->Append(*CSSNumericLiteralValue::Create(
skew.AngleY(), CSSPrimitiveValue::UnitType::kDegrees));
return result;
}
case TransformOperation::kPerspective: {
const auto& perspective = To<PerspectiveTransformOperation>(operation);
auto* result =
MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kPerspective);
result->Append(*CSSNumericLiteralValue::Create(
perspective.Perspective() / zoom,
CSSPrimitiveValue::UnitType::kPixels));
return result;
}
case TransformOperation::kMatrix: {
const auto& matrix = To<MatrixTransformOperation>(operation).Matrix();
auto* result =
MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kMatrix);
double values[6] = {matrix.A(), matrix.B(), matrix.C(),
matrix.D(), matrix.E() / zoom, matrix.F() / zoom};
for (double value : values) {
result->Append(*CSSNumericLiteralValue::Create(
value, CSSPrimitiveValue::UnitType::kNumber));
}
return result;
}
case TransformOperation::kMatrix3D: {
const auto& matrix = To<Matrix3DTransformOperation>(operation).Matrix();
CSSFunctionValue* result =
MakeGarbageCollected<CSSFunctionValue>(CSSValueID::kMatrix3d);
double values[16] = {
matrix.M11(), matrix.M12(), matrix.M13(),
matrix.M14(), matrix.M21(), matrix.M22(),
matrix.M23(), matrix.M24(), matrix.M31(),
matrix.M32(), matrix.M33(), matrix.M34(),
matrix.M41() / zoom, matrix.M42() / zoom, matrix.M43() / zoom,
matrix.M44()};
for (double value : values) {
result->Append(*CSSNumericLiteralValue::Create(
value, CSSPrimitiveValue::UnitType::kNumber));
}
return result;
}
case TransformOperation::kInterpolated:
// TODO(816803): The computed value in this case is not fully spec'd
// See https://github.com/w3c/css-houdini-drafts/issues/425
return CSSIdentifierValue::Create(CSSValueID::kNone);
default:
// The remaining operations are unsupported.
NOTREACHED();
return CSSIdentifierValue::Create(CSSValueID::kNone);
}
}
FloatRect ComputedStyleUtils::ReferenceBoxForTransform( FloatRect ComputedStyleUtils::ReferenceBoxForTransform(
const LayoutObject& layout_object, const LayoutObject& layout_object,
UsePixelSnappedBox pixel_snap_box) { UsePixelSnappedBox pixel_snap_box) {
......
...@@ -146,6 +146,10 @@ class ComputedStyleUtils { ...@@ -146,6 +146,10 @@ class ComputedStyleUtils {
kDontUsePixelSnappedBox, kDontUsePixelSnappedBox,
kUsePixelSnappedBox, kUsePixelSnappedBox,
}; };
static CSSValue* ValueForMatrixTransform(const TransformationMatrix&,
const ComputedStyle&);
static CSSValue* ValueForTransformOperation(const TransformOperation&,
float zoom);
static FloatRect ReferenceBoxForTransform( static FloatRect ReferenceBoxForTransform(
const LayoutObject&, const LayoutObject&,
UsePixelSnappedBox = kUsePixelSnappedBox); UsePixelSnappedBox = kUsePixelSnappedBox);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment