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

Fixed issue #11651 (Do not fire a blur event when calling .focus() on… #11665

Merged
merged 2 commits into from Jun 25, 2016

Conversation

@davideGiovannini
Copy link
Contributor

davideGiovannini commented Jun 7, 2016

Added check in HTMLElement.Focus to avoid requesting focus when the element already has it.
Added check in Document.commit_focus_transaction to avoid sending blur and focus events when clicking on an already focused element.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #11651
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

… a focused element)
@highfive
Copy link

highfive commented Jun 7, 2016

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

@highfive
Copy link

highfive commented Jun 7, 2016

Heads up! This PR modifies the following files:

  • @KiChjang: components/script/dom/document.rs, components/script/dom/htmlelement.rs
@highfive
Copy link

highfive commented Jun 7, 2016

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!
@KiChjang
Copy link
Member

KiChjang commented Jun 7, 2016

This PR could use a test.

@davideGiovannini
Copy link
Contributor Author

davideGiovannini commented Jun 7, 2016

I would like to write one, but I need some hints.

@KiChjang
Copy link
Member

KiChjang commented Jun 7, 2016

@paulrouget already has a test case listed in #11651. You'll need to use ./mach create-wpt path/to/test/file to create tests. Refer to https://github.com/servo/servo/blob/master/tests/wpt/README.md for more information.

@paulrouget
Copy link
Contributor

paulrouget commented Jun 9, 2016

@davideGiovannini let me know if you need help to write the test.

@jdm
Copy link
Member

jdm commented Jun 9, 2016

I haven't started reviewing the changes yet, just making note of my own investigations:
http://software.hixie.ch/utilities/js/live-dom-viewer/saved/4259 shows

log: focusing
log: focus
log: focused
log: double focused

in FF, Safari, and Chrome.

@paulrouget
Copy link
Contributor

paulrouget commented Jun 9, 2016

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/4259 shows: […]

With this PR, we get the same output.

I used this:

<!DOCTYPE html>
<input>
<script>
  var w = a => console.log(a);
  var e = document.querySelector('input');
  e.addEventListener("focus", function() { w('focus') });
  e.addEventListener("blur", function() { w('blur') });
  w('focusing');
  e.focus();
  w('focused');
  e.focus();
  w('double focused');
</script>
@jdm
Copy link
Member

jdm commented Jun 9, 2016

-S-awaiting-review +S-needs-code-changes

Previously, paulrouget (Paul Rouget) wrote…

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/4259 shows: […]

With this PR, we get the same output.

I used this:

<!DOCTYPE html>

<input>

<script>

  var w = a => console.log(a);

  var e = document.querySelector('input');

  e.addEventListener("focus", function() { w('focus') });

  e.addEventListener("blur", function() { w('blur') });

  w('focusing');

  e.focus();

  w('focused');

  e.focus();

  w('double focused');

</script>

Reviewed 2 of 2 files at r1.
Review status: all files reviewed at latest revision, 2 unresolved discussions.


components/script/dom/document.rs, line 601 [r1] (raw file):

    /// transaction, or none if no elements requested it.
    pub fn commit_focus_transaction(&self, focus_type: FocusType) {
        if self.focused != self.possibly_focused.get().r() {

Let's invert this conditional and return, to avoid the extra indentation for everything else in the method.


components/script/dom/htmlelement.rs, line 254 [r1] (raw file):

        // TODO: Mark the element as locked for focus and run the focusing steps.
        // https://html.spec.whatwg.org/multipage/#focusing-steps
        if self.upcast::<Element>().focus_state() {

I don't think this change is still necessary?


Comments from Reviewable

@jdm jdm removed the S-awaiting-review label Jun 9, 2016
@davideGiovannini
Copy link
Contributor Author

davideGiovannini commented Jun 9, 2016

@paulrouget Yes please, I'm not familiar with web platform tests and I'm not finding the documentation too helpful

@paulrouget
Copy link
Contributor

paulrouget commented Jun 9, 2016

@davideGiovannini maybe this will help: https://github.com/servo/servo/blob/master/docs/HACKING_QUICKSTART.md#add-a-new-test

Maybe you should create a test called tests/wpt/mozilla/tests/mozilla/double_focus.html. You might want to look in this directory to see how tests are written. You don't need an async test for this I believe.

@highfive
Copy link

highfive commented Jun 10, 2016

New code was committed to pull request.

…us() on a focused element)
@jdm jdm removed the S-awaiting-review label Jun 10, 2016
@KiChjang
Copy link
Member

KiChjang commented Jun 13, 2016

@davideGiovannini Any progress on adding tests?

@nox
Copy link
Member

nox commented Jun 20, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Jun 20, 2016

Trying commit 01c3640 with merge 94178db...

bors-servo added a commit that referenced this pull request Jun 20, 2016
Fixed issue #11651 (Do not fire a blur event when calling .focus() on…

<!-- Please describe your changes on the following line: -->
Added check in `HTMLElement.Focus` to avoid requesting focus when the element already has it.
Added check in `Document.commit_focus_transaction` to avoid sending `blur` and `focus` events when clicking on an already focused element.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #11651

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

<!-- 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/11665)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jun 20, 2016

@paulrouget
Copy link
Contributor

paulrouget commented Jun 20, 2016

If this lands, I can write the tests in a follow-up issue right away.

@davideGiovannini
Copy link
Contributor Author

davideGiovannini commented Jun 24, 2016

Sorry for the delay.
I tried to write the test, but I encountered some problems and unfortunately I don't think I can resume working on it untill the end of this exam session (mid July).

@KiChjang
Copy link
Member

KiChjang commented Jun 24, 2016

I'm going to land this and track the progress of writing a test in #11854.

@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Jun 24, 2016

📌 Commit 01c3640 has been approved by KiChjang

@highfive highfive assigned KiChjang and unassigned jdm Jun 24, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Jun 24, 2016

Testing commit 01c3640 with merge 908e504...

bors-servo added a commit that referenced this pull request Jun 24, 2016
Fixed issue #11651 (Do not fire a blur event when calling .focus() on…

<!-- Please describe your changes on the following line: -->
Added check in `HTMLElement.Focus` to avoid requesting focus when the element already has it.
Added check in `Document.commit_focus_transaction` to avoid sending `blur` and `focus` events when clicking on an already focused element.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #11651

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

<!-- 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/11665)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jun 24, 2016

💔 Test failed - linux-rel

@KiChjang
Copy link
Member

KiChjang commented Jun 24, 2016

@bors-servo retry

  • #InfraOnFire
@bors-servo
Copy link
Contributor

bors-servo commented Jun 24, 2016

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

@bors-servo
Copy link
Contributor

bors-servo commented Jun 24, 2016

💔 Test failed - linux-rel

@KiChjang
Copy link
Member

KiChjang commented Jun 24, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Jun 24, 2016

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

@bors-servo
Copy link
Contributor

bors-servo commented Jun 24, 2016

💔 Test failed - linux-rel

@cbrewster
Copy link
Member

cbrewster commented Jun 25, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Jun 25, 2016

Testing commit 01c3640 with merge 7d978e7...

bors-servo added a commit that referenced this pull request Jun 25, 2016
Fixed issue #11651 (Do not fire a blur event when calling .focus() on…

<!-- Please describe your changes on the following line: -->
Added check in `HTMLElement.Focus` to avoid requesting focus when the element already has it.
Added check in `Document.commit_focus_transaction` to avoid sending `blur` and `focus` events when clicking on an already focused element.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #11651

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

<!-- 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/11665)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jun 25, 2016

@bors-servo bors-servo merged commit 01c3640 into servo:master Jun 25, 2016
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
paulrouget added a commit to paulrouget/servo that referenced this pull request Jun 25, 2016
@paulrouget paulrouget mentioned this pull request Jun 25, 2016
4 of 5 tasks complete
bors-servo added a commit that referenced this pull request Jun 25, 2016
Test for double focus events (covers #11665)

<!-- Please describe your changes on the following line: -->

---
<!-- 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 #11854 (github issue number if applicable).

<!-- Either: -->
- [x] 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/11865)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Jun 25, 2016
Test for double focus events (covers #11665)

<!-- Please describe your changes on the following line: -->

---
<!-- 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 #11854 (github issue number if applicable).

<!-- Either: -->
- [x] 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/11865)
<!-- Reviewable:end -->
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.

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