Commit 60ba6e42 authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Chromium LUCI CQ

Check that container query recalc works for text inputs

We have three instances of using AllowMarkStyleDirtyFromRecalcScope to
allow marking elements style-dirty during style recalc. One of them is
for text input elements where we mark the InnerEditor() element dirty
when the input element gets new style. We typically don't mark style
during UpdateStyleAndLayoutTreeForContainer(), which is called for
container query updates during layout. This CL adds a test to check that
it still works.

Bug: 1146097
Change-Id: I432308bc96cd938e22ea424975a7c19a35aaf6a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2573139
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834216}
parent aa0bad16
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h" #include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/viewport_data.h" #include "third_party/blink/renderer/core/frame/viewport_data.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/html_collection.h" #include "third_party/blink/renderer/core/html/html_collection.h"
#include "third_party/blink/renderer/core/html/html_element.h" #include "third_party/blink/renderer/core/html/html_element.h"
#include "third_party/blink/renderer/core/html/html_iframe_element.h" #include "third_party/blink/renderer/core/html/html_iframe_element.h"
...@@ -3804,4 +3805,47 @@ TEST_F(StyleEngineTest, UpdateStyleAndLayoutTreeForContainer) { ...@@ -3804,4 +3805,47 @@ TEST_F(StyleEngineTest, UpdateStyleAndLayoutTreeForContainer) {
EXPECT_EQ(5u, GetStyleEngine().StyleForElementCount() - start_count); EXPECT_EQ(5u, GetStyleEngine().StyleForElementCount() - start_count);
} }
TEST_F(StyleEngineTest, MarkStyleDirtyFromContainerRecalc) {
GetDocument().body()->setInnerHTML(R"HTML(
<div id="container" style="contain:layout">
<input id="input" type="text" class="affected">
</div>
)HTML");
UpdateAllLifecyclePhases();
auto* container = GetDocument().getElementById("container");
auto* input = GetDocument().getElementById("input");
auto* affected = GetDocument().getElementsByClassName("affected");
ASSERT_TRUE(container);
ASSERT_TRUE(input);
auto* inner_editor = DynamicTo<HTMLInputElement>(input)->InnerEditorElement();
ASSERT_TRUE(inner_editor);
ASSERT_TRUE(affected);
SetDependsOnContainerQueries(*affected);
scoped_refptr<const ComputedStyle> old_inner_style =
inner_editor->GetComputedStyle();
EXPECT_TRUE(old_inner_style);
unsigned start_count = GetStyleEngine().StyleForElementCount();
GetStyleEngine().UpdateStyleAndLayoutTreeForContainer(*container);
// Input elements mark their InnerEditorElement() style-dirty when they are
// recalculated. That means the UpdateStyleAndLayoutTreeForContainer() call
// above will involve marking ChildNeedsStyleRecalc all the way up to the
// documentElement. Check that we don't leave anything dirty.
EXPECT_FALSE(GetDocument().NeedsLayoutTreeUpdate());
EXPECT_FALSE(GetDocument().documentElement()->ChildNeedsStyleRecalc());
// The input element is recalculated. The inner editor element isn't counted
// because we don't do normal style resolution to create the ComputedStyle for
// it, but check that we have a new ComputedStyle object for it.
EXPECT_EQ(1u, GetStyleEngine().StyleForElementCount() - start_count);
const ComputedStyle* new_inner_style = inner_editor->GetComputedStyle();
EXPECT_TRUE(new_inner_style);
EXPECT_NE(old_inner_style, new_inner_style);
}
} // namespace blink } // 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