Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for :target pseudo-selector #7720

Closed
Manishearth opened this issue Sep 23, 2015 · 17 comments
Closed

Add support for :target pseudo-selector #7720

Manishearth opened this issue Sep 23, 2015 · 17 comments

Comments

@Manishearth
Copy link
Member

@Manishearth Manishearth commented Sep 23, 2015

See #7720 (comment) for instructions on how to solve this.

Relevant spec: https://html.spec.whatwg.org/multipage/scripting.html#selector-target

@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented Sep 23, 2015

For efficiency, first check if the fragment matches the elements id or name, and then proceed with doing a document traversal.

@SimonSapin It occurs to me that pseudo-selectors that depend on a property of the document, rather than a direct property of the element (e.g. :target, :current, etc) are quite inefficient with querySelector(), since for each element, one must access the document, fetch some properties, and possibly do a tree traversal. This is in contrast with other selectors where it's always a local check.

I'm not sure how Servo's style updates happen, but there's also a chance for inefficiency there. Would these selectors cause a lot of churn on DOM manipulations?

@mbrubeck
Copy link
Contributor

@mbrubeck mbrubeck commented Sep 23, 2015

For what it's worth, Gecko and Blink do not seem to recalculate :target matching when the DOM changes, as seen in this test case:

<html>
  <head>
    <style>
      :target { color: red; }
    </style>
  </head>
  <body>
    <ul><li id="foo">hello</li></ul>
    <script>
      document.querySelector("ul").addEventListener("click", function() {
        this.insertBefore(this.firstChild.cloneNode(true), this.firstChild);
      });
    </script>
  </body>
</html>
@SimonSapin
Copy link
Member

@SimonSapin SimonSapin commented Sep 23, 2015

Yeah, we probably don’t want to traverse the document every time :target is matched on a given element. Could we maintain a "targeted" flag on every element? These flags would need to be updated (at least) when an element is inserted or removed, when an id or name attribute is added/removed/modified, or when the fragment identifier of the document’s URL changes.

@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented Sep 24, 2015

Using NodeFlags? That sounds like a good idea. I don't like stuffing lots of flags into NodeFlags, but for now that seems okay.

This still requires a full dom traversal whenever a node is moved. We can improve it so that it first does a traversal of the moved node though.

@gilles-leblanc
Copy link
Contributor

@gilles-leblanc gilles-leblanc commented Oct 16, 2015

I'd like to take a look at this one. Will be the hardest thing I have tackled on Servo as of yet.

@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented Oct 16, 2015

This really depends on that spec issue being resolved. We could do a correct but somewhat inefficient implementation (as detailed in the comments above) now, though.

@gilles-leblanc
Copy link
Contributor

@gilles-leblanc gilles-leblanc commented Oct 16, 2015

@Manishearth Ok, I'll look for another one then. I hadn't realized it was waiting on the spec being resolved.

@jdm jdm added the I-spec-unclear label Oct 16, 2015
@jdm
Copy link
Member

@jdm jdm commented May 24, 2016

@Manishearth What's the specification status here? If this isn't ready for someone to work on it, we should remove the less easy tag.

@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented May 25, 2016

I plan to fix the spec issue, but detagged for now

@Manishearth Manishearth added the E-easy label Jun 7, 2016
@highfive
Copy link

@highfive highfive commented Jun 7, 2016

Please make a comment here if you intend to work on this issue. Thank you!

@SimonSapin
Copy link
Member

@SimonSapin SimonSapin commented Jun 7, 2016

The spec was changed in whatwg/html#1370

@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented Jun 7, 2016

The specification has been updated.

To solve this bug, you need to:

Code: components/script/dom/document.rs, components/script/script_thread.rs

@SimonSapin
Copy link
Member

@SimonSapin SimonSapin commented Jun 7, 2016

Undo servo/rust-selectors#54, get a new version published (until the changes are published, use a local cargo override)

That is not needed: since then, the handling of pseudo-classes other than "tree structural" ones has been made generic and left to users of rust-selectors to implement themselves. In Servo, that happens in components/style/selector_impl.rs where you’ll need to add a variant to the NonTSPseudoClass enum and parse it in parse_non_ts_pseudo_class.

@sjmelia
Copy link
Contributor

@sjmelia sjmelia commented Jun 11, 2016

I'd like to pick this up - it looks like the spec issue is cleared up now; although it still has the flag?

i've made some progress already but have a few questions, do I open a pull request?

@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented Jun 11, 2016

Sure, feel free to open a pull request and ask any questions you have.

What flag?

@sjmelia
Copy link
Contributor

@sjmelia sjmelia commented Jun 11, 2016

Great! R.e. flag, sorry - I meant the "i-spec-unclear" label, I read your comment above as indicating that the spec was clarified and the selected element is not affected by dom changes.

@Manishearth
Copy link
Member Author

@Manishearth Manishearth commented Jun 11, 2016

oh, yeah, that label can be removed

bors-servo added a commit that referenced this issue Aug 3, 2016
Issue 7720: Add target selector and update when scrolling to fragment

<!-- Please describe your changes on the following line: -->
Add the target pseudo selector and set/unset it during scrolling to fragment. This change is not complete as no repaint is triggered after the selector is added - it will only take effect after a repaint is triggered by e.g. hovering over another element. (See manual test)

I would like some help because i'm not sure how to resolve this; I can only think to call window.reflow.

I added a manual test case, don't think this counts really! I think the applicable automated test is in /tests/wpt/web-platform-tests/dom/nodes/Element-matches.html but it currently fails, I think due to the above.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #7720  (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11726)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Aug 3, 2016
Issue 7720: Add target selector and update when scrolling to fragment

<!-- Please describe your changes on the following line: -->
Add the target pseudo selector and set/unset it during scrolling to fragment. This change is not complete as no repaint is triggered after the selector is added - it will only take effect after a repaint is triggered by e.g. hovering over another element. (See manual test)

I would like some help because i'm not sure how to resolve this; I can only think to call window.reflow.

I added a manual test case, don't think this counts really! I think the applicable automated test is in /tests/wpt/web-platform-tests/dom/nodes/Element-matches.html but it currently fails, I think due to the above.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #7720  (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11726)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Aug 3, 2016
Issue 7720: Add target selector and update when scrolling to fragment

<!-- Please describe your changes on the following line: -->
Add the target pseudo selector and set/unset it during scrolling to fragment. This change is not complete as no repaint is triggered after the selector is added - it will only take effect after a repaint is triggered by e.g. hovering over another element. (See manual test)

I would like some help because i'm not sure how to resolve this; I can only think to call window.reflow.

I added a manual test case, don't think this counts really! I think the applicable automated test is in /tests/wpt/web-platform-tests/dom/nodes/Element-matches.html but it currently fails, I think due to the above.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #7720  (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11726)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Aug 3, 2016
Issue 7720: Add target selector and update when scrolling to fragment

<!-- Please describe your changes on the following line: -->
Add the target pseudo selector and set/unset it during scrolling to fragment. This change is not complete as no repaint is triggered after the selector is added - it will only take effect after a repaint is triggered by e.g. hovering over another element. (See manual test)

I would like some help because i'm not sure how to resolve this; I can only think to call window.reflow.

I added a manual test case, don't think this counts really! I think the applicable automated test is in /tests/wpt/web-platform-tests/dom/nodes/Element-matches.html but it currently fails, I think due to the above.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #7720  (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11726)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Aug 3, 2016
Issue 7720: Add target selector and update when scrolling to fragment

<!-- Please describe your changes on the following line: -->
Add the target pseudo selector and set/unset it during scrolling to fragment. This change is not complete as no repaint is triggered after the selector is added - it will only take effect after a repaint is triggered by e.g. hovering over another element. (See manual test)

I would like some help because i'm not sure how to resolve this; I can only think to call window.reflow.

I added a manual test case, don't think this counts really! I think the applicable automated test is in /tests/wpt/web-platform-tests/dom/nodes/Element-matches.html but it currently fails, I think due to the above.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #7720  (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11726)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

8 participants
You can’t perform that action at this time.