Skip to content

Commit

Permalink
[inert] Force 'pointer-events: 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
'pointer-events: none', but without changing the computed style.
w3c/csswg-drafts#6685 (comment)

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

Note that computed_style_fields.py needs to be tweaked, otherwise the
automatically generated PropagateIndependentInheritedProperties() would
still try to call ResetPointerEventsIsInherited(), which is no longer
defined. Now it needs to be ResetPointerEventsIsInheritedInternal().

After this change, it will be possible to remove the hit-testing
retargeting for inert.

Bug: 692360

TEST=external/wpt/html/semantics/interactive-elements/the-dialog-element/dialog-inert.tentative.html
TEST=external/wpt/inert/inert-computed-style.html

Change-Id: I720908d3e1c47d7cd13b9fe9e1110e44ff70f56b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3281968
Reviewed-by: Anders Hartvoll Ruud <[email protected]>
Reviewed-by: Rune Lillesveen <[email protected]>
Commit-Queue: Oriol Brufau <[email protected]>
Cr-Commit-Position: refs/heads/main@{#942180}
NOKEYCHECK=True
GitOrigin-RevId: 6aadd45a00e1d6512dd17c3a2d31f5d89647c97e
  • Loading branch information
Loirooriol authored and copybara-github committed Nov 16, 2021
1 parent c9a1325 commit 87072d8
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ def __init__(self, field_role, name_for_methods, property_name, type_name,
assert self.is_inherited or not self.is_independent, \
'Only inherited fields can be independent'

suffix = ['is', 'inherited']
if 'getter' in self.computed_style_custom_functions:
suffix.append('internal')
self.is_inherited_method_name = name_source.to_function_name(
suffix=['is', 'inherited'])
suffix=suffix)
assert len(kwargs) == 0, \
'Unexpected arguments provided to Field: ' + str(kwargs)
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 @@ -3436,6 +3436,7 @@
{
name: "pointer-events",
property_methods: ["CSSValueFromComputedStyleInternal"],
computed_style_custom_functions: ["getter"],
independent: true,
inherited: true,
field_template: "keyword",
Expand Down
2 changes: 1 addition & 1 deletion blink/renderer/core/layout/layout_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -2849,7 +2849,7 @@ class CORE_EXPORT LayoutObject : public GarbageCollected<LayoutObject>,
NOT_DESTROYED();
return StyleRef().Visibility() == EVisibility::kVisible &&
(request.IgnorePointerEventsNone() ||
StyleRef().PointerEvents() != EPointerEvents::kNone);
StyleRef().UsedPointerEvents() != EPointerEvents::kNone);
}

bool VisibleToHitTesting() const {
Expand Down
2 changes: 1 addition & 1 deletion blink/renderer/core/layout/svg/layout_svg_container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ bool LayoutSVGContainer::NodeAtPoint(HitTestResult& result,

// pointer-events: bounding-box makes it possible for containers to be direct
// targets.
if (StyleRef().PointerEvents() == EPointerEvents::kBoundingBox) {
if (StyleRef().UsedPointerEvents() == EPointerEvents::kBoundingBox) {
// Check for a valid bounding box because it will be invalid for empty
// containers.
if (IsObjectBoundingBoxValid() &&
Expand Down
2 changes: 1 addition & 1 deletion blink/renderer/core/layout/svg/layout_svg_image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ bool LayoutSVGImage::NodeAtPoint(HitTestResult& result,
const ComputedStyle& style = StyleRef();
PointerEventsHitRules hit_rules(PointerEventsHitRules::SVG_IMAGE_HITTESTING,
result.GetHitTestRequest(),
style.PointerEvents());
style.UsedPointerEvents());
if (hit_rules.require_visible && style.Visibility() != EVisibility::kVisible)
return false;

Expand Down
2 changes: 1 addition & 1 deletion blink/renderer/core/layout/svg/layout_svg_shape.cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ bool LayoutSVGShape::NodeAtPoint(HitTestResult& result,
const ComputedStyle& style = StyleRef();
const PointerEventsHitRules hit_rules(
PointerEventsHitRules::SVG_GEOMETRY_HITTESTING,
result.GetHitTestRequest(), style.PointerEvents());
result.GetHitTestRequest(), style.UsedPointerEvents());
if (hit_rules.require_visible && style.Visibility() != EVisibility::kVisible)
return false;

Expand Down
2 changes: 1 addition & 1 deletion blink/renderer/core/layout/svg/layout_svg_text.cc
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ bool LayoutSVGText::NodeAtPoint(HitTestResult& result,
return true;

// Consider the bounding box if requested.
if (StyleRef().PointerEvents() == EPointerEvents::kBoundingBox) {
if (StyleRef().UsedPointerEvents() == EPointerEvents::kBoundingBox) {
if (IsObjectBoundingBoxValid() &&
local_location->Intersects(ObjectBoundingBox())) {
UpdateHitTestResult(result, PhysicalOffset::FromFloatPointRound(
Expand Down
2 changes: 1 addition & 1 deletion blink/renderer/core/layout/svg/line/svg_inline_text_box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ bool SVGInlineTextBox::NodeAtPoint(HitTestResult& result,
const ComputedStyle& style = line_layout_item.StyleRef();
PointerEventsHitRules hit_rules(PointerEventsHitRules::SVG_TEXT_HITTESTING,
result.GetHitTestRequest(),
style.PointerEvents());
style.UsedPointerEvents());
if (hit_rules.require_visible && style.Visibility() != EVisibility::kVisible)
return false;
if (hit_rules.can_hit_bounding_box ||
Expand Down
8 changes: 4 additions & 4 deletions blink/renderer/core/paint/ng/ng_box_fragment_painter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ inline bool IsVisibleToPaint(const NGFragmentItem& item,
inline bool IsVisibleToHitTest(const ComputedStyle& style,
const HitTestRequest& request) {
return request.IgnorePointerEventsNone() ||
style.PointerEvents() != EPointerEvents::kNone;
style.UsedPointerEvents() != EPointerEvents::kNone;
}

inline bool IsVisibleToHitTest(const NGFragmentItem& item,
Expand All @@ -117,7 +117,7 @@ inline bool IsVisibleToHitTest(const NGFragmentItem& item,
if (item.IsHiddenForPaint())
return false;
PointerEventsHitRules hit_rules(PointerEventsHitRules::SVG_TEXT_HITTESTING,
request, style.PointerEvents());
request, style.UsedPointerEvents());
if (hit_rules.require_visible && style.Visibility() != EVisibility::kVisible)
return false;
if (hit_rules.can_hit_bounding_box ||
Expand Down Expand Up @@ -1930,7 +1930,7 @@ bool NGBoxFragmentPainter::NodeAtPoint(const HitTestContext& hit_test,
hit_test_self = false;
} else if (fragment.IsSvgText()) {
pointer_events_bounding_box =
fragment.Style().PointerEvents() == EPointerEvents::kBoundingBox;
fragment.Style().UsedPointerEvents() == EPointerEvents::kBoundingBox;
hit_test_self = pointer_events_bounding_box;
}
}
Expand Down Expand Up @@ -2271,7 +2271,7 @@ bool NGBoxFragmentPainter::HitTestChildBoxItem(
}

if (cursor.ContainerFragment().IsSvgText() &&
item.Style().PointerEvents() != EPointerEvents::kBoundingBox)
item.Style().UsedPointerEvents() != EPointerEvents::kBoundingBox)
return false;

// Now hit test ourselves.
Expand Down
4 changes: 2 additions & 2 deletions blink/renderer/core/paint/paint_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3457,8 +3457,8 @@ bool PaintLayer::AttemptDirectCompositingUpdate(
// Changes in pointer-events affect hit test visibility of the scrollable
// area and its |m_scrollsOverflow| value which determines if the layer
// requires composited scrolling or not.
if (scrollable_area_ &&
layout_object_->StyleRef().PointerEvents() != old_style->PointerEvents())
if (scrollable_area_ && layout_object_->StyleRef().UsedPointerEvents() !=
old_style->UsedPointerEvents())
return false;

UpdateTransform(old_style, GetLayoutObject().StyleRef());
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 @@ -135,6 +135,7 @@ class InternalVisitedTextFillColor;
class InternalVisitedTextStrokeColor;
class LightingColor;
class OutlineColor;
class PointerEvents;
class Position;
class Resize;
class StopColor;
Expand Down Expand Up @@ -248,6 +249,7 @@ class ComputedStyle : public ComputedStyleBase,
friend class css_longhand::InternalVisitedTextStrokeColor;
friend class css_longhand::LightingColor;
friend class css_longhand::OutlineColor;
friend class css_longhand::PointerEvents;
friend class css_longhand::Position;
friend class css_longhand::Resize;
friend class css_longhand::StopColor;
Expand Down Expand Up @@ -2186,6 +2188,13 @@ class ComputedStyle : public ComputedStyleBase,
}
void SetIsForcedInert() { SetInertnessInternal(Inertness::kForced); }

// Pointer-events utility functions.
EPointerEvents UsedPointerEvents() const {
if (IsInert())
return EPointerEvents::kNone;
return PointerEventsInternal();
}

// Text decoration utility functions.
bool TextDecorationVisualOverflowEqual(const ComputedStyle& o) const;
void ApplyTextDecorations(const Color& parent_text_decoration_color,
Expand Down Expand Up @@ -2256,7 +2265,7 @@ class ComputedStyle : public ComputedStyleBase,
// Visibility utility functions.
bool VisibleToHitTesting() const {
return Visibility() == EVisibility::kVisible &&
PointerEvents() != EPointerEvents::kNone;
UsedPointerEvents() != EPointerEvents::kNone;
}

// Animation utility functions.
Expand Down Expand Up @@ -2693,6 +2702,7 @@ class ComputedStyle : public ComputedStyleBase,
private:
EClear Clear() const { return ClearInternal(); }
EFloat Floating() const { return FloatingInternal(); }
EPointerEvents PointerEvents() const { return PointerEventsInternal(); }
EResize Resize() const { return ResizeInternal(); }

bool IsInlineSizeContainer() const {
Expand Down
2 changes: 1 addition & 1 deletion blink/renderer/core/svg/svg_svg_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ bool SVGSVGElement::CheckIntersectionOrEnclosure(
LayoutObject* layout_object = element.GetLayoutObject();
DCHECK(!layout_object || layout_object->Style());
if (!layout_object ||
layout_object->StyleRef().PointerEvents() == EPointerEvents::kNone)
layout_object->StyleRef().UsedPointerEvents() == EPointerEvents::kNone)
return false;

if (!IsIntersectionOrEnclosureTarget(layout_object))
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 87072d8

Please sign in to comment.