Skip to content

Commit

Permalink
[inert] Force 'user-select: none' on inert nodes at used-value time
Browse files Browse the repository at this point in the history
The CSSWG resolved that inert nodes should behave as if they had
'user-select: none', but without changing the computed style.
w3c/csswg-drafts#6685 (comment)

This is done by adding a public ComputedStyle::UsedUserSelect() that
returns EUserSelect::kNone for inert, and privatizing the existing
ComputedStyle::UserSelect() just for friend classes.

This doesn't seem to have much impact to editing since IsSelectable()
was already checking IsInert().

But now accessibility will set kNotUserSelectableStyle=true when inert.

Bug: 692360

TEST=All/DumpAccessibilityTreeTestWithIgnoredNodes.InertAttribute/blink

AX-Relnotes: Inert nodes will be considered non-selectable.
Change-Id: Iffc15fb90976234768721a6e006de9b6defeee55
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3460673
Reviewed-by: Aaron Leventhal <[email protected]>
Reviewed-by: Rune Lillesveen <[email protected]>
Commit-Queue: Oriol Brufau <[email protected]>
Cr-Commit-Position: refs/heads/main@{#971185}
NOKEYCHECK=True
GitOrigin-RevId: f1944a2f4cd881ac3b985059e440ecb5384735eb
  • Loading branch information
Loirooriol authored and copybara-github committed Feb 15, 2022
1 parent 89d0fcc commit e854b79
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions blink/renderer/core/css/css_properties.json5
Original file line number Diff line number Diff line change
Expand Up @@ -5137,6 +5137,7 @@
{
name: "user-select",
property_methods: ["CSSValueFromComputedStyleInternal"],
computed_style_custom_functions: ["getter"],
inherited: true,
field_group: "*",
field_template: "keyword",
Expand Down
6 changes: 3 additions & 3 deletions blink/renderer/core/dom/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1670,13 +1670,13 @@ bool Node::CanStartSelection() const {

if (GetLayoutObject()) {
const ComputedStyle& style = GetLayoutObject()->StyleRef();
if (style.UserSelect() == EUserSelect::kNone)
EUserSelect user_select = style.UsedUserSelect();
if (user_select == EUserSelect::kNone)
return false;
// We allow selections to begin within |user-select: text/all| sub trees
// but not if the element is draggable.
if (style.UserDrag() != EUserDrag::kElement &&
(style.UserSelect() == EUserSelect::kText ||
style.UserSelect() == EUserSelect::kAll))
(user_select == EUserSelect::kText || user_select == EUserSelect::kAll))
return true;
}
ContainerNode* parent = FlatTreeTraversal::Parent(*this);
Expand Down
2 changes: 1 addition & 1 deletion blink/renderer/core/editing/editing_strategy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ blink::EUserSelect UsedValueOfUserSelect(const blink::Node& node) {
if (style->UserModify() != blink::EUserModify::kReadOnly)
return blink::EUserSelect::kText;

return style->UserSelect();
return style->UsedUserSelect();
}

} // namespace
Expand Down
3 changes: 2 additions & 1 deletion blink/renderer/core/editing/visible_units_paragraph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ namespace {

bool NodeIsUserSelectAll(const Node* node) {
return node && node->GetLayoutObject() &&
node->GetLayoutObject()->Style()->UserSelect() == EUserSelect::kAll;
node->GetLayoutObject()->Style()->UsedUserSelect() ==
EUserSelect::kAll;
}

template <typename Strategy>
Expand Down
2 changes: 1 addition & 1 deletion blink/renderer/core/frame/smart_clip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ String SmartClip::ExtractTextFromNode(Node* node) {
StringBuilder result;
for (Node& current_node : NodeTraversal::InclusiveDescendantsOf(*node)) {
const ComputedStyle* style = current_node.GetComputedStyle();
if (!style || style->UserSelect() == EUserSelect::kNone)
if (!style || style->UsedUserSelect() == EUserSelect::kNone)
continue;

if (Node* node_from_frame = NodeInsideFrame(&current_node))
Expand Down
12 changes: 11 additions & 1 deletion blink/renderer/core/style/computed_style.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class StopColor;
class Stroke;
class TextDecorationColor;
class TextEmphasisColor;
class UserSelect;
class WebkitTapHighlightColor;
class WebkitTextFillColor;
class WebkitTextStrokeColor;
Expand Down Expand Up @@ -257,6 +258,7 @@ class ComputedStyle : public ComputedStyleBase,
friend class css_longhand::Stroke;
friend class css_longhand::TextDecorationColor;
friend class css_longhand::TextEmphasisColor;
friend class css_longhand::UserSelect;
friend class css_longhand::WebkitTapHighlightColor;
friend class css_longhand::WebkitTextFillColor;
friend class css_longhand::WebkitTextStrokeColor;
Expand Down Expand Up @@ -2241,8 +2243,15 @@ class ComputedStyle : public ComputedStyleBase,
return PointerEventsInternal();
}

// User select utility functions.
EUserSelect UsedUserSelect() const {
if (IsInert())
return EUserSelect::kNone;
return UserSelectInternal();
}

bool IsSelectable() const {
return !IsInert() && !(UserSelect() == EUserSelect::kNone &&
return !IsInert() && !(UserSelectInternal() == EUserSelect::kNone &&
UserModify() == EUserModify::kReadOnly);
}

Expand Down Expand Up @@ -2785,6 +2794,7 @@ class ComputedStyle : public ComputedStyleBase,
EFloat Floating() const { return FloatingInternal(); }
EPointerEvents PointerEvents() const { return PointerEventsInternal(); }
EResize Resize() const { return ResizeInternal(); }
EUserSelect UserSelect() const { return UserSelectInternal(); }

bool IsInlineSizeContainer() const {
return ContainerType() & kContainerTypeInlineSize;
Expand Down
2 changes: 1 addition & 1 deletion blink/renderer/modules/accessibility/ax_layout_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ bool AXLayoutObject::IsNotUserSelectable() const {
if (!style)
return false;

return (style->UserSelect() == EUserSelect::kNone);
return (style->UsedUserSelect() == EUserSelect::kNone);
}

//
Expand Down

0 comments on commit e854b79

Please sign in to comment.