Commit e87da780 authored by Jia's avatar Jia Committed by Commit Bot

Make border width rounding visible to js via getComputedStyle.

CL (https://chromium-review.googlesource.com/c/525536/) moved rounding of border 
widths to the painting stage, hence rounding is no longer visible in js via 
getComputedStyle. This cl makes rounding visible again to users via getComputedStyle.

This cl contains the following changes
* Implemented a ZoomAdjustedPixelValueWithRounding method.
- This method is the same as ZoomAdjustedPixelValue except that it
rounds pixel value to 1 if original value is between 0 and 1.0.
* Changed ComputedStyle for border-[top|right|bottom|left] to use
ZoomAdjustedPixelValueWithRounding so that getComputedStyle will
display rounded pixels for these properties (and also border-width that
is a shorthand of these 4 longhand properties).
* Changed a layout test.

Bug: 737962
Change-Id: I0656f7ea1212fe32f866d95218995fb3de109e05
Reviewed-on: https://chromium-review.googlesource.com/560917
Commit-Queue: Jia Meng <jiameng@chromium.org>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487384}
parent 3d1e1bde
......@@ -82,13 +82,13 @@
test(function() {
assert_equals(borderAsString(testElements['0.25px']),
'0.25px 0.25px 0.25px 0.25px',
'1px 1px 1px 1px',
'Border thickness of 0.25px box should be 0.25px.');
assert_equals(borderAsString(testElements['0.5px']),
'0.5px 0.5px 0.5px 0.5px',
'1px 1px 1px 1px',
'Border thickness of 0.5px box should be 0.5px.');
assert_equals(borderAsString(testElements['0.75px']),
'0.75px 0.75px 0.75px 0.75px',
'1px 1px 1px 1px',
'Border thickness of 0.75px box should be 0.75px.');
assert_equals(borderAsString(testElements['1.25px']),
'1.25px 1.25px 1.25px 1.25px',
......
......@@ -2118,6 +2118,16 @@ static bool WidthOrHeightPropertyAppliesToObject(const LayoutObject& object) {
return !object.IsSVGChild();
}
CSSPrimitiveValue* ZoomAdjustedPixelValueWithBorderWidthRounding(
double value,
const ComputedStyle& style) {
const double px_value = AdjustFloatForAbsoluteZoom(value, style);
return CSSPrimitiveValue::Create(
px_value > 0.0 && px_value < 1 ? 1.0 : px_value,
CSSPrimitiveValue::UnitType::kPixels);
}
const CSSValue* ComputedStyleCSSValueMapping::Get(
CSSPropertyID property_id,
const ComputedStyle& style,
......@@ -2304,13 +2314,17 @@ const CSSValue* ComputedStyleCSSValueMapping::Get(
case CSSPropertyBorderLeftStyle:
return CSSIdentifierValue::Create(style.BorderLeftStyle());
case CSSPropertyBorderTopWidth:
return ZoomAdjustedPixelValue(style.BorderTopWidth(), style);
return ZoomAdjustedPixelValueWithBorderWidthRounding(
style.BorderTopWidth(), style);
case CSSPropertyBorderRightWidth:
return ZoomAdjustedPixelValue(style.BorderRightWidth(), style);
return ZoomAdjustedPixelValueWithBorderWidthRounding(
style.BorderRightWidth(), style);
case CSSPropertyBorderBottomWidth:
return ZoomAdjustedPixelValue(style.BorderBottomWidth(), style);
return ZoomAdjustedPixelValueWithBorderWidthRounding(
style.BorderBottomWidth(), style);
case CSSPropertyBorderLeftWidth:
return ZoomAdjustedPixelValue(style.BorderLeftWidth(), style);
return ZoomAdjustedPixelValueWithBorderWidthRounding(
style.BorderLeftWidth(), style);
case CSSPropertyBottom:
return ValueForPositionOffset(style, CSSPropertyBottom, layout_object);
case CSSPropertyWebkitBoxAlign:
......
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