Commit cba877dc authored by Daniel Libby's avatar Daniel Libby Committed by Commit Bot

Update root style environment variables for foldable vars

Changes to the window segments happens in the content layer as part of
the visual properties cascade. As such the current machinery to compute
and update the associated CSS environment variables is not triggered
in scenarios like page reload.

Instead of setting the variables on each frame, update the root
environment variables instance, which is used by child
DocumentStyleEnvironmentVariables instances when resolving.

Bug: 1121068
Change-Id: I0a46b41957c04708f4bd255b87a00c154477d893
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2371684Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Commit-Queue: Daniel Libby <dlibby@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#801113}
parent 70b861ed
...@@ -825,6 +825,44 @@ IN_PROC_BROWSER_TEST_F(RenderWidgetHostFoldableCSSTest, ...@@ -825,6 +825,44 @@ IN_PROC_BROWSER_TEST_F(RenderWidgetHostFoldableCSSTest,
EvalJs(shell(), "getComputedStyle(target).opacity").ExtractString()); EvalJs(shell(), "getComputedStyle(target).opacity").ExtractString());
} }
IN_PROC_BROWSER_TEST_F(RenderWidgetHostFoldableCSSTest,
FoldablesCSSWithReload) {
const char kTestPageURL[] =
R"HTML(data:text/html,<!DOCTYPE html>
<style>
@media (screen-spanning: single-fold-vertical) {
div { margin-left: env(fold-left, 10px); }
}
</style>
<div id='target'></div>)HTML";
EXPECT_TRUE(NavigateToURL(shell(), GURL(kTestPageURL)));
const gfx::Size root_view_size = view()->GetVisibleViewportSize();
const int kDisplayFeatureLength = 10;
DisplayFeature emulated_display_feature{
DisplayFeature::Orientation::kVertical,
/* offset */ root_view_size.width() / 2 - kDisplayFeatureLength / 2,
/* mask_length */ kDisplayFeatureLength};
view()->SetDisplayFeatureForTesting(emulated_display_feature);
host()->SynchronizeVisualProperties();
EXPECT_EQ(
base::NumberToString(emulated_display_feature.offset) + "px",
EvalJs(shell(), "getComputedStyle(target).marginLeft").ExtractString());
// Ensure that the environment variables have the correct values in the new
// document that is created on reloading the page.
WindowedNotificationObserver load_stop_observer(
NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
shell()->Reload();
load_stop_observer.Wait();
EXPECT_EQ(
base::NumberToString(emulated_display_feature.offset) + "px",
EvalJs(shell(), "getComputedStyle(target).marginLeft").ExtractString());
}
class RenderWidgetHostDelegatedInkMetadataTest class RenderWidgetHostDelegatedInkMetadataTest
: public RenderWidgetHostTouchEmulatorBrowserTest { : public RenderWidgetHostTouchEmulatorBrowserTest {
public: public:
......
...@@ -1141,27 +1141,25 @@ void LocalFrame::WindowSegmentsChanged( ...@@ -1141,27 +1141,25 @@ void LocalFrame::WindowSegmentsChanged(
if (!RuntimeEnabledFeatures::CSSFoldablesEnabled()) if (!RuntimeEnabledFeatures::CSSFoldablesEnabled())
return; return;
DCHECK(IsLocalRoot());
// A change in the window segments requires re-evaluation of media queries // A change in the window segments requires re-evaluation of media queries
// for the local frame subtree (the segments affect the "screen-spanning" // for the local frame subtree (the segments affect the "screen-spanning"
// feature). // feature).
MediaQueryAffectingValueChangedForLocalSubtree(MediaValueChange::kOther); MediaQueryAffectingValueChangedForLocalSubtree(MediaValueChange::kOther);
// Also need to update the environment variables related to window segments // Also need to update the environment variables related to window segments.
// on the local frame subtree.
UpdateCSSFoldEnvironmentVariables(window_segments); UpdateCSSFoldEnvironmentVariables(window_segments);
for (Frame* child = Tree().FirstChild(); child;
child = child->Tree().NextSibling()) {
if (auto* child_local_frame = DynamicTo<LocalFrame>(child))
child_local_frame->UpdateCSSFoldEnvironmentVariables(window_segments);
}
} }
void LocalFrame::UpdateCSSFoldEnvironmentVariables( void LocalFrame::UpdateCSSFoldEnvironmentVariables(
const WebVector<WebRect>& window_segments) { const WebVector<WebRect>& window_segments) {
DCHECK(RuntimeEnabledFeatures::CSSFoldablesEnabled()); DCHECK(RuntimeEnabledFeatures::CSSFoldablesEnabled());
DocumentStyleEnvironmentVariables& vars = // Update the variable values on the root instance so that documents that
GetDocument()->GetStyleEngine().EnsureEnvironmentVariables(); // are created after the values change automatically have the right values.
StyleEnvironmentVariables& vars =
StyleEnvironmentVariables::GetRootInstance();
// CSS environment variables related to window segments currently only // CSS environment variables related to window segments currently only
// expose values for a single fold (i.e. if there are two segments). In all // expose values for a single fold (i.e. if there are two segments). In all
......
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