Forward/Back keyboard shortcuts need to flip for RTL
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Jun 2016 17:54:33 +0000 (17:54 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Jun 2016 17:54:33 +0000 (17:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=158823
<rdar://problem/25975359>

Reviewed by Darin Adler.

Source/WebKit2:

Pipe the UserInterfaceLayoutDirection down to the WebContentProcess on initialization
and when it changes, and use it to flip the behavior of command-left and command-right
when in RTL mode.

Tests:
    WebKit2_CommandBackForwardTestWKView.LTR
    WebKit2_CommandBackForwardTestWKView.RTL
    WebKit2_CommandBackForwardTestWKWebView.LTR
    WebKit2_CommandBackForwardTestWKWebView.RTL

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode):
(WebKit::WebPageCreationParameters::decode):
* Shared/WebPageCreationParameters.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _webViewPrintFormatter]):
(-[WKWebView setSemanticContentAttribute:]):
(-[WKWebView _printOperationWithPrintInfo:forFrame:]):
(-[WKWebView setUserInterfaceLayoutDirection:]):
* UIProcess/API/mac/WKView.mm:
(-[WKView setUserInterfaceLayoutDirection:]):
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::windowIsFrontWindowUnderMouse):
(WebKit::toUserInterfaceLayoutDirection):
(WebKit::WebViewImpl::userInterfaceLayoutDirection):
(WebKit::WebViewImpl::setUserInterfaceLayoutDirection):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::creationParameters):
(WebKit::WebPageProxy::userInterfaceLayoutDirection):
(WebKit::WebPageProxy::setUserInterfaceLayoutDirection):
* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::hasHadSelectionChangesFromUserInteraction):
* UIProcess/ios/WKContentView.mm:
(-[WKContentView _commonInitializationWithProcessPool:configuration:]):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::m_userInterfaceLayoutDirection):
(WebKit::WebPage::setResourceCachingDisabled):
(WebKit::WebPage::setUserInterfaceLayoutDirection):
(WebKit::m_shouldDispatchFakeMouseMoveEvents): Deleted.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performNonEditingBehaviorForSelector):

Tools:

Add tests for flipping the behavior of command-left and command-right
under RTL mode.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/CommandBackForward.mm: Added.
(-[CommandBackForwardOffscreenWindow isKeyWindow]):
(-[CommandBackForwardOffscreenWindow isVisible]):
(simulateCommandArrow):
(WebKit2_CommandBackForwardTest::SetUp):
(WebKit2_CommandBackForwardTestWKView::didFinishLoadForFrame):
(WebKit2_CommandBackForwardTestWKView::SetUp):
(WebKit2_CommandBackForwardTestWKView::loadFiles):
(-[CommandBackForwardNavigationDelegate webView:didFinishNavigation:]):
(WebKit2_CommandBackForwardTestWKWebView::SetUp):
(WebKit2_CommandBackForwardTestWKWebView::loadFiles):

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

16 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebPageCreationParameters.cpp
Source/WebKit2/Shared/WebPageCreationParameters.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h
Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/CommandBackForward.mm [new file with mode: 0644]

index 17ff342..5e42749 100644 (file)
@@ -1,3 +1,56 @@
+2016-06-15  Sam Weinig  <sam@webkit.org>
+
+        Forward/Back keyboard shortcuts need to flip for RTL
+        https://bugs.webkit.org/show_bug.cgi?id=158823
+        <rdar://problem/25975359>
+
+        Reviewed by Darin Adler.
+
+        Pipe the UserInterfaceLayoutDirection down to the WebContentProcess on initialization
+        and when it changes, and use it to flip the behavior of command-left and command-right
+        when in RTL mode.
+
+        Tests:
+            WebKit2_CommandBackForwardTestWKView.LTR
+            WebKit2_CommandBackForwardTestWKView.RTL
+            WebKit2_CommandBackForwardTestWKWebView.LTR
+            WebKit2_CommandBackForwardTestWKWebView.RTL
+
+        * Shared/WebPageCreationParameters.cpp:
+        (WebKit::WebPageCreationParameters::encode):
+        (WebKit::WebPageCreationParameters::decode):
+        * Shared/WebPageCreationParameters.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _webViewPrintFormatter]):
+        (-[WKWebView setSemanticContentAttribute:]):
+        (-[WKWebView _printOperationWithPrintInfo:forFrame:]):
+        (-[WKWebView setUserInterfaceLayoutDirection:]):
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView setUserInterfaceLayoutDirection:]):
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::windowIsFrontWindowUnderMouse):
+        (WebKit::toUserInterfaceLayoutDirection):
+        (WebKit::WebViewImpl::userInterfaceLayoutDirection):
+        (WebKit::WebViewImpl::setUserInterfaceLayoutDirection):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::creationParameters):
+        (WebKit::WebPageProxy::userInterfaceLayoutDirection):
+        (WebKit::WebPageProxy::setUserInterfaceLayoutDirection):
+        * UIProcess/WebPageProxy.h:
+        (WebKit::WebPageProxy::hasHadSelectionChangesFromUserInteraction):
+        * UIProcess/ios/WKContentView.mm:
+        (-[WKContentView _commonInitializationWithProcessPool:configuration:]):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::m_userInterfaceLayoutDirection):
+        (WebKit::WebPage::setResourceCachingDisabled):
+        (WebKit::WebPage::setUserInterfaceLayoutDirection):
+        (WebKit::m_shouldDispatchFakeMouseMoveEvents): Deleted.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::performNonEditingBehaviorForSelector):
+
 2016-06-15  Tim Horton  <timothy_horton@apple.com>
 
         Expose _shouldExpandContentToViewHeightForAutoLayout SPI on WKWebView
index 1c091e5..097da02 100644 (file)
@@ -86,6 +86,7 @@ void WebPageCreationParameters::encode(IPC::ArgumentEncoder& encoder) const
 #endif
     encoder << appleMailPaginationQuirkEnabled;
     encoder << shouldScaleViewToFitDocument;
+    encoder.encodeEnum(userInterfaceLayoutDirection);
 }
 
 bool WebPageCreationParameters::decode(IPC::ArgumentDecoder& decoder, WebPageCreationParameters& parameters)
@@ -194,6 +195,9 @@ bool WebPageCreationParameters::decode(IPC::ArgumentDecoder& decoder, WebPageCre
     if (!decoder.decode(parameters.shouldScaleViewToFitDocument))
         return false;
 
+    if (!decoder.decodeEnum(parameters.userInterfaceLayoutDirection))
+        return false;
+
     return true;
 }
 
index 377c336..2f2de5a 100644 (file)
@@ -29,6 +29,7 @@
 #include "DrawingAreaInfo.h"
 #include "LayerTreeContext.h"
 #include "SessionState.h"
+#include "UserInterfaceLayoutDirection.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebPageGroupData.h"
 #include "WebPreferencesStore.h"
@@ -133,6 +134,8 @@ struct WebPageCreationParameters {
 #endif
     bool appleMailPaginationQuirkEnabled;
     bool shouldScaleViewToFitDocument;
+
+    UserInterfaceLayoutDirection userInterfaceLayoutDirection;
 };
 
 } // namespace WebKit
index 163f5b3..21beded 100644 (file)
@@ -4298,6 +4298,27 @@ static inline WebKit::FindOptions toFindOptions(_WKFindOptions wkFindOptions)
     return (_WKWebViewPrintFormatter *)viewPrintFormatter;
 }
 
+static WebKit::UserInterfaceLayoutDirection toUserInterfaceLayoutDirection(UISemanticContentAttribute contentAttribute)
+{
+    auto direction = [UIView userInterfaceLayoutDirectionForSemanticContentAttribute:contentAttribute];
+    switch (direction) {
+    case UIUserInterfaceLayoutDirectionLeftToRight:
+        return WebKit::UserInterfaceLayoutDirection::LTR;
+    case UIUserInterfaceLayoutDirectionRightToLeft:
+        return WebKit::UserInterfaceLayoutDirection::RTL;
+    }
+
+    ASSERT_NOT_REACHED();
+    return WebKit::UserInterfaceLayoutDirection::LTR;
+}
+
+- (void)setSemanticContentAttribute:(UISemanticContentAttribute)contentAttribute
+{
+    [super setSemanticContentAttribute:contentAttribute];
+
+    _page->setUserInterfaceLayoutDirection(toUserInterfaceLayoutDirection(contentAttribute));
+}
+
 #else // #if PLATFORM(IOS)
 
 #pragma mark - OS X-specific methods
@@ -4424,6 +4445,13 @@ static inline WebKit::FindOptions toFindOptions(_WKFindOptions wkFindOptions)
     return nil;
 }
 
+- (void)setUserInterfaceLayoutDirection:(NSUserInterfaceLayoutDirection)userInterfaceLayoutDirection
+{
+    [super setUserInterfaceLayoutDirection:userInterfaceLayoutDirection];
+
+    _impl->setUserInterfaceLayoutDirection(userInterfaceLayoutDirection);
+}
+
 #endif
 
 @end
index f6c783e..65be8fd 100644 (file)
@@ -1435,6 +1435,13 @@ static _WKOverlayScrollbarStyle toAPIScrollbarStyle(WTF::Optional<WebCore::Scrol
     return _data->_impl->automaticallyAdjustsContentInsets();
 }
 
+- (void)setUserInterfaceLayoutDirection:(NSUserInterfaceLayoutDirection)userInterfaceLayoutDirection
+{
+    [super setUserInterfaceLayoutDirection:userInterfaceLayoutDirection];
+
+    _data->_impl->setUserInterfaceLayoutDirection(userInterfaceLayoutDirection);
+}
+
 @end
 
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 && USE(APPLE_INTERNAL_SDK)
index b8aa88f..921caf0 100644 (file)
@@ -29,6 +29,7 @@
 #if PLATFORM(MAC)
 
 #include "PluginComplexTextInputState.h"
+#include "UserInterfaceLayoutDirection.h"
 #include "WKLayoutMode.h"
 #include "WebPageProxy.h"
 #include "_WKOverlayScrollbarStyle.h"
@@ -485,6 +486,9 @@ public:
     void setRequiresUserActionForEditingControlsManager(bool requiresUserActionForEditingControlsManager) { m_requiresUserActionForEditingControlsManager = requiresUserActionForEditingControlsManager; }
     bool requiresUserActionForEditingControlsManager() const { return m_requiresUserActionForEditingControlsManager; }
 
+    UserInterfaceLayoutDirection userInterfaceLayoutDirection();
+    void setUserInterfaceLayoutDirection(NSUserInterfaceLayoutDirection);
+
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 
     void handleAcceptedCandidate(NSTextCheckingResult *acceptedCandidate);
 #if USE(APPLE_INTERNAL_SDK)
index b221d22..7aba03e 100644 (file)
@@ -4029,7 +4029,29 @@ bool WebViewImpl::windowIsFrontWindowUnderMouse(NSEvent *event)
     return m_view.window.windowNumber != eventWindowNumber;
 }
 
-    
+static UserInterfaceLayoutDirection toUserInterfaceLayoutDirection(NSUserInterfaceLayoutDirection direction)
+{
+    switch (direction) {
+    case NSUserInterfaceLayoutDirectionLeftToRight:
+        return UserInterfaceLayoutDirection::LTR;
+    case NSUserInterfaceLayoutDirectionRightToLeft:
+        return UserInterfaceLayoutDirection::RTL;
+    }
+
+    ASSERT_NOT_REACHED();
+    return UserInterfaceLayoutDirection::LTR;
+}
+
+UserInterfaceLayoutDirection WebViewImpl::userInterfaceLayoutDirection()
+{
+    return toUserInterfaceLayoutDirection(m_view.userInterfaceLayoutDirection);
+}
+
+void WebViewImpl::setUserInterfaceLayoutDirection(NSUserInterfaceLayoutDirection direction)
+{
+    m_page->setUserInterfaceLayoutDirection(toUserInterfaceLayoutDirection(direction));
+}
+
 } // namespace WebKit
 
 #endif // PLATFORM(MAC)
index 097cfc5..d43dd16 100644 (file)
@@ -5274,6 +5274,7 @@ WebPageCreationParameters WebPageProxy::creationParameters()
     parameters.appleMailPaginationQuirkEnabled = false;
 #endif
     parameters.shouldScaleViewToFitDocument = m_shouldScaleViewToFitDocument;
+    parameters.userInterfaceLayoutDirection = m_pageClient.userInterfaceLayoutDirection();
 
     return parameters;
 }
@@ -6311,4 +6312,12 @@ UserInterfaceLayoutDirection WebPageProxy::userInterfaceLayoutDirection()
     return m_pageClient.userInterfaceLayoutDirection();
 }
 
+void WebPageProxy::setUserInterfaceLayoutDirection(UserInterfaceLayoutDirection userInterfaceLayoutDirection)
+{
+    if (!isValid())
+        return;
+
+    m_process->send(Messages::WebPage::SetUserInterfaceLayoutDirection(static_cast<uint32_t>(userInterfaceLayoutDirection)), m_pageID);
+}
+
 } // namespace WebKit
index 6436242..6c37c38 100644 (file)
@@ -1112,6 +1112,7 @@ public:
     void setResourceCachingDisabled(bool);
 
     UserInterfaceLayoutDirection userInterfaceLayoutDirection();
+    void setUserInterfaceLayoutDirection(UserInterfaceLayoutDirection);
 
     bool hasHadSelectionChangesFromUserInteraction() const { return m_hasHadSelectionChangesFromUserInteraction; }
 
index e40db31..625287e 100644 (file)
@@ -377,6 +377,7 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
 #endif
     , m_mainFrameProgressCompleted(false)
     , m_shouldDispatchFakeMouseMoveEvents(true)
+    , m_userInterfaceLayoutDirection(parameters.userInterfaceLayoutDirection)
 {
     ASSERT(m_pageID);
 
@@ -5368,4 +5369,9 @@ void WebPage::setResourceCachingDisabled(bool disabled)
     m_page->setResourceCachingDisabled(disabled);
 }
 
+void WebPage::setUserInterfaceLayoutDirection(uint32_t direction)
+{
+    m_userInterfaceLayoutDirection = static_cast<UserInterfaceLayoutDirection>(direction);
+}
+
 } // namespace WebKit
index b1daa12..9dc767d 100644 (file)
@@ -23,8 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef WebPage_h
-#define WebPage_h
+#pragma once
 
 #include "APIInjectedBundleFormClient.h"
 #include "APIInjectedBundlePageContextMenuClient.h"
@@ -48,6 +47,7 @@
 #include "SandboxExtension.h"
 #include "ShareableBitmap.h"
 #include "UserData.h"
+#include "UserInterfaceLayoutDirection.h"
 #include "UserMediaPermissionRequestManager.h"
 #include <WebCore/DictationAlternative.h>
 #include <WebCore/DictionaryPopupInfo.h>
@@ -1199,6 +1199,7 @@ private:
 #endif
 
     void setResourceCachingDisabled(bool);
+    void setUserInterfaceLayoutDirection(uint32_t);
 
     uint64_t m_pageID;
 
@@ -1468,8 +1469,9 @@ private:
 #if USE(OS_STATE)
     std::chrono::system_clock::time_point m_loadCommitTime;
 #endif
+
+    UserInterfaceLayoutDirection m_userInterfaceLayoutDirection { UserInterfaceLayoutDirection::LTR };
 };
 
 } // namespace WebKit
 
-#endif // WebPage_h
index 0117a71..8dc4d0d 100644 (file)
@@ -428,4 +428,6 @@ messages -> WebPage LegacyReceiver {
 #endif
 
     SetResourceCachingDisabled(bool disabled)
+
+    SetUserInterfaceLayoutDirection(uint32_t direction)
 }
index 3793b48..d8f4dff 100644 (file)
@@ -551,13 +551,13 @@ bool WebPage::performNonEditingBehaviorForSelector(const String& selector, Keybo
     else if (selector == "moveWordLeft:")
         didPerformAction = scroll(m_page.get(), ScrollLeft, ScrollByPage);
     else if (selector == "moveToLeftEndOfLine:")
-        didPerformAction = m_page->backForward().goBack();
+        didPerformAction = m_userInterfaceLayoutDirection == UserInterfaceLayoutDirection::LTR ? m_page->backForward().goBack() : m_page->backForward().goForward();
     else if (selector == "moveRight:")
         didPerformAction = scroll(m_page.get(), ScrollRight, ScrollByLine);
     else if (selector == "moveWordRight:")
         didPerformAction = scroll(m_page.get(), ScrollRight, ScrollByPage);
     else if (selector == "moveToRightEndOfLine:")
-        didPerformAction = m_page->backForward().goForward();
+        didPerformAction = m_userInterfaceLayoutDirection == UserInterfaceLayoutDirection::LTR ? m_page->backForward().goForward() : m_page->backForward().goBack();
 
     return didPerformAction;
 }
index 0ef0e5d..df3676a 100644 (file)
@@ -1,3 +1,27 @@
+2016-06-15  Sam Weinig  <sam@webkit.org>
+
+        Forward/Back keyboard shortcuts need to flip for RTL
+        https://bugs.webkit.org/show_bug.cgi?id=158823
+        <rdar://problem/25975359>
+
+        Reviewed by Darin Adler.
+
+        Add tests for flipping the behavior of command-left and command-right
+        under RTL mode.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/CommandBackForward.mm: Added.
+        (-[CommandBackForwardOffscreenWindow isKeyWindow]):
+        (-[CommandBackForwardOffscreenWindow isVisible]):
+        (simulateCommandArrow):
+        (WebKit2_CommandBackForwardTest::SetUp):
+        (WebKit2_CommandBackForwardTestWKView::didFinishLoadForFrame):
+        (WebKit2_CommandBackForwardTestWKView::SetUp):
+        (WebKit2_CommandBackForwardTestWKView::loadFiles):
+        (-[CommandBackForwardNavigationDelegate webView:didFinishNavigation:]):
+        (WebKit2_CommandBackForwardTestWKWebView::SetUp):
+        (WebKit2_CommandBackForwardTestWKWebView::loadFiles):
+
 2016-06-15  Tim Horton  <timothy_horton@apple.com>
 
         Expose _shouldExpandContentToViewHeightForAutoLayout SPI on WKWebView
index c077f01..88ac793 100644 (file)
@@ -98,6 +98,7 @@
                7A1458FC1AD5C07000E06772 /* mouse-button-listener.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7A1458FB1AD5C03500E06772 /* mouse-button-listener.html */; };
                7AE9E5091AE5AE8B00CF874B /* test.pdf in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7AE9E5081AE5AE8B00CF874B /* test.pdf */; };
                7C3965061CDD74F90094DBB8 /* Color.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C3965051CDD74F90094DBB8 /* Color.cpp */; };
+               7C3DB8E41D12129B00AE8CC3 /* CommandBackForward.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7C3DB8E21D12129B00AE8CC3 /* CommandBackForward.mm */; };
                7C486BA11AA12567003F6F9B /* bundle-file.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7C486BA01AA1254B003F6F9B /* bundle-file.html */; };
                7C54A4BE1AA11CCA00380F78 /* WKBundleFileHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C54A4BC1AA11CCA00380F78 /* WKBundleFileHandle.cpp */; };
                7C54A4C11AA11CE400380F78 /* WKBundleFileHandle_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C54A4BF1AA11CE400380F78 /* WKBundleFileHandle_Bundle.cpp */; };
                7AA6A1511AAC0B31002B2ED3 /* WorkQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkQueue.cpp; sourceTree = "<group>"; };
                7AE9E5081AE5AE8B00CF874B /* test.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = test.pdf; sourceTree = "<group>"; };
                7C3965051CDD74F90094DBB8 /* Color.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Color.cpp; sourceTree = "<group>"; };
+               7C3DB8E21D12129B00AE8CC3 /* CommandBackForward.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CommandBackForward.mm; sourceTree = "<group>"; };
                7C486BA01AA1254B003F6F9B /* bundle-file.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "bundle-file.html"; sourceTree = "<group>"; };
                7C54A4BC1AA11CCA00380F78 /* WKBundleFileHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKBundleFileHandle.cpp; sourceTree = "<group>"; };
                7C54A4BF1AA11CE400380F78 /* WKBundleFileHandle_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKBundleFileHandle_Bundle.cpp; sourceTree = "<group>"; };
                                A13EBBAE1B87436F00097110 /* BundleParametersPlugIn.mm */,
                                1C2B817E1C891E4200A5529F /* CancelFontSubresource.mm */,
                                1C2B81811C891EFA00A5529F /* CancelFontSubresourcePlugIn.mm */,
+                               7C3DB8E21D12129B00AE8CC3 /* CommandBackForward.mm */,
                                A18AA8CC1C3FA218009B2B97 /* ContentFiltering.h */,
                                A14FC5861B8991B600D107EB /* ContentFiltering.mm */,
                                A14FC5891B89927100D107EB /* ContentFilteringPlugIn.mm */,
                                7C882E0A1C80C764006BF731 /* UserContentWorld.mm in Sources */,
                                7CCE7F271A411AF600447C4C /* UserContentController.mm in Sources */,
                                7C83E04F1D0A641800FEBCF3 /* FileSystem.cpp in Sources */,
+                               7C3DB8E41D12129B00AE8CC3 /* CommandBackForward.mm in Sources */,
                                7CCE7F2D1A411B1000447C4C /* UserContentTest.mm in Sources */,
                                7CCE7F171A411AE600447C4C /* UserMedia.cpp in Sources */,
                                7C83E0C41D0A654200FEBCF3 /* RequiresUserActionForPlayback.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/CommandBackForward.mm b/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/CommandBackForward.mm
new file mode 100644 (file)
index 0000000..a9b6b98
--- /dev/null
@@ -0,0 +1,301 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if PLATFORM(MAC)
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import <Carbon/Carbon.h> // for GetCurrentEventTime()
+#import <WebKit/WKRetainPtr.h>
+#import <WebKit/WKViewPrivate.h>
+#import <wtf/RetainPtr.h>
+
+@interface CommandBackForwardOffscreenWindow : NSWindow
+@end
+
+@implementation CommandBackForwardOffscreenWindow
+- (BOOL)isKeyWindow
+{
+    return YES;
+}
+- (BOOL)isVisible
+{
+    return YES;
+}
+@end
+
+enum ArrowDirection {
+    Left,
+    Right
+};
+
+static void simulateCommandArrow(NSView *view, ArrowDirection direction)
+{
+    const unichar right = NSRightArrowFunctionKey;
+    const unichar left = NSLeftArrowFunctionKey;
+
+    NSString *eventCharacter = (direction == Left) ? [NSString stringWithCharacters:&left length:1] : [NSString stringWithCharacters:&right length:1];
+    unsigned short keyCode = (direction == Left) ? 0x7B : 0x7C;
+
+    NSEvent *event = [NSEvent keyEventWithType:NSKeyDown
+                                      location:NSMakePoint(5, 5)
+                                 modifierFlags:NSCommandKeyMask
+                                     timestamp:GetCurrentEventTime()
+                                  windowNumber:[view.window windowNumber]
+                                       context:[NSGraphicsContext currentContext]
+                                    characters:eventCharacter
+                   charactersIgnoringModifiers:eventCharacter
+                                     isARepeat:NO
+                                       keyCode:keyCode];
+
+    [view keyDown:event];
+
+    event = [NSEvent keyEventWithType:NSKeyUp
+                             location:NSMakePoint(5, 5)
+                        modifierFlags:NSCommandKeyMask
+                            timestamp:GetCurrentEventTime()
+                         windowNumber:[view.window windowNumber]
+                              context:[NSGraphicsContext currentContext]
+                           characters:eventCharacter
+          charactersIgnoringModifiers:eventCharacter
+                            isARepeat:NO
+                              keyCode:keyCode];
+
+    [view keyUp:event];
+}
+
+class WebKit2_CommandBackForwardTest : public testing::Test {
+public:
+    RetainPtr<NSWindow> window;
+
+    virtual void SetUp()
+    {
+        NSWindow *window = [[CommandBackForwardOffscreenWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
+        [window setColorSpace:[[NSScreen mainScreen] colorSpace]];
+        [window orderBack:nil];
+        [window setAutodisplay:NO];
+        [window setReleasedWhenClosed:NO];
+    }
+};
+
+static bool didFinishNavigation;
+
+class WebKit2_CommandBackForwardTestWKView : public WebKit2_CommandBackForwardTest {
+public:
+    RetainPtr<WKView> webView;
+    WKRetainPtr<WKURLRef> file1;
+    WKRetainPtr<WKURLRef> file2;
+
+    static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void* clientInfo)
+    {
+        didFinishNavigation = true;
+    }
+
+    virtual void SetUp()
+    {
+        WebKit2_CommandBackForwardTest::SetUp();
+
+        WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate());
+        WKRetainPtr<WKPageConfigurationRef> configuration = adoptWK(WKPageConfigurationCreate());        
+        WKPageConfigurationSetContext(configuration.get(), context.get());
+
+        webView = [[WKView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) configurationRef:configuration.get()];
+
+        WKPageLoaderClientV6 loaderClient;
+        memset(&loaderClient, 0, sizeof(loaderClient));
+
+        loaderClient.base.version = 6;
+        loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
+
+        WKPageSetPageLoaderClient([webView pageRef], &loaderClient.base);
+        
+        file1 = adoptWK(TestWebKitAPI::Util::createURLForResource("simple", "html"));
+        file2 = adoptWK(TestWebKitAPI::Util::createURLForResource("simple2", "html"));
+
+    }
+
+    void loadFiles()
+    {
+        WKPageLoadFile([webView pageRef], file1.get(), nullptr);
+        TestWebKitAPI::Util::run(&didFinishNavigation);
+        didFinishNavigation = false;
+
+        WKPageLoadFile([webView pageRef], file2.get(), nullptr);
+        TestWebKitAPI::Util::run(&didFinishNavigation);
+        didFinishNavigation = false;
+    }
+};
+
+#if WK_API_ENABLED
+
+@interface CommandBackForwardNavigationDelegate : NSObject <WKNavigationDelegate>
+@end
+
+@implementation CommandBackForwardNavigationDelegate
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
+{
+    didFinishNavigation = true;
+}
+
+@end
+
+
+class WebKit2_CommandBackForwardTestWKWebView : public WebKit2_CommandBackForwardTest {
+public:
+    RetainPtr<WKWebView> webView;
+
+    virtual void SetUp()
+    {
+        WebKit2_CommandBackForwardTest::SetUp();
+
+        webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
+        [[window contentView] addSubview:webView.get()];
+
+        CommandBackForwardNavigationDelegate *delegate = [[CommandBackForwardNavigationDelegate alloc] init];
+        [webView setNavigationDelegate:delegate];
+    }
+    
+    void loadFiles()
+    {
+        NSURL *file1 = [[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
+        [webView loadFileURL:file1 allowingReadAccessToURL:file1];
+
+        TestWebKitAPI::Util::run(&didFinishNavigation);
+        didFinishNavigation = false;
+
+        NSURL *file2 = [[NSBundle mainBundle] URLForResource:@"simple2" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
+        [webView loadFileURL:file2 allowingReadAccessToURL:file2];
+
+        TestWebKitAPI::Util::run(&didFinishNavigation);
+        didFinishNavigation = false;
+    }
+};
+
+TEST_F(WebKit2_CommandBackForwardTestWKWebView, LTR)
+{
+    EXPECT_EQ(NSUserInterfaceLayoutDirectionLeftToRight, [webView userInterfaceLayoutDirection]);
+    
+    loadFiles();
+
+    EXPECT_WK_STREQ([webView URL].path.lastPathComponent, @"simple2.html");
+
+    // Attempt to go back (using command-left).
+    simulateCommandArrow(webView.get(), Left);
+    TestWebKitAPI::Util::run(&didFinishNavigation);
+    didFinishNavigation = false;
+
+    EXPECT_WK_STREQ([webView URL].path.lastPathComponent, @"simple.html");
+
+    // Attempt to go back (using command-right).
+    simulateCommandArrow(webView.get(), Right);
+    TestWebKitAPI::Util::run(&didFinishNavigation);
+    didFinishNavigation = false;
+
+    EXPECT_WK_STREQ([webView URL].path.lastPathComponent, @"simple2.html");
+}
+
+TEST_F(WebKit2_CommandBackForwardTestWKWebView, RTL)
+{
+    // Override the layout direction to be RTL.
+    [webView setUserInterfaceLayoutDirection:NSUserInterfaceLayoutDirectionRightToLeft];
+    
+    loadFiles();
+
+    EXPECT_WK_STREQ([webView URL].path.lastPathComponent, @"simple2.html");
+
+    // Attempt to go back (using command-right)
+    simulateCommandArrow(webView.get(), Right);
+    TestWebKitAPI::Util::run(&didFinishNavigation);
+    didFinishNavigation = false;
+
+    EXPECT_WK_STREQ([webView URL].path.lastPathComponent, @"simple.html");
+
+    // Attempt to go back (using command-left).
+    simulateCommandArrow(webView.get(), Left);
+    TestWebKitAPI::Util::run(&didFinishNavigation);
+    didFinishNavigation = false;
+
+    EXPECT_WK_STREQ([webView URL].path.lastPathComponent, @"simple2.html");
+}
+
+#endif
+
+TEST_F(WebKit2_CommandBackForwardTestWKView, LTR)
+{
+    EXPECT_EQ(NSUserInterfaceLayoutDirectionLeftToRight, [webView userInterfaceLayoutDirection]);
+    
+    loadFiles();
+
+    auto currentURL = adoptWK(WKPageCopyActiveURL([webView pageRef]));
+    EXPECT_TRUE(WKURLIsEqual(file2.get(), currentURL.get()));
+
+    // Attempt to go back (using command-left).
+    simulateCommandArrow(webView.get(), Left);
+    TestWebKitAPI::Util::run(&didFinishNavigation);
+    didFinishNavigation = false;
+
+    auto currentURL2 = adoptWK(WKPageCopyActiveURL([webView pageRef]));
+    EXPECT_TRUE(WKURLIsEqual(file1.get(), currentURL2.get()));
+
+    // Attempt to go back (using command-right).
+    simulateCommandArrow(webView.get(), Right);
+    TestWebKitAPI::Util::run(&didFinishNavigation);
+    didFinishNavigation = false;
+
+    auto currentURL3 = adoptWK(WKPageCopyActiveURL([webView pageRef]));
+    EXPECT_TRUE(WKURLIsEqual(file2.get(), currentURL3.get()));
+}
+
+TEST_F(WebKit2_CommandBackForwardTestWKView, RTL)
+{
+    // Override the layout direction to be RTL.
+    [webView setUserInterfaceLayoutDirection:NSUserInterfaceLayoutDirectionRightToLeft];
+    
+    loadFiles();
+
+    auto currentURL = adoptWK(WKPageCopyActiveURL([webView pageRef]));
+    EXPECT_TRUE(WKURLIsEqual(file2.get(), currentURL.get()));
+
+    // Attempt to go back (using command-right)
+    simulateCommandArrow(webView.get(), Right);
+    TestWebKitAPI::Util::run(&didFinishNavigation);
+    didFinishNavigation = false;
+
+    auto currentURL2 = adoptWK(WKPageCopyActiveURL([webView pageRef]));
+    EXPECT_TRUE(WKURLIsEqual(file1.get(), currentURL2.get()));
+
+    // Attempt to go back (using command-left).
+    simulateCommandArrow(webView.get(), Left);
+    TestWebKitAPI::Util::run(&didFinishNavigation);
+    didFinishNavigation = false;
+
+    auto currentURL3 = adoptWK(WKPageCopyActiveURL([webView pageRef]));
+    EXPECT_TRUE(WKURLIsEqual(file2.get(), currentURL3.get()));
+}
+
+#endif // PLATFORM(MAC)