Open Bug 1554009 Opened 5 years ago Updated 2 years ago

InspectorUtils.selectorMatchesElement is a bit broken in presence of :host and ::slotted rules.

Categories

(DevTools :: Inspector, defect, P3)

defect

Tracking

(Not tracked)

People

(Reporter: emilio, Unassigned)

References

(Blocks 1 open bug)

Details

In particular, since we never pass it the shadow host the style rule is in, it'll never match these selectors.

This was caught by an assertion in bug 1544242.

This is fixable, CssStyleRule should just get the AssociatedDocumentOrShadowRoot() and pass it down or something.

I'm removing that assertion since even if we did that we could trigger it: The style system should never itself try to match a :host or ::slotted outside of a shadow tree, but the OM and inspector can try, and we'd correctly return false.

Julian, how do we use this API? I assume it's desirable to match these rules correctly? Or is this API not used for anything important? (I haven't seen any bug about this...)

Flags: needinfo?(jdescottes)

Thanks for filing Emilio!

I think it is used in various places. Basically we are checking it in various places the check that a given rule actually applies to the current element.

So I think I have STRs for this bug in DevTools:

Expected result: In the rule view, the rule background: rgb(255, 0, 0); should be marked as overridden (greyed + strikethrough)
Actual result: In the rule view, the rule background: rgb(255, 0, 0); has the default style.

This is related to the following code https://searchfox.org/mozilla-central/rev/662de518b1686c4769320d6b8825ce4864c4eda0/devtools/client/inspector/rules/models/element-style.js#285 . Basically we don't update properly this rule because we think it doesn't really apply to the element.

So it's probably not used in critical paths, that's why we didn't get any bug report so far. But it would be great to fix it!
Emilio do you have more pointers to fix this by any chance?

Flags: needinfo?(jdescottes) → needinfo?(emilio)

Yes, this function: https://searchfox.org/mozilla-central/rev/662de518b1686c4769320d6b8825ce4864c4eda0/layout/style/CSSStyleRule.cpp#201

Should do something like:

Element* containingHost = nullptr;
if (StyleSheet* sheet = GetStyleSheet()) {
  if (ShadowRoot* shadow = sheet->GetContainingShadow()) {
    containingHost = shadow->Host();
  }
}

(Need to make GetContainingShadow() public).

Then you need to pass that as an argument to the style system, so like: https://searchfox.org/mozilla-central/rev/662de518b1686c4769320d6b8825ce4864c4eda0/servo/ports/geckolib/glue.rs#2147

But optional (so containing_host: Option<&RawGeckoElement>).

Then you need to use that in the MatchingContext, so:

ctx.current_host = containing_host.map(|e| GeckoElement(e).opaque())

In that function. That should do (And tests, of course :)).

Flags: needinfo?(emilio)

Alternatively, we could take the current host as an argument from devtools if that'd be useful.

The priority flag is not set for this bug.
:dholbert, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(dholbert)
Component: Layout: Images, Video, and HTML Frames → Inspector
Flags: needinfo?(dholbert)
Product: Core → DevTools
Priority: -- → P3
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.