Commit a46a3915 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Fix zoom handling in CSSMathFunctionValue::Create(length, zoom)

This patch fixes a regression introduced by crrev.com/c/1744799.

Before the regression, the creator divides the pixel value of the length
by the zooming after. The above patch incorrectly changed that into
multiplication, which is the regression.

This patch changes that back into a division.

Bug: 999875
Change-Id: Ic5f07c2af52cdc94bde8b355e5c30a7f01c0a49c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1783638
Commit-Queue: Emil A Eklund <eae@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693131}
parent 348087fe
...@@ -41,7 +41,7 @@ CSSMathFunctionValue* CSSMathFunctionValue::Create( ...@@ -41,7 +41,7 @@ CSSMathFunctionValue* CSSMathFunctionValue::Create(
CSSMathFunctionValue* CSSMathFunctionValue::Create(const Length& length, CSSMathFunctionValue* CSSMathFunctionValue::Create(const Length& length,
float zoom) { float zoom) {
DCHECK(length.IsCalculated()); DCHECK(length.IsCalculated());
auto calc = length.GetCalculationValue().Zoom(zoom); auto calc = length.GetCalculationValue().Zoom(1.0 / zoom);
return Create(CSSMathExpressionNode::Create(*calc), calc->GetValueRange()); return Create(CSSMathExpressionNode::Create(*calc), calc->GetValueRange());
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "third_party/blink/renderer/core/css/css_math_expression_node.h" #include "third_party/blink/renderer/core/css/css_math_expression_node.h"
#include "third_party/blink/renderer/core/css/css_math_function_value.h" #include "third_party/blink/renderer/core/css/css_math_function_value.h"
#include "third_party/blink/renderer/core/css/css_numeric_literal_value.h" #include "third_party/blink/renderer/core/css/css_numeric_literal_value.h"
#include "third_party/blink/renderer/core/css/css_to_length_conversion_data.h"
namespace blink { namespace blink {
namespace { namespace {
...@@ -78,5 +79,28 @@ TEST(CSSPrimitiveValueTest, IsResolution) { ...@@ -78,5 +79,28 @@ TEST(CSSPrimitiveValueTest, IsResolution) {
EXPECT_TRUE(Create({5.0, UnitType::kDotsPerCentimeter})->IsResolution()); EXPECT_TRUE(Create({5.0, UnitType::kDotsPerCentimeter})->IsResolution());
} }
// https://crbug.com/999875
TEST(CSSPrimitiveValueTest, Zooming) {
// Tests that the conversion CSSPrimitiveValue -> Length -> CSSPrimitiveValue
// yields the same value under zooming.
UnitValue a = {100, UnitType::kPixels};
UnitValue b = {10, UnitType::kPercentage};
CSSPrimitiveValue* original = CreateAddition(a, b);
CSSToLengthConversionData conversion_data;
conversion_data.SetZoom(0.5);
Length length = original->ConvertToLength(conversion_data);
EXPECT_TRUE(length.IsCalculated());
EXPECT_EQ(50.0, length.GetPixelsAndPercent().pixels);
EXPECT_EQ(10.0, length.GetPixelsAndPercent().percent);
CSSPrimitiveValue* converted =
CSSPrimitiveValue::CreateFromLength(length, conversion_data.Zoom());
EXPECT_TRUE(converted->IsMathFunctionValue());
EXPECT_EQ("calc(10% + 100px)", converted->CustomCSSText());
}
} // namespace } // namespace
} // namespace blink } // namespace blink
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