Skip to content

Commit

Permalink
[inert] Track inertness in ComputedStyle
Browse files Browse the repository at this point in the history
Both Gecko and WebKit implement inertness based on CSS primitives like
forcing 'pointer-events: none' at used value time, instead of using
a magical hit testing retargeting for inert.

And in whatwg/html#5650, the CSSWG resolved
that this is the right approach.

Then rather than tracking inertness using Node::IsInert, it will just be
simpler to use ComputedStyle::IsInert. This patch implements that.

There are some differences, like nodes in a 'display: none' subtree
won't have a ComputedStyle so we can't really tell if they are inert,
but in practice this doesn't matter since they are not rendered.

Bug: 692360

TEST=StyleResolverTest.IsInertWithAttributeAndDialog
TEST=StyleResolverTest.IsInertWithDialogs
TEST=StyleResolverTest.IsInertWithFullscreen
TEST=StyleResolverTest.IsInertWithFrameAndFullscreen
TEST=StyleResolverTest.IsInertWithBackdrop

Change-Id: I4f8c87ea2fbc17f57290edaf185cdff4aebb7e58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3263937
Reviewed-by: Rune Lillesveen <[email protected]>
Commit-Queue: Oriol Brufau <[email protected]>
Cr-Commit-Position: refs/heads/main@{#941651}
NOKEYCHECK=True
GitOrigin-RevId: ab14f17b660d05dc15925fea64f3cfd92c6f1ed1
  • Loading branch information
Loirooriol authored and copybara-github committed Nov 15, 2021
1 parent 635e313 commit 9605d54
Show file tree
Hide file tree
Showing 17 changed files with 551 additions and 83 deletions.
29 changes: 29 additions & 0 deletions blink/renderer/core/css/resolver/style_adjuster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/core/fullscreen/fullscreen.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/forms/html_text_area_element.h"
#include "third_party/blink/renderer/core/html/html_body_element.h"
#include "third_party/blink/renderer/core/html/html_dialog_element.h"
#include "third_party/blink/renderer/core/html/html_iframe_element.h"
#include "third_party/blink/renderer/core/html/html_image_element.h"
#include "third_party/blink/renderer/core/html/html_plugin_element.h"
Expand Down Expand Up @@ -677,6 +679,31 @@ static void AdjustStateForContentVisibility(ComputedStyle& style,
context->AdjustElementStyle(&style);
}

static void AdjustStyleForInert(ComputedStyle& style, Element* element) {
if (!element || style.IsForcedInert())
return;

if (RuntimeEnabledFeatures::InertAttributeEnabled() &&
element->FastHasAttribute(html_names::kInertAttr) &&
element->IsHTMLElement()) {
style.SetIsForcedInert();
return;
}

Document& document = element->GetDocument();
const Element* modal_element = document.ActiveModalDialog();
if (!modal_element)
modal_element = Fullscreen::FullscreenElementFrom(document);
if (modal_element == element) {
style.SetIsInert(false);
return;
}
if (modal_element && element == document.documentElement()) {
style.SetIsInert(true);
return;
}
}

void StyleAdjuster::AdjustForForcedColorsMode(ComputedStyle& style) {
if (!style.InForcedColorsMode() ||
style.ForcedColorAdjust() != EForcedColorAdjust::kAuto)
Expand Down Expand Up @@ -818,6 +845,8 @@ void StyleAdjuster::AdjustComputedStyle(StyleResolverState& state,
// Let the theme also have a crack at adjusting the style.
LayoutTheme::GetTheme().AdjustStyle(element, style);

AdjustStyleForInert(style, element);

AdjustStyleForEditing(style);

bool is_svg_root = false;
Expand Down
3 changes: 3 additions & 0 deletions blink/renderer/core/css/resolver/style_resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,9 @@ scoped_refptr<ComputedStyle> StyleResolver::InitialStyleForElement() const {
if (initial_data)
initial_style->SetInitialData(std::move(initial_data));

if (frame && frame->IsInert())
initial_style->SetIsForcedInert();

return initial_style;
}

Expand Down
Loading

0 comments on commit 9605d54

Please sign in to comment.