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

Implement ask_for_reset for HTMLSelectElement. #7963

Merged
merged 11 commits into from Oct 28, 2015
Merged

Conversation

@dagnir
Copy link
Contributor

dagnir commented Oct 10, 2015

Fixes #7774

Review on Reviewable

@highfive
Copy link

highfive commented Oct 10, 2015

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @SimonSapin (or someone else) soon.

@frewsxcv
Copy link
Member

frewsxcv commented Oct 10, 2015

ask_for_reset (the function you just created) should get called here

@dagnir
Copy link
Contributor Author

dagnir commented Oct 10, 2015

Hmmm ask_for_reset calls HTMLOptionElement::SetSeledcted so that will make them mutually recursive. Is this intentional? Or should I be setting HTMLOptionElement::selectedness directly somehow?


Review status: 0 of 1 files reviewed at latest revision, all discussions resolved, some commit checks pending.


Comments from the review on Reviewable.io

@frewsxcv
Copy link
Member

frewsxcv commented Oct 11, 2015

Or should I be setting HTMLOptionElement::selectedness directly somehow?

You could add a set_selectedness method on HTMLOptionElement so that you could set it directly


Comments from the review on Reviewable.io

@frewsxcv
Copy link
Member

frewsxcv commented Oct 11, 2015

components/script/dom/htmloptionelement.rs, line 153 [r4] (raw file):
Instead of doing .find(|a| a.is_htmlselectelement) and then HTMLSelectElementCast::to_root(..).unwrap, use filter_map with HTMLSelectElementCast::to_root

http://doc.servo.org/std/iter/trait.Iterator.html#method.filter_map

Let me know if you need help


Comments from the review on Reviewable.io

@dagnir
Copy link
Contributor Author

dagnir commented Oct 11, 2015

Review status: 0 of 2 files reviewed at latest revision, 1 unresolved discussion, some commit checks pending.


components/script/dom/htmloptionelement.rs, line 153 [r4] (raw file):
Thanks, changed to filter_map.


Comments from the review on Reviewable.io

@frewsxcv
Copy link
Member

frewsxcv commented Oct 11, 2015

components/script/dom/htmlselectelement.rs, line 78 [r5] (raw file):
This could be simplified to is_none and get_enabled_state


Comments from the review on Reviewable.io

@frewsxcv
Copy link
Member

frewsxcv commented Oct 11, 2015

components/script/dom/htmlselectelement.rs, line 72 [r5] (raw file):
Since we implement Deref on Root, you don't need to explicitly call .r(). It's the same reason one can do String::from("hello").len() even though len() is a &str method (String Derefs to &str)


Comments from the review on Reviewable.io

@frewsxcv
Copy link
Member

frewsxcv commented Oct 11, 2015

components/script/dom/htmlselectelement.rs, line 78 [r5] (raw file):
Actually, get_enabled_state might be something different


Comments from the review on Reviewable.io

@dagnir
Copy link
Contributor Author

dagnir commented Oct 12, 2015

Review status: 0 of 2 files reviewed at latest revision, 3 unresolved discussions, some commit checks failed.


components/script/dom/htmlselectelement.rs, line 72 [r5] (raw file):
Removed unneeded calls to r().


components/script/dom/htmlselectelement.rs, line 78 [r5] (raw file):
Simplified check.


Comments from the review on Reviewable.io

@frewsxcv
Copy link
Member

frewsxcv commented Oct 13, 2015

FYI, the latest commit doesn't pass the style checker, one of the lines is too long

https://travis-ci.org/servo/servo/jobs/84851573

@dagnir
Copy link
Contributor Author

dagnir commented Oct 13, 2015

Hi @frewsxcv, is there anything else needed for this PR?

@frewsxcv
Copy link
Member

frewsxcv commented Oct 13, 2015

Have you tried running the web-platform-tests (test-wpt) test suite to see if any tests unexpectedly pass or fail. If you need help doing that, check out this link). If after running the tests, nothing changes, a regression test will need to be written to make sure algorithm this doesn't break in the future. If you need help with any of this or want clarification, please let me know, I'll be happy to help! I'm currently doing IRL non-Servo work at the moment, but when I get home I'll actually read through the spec and make sure your implementation looks correct.

@dagnir
Copy link
Contributor Author

dagnir commented Oct 13, 2015

I'm running test-wpt now. If you would show me how to get started with writing the regression test for this, I'd appreciate it!

Thanks!

@frewsxcv
Copy link
Member

frewsxcv commented Oct 14, 2015

(to anyone who is reading this PR and wondering why we haven't responded, we just chatted 1 on 1 on IRC)

@bors-servo
Copy link
Contributor

bors-servo commented Oct 14, 2015

The latest upstream changes (presumably #7984) made this pull request unmergeable. Please resolve the merge conflicts.

@dagnir dagnir force-pushed the dagnir:issue-7774 branch 2 times, most recently from 369d5cb to e1fbad2 Oct 17, 2015
@dagnir
Copy link
Contributor Author

dagnir commented Oct 17, 2015

@frewsxcv, I've added some tests, please take a look. Only the third one passes at the moment because ask_for_reset doesn't get called on node insert and remove.

@eefriedman
Copy link
Contributor

eefriedman commented Oct 18, 2015

The relevant hooks for node insert and remove are bind_to_tree() and unbind_from_tree().

@dagnir
Copy link
Contributor Author

dagnir commented Oct 18, 2015

Thanks!

@frewsxcv
Copy link
Member

frewsxcv commented Oct 18, 2015

FYI, in case you missed it, there are merge conflicts that will eventually need to be addressed

@dagnir dagnir force-pushed the dagnir:issue-7774 branch 3 times, most recently from 0a1ced2 to 2855e2d Oct 18, 2015
- Whitespace and indentation issues

- call as_for_reset on option insert

- add link to 'pick' in standard
@dagnir
Copy link
Contributor Author

dagnir commented Oct 27, 2015

@eefriedman
Copy link
Contributor

eefriedman commented Oct 27, 2015

Review status: 0 of 5 files reviewed at latest revision, 7 unresolved discussions, some commit checks pending.


components/script/dom/htmlselectelement.rs, line 73 [r14] (raw file):
if let is generally preferred over is_none()+unwrap(); I don't think that review comment was specifically suggesting the opposite.


Comments from the review on Reviewable.io

@dagnir
Copy link
Contributor Author

dagnir commented Oct 27, 2015

Review status: 0 of 5 files reviewed at latest revision, 7 unresolved discussions, some commit checks pending.


components/script/dom/htmlselectelement.rs, line 73 [r14] (raw file):
Hmm is it possible you saw an outdated revision? This is what it currently looks like dagnir@b5e991c


Comments from the review on Reviewable.io

@eefriedman
Copy link
Contributor

eefriedman commented Oct 27, 2015

Review status: 0 of 5 files reviewed at latest revision, 7 unresolved discussions, some commit checks pending.


components/script/dom/htmlselectelement.rs, line 73 [r14] (raw file):
Oh, right, sorry, I somehow got flipped to the wrong revision just now. Still, if let is generally preferred over match.


Comments from the review on Reviewable.io

@frewsxcv
Copy link
Member

frewsxcv commented Oct 27, 2015

components/script/dom/htmlselectelement.rs, line 73 [r14] (raw file):
"Oh, right, sorry, I somehow got flipped to the wrong revision just now. Still, if let is generally preferred over match."

I disagree, I think they're both perfectly valid. match gives you the benefit of erroring when all cases are not covered.


Comments from the review on Reviewable.io

@frewsxcv
Copy link
Member

frewsxcv commented Oct 27, 2015

Thanks for looking at this @eefriedman, I've been busy these past few days and haven't had time to review this.

@eefriedman
Copy link
Contributor

eefriedman commented Oct 27, 2015

I disagree, I think they're both perfectly valid. match gives you the benefit of erroring when all cases are not covered.

You're right. I'll narrow it a bit; "if let" is preferred over "match" for Option<T>.

@dagnir
Copy link
Contributor Author

dagnir commented Oct 27, 2015

@frewsxcv @eefriedman okay to leave, or should I change it?

@eefriedman
Copy link
Contributor

eefriedman commented Oct 28, 2015

Please change it. Also, please refactor the identical code in SetSelected and ask_for_reset.

@dagnir
Copy link
Contributor Author

dagnir commented Oct 28, 2015

@eefriedman I'm not sure what identical code you're referring to; unless you mean the option element traversal in ask_for_reset and pick_option?

@eefriedman
Copy link
Contributor

eefriedman commented Oct 28, 2015

SetSelected:

+        if let Some(select) = self.upcast::<Node>().ancestors()
+                .filter_map(Root::downcast::<HTMLSelectElement>).next() {
+            if selected {
+                select.pick_option(self);
+            }
+            select.ask_for_reset();
+        }

bind_to_tree:

+        if let Some(select) = self.upcast::<Node>().ancestors()
+                .filter_map(Root::downcast::<HTMLSelectElement>)
+                .next() {
+            if self.Selected() {
+                select.pick_option(self);
+            }
+            select.ask_for_reset();
+        }
@eefriedman
Copy link
Contributor

eefriedman commented Oct 28, 2015

Err, oops, I meant SetSelected and bind_to_tree.

- Use if let instead of match for Option

- Refactor common code into pick_if_selected_and_reset
@dagnir
Copy link
Contributor Author

dagnir commented Oct 28, 2015

Thanks, done.


Review status: 0 of 5 files reviewed at latest revision, 7 unresolved discussions, some commit checks pending.


Comments from the review on Reviewable.io

@eefriedman
Copy link
Contributor

eefriedman commented Oct 28, 2015

@bors-servo
Copy link
Contributor

bors-servo commented Oct 28, 2015

📌 Commit 4849033 has been approved by eefriedman

@bors-servo
Copy link
Contributor

bors-servo commented Oct 28, 2015

Testing commit 4849033 with merge 3951c57...

bors-servo added a commit that referenced this pull request Oct 28, 2015
Implement ask_for_reset for HTMLSelectElement.

Fixes #7774

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7963)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Oct 28, 2015

💔 Test failed - mac-rel-css

@frewsxcv
Copy link
Member

frewsxcv commented Oct 28, 2015

@bors-servo
Copy link
Contributor

bors-servo commented Oct 28, 2015

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

@bors-servo
Copy link
Contributor

bors-servo commented Oct 28, 2015

@bors-servo bors-servo merged commit 4849033 into servo:master Oct 28, 2015
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@Ms2ger
Copy link
Contributor

Ms2ger commented Oct 28, 2015

For future reference:

"if let" is preferred over "match" for Option<T>

is not true. It is preferred only for (some) cases where only a single variant has code associated with it.

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

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