Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

beforematch: Target element definition is ambiguous. #160

Open
emilio opened this issue May 2, 2020 · 5 comments
Open

beforematch: Target element definition is ambiguous. #160

emilio opened this issue May 2, 2020 · 5 comments
Assignees

Comments

@emilio
Copy link

emilio commented May 2, 2020

It says:

the element that contains the text which was matched by find-in-page or scroll-to-text navigation.

What happens when the text to be found spans multiple elements, like:

<span>foo</span> <span>bar</span>

What if the match happens across shadow tree boundaries?

josepharhar added a commit to josepharhar/display-locking that referenced this issue May 5, 2020
@josepharhar
Copy link
Collaborator

I agree this is ambiguous, I need to update the explainer.

The event is fired on the block-level element containing the text which will be scrolled to. In the case of <div id=parent> <span>foo</span> <span>bar</span> </div>, beforematch will be fired on parent in the scroll-to-text and find-in-page cases.

As for shadow boundaries, the beforematch event is fired on the first block-level element containing the matching text in the flat tree. I just tested it out and it appears to basically ignore shadow boundaries, the event is fired on whatever the first block-level containing element is, whether its in shadow or not. If the shadow boundary is inline and the matching text goes across it, it just goes to the first block-level containing element which in this case would be outside of the shadow dom.

josepharhar added a commit to josepharhar/display-locking that referenced this issue May 6, 2020
@josepharhar
Copy link
Collaborator

@emilio I updated the explainer to elaborate some more. Has the ambiguity been resolved?

@emilio
Copy link
Author

emilio commented May 8, 2020

What does "block-level ancestor element" mean in this case? An inline-block is a block inside, but not outside, for example. Also probably should reference "block level boxes".

The new definition is a bit concerning, consider you have an inline element with a shadow root, with a bunch of text in it. The closest block ancestor is outside the shadow root, but it doesn't know it has any text on it. Seems like this breaks shadow boundary encapsulation by dispatching events outside of a shadow tree for stuff that happens inside of the shadow tree.

@josepharhar
Copy link
Collaborator

Thanks for the feedback!

What does "block-level ancestor element" mean in this case? An inline-block is a block inside, but not outside, for example. Also probably should reference "block level boxes".

I tested this out with this HTML:

<div id=one style="display: block">
  one 
  <div id=two style="display: inline-block">
    two 
    <div id=three style="display: inline">
      three
    </div>
  </div>
</div>

I found that whatever text is searched for, <div id=one> is always selected to fire beforematch on. Is this the case you are talking about, or is it something else? Is <div id=two> a block level box?

The new definition is a bit concerning, consider you have an inline element with a shadow root, with a bunch of text in it. The closest block ancestor is outside the shadow root, but it doesn't know it has any text on it. Seems like this breaks shadow boundary encapsulation by dispatching events outside of a shadow tree for stuff that happens inside of the shadow tree.

I see how this breaks shadow encapsulation. Which element do you think would be best to fire the event on in this case? Should we fire it at all? What about when the match crosses a shadow boundary? @vmpstr

@emilio
Copy link
Author

emilio commented May 9, 2020

I found that whatever text is searched for, <div id=one> is always selected to fire beforematch on. Is this the case you are talking about, or is it something else? Is <div id=two> a block level box?

Well, sure, in Chrome, which is the only implementation of this draft :)

Yeah, I guess <div id=one> is a block-level box per https://drafts.csswg.org/css2/visuren.html#block-boxes, and <div id=two> is a block container, but not a block level box. So I guess that's fine as a definition, but you should link to that probably.

...

Which element do you think would be best to fire the event on in this case?

We could probably fire the event on the text node, and let it bubble. That behaves sanely with Shadow DOM I think.

About what happens when it crosses a shadow boundary, or where it matches multiple text-nodes... that's unclear.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants