Add -[WKNavigationAction modifierFlags] and -[WKNavigationAction buttonNumber]
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 May 2014 19:20:35 +0000 (19:20 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 May 2014 19:20:35 +0000 (19:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=132880
<rdar://problem/16901354>

Reviewed by Dan Bernstein.

* Shared/API/Cocoa/WKFoundation.h:
Add typedef for older systems.

* UIProcess/API/Cocoa/WKNavigationAction.h:
Add -[WKNavigationAction modifierFlags] and -[WKNavigationAction buttonNumber]

* UIProcess/API/Cocoa/WKNavigationAction.mm:
(toWKNavigationType):
This can be static now.

(toNSEventModifierFlags):
Helper to convert WebEvent::Modifiers to NSEventModifierFlags.

(toNSButtonNumber):
Helper to convert WebMouseEvent::Button to an AppKit button number.

(-[WKNavigationAction initWithNavigationActionData:WebKit::]):
New initializer that takes a NavigationActionData and fills in the relevant ivars from it.

(-[WKNavigationAction _isUserInitiated]):
Return the new ivar.

* UIProcess/API/Cocoa/WKNavigationActionInternal.h:
Remove readwrite overrides.

* UIProcess/Cocoa/NavigationState.mm:
(WebKit::NavigationState::PolicyClient::decidePolicyForNavigationAction):
Use initWithNavigationActionData:

* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::UIClient::createNewPage):
Use initWithNavigationActionData:

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

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/API/Cocoa/WKFoundation.h
Source/WebKit2/UIProcess/API/Cocoa/WKNavigationAction.h
Source/WebKit2/UIProcess/API/Cocoa/WKNavigationAction.mm
Source/WebKit2/UIProcess/API/Cocoa/WKNavigationActionInternal.h
Source/WebKit2/UIProcess/Cocoa/NavigationState.mm
Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm

index 5e3e475..405761c 100644 (file)
@@ -1,3 +1,44 @@
+2014-05-13  Anders Carlsson  <andersca@apple.com>
+
+        Add -[WKNavigationAction modifierFlags] and -[WKNavigationAction buttonNumber]
+        https://bugs.webkit.org/show_bug.cgi?id=132880
+        <rdar://problem/16901354>
+
+        Reviewed by Dan Bernstein.
+
+        * Shared/API/Cocoa/WKFoundation.h:
+        Add typedef for older systems.
+
+        * UIProcess/API/Cocoa/WKNavigationAction.h:
+        Add -[WKNavigationAction modifierFlags] and -[WKNavigationAction buttonNumber]
+
+        * UIProcess/API/Cocoa/WKNavigationAction.mm:
+        (toWKNavigationType):
+        This can be static now.
+
+        (toNSEventModifierFlags):
+        Helper to convert WebEvent::Modifiers to NSEventModifierFlags.
+
+        (toNSButtonNumber):
+        Helper to convert WebMouseEvent::Button to an AppKit button number.
+
+        (-[WKNavigationAction initWithNavigationActionData:WebKit::]):
+        New initializer that takes a NavigationActionData and fills in the relevant ivars from it.
+
+        (-[WKNavigationAction _isUserInitiated]):
+        Return the new ivar.
+
+        * UIProcess/API/Cocoa/WKNavigationActionInternal.h:
+        Remove readwrite overrides.
+
+        * UIProcess/Cocoa/NavigationState.mm:
+        (WebKit::NavigationState::PolicyClient::decidePolicyForNavigationAction):
+        Use initWithNavigationActionData:
+
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::UIClient::createNewPage):
+        Use initWithNavigationActionData:
+
 2014-05-13  Tim Horton  <timothy_horton@apple.com>
 
         WebKit2 View Gestures (Swipe): Encode snapshots as JPEG on some platforms
index 53ea6ed..27c082e 100644 (file)
 #define WK_AVAILABLE(_mac, _ios)
 #define WK_CLASS_AVAILABLE(_mac, _ios) __attribute__((visibility ("default")))
 #define WK_ENUM_AVAILABLE(_mac, _ios)
+
+#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED <= 1090
+typedef NSUInteger NSEventModifierFlags;
+#endif
+
 #endif
 
 #define WK_DESIGNATED_INITIALIZER
index d527af8..030699a 100644 (file)
 
 #if WK_API_ENABLED
 
+#if TARGET_OS_IPHONE
 #import <Foundation/Foundation.h>
+#else
+#import <AppKit/AppKit.h>
+#endif
 
 @class WKFrameInfo;
 
@@ -49,7 +53,6 @@ typedef NS_ENUM(NSInteger, WKNavigationType) {
     WKNavigationTypeOther = -1,
 } WK_ENUM_AVAILABLE(10_10, 8_0);
 
-
 /*! Contains information about an action that may cause a navigation, used for making policy decisions.
  */
 WK_CLASS_AVAILABLE(10_10, 8_0)
@@ -71,6 +74,18 @@ WK_CLASS_AVAILABLE(10_10, 8_0)
  */
 @property (nonatomic, readonly) NSURLRequest *request;
 
+#if !TARGET_OS_IPHONE
+
+/*! @abstract The modifier keys that were in effect when the navigation was requested.
+ */
+@property (nonatomic, readonly) NSEventModifierFlags modifierFlags;
+
+/*! @abstract The mouse button number that caused the navigation to be requested.
+ */
+@property (nonatomic, readonly) NSInteger buttonNumber;
+
+#endif
+
 @end
 
 #endif
index 2fb3ae8..785e70e 100644 (file)
@@ -28,6 +28,7 @@
 
 #if WK_API_ENABLED
 
+#import "NavigationActionData.h"
 #import <wtf/RetainPtr.h>
 
 @implementation WKNavigationAction {
     RetainPtr<WKFrameInfo> _targetFrame;
     RetainPtr<NSURLRequest> _request;
     RetainPtr<NSURL> _originalURL;
+    BOOL _isUserInitiated;
+}
+
+static WKNavigationType toWKNavigationType(WebCore::NavigationType navigationType)
+{
+    switch (navigationType) {
+    case WebCore::NavigationTypeLinkClicked:
+        return WKNavigationTypeLinkActivated;
+    case WebCore::NavigationTypeFormSubmitted:
+        return WKNavigationTypeFormSubmitted;
+    case WebCore::NavigationTypeBackForward:
+        return WKNavigationTypeBackForward;
+    case WebCore::NavigationTypeReload:
+        return WKNavigationTypeReload;
+    case WebCore::NavigationTypeFormResubmitted:
+        return WKNavigationTypeFormResubmitted;
+    case WebCore::NavigationTypeOther:
+        return WKNavigationTypeOther;
+    }
+
+    ASSERT_NOT_REACHED();
+    return WKNavigationTypeOther;
+}
+
+#if PLATFORM(MAC)
+
+// FIXME: This really belongs in WebEventFactory.
+static NSEventModifierFlags toNSEventModifierFlags(WebKit::WebEvent::Modifiers modifiers)
+{
+    NSEventModifierFlags modifierFlags = 0;
+
+    if (modifiers & WebKit::WebEvent::CapsLockKey)
+        modifierFlags |= NSAlphaShiftKeyMask;
+    if (modifiers & WebKit::WebEvent::ShiftKey)
+        modifierFlags |= NSShiftKeyMask;
+    if (modifiers & WebKit::WebEvent::ControlKey)
+        modifierFlags |= NSControlKeyMask;
+    if (modifiers & WebKit::WebEvent::AltKey)
+        modifierFlags |= NSAlternateKeyMask;
+    if (modifiers & WebKit::WebEvent::MetaKey)
+        modifierFlags |= NSCommandKeyMask;
+
+    return modifierFlags;
+}
+
+static NSInteger toNSButtonNumber(WebKit::WebMouseEvent::Button mouseButton)
+{
+    switch (mouseButton) {
+    case WebKit::WebMouseEvent::NoButton:
+        return 0;
+
+    case WebKit::WebMouseEvent::LeftButton:
+        return 1 << 0;
+
+    case WebKit::WebMouseEvent::RightButton:
+        return 1 << 1;
+
+    case WebKit::WebMouseEvent::MiddleButton:
+        return 1 << 2;
+
+    default:
+        return 0;
+    }
+}
+#endif
+
+- (instancetype)_initWithNavigationActionData:(const WebKit::NavigationActionData&)navigationActionData
+{
+    if (!(self = [super init]))
+        return nil;
+
+    _navigationType = toWKNavigationType(navigationActionData.navigationType);
+
+#if PLATFORM(MAC)
+    _modifierFlags = toNSEventModifierFlags(navigationActionData.modifiers);
+    _buttonNumber = toNSButtonNumber(navigationActionData.mouseButton);
+#endif
+
+    _isUserInitiated = navigationActionData.isProcessingUserGesture;
+
+    return self;
 }
 
 - (NSString *)description
     return _originalURL.get();
 }
 
-@end
-
-WKNavigationType toWKNavigationType(WebCore::NavigationType navigationType)
+- (BOOL)_isUserInitiated
 {
-    switch (navigationType) {
-    case WebCore::NavigationTypeLinkClicked:
-        return WKNavigationTypeLinkActivated;
-    case WebCore::NavigationTypeFormSubmitted:
-        return WKNavigationTypeFormSubmitted;
-    case WebCore::NavigationTypeBackForward:
-        return WKNavigationTypeBackForward;
-    case WebCore::NavigationTypeReload:
-        return WKNavigationTypeReload;
-    case WebCore::NavigationTypeFormResubmitted:
-        return WKNavigationTypeFormResubmitted;
-    case WebCore::NavigationTypeOther:
-        return WKNavigationTypeOther;
-    }
-
-    ASSERT_NOT_REACHED();
-    return WKNavigationTypeOther;
+    return _isUserInitiated;
 }
 
+@end
+
 #endif
index 328c13d..088036f 100644 (file)
 
 #import <WebCore/FrameLoaderTypes.h>
 
+namespace WebKit {
+struct NavigationActionData;
+}
+
 @interface WKNavigationAction ()
 
 @property (nonatomic, readwrite, strong) WKFrameInfo *sourceFrame;
 @property (nonatomic, readwrite, strong) WKFrameInfo *targetFrame;
 
-@property (nonatomic, readwrite) WKNavigationType navigationType;
 @property (nonatomic, readwrite, copy) NSURLRequest *request;
 
 @property (nonatomic, readwrite, copy, setter=_setOriginalURL:) NSURL *_originalURL;
-@property (nonatomic, readwrite, getter=_isUserInitiated, setter=_setUserInitiated:) BOOL _userInitiated;
 
-@end
+- (instancetype)_initWithNavigationActionData:(const WebKit::NavigationActionData&)navigationActionData;
 
-WKNavigationType toWKNavigationType(WebCore::NavigationType);
+@end
 
 #endif
index 8f77347..66e2956 100644 (file)
@@ -248,8 +248,7 @@ void NavigationState::PolicyClient::decidePolicyForNavigationAction(WebPageProxy
     if (!navigationDelegate)
         return;
 
-    // FIXME: Set up the navigation action object.
-    auto navigationAction = adoptNS([[WKNavigationAction alloc] init]);
+    auto navigationAction = adoptNS([[WKNavigationAction alloc] _initWithNavigationActionData:navigationActionData]);
 
     if (destinationFrame)
         [navigationAction setTargetFrame:adoptNS([[WKFrameInfo alloc] initWithWebFrameProxy:*destinationFrame]).get()];
@@ -261,10 +260,8 @@ void NavigationState::PolicyClient::decidePolicyForNavigationAction(WebPageProxy
             [navigationAction setSourceFrame:adoptNS([[WKFrameInfo alloc] initWithWebFrameProxy:*sourceFrame]).get()];
     }
 
-    [navigationAction setNavigationType:toWKNavigationType(navigationActionData.navigationType)];
     [navigationAction setRequest:request.nsURLRequest(WebCore::DoNotUpdateHTTPBody)];
     [navigationAction _setOriginalURL:originalRequest.url()];
-    [navigationAction _setUserInitiated:navigationActionData.isProcessingUserGesture];
 
     [navigationDelegate webView:m_navigationState.m_webView decidePolicyForNavigationAction:navigationAction.get() decisionHandler:[listener](WKNavigationActionPolicy actionPolicy) {
         switch (actionPolicy) {
index ef4983b..c22a0ac 100644 (file)
@@ -143,12 +143,10 @@ PassRefPtr<WebKit::WebPageProxy> UIDelegate::UIClient::createNewPage(WebKit::Web
     auto configuration = adoptNS([m_uiDelegate.m_webView->_configuration copy]);
     [configuration _setRelatedWebView:m_uiDelegate.m_webView];
 
-    auto navigationAction = adoptNS([[WKNavigationAction alloc] init]);
+    auto navigationAction = adoptNS([[WKNavigationAction alloc] _initWithNavigationActionData:navigationActionData]);
 
     [navigationAction setSourceFrame:adoptNS([[WKFrameInfo alloc] initWithWebFrameProxy:*initiatingFrame]).get()];
-    [navigationAction setNavigationType:toWKNavigationType(navigationActionData.navigationType)];
     [navigationAction setRequest:request.nsURLRequest(WebCore::DoNotUpdateHTTPBody)];
-    [navigationAction _setUserInitiated:navigationActionData.isProcessingUserGesture];
 
     RetainPtr<WKWebView> webView = [delegate.get() webView:m_uiDelegate.m_webView createWebViewWithConfiguration:configuration.get() forNavigationAction:navigationAction.get() windowFeatures:adoptNS([[WKWindowFeatures alloc] _initWithWindowFeatures:windowFeatures]).get()];