Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd support for :target pseudo-selector #7720
Comments
|
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. 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? |
|
For what it's worth, Gecko and Blink do not seem to recalculate <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> |
|
Yeah, we probably don’t want to traverse the document every time |
|
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. |
|
I'd like to take a look at this one. Will be the hardest thing I have tackled on Servo as of yet. |
|
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. |
|
@Manishearth Ok, I'll look for another one then. I hadn't realized it was waiting on the spec being resolved. |
|
@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. |
|
I plan to fix the spec issue, but detagged for now |
|
Please make a comment here if you intend to work on this issue. Thank you! |
|
The spec was changed in whatwg/html#1370 |
|
The specification has been updated. To solve this bug, you need to:
Code: |
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 |
|
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? |
|
Sure, feel free to open a pull request and ask any questions you have. What flag? |
|
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. |
|
oh, yeah, that label can be removed |
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 -->
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 -->
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 -->
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 -->
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 -->
See #7720 (comment) for instructions on how to solve this.
Relevant spec: https://html.spec.whatwg.org/multipage/scripting.html#selector-target