Commit b6f5e512 authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Commit Bot

Use the style being computed as rem base for root element.

If we are resolving style for the root element, return the style being
built as the root style. That style is not available at the point we are
initialising the root style in ElementResolveContext.

Bug: 918480
Change-Id: If04aa2db7de9f74b9089b29cfda2e20c43762d65
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2279802Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785359}
parent 47722a27
......@@ -50,14 +50,10 @@ ElementResolveContext::ElementResolveContext(Element& element)
layout_parent_ = nullptr;
}
const Document& document = element.GetDocument();
Node* document_element = document.documentElement();
const ComputedStyle* document_style = document.GetComputedStyle();
root_element_style_ = document_element && element != document_element
? document_element->GetComputedStyle()
: document_style;
if (!root_element_style_)
root_element_style_ = document_style;
if (auto* document_element = element.GetDocument().documentElement()) {
if (element != document_element)
root_element_style_ = document_element->GetComputedStyle();
}
}
} // namespace blink
......@@ -77,7 +77,9 @@ class CORE_EXPORT StyleResolverState {
return element_context_.ParentNode();
}
const ComputedStyle* RootElementStyle() const {
return element_context_.RootElementStyle();
if (const auto* root_element_style = element_context_.RootElementStyle())
return root_element_style;
return Style();
}
EInsideLink ElementLinkState() const {
return element_context_.ElementLinkState();
......
<!doctype html>
<title>CSS Values and Units Test: rem units on the root element</title>
<link rel="help" href="https://drafts.csswg.org/css-values/#rem">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
:root {
font-size: 50px;
margin-left: 2rem;
padding-top: 2rem;
line-height: 2rem;
}
</style>
<script>
let rootStyle = getComputedStyle(document.documentElement);
test(() => assert_equals(rootStyle.marginLeft, "100px"), "rem based margin.");
test(() => assert_equals(rootStyle.paddingTop, "100px"), "rem based padding.");
test(() => assert_equals(rootStyle.lineHeight, "100px"), "rem based line-height.");
test(() => {
document.documentElement.style.fontSize = "initial";
let initialFontSize = parseInt(getComputedStyle(document.documentElement).fontSize);
document.documentElement.style.fontSize = "3rem";
assert_equals(getComputedStyle(document.documentElement).fontSize, 3*initialFontSize + "px");
}, "Check that rem font-size is based on the initial font-size.");
</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