Commit 6bba7dec authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Commit Bot

Apply zoom to thin/medium/think border/outline/column-rule.

These values map to a fixed number of CSS pixels, but zoom was not
applied as for other pixel lengths so that the output would not scale
with the zoom level.

Discovered running wpt/css tests with dpr=2.

TEST=external/wpt/css/CSS2/floats-clear/floats-114.xht

Bug: 1078776
Change-Id: I6cc8aa6d3f6e077539492166760967ce6fa31b96
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2184889Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#766308}
parent ce50f4fe
......@@ -962,20 +962,29 @@ void StyleBuilderConverter::CreateImplicitNamedGridLinesFromGridArea(
float StyleBuilderConverter::ConvertBorderWidth(StyleResolverState& state,
const CSSValue& value) {
double result = 0;
if (auto* identifier_value = DynamicTo<CSSIdentifierValue>(value)) {
CSSValueID value_id = identifier_value->GetValueID();
if (value_id == CSSValueID::kThin)
return 1;
if (value_id == CSSValueID::kMedium)
return 3;
if (value_id == CSSValueID::kThick)
return 5;
NOTREACHED();
return 0;
switch (identifier_value->GetValueID()) {
case CSSValueID::kThin:
result = 1;
break;
case CSSValueID::kMedium:
result = 3;
break;
case CSSValueID::kThick:
result = 5;
break;
default:
NOTREACHED();
break;
}
result = state.CssToLengthConversionData().ZoomedComputedPixels(
result, CSSPrimitiveValue::UnitType::kPixels);
} else {
const auto& primitive_value = To<CSSPrimitiveValue>(value);
result =
primitive_value.ComputeLength<float>(state.CssToLengthConversionData());
}
const auto& primitive_value = To<CSSPrimitiveValue>(value);
double result =
primitive_value.ComputeLength<float>(state.CssToLengthConversionData());
double zoomed_result = state.StyleRef().EffectiveZoom() * result;
if (zoomed_result > 0.0 && zoomed_result < 1.0)
return 1.0;
......
......@@ -312,26 +312,34 @@ T StyleBuilderConverter::ConvertFlags(StyleResolverState& state,
template <typename T>
T StyleBuilderConverter::ConvertLineWidth(StyleResolverState& state,
const CSSValue& value) {
double result = 0;
if (auto* identifier_value = DynamicTo<CSSIdentifierValue>(value)) {
CSSValueID value_id = identifier_value->GetValueID();
if (value_id == CSSValueID::kThin)
return 1;
if (value_id == CSSValueID::kMedium)
return 3;
if (value_id == CSSValueID::kThick)
return 5;
NOTREACHED();
return 0;
switch (identifier_value->GetValueID()) {
case CSSValueID::kThin:
result = 1;
break;
case CSSValueID::kMedium:
result = 3;
break;
case CSSValueID::kThick:
result = 5;
break;
default:
NOTREACHED();
break;
}
result = state.CssToLengthConversionData().ZoomedComputedPixels(
result, CSSPrimitiveValue::UnitType::kPixels);
} else {
result = To<CSSPrimitiveValue>(value).ComputeLength<double>(
state.CssToLengthConversionData());
}
const auto& primitive_value = To<CSSPrimitiveValue>(value);
// FIXME: We are moving to use the full page zoom implementation to handle
// high-dpi. In that case specyfing a border-width of less than 1px would
// result in a border that is one device pixel thick. With this change that
// would instead be rounded up to 2 device pixels. Consider clamping it to
// device pixels or zoom adjusted CSS pixels instead of raw CSS pixels.
// Reference crbug.com/485650 and crbug.com/382483
double result =
primitive_value.ComputeLength<double>(state.CssToLengthConversionData());
// TODO(crbug.com/485650, crbug.com/382483): We are moving to use the full
// page zoom implementation to handle high-dpi. In that case specyfing a
// border-width of less than 1px would result in a border that is one device
// pixel thick. With this change that would instead be rounded up to 2
// device pixels. Consider clamping it to device pixels or zoom adjusted CSS
// pixels instead of raw CSS pixels.
double zoomed_result = state.StyleRef().EffectiveZoom() * result;
if (zoomed_result > 0.0 && zoomed_result < 1.0)
return 1.0;
......
......@@ -930,4 +930,50 @@ TEST(ComputedStyleTest, InitialAndInheritedAndNonInheritedVariableNames) {
EXPECT_TRUE(style->GetVariableNames().Contains("--e"));
}
TEST(ComputedStyleTest, BorderWidthZoom) {
std::unique_ptr<DummyPageHolder> dummy_page_holder_ =
std::make_unique<DummyPageHolder>(IntSize(0, 0), nullptr);
const ComputedStyle* initial = &ComputedStyle::InitialStyle();
StyleResolverState state(dummy_page_holder_->GetDocument(),
*dummy_page_holder_->GetDocument().documentElement(),
initial, initial);
scoped_refptr<ComputedStyle> style = ComputedStyle::Create();
style->SetEffectiveZoom(2);
style->SetBorderLeftStyle(EBorderStyle::kSolid);
style->SetOutlineStyle(EBorderStyle::kSolid);
style->SetColumnRuleStyle(EBorderStyle::kSolid);
state.SetStyle(style);
const struct {
CSSIdentifierValue* css_value;
double expected_px;
STACK_ALLOCATED();
} tests[] = {
{CSSIdentifierValue::Create(CSSValueID::kThin), 1.0},
{CSSIdentifierValue::Create(CSSValueID::kMedium), 3.0},
{CSSIdentifierValue::Create(CSSValueID::kThick), 5.0},
};
for (const auto& test : tests) {
for (const auto* property :
{&GetCSSPropertyBorderLeftWidth(), &GetCSSPropertyOutlineWidth(),
&GetCSSPropertyColumnRuleWidth()}) {
const Longhand& longhand = To<Longhand>(*property);
longhand.ApplyValue(state, *test.css_value);
auto* computed_value = longhand.CSSValueFromComputedStyleInternal(
*style, style->SvgStyle(), nullptr /* layout_object */,
false /* allow_visited_style */);
AtomicString prop_name = longhand.GetCSSPropertyName().ToAtomicString();
ASSERT_TRUE(computed_value) << prop_name;
auto* numeric_value = DynamicTo<CSSNumericLiteralValue>(computed_value);
ASSERT_TRUE(numeric_value) << prop_name;
EXPECT_TRUE(numeric_value->IsPx()) << prop_name;
EXPECT_EQ(test.expected_px, numeric_value->DoubleValue()) << prop_name;
}
}
}
} // 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