[iOS] Should not scroll when checkbox, radio, submit, reset, or button is spacebar...
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Mar 2019 23:40:08 +0000 (23:40 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Mar 2019 23:40:08 +0000 (23:40 +0000)
commit60a29c8348f955a2135612ac404c37cee56b5581
tree984034243ce99022adad5158e2be733943267386
parent4b731ca6200bd1051d38feb5458ab4cffac27f98
[iOS] Should not scroll when checkbox, radio, submit, reset, or button is spacebar activated
https://bugs.webkit.org/show_bug.cgi?id=195281
<rdar://problem/48564347>

Reviewed by Simon Fraser.

Source/WebCore:

Do not call the base class's default event handler (HTMLTextFormControlElement::defaultEventHandler())
when WebCore sees a keydown of the spacebar as we consider such an event as handled.
Otherwise, calling the base class's default event handler ultimately gives the embedding
client a chance to wrongly handle the event. In the case of iOS, keydown of the spacebar
causes the page to scroll.

WebCore implements spacebar activation on keydown for form controls. For IE compatibility
WebCore does not mark such keydown events as handled so that a DOM keypress event will
be subsequently dispatched. The current logic only skips calling the base class's default
event handler if the DOM event was not marked handled. This is insufficient. We need to
know whether WebCore handled the event. If asking the input type to handle the key down
marks the DOM event as handled then, clearly, WebCore handled the event. However, if the
event is not marked as handled, but WebCore actually accounted for this event then we need
to know this so that we do not call the base class's default event handler and ultimately
the embedding client asking for an interpretation of the key event. Towards this, have
InputType::handleKeydownEvent() return a bit whether or not the base class's default
event handler should be invoked.

Tests: fast/events/ios/activating-button-should-not-scroll-page.html
       fast/events/ios/activating-checkbox-should-not-scroll-page.html
       fast/events/ios/activating-radio-button-should-not-scroll-page.html
       fast/events/ios/activating-reset-button-should-not-scroll-page.html
       fast/events/ios/activating-submit-button-should-not-scroll-page.html

* html/BaseCheckableInputType.cpp:
(WebCore::BaseCheckableInputType::handleKeydownEvent): Return ShouldCallBaseEventHandler::No
if WebCore handled the spacebar activation. Otherewise, return ShouldCallBaseEventHandler::Yes.
* html/BaseCheckableInputType.h:
* html/BaseChooserOnlyDateAndTimeInputType.cpp:
(WebCore::BaseChooserOnlyDateAndTimeInputType::handleKeydownEvent): Ditto.
* html/BaseChooserOnlyDateAndTimeInputType.h:
* html/BaseClickableWithKeyInputType.cpp:
(WebCore::BaseClickableWithKeyInputType::handleKeydownEvent): Keep our current behavior by returning ShouldCallBaseEventHandler::Yes.
* html/BaseClickableWithKeyInputType.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::defaultEventHandler): Do not fallthrough and call the base class's default
event handler if the input type told us it handled the event regardless of whether the event was handled
from the perspective of the DOM.
* html/InputType.cpp:
(WebCore::InputType::handleKeydownEvent): Keep our current behavior by returning ShouldCallBaseEventHandler::Yes.
* html/InputType.h:

* html/NumberInputType.cpp:
(WebCore::NumberInputType::handleKeydownEvent):
* html/NumberInputType.h:
* html/RadioInputType.cpp:
(WebCore::RadioInputType::handleKeydownEvent):
* html/RadioInputType.h:
* html/RangeInputType.cpp:
(WebCore::RangeInputType::handleKeydownEvent):
* html/RangeInputType.h:
* html/SearchInputType.cpp:
(WebCore::SearchInputType::handleKeydownEvent):
* html/SearchInputType.h:
* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::handleKeydownEvent):
* html/TextFieldInputType.h:
Keep our current behavior by returning ShouldCallBaseEventHandler::Yes.

LayoutTests:

Add some tests to ensure that we do not scroll when a checkbox, radio, submit, reset, or button
is spacebar activated.

* fast/events/ios/activating-button-should-not-scroll-page-expected.txt: Added.
* fast/events/ios/activating-button-should-not-scroll-page.html: Added.
* fast/events/ios/activating-checkbox-should-not-scroll-page-expected.txt: Added.
* fast/events/ios/activating-checkbox-should-not-scroll-page.html: Added.
* fast/events/ios/activating-radio-button-should-not-scroll-page-expected.txt: Added.
* fast/events/ios/activating-radio-button-should-not-scroll-page.html: Added.
* fast/events/ios/activating-reset-button-should-not-scroll-page-expected.txt: Added.
* fast/events/ios/activating-reset-button-should-not-scroll-page.html: Added.
* fast/events/ios/activating-submit-button-should-not-scroll-page-expected.txt: Added.
* fast/events/ios/activating-submit-button-should-not-scroll-page.html: Added.
* fast/events/ios/resources/press-spacebar-at-element-and-check-for-page-scroll.js: Added.
(done):
(handleInteraction.checkForScrollAndDone):
(handleInteraction):
(handleScroll):
(handleFocus):
(checkActivatingElementUsingSpacebarDoesNotScrollPage):
* platform/ios/TestExpectations: Skip the tests for now until ENABLE(FULL_KEYBOARD_ACCESS) is enabled
by default on iOS.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242518 268f45cc-cd09-0410-ab3c-d52691b4dbfc
33 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/events/ios/activating-button-should-not-scroll-page-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/ios/activating-button-should-not-scroll-page.html [new file with mode: 0644]
LayoutTests/fast/events/ios/activating-checkbox-should-not-scroll-page-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/ios/activating-checkbox-should-not-scroll-page.html [new file with mode: 0644]
LayoutTests/fast/events/ios/activating-radio-button-should-not-scroll-page-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/ios/activating-radio-button-should-not-scroll-page.html [new file with mode: 0644]
LayoutTests/fast/events/ios/activating-reset-button-should-not-scroll-page-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/ios/activating-reset-button-should-not-scroll-page.html [new file with mode: 0644]
LayoutTests/fast/events/ios/activating-submit-button-should-not-scroll-page-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/ios/activating-submit-button-should-not-scroll-page.html [new file with mode: 0644]
LayoutTests/fast/events/ios/resources/press-spacebar-at-element-and-check-for-page-scroll.js [new file with mode: 0644]
LayoutTests/platform/ios/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/html/BaseCheckableInputType.cpp
Source/WebCore/html/BaseCheckableInputType.h
Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.cpp
Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.h
Source/WebCore/html/BaseClickableWithKeyInputType.cpp
Source/WebCore/html/BaseClickableWithKeyInputType.h
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/InputType.cpp
Source/WebCore/html/InputType.h
Source/WebCore/html/NumberInputType.cpp
Source/WebCore/html/NumberInputType.h
Source/WebCore/html/RadioInputType.cpp
Source/WebCore/html/RadioInputType.h
Source/WebCore/html/RangeInputType.cpp
Source/WebCore/html/RangeInputType.h
Source/WebCore/html/SearchInputType.cpp
Source/WebCore/html/SearchInputType.h
Source/WebCore/html/TextFieldInputType.cpp
Source/WebCore/html/TextFieldInputType.h