AX: Speak Selection does not work in an iframe
authorn_wang@apple.com <n_wang@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Jan 2017 20:44:38 +0000 (20:44 +0000)
committern_wang@apple.com <n_wang@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Jan 2017 20:44:38 +0000 (20:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=166794
<rdar://problem/29913013>

Reviewed by Chris Fleizach.

Source/WebKit2:

Making sure WebPage::getSelectionOrContentsAsString() is getting the
selection content in the right frame.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _accessibilityRetrieveSpeakSelectionContent]):
(-[WKWebView _accessibilityDidGetSpeakSelectionContent:]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView accessibilityRetrieveSpeakSelectionContent]):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::getSelectionOrContentsAsString):

Tools:

* DumpRenderTree/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::retrieveSpeakSelectionContent):
(WTR::UIScriptController::accessibilitySpeakSelectionContent):
* TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
* TestRunnerShared/UIScriptContext/UIScriptController.cpp:
(WTR::UIScriptController::retrieveSpeakSelectionContent):
(WTR::UIScriptController::accessibilitySpeakSelectionContent):
* TestRunnerShared/UIScriptContext/UIScriptController.h:
* WebKitTestRunner/cocoa/TestRunnerWKWebView.h:
* WebKitTestRunner/cocoa/TestRunnerWKWebView.mm:
(-[TestRunnerWKWebView dealloc]):
(-[TestRunnerWKWebView _accessibilityDidGetSpeakSelectionContent:]):
(-[TestRunnerWKWebView accessibilityRetrieveSpeakSelectionContentWithCompletionHandler:]):
* WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::retrieveSpeakSelectionContent):
(WTR::UIScriptController::accessibilitySpeakSelectionContent):

LayoutTests:

* accessibility/ios-simulator/speak-selection-content-expected.txt: Added.
* accessibility/ios-simulator/speak-selection-content.html: Added.
* platform/ios-simulator-wk1/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@211095 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
LayoutTests/ChangeLog
LayoutTests/accessibility/ios-simulator/speak-selection-content-expected.txt [new file with mode: 0644]
LayoutTests/accessibility/ios-simulator/speak-selection-content.html [new file with mode: 0644]
LayoutTests/platform/ios-simulator-wk1/TestExpectations
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
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.h
Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.mm
Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

index 2eaa11f..757c35f 100644 (file)
@@ -1,3 +1,15 @@
+2017-01-24  Nan Wang  <n_wang@apple.com>
+
+        AX: Speak Selection does not work in an iframe
+        https://bugs.webkit.org/show_bug.cgi?id=166794
+        <rdar://problem/29913013>
+
+        Reviewed by Chris Fleizach.
+
+        * accessibility/ios-simulator/speak-selection-content-expected.txt: Added.
+        * accessibility/ios-simulator/speak-selection-content.html: Added.
+        * platform/ios-simulator-wk1/TestExpectations:
+
 2017-01-24  Ryan Haddad  <ryanhaddad@apple.com>
 
         modern-media-controls LayoutTest gardening.
diff --git a/LayoutTests/accessibility/ios-simulator/speak-selection-content-expected.txt b/LayoutTests/accessibility/ios-simulator/speak-selection-content-expected.txt
new file mode 100644 (file)
index 0000000..aa2da7c
--- /dev/null
@@ -0,0 +1,15 @@
+This test has to run in iOS WebKitTestRunner.
+
+This tests that accessibility speak selection content is correct.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Content: Text outside iframe
+Content: Text inside iframe
+Content: text3
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/accessibility/ios-simulator/speak-selection-content.html b/LayoutTests/accessibility/ios-simulator/speak-selection-content.html
new file mode 100644 (file)
index 0000000..9fc74c1
--- /dev/null
@@ -0,0 +1,84 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../../editing/editing.js" language="JavaScript" type="text/JavaScript" ></script>
+<script id="ui-script" type="text/plain">
+    (function() {
+        uiController.retrieveSpeakSelectionContent(function() {
+            uiController.uiScriptComplete(uiController.accessibilitySpeakSelectionContent);
+        });
+    })();
+</script>
+</head>
+
+<body onload="runTest();">
+<p id="result">This test has to run in iOS WebKitTestRunner.</p>
+
+<input type="text" id="myText" value="Text outside iframe">
+<iframe id="frame" srcdoc="<html><body><input id='myText2' type='text' value='Text inside iframe'><span tabindex=0 id='myText3'>text3</span></body></html>"></iframe>
+
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+    description("This tests that accessibility speak selection content is correct.");
+
+    if (window.testRunner)
+        window.jsTestIsAsync = true;
+
+    function runTest() {
+        var input1 = document.getElementById("myText");
+        selectInputContent(input1);
+        if (testRunner.runUIScript) {
+            var uiScript = document.getElementById('ui-script').text;
+            testRunner.runUIScript(uiScript, function(result) {
+                debug("Content: " + result);
+                testInsideFrame(document.getElementById('frame').contentWindow.document);
+            });
+        }
+    }
+    
+    function testInsideFrame(iframeDocument) {
+        var input2 = iframeDocument.getElementById("myText2");
+        selectInputContent(input2);
+        if (testRunner.runUIScript) {
+            var uiScript = document.getElementById('ui-script').text;
+            testRunner.runUIScript(uiScript, function(result) {
+                debug("Content: " + result);
+                testNonInputInsideFrame(iframeDocument);
+            });
+        }
+    }
+    
+    function testNonInputInsideFrame(iframeDocument) {
+        var text3 =  iframeDocument.getElementById("myText3");
+        var text3Obj = accessibilityController.accessibleElementById("myText3");
+        selectElementContent(text3, text3Obj, 5);
+        if (testRunner.runUIScript) {
+            var uiScript = document.getElementById('ui-script').text;
+            testRunner.runUIScript(uiScript, function(result) {
+                debug("Content: " + result);
+                finishJSTest();
+            });
+        }
+    }
+    
+    function selectInputContent(input) {
+        input.focus();
+        input.selectionStart = 0;
+        input.selectionEnd = 100;
+    }
+    
+    function selectElementContent(element, elementObj, length) {
+        element.focus();
+        setSelectionCommand(element, 0, element, 0);
+        for (var i = 0; i < length; i++)
+            elementObj.increaseTextSelection;
+    }
+    
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
\ No newline at end of file
index 7c0fb6f..d49de48 100644 (file)
@@ -105,6 +105,9 @@ editing/unsupported-content/table-type-before.html
 # Zooming works differently in iOS DRT
 fast/zooming/uiscript-zooming.html [ Failure ]
 
+# Not supported on WK1
+accessibility/ios-simulator/speak-selection-content.html [ Skip ]
+
 # FIXME: Tests that fail due to lack of textInputController <rdar://problem/5106287>
 editing/inserting/insert-composition-whitespace.html [ Failure ]
 
index d89f633..04f7cb2 100644 (file)
@@ -1,3 +1,24 @@
+2017-01-24  Nan Wang  <n_wang@apple.com>
+
+        AX: Speak Selection does not work in an iframe
+        https://bugs.webkit.org/show_bug.cgi?id=166794
+        <rdar://problem/29913013>
+
+        Reviewed by Chris Fleizach.
+
+        Making sure WebPage::getSelectionOrContentsAsString() is getting the
+        selection content in the right frame. 
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _accessibilityRetrieveSpeakSelectionContent]):
+        (-[WKWebView _accessibilityDidGetSpeakSelectionContent:]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView accessibilityRetrieveSpeakSelectionContent]):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::getSelectionOrContentsAsString):
+
 2017-01-24  Jer Noble  <jer.noble@apple.com>
 
         Make _WKFullscreenDelegate available to users of the WebKit2 C-API.
index 1887228..0acaf4e 100644 (file)
@@ -3464,6 +3464,18 @@ static int32_t activeOrientation(WKWebView *webView)
 {
     return [_contentView _dataDetectionResults];
 }
+
+- (void)_accessibilityRetrieveSpeakSelectionContent
+{
+    [_contentView accessibilityRetrieveSpeakSelectionContent];
+}
+
+// This method is for subclasses to override.
+// Currently it's only in TestRunnerWKWebView.
+- (void)_accessibilityDidGetSpeakSelectionContent:(NSString *)content
+{
+}
+
 #endif
 
 - (void)_didRelaunchProcess
index 68f0569..a57953c 100644 (file)
@@ -181,6 +181,9 @@ typedef NS_ENUM(NSInteger, _WKImmediateActionType) {
 - (id)_snapshotLayerContentsForBackForwardListItem:(WKBackForwardListItem *)item WK_API_AVAILABLE(ios(9_0));
 - (NSArray *)_dataDetectionResults;
 
+- (void)_accessibilityRetrieveSpeakSelectionContent;
+- (void)_accessibilityDidGetSpeakSelectionContent:(NSString *)content;
+
 #else
 @property (readonly) NSColor *_pageExtendedBackgroundColor;
 @property (nonatomic, setter=_setDrawsBackground:) BOOL _drawsBackground;
index b400340..f48d67e 100644 (file)
@@ -231,6 +231,7 @@ struct WKAutoCorrectionData {
 - (void)_setDoubleTapGesturesEnabled:(BOOL)enabled;
 - (NSArray *)_dataDetectionResults;
 - (NSArray<NSValue *> *)_uiTextSelectionRects;
+- (void)accessibilityRetrieveSpeakSelectionContent;
 @end
 
 @interface WKContentView (WKTesting)
index 723a05d..de6e3bb 100644 (file)
@@ -2090,9 +2090,11 @@ static void cancelPotentialTapIfNecessary(WKContentView* contentView)
 - (void)accessibilityRetrieveSpeakSelectionContent
 {
     RetainPtr<WKContentView> view = self;
-    _page->getSelectionOrContentsAsString([view](const String& string, WebKit::CallbackBase::Error error) {
+    RetainPtr<WKWebView> webView = _webView;
+    _page->getSelectionOrContentsAsString([view, webView](const String& string, WebKit::CallbackBase::Error error) {
         if (error != WebKit::CallbackBase::Error::None)
             return;
+        [webView _accessibilityDidGetSpeakSelectionContent:string];
         if ([view respondsToSelector:@selector(accessibilitySpeakSelectionSetContent:)])
             [view accessibilitySpeakSelectionSetContent:string];
     });
index bfe0d27..95e2fd8 100644 (file)
@@ -2832,9 +2832,10 @@ void WebPage::getSelectionAsWebArchiveData(uint64_t callbackID)
 
 void WebPage::getSelectionOrContentsAsString(uint64_t callbackID)
 {
-    String resultString = m_mainFrame->selectionAsString();
+    WebFrame* focusedOrMainFrame = WebFrame::fromCoreFrame(m_page->focusController().focusedOrMainFrame());
+    String resultString = focusedOrMainFrame->selectionAsString();
     if (resultString.isEmpty())
-        resultString = m_mainFrame->contentsAsString();
+        resultString = focusedOrMainFrame->contentsAsString();
     send(Messages::WebPageProxy::StringCallback(resultString, callbackID));
 }
 
index d46a5ed..714b4f8 100644 (file)
@@ -1,3 +1,28 @@
+2017-01-24  Nan Wang  <n_wang@apple.com>
+
+        AX: Speak Selection does not work in an iframe
+        https://bugs.webkit.org/show_bug.cgi?id=166794
+        <rdar://problem/29913013>
+
+        Reviewed by Chris Fleizach.
+
+        * DumpRenderTree/ios/UIScriptControllerIOS.mm:
+        (WTR::UIScriptController::retrieveSpeakSelectionContent):
+        (WTR::UIScriptController::accessibilitySpeakSelectionContent):
+        * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
+        * TestRunnerShared/UIScriptContext/UIScriptController.cpp:
+        (WTR::UIScriptController::retrieveSpeakSelectionContent):
+        (WTR::UIScriptController::accessibilitySpeakSelectionContent):
+        * TestRunnerShared/UIScriptContext/UIScriptController.h:
+        * WebKitTestRunner/cocoa/TestRunnerWKWebView.h:
+        * WebKitTestRunner/cocoa/TestRunnerWKWebView.mm:
+        (-[TestRunnerWKWebView dealloc]):
+        (-[TestRunnerWKWebView _accessibilityDidGetSpeakSelectionContent:]):
+        (-[TestRunnerWKWebView accessibilityRetrieveSpeakSelectionContentWithCompletionHandler:]):
+        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
+        (WTR::UIScriptController::retrieveSpeakSelectionContent):
+        (WTR::UIScriptController::accessibilitySpeakSelectionContent):
+
 2017-01-24  Daniel Bates  <dabates@apple.com>
 
         StringView.split() should use an iterator design pattern instead of allocating a Vector
index 472dde9..803f462 100644 (file)
@@ -289,6 +289,15 @@ JSRetainPtr<JSStringRef> UIScriptController::scrollingTreeAsText() const
     return nullptr;
 }
 
+void UIScriptController::retrieveSpeakSelectionContent(JSValueRef)
+{
+}
+
+JSRetainPtr<JSStringRef> UIScriptController::accessibilitySpeakSelectionContent() const
+{
+    return nullptr;
+}
+
 }
 
 #endif // PLATFORM(IOS)
index 372c475..f100f1e 100644 (file)
@@ -214,4 +214,7 @@ interface UIScriptController {
     readonly attribute DOMString scrollingTreeAsText;
 
     void uiScriptComplete(DOMString result);
+
+    void retrieveSpeakSelectionContent(object callback);
+    readonly attribute DOMString accessibilitySpeakSelectionContent;
 };
index 218c5eb..2088ce4 100644 (file)
@@ -375,6 +375,16 @@ void UIScriptController::platformSetDidHideKeyboardCallback()
 void UIScriptController::platformClearAllCallbacks()
 {
 }
+
+void UIScriptController::retrieveSpeakSelectionContent(JSValueRef)
+{
+}
+
+JSRetainPtr<JSStringRef> UIScriptController::accessibilitySpeakSelectionContent() const
+{
+    return nullptr;
+}
+
 #endif
 
 #if !PLATFORM(MAC)
index 05dc500..dc22836 100644 (file)
@@ -139,6 +139,9 @@ public:
     JSRetainPtr<JSStringRef> scrollingTreeAsText() const;
 
     void uiScriptComplete(JSStringRef result);
+    
+    void retrieveSpeakSelectionContent(JSValueRef callback);
+    JSRetainPtr<JSStringRef> accessibilitySpeakSelectionContent() const;
 
 private:
     UIScriptController(UIScriptContext&);
index 078a652..4b73a74 100644 (file)
 @property (nonatomic, copy) void (^didShowKeyboardCallback)(void);
 @property (nonatomic, copy) void (^didHideKeyboardCallback)(void);
 @property (nonatomic, copy) void (^didEndScrollingCallback)(void);
+@property (nonatomic, copy) NSString *accessibilitySpeakSelectionContent;
 
 - (void)zoomToScale:(double)scale animated:(BOOL)animated completionHandler:(void (^)(void))completionHandler;
+- (void)accessibilityRetrieveSpeakSelectionContentWithCompletionHandler:(void (^)(void))completionHandler;
+
 #endif
 
 @property (nonatomic, retain, setter=_setStableStateOverride:) NSNumber *_stableStateOverride;
index 5d6d308..5bd17af 100644 (file)
@@ -31,6 +31,7 @@
 #import <wtf/RetainPtr.h>
 
 #if PLATFORM(IOS)
+#import <WebKit/WKWebViewPrivate.h>
 @interface WKWebView ()
 
 // FIXME: move these to WKWebView_Private.h
@@ -50,6 +51,7 @@
 
 @property (nonatomic, copy) void (^zoomToScaleCompletionHandler)(void);
 @property (nonatomic, copy) void (^showKeyboardCompletionHandler)(void);
+@property (nonatomic, copy) void (^retrieveSpeakSelectionContentCompletionHandler)(void);
 @property (nonatomic) BOOL isShowingKeyboard;
 
 @end
@@ -91,6 +93,7 @@
 
     self.zoomToScaleCompletionHandler = nil;
     self.showKeyboardCompletionHandler = nil;
+    self.retrieveSpeakSelectionContentCompletionHandler = nil;
 
     [super dealloc];
 }
     [self _updateVisibleContentRects];
 }
 
+- (void)_accessibilityDidGetSpeakSelectionContent:(NSString *)content
+{
+    self.accessibilitySpeakSelectionContent = content;
+    if (self.retrieveSpeakSelectionContentCompletionHandler)
+        self.retrieveSpeakSelectionContentCompletionHandler();
+}
+
+- (void)accessibilityRetrieveSpeakSelectionContentWithCompletionHandler:(void (^)(void))completionHandler
+{
+    self.retrieveSpeakSelectionContentCompletionHandler = completionHandler;
+    [self _accessibilityRetrieveSpeakSelectionContent];
+}
+
 #endif
 
 @end
index 20a1da5..86b4422 100644 (file)
@@ -107,6 +107,25 @@ void UIScriptController::zoomToScale(double scale, JSValueRef callback)
     }];
 }
 
+void UIScriptController::retrieveSpeakSelectionContent(JSValueRef callback)
+{
+    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
+    
+    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
+    
+    [webView accessibilityRetrieveSpeakSelectionContentWithCompletionHandler:^() {
+        if (!m_context)
+            return;
+        m_context->asyncTaskComplete(callbackID);
+    }];
+}
+
+JSRetainPtr<JSStringRef> UIScriptController::accessibilitySpeakSelectionContent() const
+{
+    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
+    return JSStringCreateWithCFString((CFStringRef)webView.accessibilitySpeakSelectionContent);
+}
+
 void UIScriptController::simulateAccessibilitySettingsChangeNotification(JSValueRef callback)
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);