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

Addresses Issue #1716. Indicated part of the document. #9632

Merged
merged 1 commit into from Feb 17, 2016

Conversation

@peterjoel
Copy link
Contributor

peterjoel commented Feb 14, 2016

Fixes #1716.

Review on Reviewable

@highfive
Copy link

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
Copy link

highfive commented Feb 14, 2016

warning Warning warning

  • This pull request adds a file without the .ini file extension to tests/wpt/metadata. Please consider removing it!
@jdm
Copy link
Member

jdm commented Feb 14, 2016

We can ignore the warning from @highfive due to servo/highfive#59.

@peterjoel
Copy link
Contributor Author

peterjoel commented Feb 14, 2016

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.

@peterjoel peterjoel force-pushed the peterjoel:issue_1716 branch from 56b21c6 to f8c5cce Feb 14, 2016
@peterjoel peterjoel changed the title Issue 1716 Addresses Issue #1716. Indicated part of the document. Feb 14, 2016
@peterjoel
Copy link
Contributor Author

peterjoel commented Feb 14, 2016

.find(|node| check_anchor(&node))
.map(Root::upcast)
})
if fragid == "" {

This comment has been minimized.

@KiChjang

KiChjang Feb 15, 2016

Member

Step annotations here would be nice.

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.

@KiChjang

KiChjang Feb 15, 2016

Member

I think or would suffice here.

This comment has been minimized.

@peterjoel

peterjoel Feb 15, 2016

Author Contributor

@KiChjang I don't follow where you mean it could be used.

This comment has been minimized.

@KiChjang

KiChjang Feb 15, 2016

Member

Instead of or_else, or can be used.

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.

@KiChjang

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.

@KiChjang

KiChjang Feb 15, 2016

Member

On that note, where is step 1 and 2?

This comment has been minimized.

@peterjoel

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.

@KiChjang

KiChjang Feb 15, 2016

Member

In any case, the step annotations still needs to be changed.

// 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.

@KiChjang

KiChjang Feb 15, 2016

Member

or_else can be changed into or.

This comment has been minimized.

@peterjoel

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.

@KiChjang

KiChjang Feb 15, 2016

Member

Hmm, true, never thought about it in the aspect of eager vs lazy evaluation!

@peterjoel peterjoel force-pushed the peterjoel:issue_1716 branch from f3b6e3a to 11debf2 Feb 15, 2016
let doc_node = self.upcast::<Node>();
doc_node.traverse_preorder()
.filter_map(Root::downcast)
.find(|node| check_anchor(&node))

This comment has been minimized.

@KiChjang

KiChjang Feb 15, 2016

Member

Would .find(check_anchor) work here?

This comment has been minimized.

@peterjoel

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.

@KiChjang

KiChjang Feb 15, 2016

Member

nit: This could be fn check_anchor(node: &HTMLAnchorElement) instead.

This comment has been minimized.

@peterjoel

peterjoel Feb 15, 2016

Author Contributor

Needs to be a closure, or else it can't access name.

.map(Root::upcast)
})
// Step 2
if fragid == "" {

This comment has been minimized.

@KiChjang

KiChjang Feb 15, 2016

Member

if fragid.is_empty() {

.find(|node| check_anchor(&node))
.map(Root::upcast)
})
// Step 2

This comment has been minimized.

@KiChjang

KiChjang Feb 15, 2016

Member

We really should leave a note here detailing why Step 1 isn't necessary.

This comment has been minimized.

@peterjoel

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.

@KiChjang

KiChjang Feb 15, 2016

Member

Yes, that looks perfect!

if fragid == "" {
self.GetDocumentElement()
} else {
use url::percent_encoding::percent_decode;

This comment has been minimized.

@KiChjang

KiChjang Feb 15, 2016

Member

Move this to the top of the file.

}
}

fn get_anchor_by_name(&self, name: &str ) -> Option<Root<Element>> {

This comment has been minimized.

@KiChjang

KiChjang Feb 15, 2016

Member

nit: extra space after &str

@peterjoel peterjoel force-pushed the peterjoel:issue_1716 branch from bc59a40 to 17b51c5 Feb 15, 2016
@KiChjang
Copy link
Member

KiChjang commented Feb 15, 2016

@bors-servo r+

Thanks for working on this!

@bors-servo
Copy link
Contributor

bors-servo commented Feb 15, 2016

📌 Commit 17b51c5 has been approved by KiChjang

@peterjoel
Copy link
Contributor Author

peterjoel commented Feb 15, 2016

Tests are failing because scrollTop is not yet implemented (#9650) and I can't see another obvious way to detect scrolling - for example getClientRects() does not take scroll position into account yet.

@KiChjang Should I disable the test or should this issue be blocked on #9650?

@jdm
Copy link
Member

jdm commented Feb 15, 2016

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 getClientRects or getBoundingClientRect should be affected by the scroll position; I don't see any language in https://drafts.csswg.org/cssom-view/#dom-element-getclientrects that suggests that.

@peterjoel
Copy link
Contributor Author

peterjoel commented Feb 15, 2016

@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 top is (and I'm not sure why 8) 8 - element.scrollTop.

@peterjoel peterjoel force-pushed the peterjoel:issue_1716 branch from 8edcadc to d74b665 Feb 16, 2016
    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
@peterjoel peterjoel force-pushed the peterjoel:issue_1716 branch from db1c42e to e39e59e Feb 17, 2016
@KiChjang
Copy link
Member

KiChjang commented Feb 17, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Feb 17, 2016

📌 Commit e39e59e has been approved by KiChjang

@bors-servo
Copy link
Contributor

bors-servo commented Feb 17, 2016

Testing commit e39e59e with merge 6eb2e8a...

bors-servo added a commit that referenced this pull request Feb 17, 2016
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
Copy link
Contributor

bors-servo commented Feb 17, 2016

💔 Test failed - linux-rel

@KiChjang
Copy link
Member

KiChjang commented Feb 17, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Feb 17, 2016

Testing commit e39e59e with merge 8d63eff...

bors-servo added a commit that referenced this pull request Feb 17, 2016
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
Copy link
Contributor

bors-servo commented Feb 17, 2016

💔 Test failed - linux-rel

@KiChjang
Copy link
Member

KiChjang commented Feb 17, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Feb 17, 2016

Previous build results for android, gonk, linux-dev, mac-dev-unit, mac-rel-css, mac-rel-wpt are reusable. Rebuilding only linux-rel...

@bors-servo
Copy link
Contributor

bors-servo commented Feb 17, 2016

@bors-servo bors-servo merged commit e39e59e into servo:master Feb 17, 2016
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@peterjoel peterjoel deleted the peterjoel:issue_1716 branch Feb 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

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