Ignore <input> and <textarea>'s user-select styling
Background:
The CSS spec says that user-select does "selective inheritance",
see https://drafts.csswg.org/css-ui-4/#propdef-user-select.
<input> and <textarea> are two elements that are affected
by this. These elements should not inherit user-select from
parent elements.
Fixed problem:
<input|textarea readonly|disabled> could inherit
"user-select: none".
This regressed because
https://chromium-review.googlesource.com/570246
removed input|textarea's default user-select styling.
Solution:
Make all text controls always selectable. This is done in
LayoutTextControl::AdjustInnerEditorStyle.
Interoperability note:
<input readonly style="user-select: none"
value="Chrome 61 cannot select this.">. This CL fixes
this by ensuring that all text fields (i.e also readonly fields)
are always selectable (no matter user-select styling).
In other words, <input> and <input readonly> now behave in
the same way (both always allow selections) which aligns
us with Firefox and Edge.
BUG=761433, 764316
[email protected]
(cherry picked from commit ba7c210328c00a6693ddc5da6504f8520bb3bdc2)
Change-Id: I89fc94a2a04caf3a87b12a9071081dafd48a8727
Reviewed-on: https://chromium-review.googlesource.com/663217
Reviewed-by: Yoshifumi Inoue <[email protected]>
Reviewed-by: Kent Tamura <[email protected]>
Commit-Queue: Hugo Holgersson <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#503793}
Reviewed-on: https://chromium-review.googlesource.com/685655
Reviewed-by: Hugo Holgersson <[email protected]>
Cr-Commit-Position: refs/branch-heads/3202@{#453}
Cr-Branched-From: fa6a5d87adff761bc16afc5498c3f5944c1daa68-refs/heads/master@{#499098}
diff --git a/third_party/WebKit/Source/core/input/EventHandlerTest.cpp b/third_party/WebKit/Source/core/input/EventHandlerTest.cpp
index 73eb50f..cfc9199 100644
--- a/third_party/WebKit/Source/core/input/EventHandlerTest.cpp
+++ b/third_party/WebKit/Source/core/input/EventHandlerTest.cpp
@@ -429,6 +429,28 @@
hit));
}
+TEST_F(EventHandlerTest, ReadOnlyInputDoesNotInheritUserSelect) {
+ SetHtmlInnerHTML(
+ "<div style='user-select: none'>"
+ "<input readonly value='blabla'>"
+ "</div>");
+ Element* const field =
+ ToElement(GetDocument().body()->firstChild()->firstChild());
+ ShadowRoot* const shadow_root = field->UserAgentShadowRoot();
+
+ Element* const text = shadow_root->getElementById("inner-editor");
+ LayoutPoint location = text->GetLayoutObject()->VisualRect().Center();
+ HitTestResult hit =
+ GetDocument().GetFrame()->GetEventHandler().HitTestResultAtPoint(
+ location);
+ EXPECT_TRUE(text->CanStartSelection());
+
+ // TODO(crbug.com/764661): Show I-beam because field is selectable.
+ // EXPECT_TRUE(
+ // GetDocument().GetFrame()->GetEventHandler().ShouldShowIBeamForNode(field,
+ // hit));
+}
+
TEST_F(EventHandlerTest, ImagesCannotStartSelection) {
SetHtmlInnerHTML("<img>");
Element* const img = ToElement(GetDocument().body()->firstChild());
diff --git a/third_party/WebKit/Source/core/layout/LayoutTextControl.cpp b/third_party/WebKit/Source/core/layout/LayoutTextControl.cpp
index 706c45f..b623ea8 100644
--- a/third_party/WebKit/Source/core/layout/LayoutTextControl.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutTextControl.cpp
@@ -79,6 +79,7 @@
// element.
text_block_style.SetDirection(Style()->Direction());
text_block_style.SetUnicodeBidi(Style()->GetUnicodeBidi());
+ text_block_style.SetUserSelect(EUserSelect::kText);
UpdateUserModifyProperty(*GetTextControlElement(), text_block_style);
}