Commit 838c89ea authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Resolve stroke-width 'em' units against unzoomed font size

When resolving style for the 'stroke-width' property we would use
CSSToLengthConversionData::CopyWithAdjustedZoom() with an argument of 1
to get an "unzoomed" length. The FontSizes object was however not
adjusted, so still carried zoomed base font sizes.

Make a new method on StyleResolverState that returns an
CSSToLengthConversionData that uses unzoomed unit bases, basing it on
the existing FontSizeConversionData() method which does roughly the
same thing except it uses the parent style for unit bases.

Bug: 933689
Change-Id: Icfbc59a641f0dc2d94f00ba5f3e9a15b36f8c195
Reviewed-on: https://chromium-review.googlesource.com/c/1481417Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#634750}
parent f6fad153
...@@ -997,7 +997,7 @@ UnzoomedLength StyleBuilderConverter::ConvertUnzoomedLength( ...@@ -997,7 +997,7 @@ UnzoomedLength StyleBuilderConverter::ConvertUnzoomedLength(
const StyleResolverState& state, const StyleResolverState& state,
const CSSValue& value) { const CSSValue& value) {
return UnzoomedLength(ToCSSPrimitiveValue(value).ConvertToLength( return UnzoomedLength(ToCSSPrimitiveValue(value).ConvertToLength(
state.CssToLengthConversionData().CopyWithAdjustedZoom(1.0f))); state.UnzoomedLengthConversionData()));
} }
Length StyleBuilderConverter::ConvertLengthOrAuto( Length StyleBuilderConverter::ConvertLengthOrAuto(
......
...@@ -94,17 +94,29 @@ scoped_refptr<ComputedStyle> StyleResolverState::TakeStyle() { ...@@ -94,17 +94,29 @@ scoped_refptr<ComputedStyle> StyleResolverState::TakeStyle() {
return std::move(style_); return std::move(style_);
} }
CSSToLengthConversionData StyleResolverState::FontSizeConversionData() const { CSSToLengthConversionData StyleResolverState::UnzoomedLengthConversionData(
float em = ParentStyle()->SpecifiedFontSize(); const ComputedStyle* font_style) const {
float em = font_style->SpecifiedFontSize();
float rem = RootElementStyle() ? RootElementStyle()->SpecifiedFontSize() : 1; float rem = RootElementStyle() ? RootElementStyle()->SpecifiedFontSize() : 1;
// TODO(fs): Since 'ch' and 'ex' are still accessed directly from the font,
// they will still have zoom applied.
CSSToLengthConversionData::FontSizes font_sizes(em, rem, CSSToLengthConversionData::FontSizes font_sizes(em, rem,
&ParentStyle()->GetFont()); &font_style->GetFont());
CSSToLengthConversionData::ViewportSize viewport_size( CSSToLengthConversionData::ViewportSize viewport_size(
GetDocument().GetLayoutView()); GetDocument().GetLayoutView());
return CSSToLengthConversionData(Style(), font_sizes, viewport_size, 1); return CSSToLengthConversionData(Style(), font_sizes, viewport_size, 1);
} }
CSSToLengthConversionData StyleResolverState::FontSizeConversionData() const {
return UnzoomedLengthConversionData(ParentStyle());
}
CSSToLengthConversionData StyleResolverState::UnzoomedLengthConversionData()
const {
return UnzoomedLengthConversionData(Style());
}
void StyleResolverState::SetParentStyle( void StyleResolverState::SetParentStyle(
scoped_refptr<const ComputedStyle> parent_style) { scoped_refptr<const ComputedStyle> parent_style) {
parent_style_ = std::move(parent_style); parent_style_ = std::move(parent_style);
......
...@@ -97,6 +97,7 @@ class CORE_EXPORT StyleResolverState { ...@@ -97,6 +97,7 @@ class CORE_EXPORT StyleResolverState {
return css_to_length_conversion_data_; return css_to_length_conversion_data_;
} }
CSSToLengthConversionData FontSizeConversionData() const; CSSToLengthConversionData FontSizeConversionData() const;
CSSToLengthConversionData UnzoomedLengthConversionData() const;
void SetConversionFontSizes( void SetConversionFontSizes(
const CSSToLengthConversionData::FontSizes& font_sizes) { const CSSToLengthConversionData::FontSizes& font_sizes) {
...@@ -193,6 +194,9 @@ class CORE_EXPORT StyleResolverState { ...@@ -193,6 +194,9 @@ class CORE_EXPORT StyleResolverState {
const CSSPendingSubstitutionValue&) const; const CSSPendingSubstitutionValue&) const;
private: private:
CSSToLengthConversionData UnzoomedLengthConversionData(
const ComputedStyle* font_style) const;
ElementResolveContext element_context_; ElementResolveContext element_context_;
Member<Document> document_; Member<Document> document_;
......
<!DOCTYPE html>
<title>Zoomed EM resolution for 'stroke-width'</title>
<script src="../../resources/ahem.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<style>
html {
font-size: 50px;
font-family: Ahem;
zoom: 4;
}
body {
font-size: initial;
font-family: initial;
zoom: 0.25;
}
</style>
<svg font-size="50" font-family="Ahem" style="zoom: 3">
<rect width="100" height="100" stroke-width="1em"/>
<rect width="100" height="100" stroke-width="1rem"/>
</svg>
<script>
const elements = document.querySelectorAll('rect');
test(function() {
let computed_size = getComputedStyle(elements[0]).getPropertyValue('stroke-width');
assert_equals(computed_size, '50px', 'em');
}, document.title + ', em');
test(function() {
let computed_size = getComputedStyle(elements[1]).getPropertyValue('stroke-width');
assert_equals(computed_size, '50px', 'rem');
}, document.title + ', rem');
</script>
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