[Cocoa] First pass at implementing alternative presentation button element
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Nov 2017 18:31:31 +0000 (18:31 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Nov 2017 18:31:31 +0000 (18:31 +0000)
commit1171cc981a5f994607b09b46262d97dff8521f76
tree2faa00f4a57f5cfd7daf47560d2d6de7aa5fb455
parent07da79b41422415078b1b452555dc86a9f877f82
[Cocoa] First pass at implementing alternative presentation button element
https://bugs.webkit.org/show_bug.cgi?id=179785
Part of <rdar://problem/34917108>

Reviewed by Brent Fulgham.

Source/WebCore:

Implement support for substituting a button for one or more elements in a page.
This is a first pass. We will refine the logic and the API/SPI in subsequent
commits.

Tests: accessibility/alternative-presentation-button-input-type.html
       accessibility/alternative-presentation-button.html
       fast/forms/alternative-presentation-button/replace-and-remove.html
       fast/forms/alternative-presentation-button/replacement.html

* English.lproj/Localizable.strings: Add placeholder strings for localization.
* SourcesCocoa.txt: Add some files.
* WebCore.xcodeproj/project.pbxproj: Ditto.
* dom/Element.h:
* editing/Editor.cpp:
(WebCore::Editor::clear): Clear out all substitutions. This is called whenever
we are navigating between pages.
(WebCore::Editor::substituteWithAlternativePresentationButton): Added.
(WebCore::Editor::removeAlternativePresentationButton): Added.
(WebCore::Editor::didInsertAlternativePresentationButtonElement): Added.
(WebCore::Editor::didRemoveAlternativePresentationButtonElement): Added.
* editing/Editor.h:
* editing/cocoa/AlternativePresentationButtonSubstitution.cpp: Added.
(WebCore::AlternativePresentationButtonSubstitution::AlternativePresentationButtonSubstitution):
(WebCore::AlternativePresentationButtonSubstitution::initializeSavedDisplayStyles):
(WebCore::AlternativePresentationButtonSubstitution::apply):
(WebCore::AlternativePresentationButtonSubstitution::unapply):
* editing/cocoa/AlternativePresentationButtonSubstitution.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::alternativePresentationButtonElement const): Added.
(WebCore::HTMLInputElement::setTypeWithoutUpdatingAttribute): Added.
(WebCore::HTMLInputElement::createInputType): Extracted the logic to create the InputType from
HTMLInputElement::updateType() to here and added logic to create the input type for the
alternative presentation button. This input type is not web exposed.
(WebCore::HTMLInputElement::updateType): Modified to take the name of the InputType object to
create as an argument and pass it through to HTMLInputElement::createInputType() to actually
create it. Reordered the logic for destroying the shadow tree of the old InputType, deallocating
the old InputType, and assigning the new InputType such that we assign the new InputType,
destroy the shadow tree of the old InputType, and deallocate the old InputType. This ordering
allows AlternativePresentationButtonSubstitution::substitute() to avoid restoring the input
type saved before the substitution when the input type is changed by the page as opposed to
by SPI.
(WebCore::HTMLInputElement::parseAttribute): Pass the parsed type.
(WebCore::HTMLInputElement::willAttachRenderers): Ditto.
* html/HTMLInputElement.h: Change visibility of removeShadowRoot() from private to public so
that it can be called from AlternativePresentationButtonSubstitution.
* html/InputType.h:
(WebCore::InputType::alternativePresentationButtonElement const): Added.
* html/InputTypeNames.cpp:
(WebCore::InputTypeNames::alternativePresentationButton): Added.
* html/InputTypeNames.h:
* html/shadow/cocoa/AlternativePresentationButtonElement.cpp: Added.
(WebCore::AlternativePresentationButtonElement::create):
(WebCore::AlternativePresentationButtonElement::AlternativePresentationButtonElement):
(WebCore::AlternativePresentationButtonElement::insertedIntoAncestor):
(WebCore::AlternativePresentationButtonElement::removedFromAncestor):
(WebCore::AlternativePresentationButtonElement::didFinishInsertingNode):
(WebCore::AlternativePresentationButtonElement::defaultEventHandler):
* html/shadow/cocoa/AlternativePresentationButtonElement.h:
* html/shadow/cocoa/AlternativePresentationButtonInputType.cpp: Added.
(WebCore::AlternativePresentationButtonInputType::AlternativePresentationButtonInputType):
(WebCore::AlternativePresentationButtonInputType::formControlType const):
(WebCore::AlternativePresentationButtonInputType::appendFormData const):
(WebCore::AlternativePresentationButtonInputType::supportsValidation const):
(WebCore::AlternativePresentationButtonInputType::isTextButton const):
(WebCore::AlternativePresentationButtonInputType::alternativePresentationButtonElement const):
(WebCore::AlternativePresentationButtonInputType::createShadowSubtree):
(WebCore::AlternativePresentationButtonInputType::destroyShadowSubtree):
* html/shadow/cocoa/AlternativePresentationButtonInputType.h:
* page/ChromeClient.h:
* platform/LocalizedStrings.cpp:
(WebCore::AXAlternativePresentationButtonLabel):
(WebCore::alternativePresentationButtonTitle):
(WebCore::alternativePresentationButtonSubtitle):
* platform/LocalizedStrings.h:
* testing/Internals.cpp:
(WebCore::Internals::substituteWithAlternativePresentationButton): Added.
(WebCore::Internals::removeAlternativePresentationButton): Added.
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

Expose SPI to substitute the alternative presentation button for one or more elements
and remove the alternative presentation button. Add a private delegate callback when
the alternative presentation button is clicked.

* UIProcess/API/APIUIClient.h:
(API::UIClient::didClickAlternativePresentationButton): Added.
* UIProcess/API/C/WKPageUIClient.h:
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/Cocoa/UIDelegate.h:
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::setDelegate): Wired up delegate callback.
(WebKit::UIDelegate::UIClient::didClickAlternativePresentationButton): Added.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::handleAlternativePresentationButtonClick): Added.
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/InjectedBundle/API/APIInjectedBundlePageUIClient.h:
(API::InjectedBundle::PageUIClient::didClickAlternativePresentationButton): Added.
* WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFrame.h:
* WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFrame.mm:
(-[WKWebProcessPlugInFrame substituteElements:withAlternativePresentationButtonWithIdentifier:]): Added.
(-[WKWebProcessPlugInFrame removeAlternativePresentationButton:]): Added.
* WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFramePrivate.h:
* WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp:
(WKBundleSubstituteWithAlternativePresentationButton): Added.
(WKBundleRemoveAlternativePresentationButton): Added.
* WebProcess/InjectedBundle/API/c/WKBundleFramePrivate.h:
* WebProcess/InjectedBundle/API/c/WKBundlePageUIClient.h:
* WebProcess/InjectedBundle/InjectedBundlePageUIClient.cpp:
(WebKit::InjectedBundlePageUIClient::didClickAlternativePresentationButton): Added.
* WebProcess/InjectedBundle/InjectedBundlePageUIClient.h:
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::handleAlternativePresentationButtonClick): Added.
* WebProcess/WebCoreSupport/WebChromeClient.h:

Tools:

Add a test that substitutes the alternative presentation button for an element in
the page and clicks it.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Add test.
* TestWebKitAPI/Tests/WebKitCocoa/ClickAlternativePresentationButton.mm: Added.
(didClickAlternativePresentationButton):
(-[ClickAlternativePresentationButton webProcessPlugIn:didCreateBrowserContextController:]):
* TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
(TEST):
(-[AlternativePresentationButtonDelegate _webView:didClickAlternativePresentationButtonWithUserInfo:]):
(-[AlternativePresentationButtonDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):

LayoutTests:

Adds tests to ensure that we can apply and remove the substitution of one or more
elements with the alternative presentation button.

Also added some accessibility tests to ensure that the alternative presentation button
can be seen and hit tested by the accessibility machinery. When the alternative presentation
button is substituted for an <input> it masquerades as a text button and when it is
substituted for an arbitrary HTML element it masquerades as the original element. As a
result the accessibility machinery shows an empty role description in the former case
because it does find the ARIA label for the button and the accessibility element hierarchy
may be incorrect in the latter case. We will fix these issues in a subsequent commit(s).

* TestExpectations: Skip the test on all platforms. We will selectively enable
tests on Cocoa platforms (below).
* accessibility/alternative-presentation-button-expected.txt: Added.
* accessibility/alternative-presentation-button-input-type-expected.txt: Added.
* accessibility/alternative-presentation-button-input-type.html: Added.
* accessibility/alternative-presentation-button.html: Added.
* fast/forms/alternative-presentation-button/replace-and-remove-expected.html: Added.
* fast/forms/alternative-presentation-button/replace-and-remove.html: Added.
* fast/forms/alternative-presentation-button/replacement-expected.txt: Added.
* fast/forms/alternative-presentation-button/replacement.html: Added.
* platform/ios/TestExpectations: Mark tests as PASS so that we run them.
* platform/ios/fast/forms/alternative-presentation-button/replacement-expected.txt: Added.
* platform/mac/TestExpectations: Mark tests as PASS so that we run them.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225223 268f45cc-cd09-0410-ab3c-d52691b4dbfc
61 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/accessibility/alternative-presentation-button-expected.txt [new file with mode: 0644]
LayoutTests/accessibility/alternative-presentation-button-input-type-expected.txt [new file with mode: 0644]
LayoutTests/accessibility/alternative-presentation-button-input-type.html [new file with mode: 0644]
LayoutTests/accessibility/alternative-presentation-button.html [new file with mode: 0644]
LayoutTests/fast/forms/alternative-presentation-button/replace-and-remove-expected.html [new file with mode: 0644]
LayoutTests/fast/forms/alternative-presentation-button/replace-and-remove.html [new file with mode: 0644]
LayoutTests/fast/forms/alternative-presentation-button/replacement-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/alternative-presentation-button/replacement.html [new file with mode: 0644]
LayoutTests/platform/ios/TestExpectations
LayoutTests/platform/ios/fast/forms/alternative-presentation-button/replacement-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/English.lproj/Localizable.strings
Source/WebCore/SourcesCocoa.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/Element.h
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/Editor.h
Source/WebCore/editing/cocoa/AlternativePresentationButtonSubstitution.cpp [new file with mode: 0644]
Source/WebCore/editing/cocoa/AlternativePresentationButtonSubstitution.h [new file with mode: 0644]
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLInputElement.h
Source/WebCore/html/InputType.h
Source/WebCore/html/InputTypeNames.cpp
Source/WebCore/html/InputTypeNames.h
Source/WebCore/html/shadow/cocoa/AlternativePresentationButtonElement.cpp [new file with mode: 0644]
Source/WebCore/html/shadow/cocoa/AlternativePresentationButtonElement.h [new file with mode: 0644]
Source/WebCore/html/shadow/cocoa/AlternativePresentationButtonInputType.cpp [new file with mode: 0644]
Source/WebCore/html/shadow/cocoa/AlternativePresentationButtonInputType.h [new file with mode: 0644]
Source/WebCore/page/ChromeClient.h
Source/WebCore/platform/LocalizedStrings.cpp
Source/WebCore/platform/LocalizedStrings.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/APIUIClient.h
Source/WebKit/UIProcess/API/C/WKPageUIClient.h
Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
Source/WebKit/UIProcess/Cocoa/UIDelegate.h
Source/WebKit/UIProcess/Cocoa/UIDelegate.mm
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebPageProxy.messages.in
Source/WebKit/WebProcess/InjectedBundle/API/APIInjectedBundlePageUIClient.h
Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFrame.h
Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFrame.mm
Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFramePrivate.h
Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp
Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleFramePrivate.h
Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePageUIClient.h
Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageUIClient.cpp
Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageUIClient.h
Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/ClickAlternativePresentationButton.mm [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm