Diff
Modified: trunk/Source/WebKit2/ChangeLog (202128 => 202129)
--- trunk/Source/WebKit2/ChangeLog 2016-06-16 17:43:43 UTC (rev 202128)
+++ trunk/Source/WebKit2/ChangeLog 2016-06-16 17:54:33 UTC (rev 202129)
@@ -1,3 +1,56 @@
+2016-06-15 Sam Weinig <s...@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_hor...@apple.com>
Expose _shouldExpandContentToViewHeightForAutoLayout SPI on WKWebView
Modified: trunk/Source/WebKit2/Shared/WebPageCreationParameters.cpp (202128 => 202129)
--- trunk/Source/WebKit2/Shared/WebPageCreationParameters.cpp 2016-06-16 17:43:43 UTC (rev 202128)
+++ trunk/Source/WebKit2/Shared/WebPageCreationParameters.cpp 2016-06-16 17:54:33 UTC (rev 202129)
@@ -86,6 +86,7 @@
#endif
encoder << appleMailPaginationQuirkEnabled;
encoder << shouldScaleViewToFitDocument;
+ encoder.encodeEnum(userInterfaceLayoutDirection);
}
bool WebPageCreationParameters::decode(IPC::ArgumentDecoder& decoder, WebPageCreationParameters& parameters)
@@ -194,6 +195,9 @@
if (!decoder.decode(parameters.shouldScaleViewToFitDocument))
return false;
+ if (!decoder.decodeEnum(parameters.userInterfaceLayoutDirection))
+ return false;
+
return true;
}
Modified: trunk/Source/WebKit2/Shared/WebPageCreationParameters.h (202128 => 202129)
--- trunk/Source/WebKit2/Shared/WebPageCreationParameters.h 2016-06-16 17:43:43 UTC (rev 202128)
+++ trunk/Source/WebKit2/Shared/WebPageCreationParameters.h 2016-06-16 17:54:33 UTC (rev 202129)
@@ -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 @@
#endif
bool appleMailPaginationQuirkEnabled;
bool shouldScaleViewToFitDocument;
+
+ UserInterfaceLayoutDirection userInterfaceLayoutDirection;
};
} // namespace WebKit
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (202128 => 202129)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2016-06-16 17:43:43 UTC (rev 202128)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2016-06-16 17:54:33 UTC (rev 202129)
@@ -4298,6 +4298,27 @@
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 @@
return nil;
}
+- (void)setUserInterfaceLayoutDirection:(NSUserInterfaceLayoutDirection)userInterfaceLayoutDirection
+{
+ [super setUserInterfaceLayoutDirection:userInterfaceLayoutDirection];
+
+ _impl->setUserInterfaceLayoutDirection(userInterfaceLayoutDirection);
+}
+
#endif
@end
Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (202128 => 202129)
--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm 2016-06-16 17:43:43 UTC (rev 202128)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm 2016-06-16 17:54:33 UTC (rev 202129)
@@ -1435,6 +1435,13 @@
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)
Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h (202128 => 202129)
--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h 2016-06-16 17:43:43 UTC (rev 202128)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h 2016-06-16 17:54:33 UTC (rev 202129)
@@ -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 @@
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)
Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm (202128 => 202129)
--- trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm 2016-06-16 17:43:43 UTC (rev 202128)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm 2016-06-16 17:54:33 UTC (rev 202129)
@@ -4029,7 +4029,29 @@
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)
Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (202128 => 202129)
--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp 2016-06-16 17:43:43 UTC (rev 202128)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp 2016-06-16 17:54:33 UTC (rev 202129)
@@ -5274,6 +5274,7 @@
parameters.appleMailPaginationQuirkEnabled = false;
#endif
parameters.shouldScaleViewToFitDocument = m_shouldScaleViewToFitDocument;
+ parameters.userInterfaceLayoutDirection = m_pageClient.userInterfaceLayoutDirection();
return parameters;
}
@@ -6311,4 +6312,12 @@
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
Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (202128 => 202129)
--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h 2016-06-16 17:43:43 UTC (rev 202128)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h 2016-06-16 17:54:33 UTC (rev 202129)
@@ -1112,6 +1112,7 @@
void setResourceCachingDisabled(bool);
UserInterfaceLayoutDirection userInterfaceLayoutDirection();
+ void setUserInterfaceLayoutDirection(UserInterfaceLayoutDirection);
bool hasHadSelectionChangesFromUserInteraction() const { return m_hasHadSelectionChangesFromUserInteraction; }
Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (202128 => 202129)
--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp 2016-06-16 17:43:43 UTC (rev 202128)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp 2016-06-16 17:54:33 UTC (rev 202129)
@@ -377,6 +377,7 @@
#endif
, m_mainFrameProgressCompleted(false)
, m_shouldDispatchFakeMouseMoveEvents(true)
+ , m_userInterfaceLayoutDirection(parameters.userInterfaceLayoutDirection)
{
ASSERT(m_pageID);
@@ -5368,4 +5369,9 @@
m_page->setResourceCachingDisabled(disabled);
}
+void WebPage::setUserInterfaceLayoutDirection(uint32_t direction)
+{
+ m_userInterfaceLayoutDirection = static_cast<UserInterfaceLayoutDirection>(direction);
+}
+
} // namespace WebKit
Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (202128 => 202129)
--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h 2016-06-16 17:43:43 UTC (rev 202128)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h 2016-06-16 17:54:33 UTC (rev 202129)
@@ -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 @@
#endif
void setResourceCachingDisabled(bool);
+ void setUserInterfaceLayoutDirection(uint32_t);
uint64_t m_pageID;
@@ -1468,8 +1469,9 @@
#if USE(OS_STATE)
std::chrono::system_clock::time_point m_loadCommitTime;
#endif
+
+ UserInterfaceLayoutDirection m_userInterfaceLayoutDirection { UserInterfaceLayoutDirection::LTR };
};
} // namespace WebKit
-#endif // WebPage_h
Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (202128 => 202129)
--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in 2016-06-16 17:43:43 UTC (rev 202128)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in 2016-06-16 17:54:33 UTC (rev 202129)
@@ -428,4 +428,6 @@
#endif
SetResourceCachingDisabled(bool disabled)
+
+ SetUserInterfaceLayoutDirection(uint32_t direction)
}
Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (202128 => 202129)
--- trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm 2016-06-16 17:43:43 UTC (rev 202128)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm 2016-06-16 17:54:33 UTC (rev 202129)
@@ -551,13 +551,13 @@
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;
}
Modified: trunk/Tools/ChangeLog (202128 => 202129)
--- trunk/Tools/ChangeLog 2016-06-16 17:43:43 UTC (rev 202128)
+++ trunk/Tools/ChangeLog 2016-06-16 17:54:33 UTC (rev 202129)
@@ -1,3 +1,27 @@
+2016-06-15 Sam Weinig <s...@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_hor...@apple.com>
Expose _shouldExpandContentToViewHeightForAutoLayout SPI on WKWebView
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (202128 => 202129)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2016-06-16 17:43:43 UTC (rev 202128)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2016-06-16 17:54:33 UTC (rev 202129)
@@ -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 */; };
@@ -748,6 +749,7 @@
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>"; };
@@ -1131,6 +1133,7 @@
A13EBBAE1B87436F00097110 /* BundleParametersPlugIn.mm */,
1C2B817E1C891E4200A5529F /* CancelFontSubresource.mm */,
1C2B81811C891EFA00A5529F /* CancelFontSubresourcePlugIn.mm */,
+ 7C3DB8E21D12129B00AE8CC3 /* CommandBackForward.mm */,
A18AA8CC1C3FA218009B2B97 /* ContentFiltering.h */,
A14FC5861B8991B600D107EB /* ContentFiltering.mm */,
A14FC5891B89927100D107EB /* ContentFilteringPlugIn.mm */,
@@ -2145,6 +2148,7 @@
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 */,
Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/CommandBackForward.mm (0 => 202129)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/CommandBackForward.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/CommandBackForward.mm 2016-06-16 17:54:33 UTC (rev 202129)
@@ -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)