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 upAddresses Issue #1716. Indicated part of the document. #9632
Conversation
highfive
commented
Feb 14, 2016
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @mbrubeck (or someone else) soon. |
highfive
commented
Feb 14, 2016
|
We can ignore the warning from @highfive due to servo/highfive#59. |
|
Actually @jdm, the highfive warning has reminded me that I didn't add all the tests in the manifest.json. I'll address that now. |
| .find(|node| check_anchor(&node)) | ||
| .map(Root::upcast) | ||
| }) | ||
| if fragid == "" { |
This comment has been minimized.
This comment has been minimized.
| String::from_utf8(percent_decode(fragid.as_bytes())).ok() | ||
| .and_then(|decoded_fragid| self.get_element_by_id(&Atom::from(&*decoded_fragid))) | ||
| .or_else(|| self.get_anchor_by_name(fragid)) | ||
| .or_else(|| if fragid.to_lowercase() == "top" { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| self.GetDocumentElement() | ||
| } else { | ||
| use url::percent_encoding::percent_decode; | ||
| // 3. Let fragid bytes be the result of percent-decoding fragid. |
This comment has been minimized.
This comment has been minimized.
KiChjang
Feb 15, 2016
Member
// Step 3 would be enough, we don't need to quote the entire step from the spec.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
peterjoel
Feb 15, 2016
Author
Contributor
Step 2 is directly above, on line 520.
Step 1 is about getting the fragid from the url, but the value is already obtained elsewhere and passed in as an argument. I stuck that step above the function declaration to document that it arises elsewhere, since it wouldn't be very helpful at the actual point where it happens (in another file).
This comment has been minimized.
This comment has been minimized.
| // 7. If fragid is an ASCII case-insensitive match for the string top, then the | ||
| // indicated part of the document is the top of the document; stop the algorithm | ||
| // here. | ||
| .or_else(|| if fragid.to_lowercase() == "top" { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
peterjoel
Feb 15, 2016
Author
Contributor
@KiChjang Lazily evaluating those expressions seems better, since quite often the values will never be needed. As written, at most one Some value will be evaluated, and we don't unnecessarily search the document tree for an anchor if we already found an id match. This function probably isn't performance-critical, but I don't think it alters too much in readability either.
I can of course change it if you think it's best.
This comment has been minimized.
This comment has been minimized.
KiChjang
Feb 15, 2016
Member
Hmm, true, never thought about it in the aspect of eager vs lazy evaluation!
| let doc_node = self.upcast::<Node>(); | ||
| doc_node.traverse_preorder() | ||
| .filter_map(Root::downcast) | ||
| .find(|node| check_anchor(&node)) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
peterjoel
Feb 15, 2016
Author
Contributor
To be honest, this was existing code that I extracted into its own function, and I didn't look too hard at the details.
A quick attempt tells me that this isn't a straightforward change. I don't fully understand the type-conversions going on there, but I can't see this code getting shorter by going down that path.
| } | ||
|
|
||
| fn get_anchor_by_name(&self, name: &str ) -> Option<Root<Element>> { | ||
| let check_anchor = |node: &HTMLAnchorElement| { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| .map(Root::upcast) | ||
| }) | ||
| // Step 2 | ||
| if fragid == "" { |
This comment has been minimized.
This comment has been minimized.
| .find(|node| check_anchor(&node)) | ||
| .map(Root::upcast) | ||
| }) | ||
| // Step 2 |
This comment has been minimized.
This comment has been minimized.
KiChjang
Feb 15, 2016
Member
We really should leave a note here detailing why Step 1 isn't necessary.
This comment has been minimized.
This comment has been minimized.
peterjoel
Feb 15, 2016
Author
Contributor
// Step 1 is not handled here; the fragid is already obtained by the calling function
That ok? I think including the name of the file/function that obtains the fragid isn't a good idea, for maintainability reasons. It would be in danger of going out of date if it the other code changed without affecting this location.
This comment has been minimized.
This comment has been minimized.
| if fragid == "" { | ||
| self.GetDocumentElement() | ||
| } else { | ||
| use url::percent_encoding::percent_decode; |
This comment has been minimized.
This comment has been minimized.
| } | ||
| } | ||
|
|
||
| fn get_anchor_by_name(&self, name: &str ) -> Option<Root<Element>> { |
This comment has been minimized.
This comment has been minimized.
|
@bors-servo r+ Thanks for working on this! |
|
|
|
No need to disable the tests, but we can mark that they are expected to fail so we'll be notified when they start passing in the future :) That being said, I'm not clear on why |
|
@jdm I can't see it in the spec either. However, in 3 browsers that I checked (Firefox, Chrome and Safari), all of them have values that change as you scroll. The value of the rectangle's |
Interactive test for fragid resolution.
Added HTML tests for scrolling to fragid
Applied algorithm from whatwg spec
https://html.spec.whatwg.org/multipage/#the-indicated-part-of-the-document
Changes following code review
|
@bors-servo r+ |
|
|
|
|
Addresses Issue #1716. Indicated part of the document. Fixes #1716. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9632) <!-- Reviewable:end -->
|
|
|
@bors-servo retry |
Addresses Issue #1716. Indicated part of the document. Fixes #1716. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9632) <!-- Reviewable:end -->
|
|
|
@bors-servo retry |
|
|
|
|
peterjoel commentedFeb 14, 2016
Fixes #1716.