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

Normalize behaviour of space vs. return for activating elements #22782

Closed
jdm opened this issue Jan 30, 2019 · 19 comments
Closed

Normalize behaviour of space vs. return for activating elements #22782

jdm opened this issue Jan 30, 2019 · 19 comments

Comments

@jdm
Copy link
Member

@jdm jdm commented Jan 30, 2019

Right now, Document::dispatch_key_event triggers different behaviour for elements if you activate them with spacebar or return. Spacebar performs a synthetic click activation, while Return triggers implicit form submission. This means that pressing Return with an anchor element active does not navigate to the link, and special cases the behaviour for text input elements and buttons. I propose the following:

  • remove the implicit_submission method from the Activatable trait
  • remove the implicit_submission implementation for HTMLButtonElement entirely
  • make the implicit_submission implementation for HTMLInputElement a regular method
  • treat the Space and Return cases the same in dispatch_key_event; remove any reference to implicit submission

This should allow implicit submissions of forms from text inputs to continue working, since there is code in HTMLInputElement::handle_event to recognize the Return key already. Activating buttons with the Return key should also work as expected, since they will receive a synthetic click event.

Code: components/script/dom/activation.rs, components/script/dom/document.rs, components/script/dom/htmlinputelement.rs, components/script/htmlbuttonelement.rs

Some tests that might be relevant:

  • ./mach test-wpt tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/
  • ./mach test-wpt tests/wpt/web-platform-tests/html/semantics/forms/attributes-common-to-form-controls/
  • ./mach test-wpt tests/wpt/web-platform-tests/html/semantics/forms/form-submission-0/
@highfive
Copy link

@highfive highfive commented Jan 30, 2019

Hi! If you have any questions regarding this issue, feel free to make a comment here, or ask it in the #servo channel in IRC.

If you intend to work on this issue, then add @highfive: assign me to your comment, and I'll assign this to you. 😄

@nishanthkarthik
Copy link

@nishanthkarthik nishanthkarthik commented Jan 30, 2019

@highfive assign me

@highfive highfive added the C-assigned label Jan 30, 2019
@highfive
Copy link

@highfive highfive commented Jan 30, 2019

Hey @nishanthkarthik! Thanks for your interest in working on this issue. It's now assigned to you!

@nishanthkarthik
Copy link

@nishanthkarthik nishanthkarthik commented Jan 30, 2019

@jdm This is my first issue on servo. Let me give it a shot!

@jdm
Copy link
Member Author

@jdm jdm commented Feb 13, 2019

@nishanthkarthik Have you made progress?

@nishanthkarthik
Copy link

@nishanthkarthik nishanthkarthik commented Feb 14, 2019

I'm on the test cases. I expect to send a PR by this weekend

@nishanthkarthik
Copy link

@nishanthkarthik nishanthkarthik commented Feb 16, 2019

@jdm I tried dispatchEvent with keydown event this way.

<!doctype html>
<meta charset="utf-8">
<title>Click action on label</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<div id="test"></div>
<a id="anch" href="about:blank">test</a>

<script>
async_test(function(t) {
        document.querySelector("#test").innerHTML = '<iframe src=html-anchor-navigation.html \
            id="foo" name="foo"></iframe>'

        var loaded = false;
        var iframe = document.getElementById('foo');
        iframe.onload = t.step_func(function() {
            if (!loaded) {
                loaded = true;
                var ev = new KeyboardEvent('keydown', { code: "Space" });
                var elem = iframe.contentDocument.getElementById('anc');
                elem.focus();
                elem.dispatchEvent(ev);
            } else {
                t.done();
            }
        });
    }, "space keydown should navigate away");
</script>

When I manually press space, it navigates away. It does not, when it is done through dispatchEvent. I also tried using testdriver.js to send the event, but it doesn't support sending it to a node in an iframe.

@jdm
Copy link
Member Author

@jdm jdm commented Mar 5, 2019

Oh, right. That makes sense, because there is no code in htmlanchorelement.rs to recognize key events and act on them.

That being said, I just tested Firefox and Chrome, and they don't actually invoke links on space, so we should not deviate from their behaviour. However, they do activate a <button> element on space, so we should make sure we still support that.

@jdm
Copy link
Member Author

@jdm jdm commented Mar 5, 2019

I think the right choice may be to add custom handle_event implementations for elements like <button> that should recognize both space and enter: https://searchfox.org/mozilla-central/rev/3e0f1d95fcf8832413457e3bec802113bdd1f8e8/dom/html/HTMLButtonElement.cpp#233-251

That will allow us to write automated tests that verify that property.

@stevenloppe
Copy link

@stevenloppe stevenloppe commented May 22, 2019

@highfive: assign me

@highfive highfive added the C-assigned label May 22, 2019
@highfive
Copy link

@highfive highfive commented May 22, 2019

Hey @stevenloppe! Thanks for your interest in working on this issue. It's now assigned to you!

@dralley
Copy link
Contributor

@dralley dralley commented Jun 24, 2019

@stevenloppe Are you working on this?

@jdm jdm removed the C-assigned label Jul 12, 2019
@jdm
Copy link
Member Author

@jdm jdm commented Jul 12, 2019

Unassigning due to lack of activity.

@Ersikan
Copy link

@Ersikan Ersikan commented Jul 19, 2019

@highfive: assign me

@highfive
Copy link

@highfive highfive commented Jul 19, 2019

Hey @Ersikan! Thanks for your interest in working on this issue. It's now assigned to you!

@highfive highfive added the C-assigned label Jul 19, 2019
@jdm
Copy link
Member Author

@jdm jdm commented Oct 10, 2019

Unassigning due to lack of activity.

@jdm jdm removed the C-assigned label Oct 10, 2019
@garasubo
Copy link
Contributor

@garasubo garasubo commented Oct 11, 2019

@highfive assign me

@highfive highfive added the C-assigned label Oct 11, 2019
@highfive
Copy link

@highfive highfive commented Oct 11, 2019

Hey @garasubo! Thanks for your interest in working on this issue. It's now assigned to you!

garasubo added a commit to garasubo/servo that referenced this issue Oct 12, 2019
TODO: write tests for my change
garasubo added a commit to garasubo/servo that referenced this issue Oct 18, 2019
TODO: write tests for my change
garasubo added a commit to garasubo/servo that referenced this issue Oct 18, 2019
TODO: write tests for my change
garasubo added a commit to garasubo/servo that referenced this issue Oct 18, 2019
TODO: write tests for my change
@garasubo garasubo mentioned this issue Oct 18, 2019
2 of 5 tasks complete
bors-servo added a commit that referenced this issue Oct 18, 2019
Refactor submission

This is my first contribution, so please correct me if I'm wrong

I refactored the code as described #22782.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #22782  (GitHub issue number if applicable)

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

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
bors-servo added a commit that referenced this issue Oct 22, 2019
Refactor submission

This is my first contribution, so please correct me if I'm wrong

I refactored the code as described #22782.

---
<!-- 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
- [ ] These changes fix #22782  (GitHub issue number if applicable)

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

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
bors-servo added a commit that referenced this issue Oct 22, 2019
Refactor submission

This is my first contribution, so please correct me if I'm wrong

I refactored the code as described #22782.

---
<!-- 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
- [ ] These changes fix #22782  (GitHub issue number if applicable)

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

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
garasubo added a commit to garasubo/servo that referenced this issue Oct 25, 2019
@garasubo garasubo mentioned this issue Oct 25, 2019
2 of 5 tasks complete
@garasubo
Copy link
Contributor

@garasubo garasubo commented Oct 25, 2019

I'm sorry, but I found that one of commits were not included in the previous PR. I resubmit another PR to add this commit #24546. Could you take a look?

garasubo added a commit to garasubo/servo that referenced this issue Oct 25, 2019
bors-servo added a commit that referenced this issue Oct 28, 2019
Re-add missing commit in PR #24489

Fix #22782

I'm sorry, but I failed to add one of commits during the squash phase in #24489.
Could you review and merge this?

---
<!-- 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
- [ ] These changes fix #___ (GitHub issue number if applicable)

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

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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