[WK2] autocorrect and autocapitalize attributes do not work in contenteditable elements
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 12 Nov 2016 00:20:00 +0000 (00:20 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 12 Nov 2016 00:20:00 +0000 (00:20 +0000)
commitf2d60d1f3256b04c1b1912c726a5dcbc2d06945c
tree3f905928c69a86f05cf76e542ffb5a6fd024d10b
parenta800d3f8763ab8bc6e0ab8617236ce760a5918e3
[WK2] autocorrect and autocapitalize attributes do not work in contenteditable elements
https://bugs.webkit.org/show_bug.cgi?id=164538
<rdar://problem/8418711>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Adds autocorrect and autocapitalize getters and setters to HTMLElements. These check the `autocorrect` and
`autocapitalize` attributes and return whether or not the element supports autocorrect, and the
autocapitalization type, respectively. By default, autocorrection is enabled and autocapitalization is enabled
on the sentence level for elements. Also refactors/renames WebAutocapitalizeType so that in WebCore, we deal
solely with AutocapitalizeTypes and WebKit1 converts from AutocapitalizeType to WebAutocapitalizeType as needed
for UIKit.

Tests: fast/events/ios/contenteditable-autocapitalize.html
       fast/events/ios/contenteditable-autocorrect.html

* WebCore.xcodeproj/project.pbxproj:
* html/Autocapitalize.cpp:
(WebCore::autocapitalizeTypeForAttributeValue):
(WebCore::stringForAutocapitalizeType):
* html/Autocapitalize.h:
* html/AutocapitalizeTypes.h: Renamed from Source/WebCore/html/WebAutocapitalize.h.

Move WebAutocapitalizeType into AutocapitalizeTypes.h as simply AutocapitalizeType.

* html/HTMLElement.cpp:
(WebCore::HTMLElement::autocapitalize):
(WebCore::HTMLElement::autocapitalizeType):
(WebCore::HTMLElement::setAutocapitalize):
(WebCore::HTMLElement::shouldAutocorrect):
(WebCore::HTMLElement::setAutocorrect):
* html/HTMLElement.h:
(WebCore::HTMLElement::autocorrect):
* html/HTMLElement.idl:
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::shouldAutocorrect):
(WebCore::HTMLFormControlElement::autocapitalizeType):
(WebCore::HTMLFormControlElement::autocorrect): Deleted.
(WebCore::HTMLFormControlElement::setAutocorrect): Deleted.
(WebCore::HTMLFormControlElement::autocapitalize): Deleted.
(WebCore::HTMLFormControlElement::setAutocapitalize): Deleted.

Fold autocorrect/autocapitalize member functions into HTMLElement and remove element-specific code in
HTML(FormControl|Form)Element.cpp.

* html/HTMLFormControlElement.h:
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::shouldAutocorrect):
(WebCore::HTMLFormElement::autocorrect): Deleted.
(WebCore::HTMLFormElement::setAutocorrect): Deleted.
(WebCore::HTMLFormElement::autocapitalizeType): Deleted.
(WebCore::HTMLFormElement::autocapitalize): Deleted.
(WebCore::HTMLFormElement::setAutocapitalize): Deleted.
* html/HTMLFormElement.h:
* html/HTMLFormElement.idl:
* html/HTMLInputElement.idl:
* html/HTMLTextAreaElement.idl:

Source/WebKit:

Introduce WebAutocapitalizeTypes.h to WebKit.

* WebKit.xcodeproj/project.pbxproj:

Source/WebKit/mac:

Account for renaming HTMLElement::autocorrect to HTMLElement::shouldAutocorrect, as well as moving
WebAutocapitalizeType to WebKit from WebCore. Additionally, moves the -autocorrect and -autocapitalize SPIs out
of HTML(Input|Form|TextArea)ElementPrivate.h and into HTMLElementPrivate.h. This also means removing redundant
code for interfacing with the unwrapped HTMLElement's autocorrect and autocapitalize attributes.

* DOM/DOMHTML.mm:
(webAutocapitalizeType):
(-[DOMHTMLInputElement _autocapitalizeType]):
(-[DOMHTMLTextAreaElement _autocapitalizeType]):
* DOM/DOMHTMLElement.mm:
(-[DOMHTMLElement autocorrect]):
(-[DOMHTMLElement setAutocorrect:]):
(-[DOMHTMLElement autocapitalize]):
(-[DOMHTMLElement setAutocapitalize:]):
* DOM/DOMHTMLElementPrivate.h: Copied from Source/WebCore/html/Autocapitalize.h.
* DOM/DOMHTMLFormElement.mm:
(-[DOMHTMLFormElement autocorrect]): Deleted.
(-[DOMHTMLFormElement setAutocorrect:]): Deleted.
(-[DOMHTMLFormElement autocapitalize]): Deleted.
(-[DOMHTMLFormElement setAutocapitalize:]): Deleted.
* DOM/DOMHTMLInputElement.mm:
(-[DOMHTMLInputElement autocorrect]): Deleted.
(-[DOMHTMLInputElement setAutocorrect:]): Deleted.
(-[DOMHTMLInputElement autocapitalize]): Deleted.
(-[DOMHTMLInputElement setAutocapitalize:]): Deleted.
* DOM/DOMHTMLInputElementPrivate.h:
* DOM/DOMHTMLTextAreaElement.mm:
(-[DOMHTMLTextAreaElement autocorrect]): Deleted.
(-[DOMHTMLTextAreaElement setAutocorrect:]): Deleted.
(-[DOMHTMLTextAreaElement autocapitalize]): Deleted.
(-[DOMHTMLTextAreaElement setAutocapitalize:]): Deleted.
* DOM/DOMHTMLTextAreaElementPrivate.h:

We need to import DOMHTMLElementPrivate.h here to avoid breaking UIKit. We should follow this up with a UIKit
change to import DOMHTMLElementPrivate.h directly.

* DOM/DOMPrivate.h:
* DOM/WebAutocapitalizeTypes.h: Copied from Tools/WebKitTestRunner/ios/UIKitSPI.h.
* MigrateHeaders.make:

Source/WebKit2:

Consult HTMLElement::autocorrect() and HTMLElement::autocapitalizeType() when assembling the assisted node
information for the currently assisted node.

* Shared/AssistedNodeInformation.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(toUITextAutocapitalize):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::getAssistedNodeInformation):

Tools:

Adds support for being able to test autocorrect and autocapitalize attributes in contenteditable areas. To do
this, we add removeAllDynamicDictionaries to UIScriptController in order to ensure that autocorrect suggestions
are reset to their defaults prior to running contenteditable-autocorrect-off.html.

* DumpRenderTree/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::removeAllDynamicDictionaries):
* Scripts/webkitpy/port/ios.py:
(IOSSimulatorPort._createSimulatorApp):
* TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
* TestRunnerShared/UIScriptContext/UIScriptController.cpp:
(WTR::UIScriptController::removeAllDynamicDictionaries):
* TestRunnerShared/UIScriptContext/UIScriptController.h:
* WebKitTestRunner/cocoa/TestRunnerWKWebView.mm:
(-[TestRunnerWKWebView _keyboardDidShow:]):
(-[TestRunnerWKWebView _keyboardDidHide:]):

Work around an issue where consecutive UIKeyboardDidShowNotification would cause keyboard appearance callbacks
to be fired multiple times. This was causing a single key press to cause two characters to be typed. While this
does not affect the correctness of existing tests, the new autocorrection test requires this workaround.

* WebKitTestRunner/ios/UIKitSPI.h:
* WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::waitForTextPredictionsViewAndSelectCandidateAtIndex):
(WTR::UIScriptController::removeAllDynamicDictionaries):

LayoutTests:

Adds new layout tests verifying that `autocorrect` and `autocapitalize` attributes can be used to opt out of
autocapitalization and autocorrection in a contenteditable area in WK2. Additionally, tests that autocorrection
and autocapitalization attributes may be changed by setting `element.autocorrect` and `element.autocapitalize`,
respectively.

* fast/events/ios/contenteditable-autocapitalize-none-expected.txt: Added.
* fast/events/ios/contenteditable-autocapitalize-none.html: Added.
* fast/events/ios/contenteditable-autocorrect-off-expected.txt: Added.
* fast/events/ios/contenteditable-autocorrect-off.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208624 268f45cc-cd09-0410-ab3c-d52691b4dbfc
46 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/events/ios/contenteditable-autocapitalize-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/ios/contenteditable-autocapitalize.html [new file with mode: 0644]
LayoutTests/fast/events/ios/contenteditable-autocorrect-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/ios/contenteditable-autocorrect.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/html/Autocapitalize.cpp
Source/WebCore/html/Autocapitalize.h
Source/WebCore/html/AutocapitalizeTypes.h [moved from Source/WebCore/html/WebAutocapitalize.h with 82% similarity]
Source/WebCore/html/HTMLElement.cpp
Source/WebCore/html/HTMLElement.h
Source/WebCore/html/HTMLElement.idl
Source/WebCore/html/HTMLFormControlElement.cpp
Source/WebCore/html/HTMLFormControlElement.h
Source/WebCore/html/HTMLFormElement.cpp
Source/WebCore/html/HTMLFormElement.h
Source/WebCore/html/HTMLFormElement.idl
Source/WebCore/html/HTMLInputElement.idl
Source/WebCore/html/HTMLTextAreaElement.idl
Source/WebKit/ChangeLog
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/DOM/DOMHTML.mm
Source/WebKit/mac/DOM/DOMHTMLElement.mm
Source/WebKit/mac/DOM/DOMHTMLElementPrivate.h [new file with mode: 0644]
Source/WebKit/mac/DOM/DOMHTMLFormElement.mm
Source/WebKit/mac/DOM/DOMHTMLInputElement.mm
Source/WebKit/mac/DOM/DOMHTMLInputElementPrivate.h
Source/WebKit/mac/DOM/DOMHTMLTextAreaElement.mm
Source/WebKit/mac/DOM/DOMHTMLTextAreaElementPrivate.h
Source/WebKit/mac/DOM/DOMPrivate.h
Source/WebKit/mac/DOM/WebAutocapitalizeTypes.h [new file with mode: 0644]
Source/WebKit/mac/MigrateHeaders.make
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/AssistedNodeInformation.h
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm
Tools/ChangeLog
Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm
Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl
Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp
Tools/TestRunnerShared/UIScriptContext/UIScriptController.h
Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.mm
Tools/WebKitTestRunner/ios/UIKitSPI.h
Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm