Title: [221694] trunk
Revision
221694
Author
[email protected]
Date
2017-09-06 13:15:47 -0700 (Wed, 06 Sep 2017)

Log Message

Add WKUIDelegatePrivate equivalent of WKPageUIClient's pinnedStateDidChange
https://bugs.webkit.org/show_bug.cgi?id=176474
<rdar://problem/29270035>

Reviewed by Tim Horton.

Source/WebKit:

Rather than telling the UIClient that the pinned state changed and having the application check 4 bools
like we do with WKPage, I made a KVO property on the WKWebView.  I introduce _WKRectEdge for this purpose,
which is like UIRectEdge but unfortunately NSRectEdge and CGRectEdge cannot be used as NS_OPTIONS/flags.
This same structure is used for rubber band state.
        
Covered by a new API test.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _pinnedState]):
(-[WKWebView _rubberBandState]):
(-[WKWebView _setRubberBandState:]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::pinnedState):
(WebKit::WebViewImpl::rubberBandState):
(WebKit::WebViewImpl::setRubberBandState):
* UIProcess/PageClient.h:
(WebKit::PageClient::pinnedStateWillChange):
(WebKit::PageClient::pinnedStateDidChange):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didChangeScrollOffsetPinningForMainFrame):
* UIProcess/mac/PageClientImplMac.h:
* UIProcess/mac/PageClientImplMac.mm:
(WebKit::PageClientImpl::pinnedStateWillChange):
(WebKit::PageClientImpl::pinnedStateDidChange):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
(-[PinnedStateObserver observeValueForKeyPath:ofObject:change:context:]):
(TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (221693 => 221694)


--- trunk/Source/WebKit/ChangeLog	2017-09-06 20:09:28 UTC (rev 221693)
+++ trunk/Source/WebKit/ChangeLog	2017-09-06 20:15:47 UTC (rev 221694)
@@ -1,3 +1,38 @@
+2017-09-06  Alex Christensen  <[email protected]>
+
+        Add WKUIDelegatePrivate equivalent of WKPageUIClient's pinnedStateDidChange
+        https://bugs.webkit.org/show_bug.cgi?id=176474
+        <rdar://problem/29270035>
+
+        Reviewed by Tim Horton.
+
+        Rather than telling the UIClient that the pinned state changed and having the application check 4 bools
+        like we do with WKPage, I made a KVO property on the WKWebView.  I introduce _WKRectEdge for this purpose,
+        which is like UIRectEdge but unfortunately NSRectEdge and CGRectEdge cannot be used as NS_OPTIONS/flags.
+        This same structure is used for rubber band state.
+        
+        Covered by a new API test.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _pinnedState]):
+        (-[WKWebView _rubberBandState]):
+        (-[WKWebView _setRubberBandState:]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::pinnedState):
+        (WebKit::WebViewImpl::rubberBandState):
+        (WebKit::WebViewImpl::setRubberBandState):
+        * UIProcess/PageClient.h:
+        (WebKit::PageClient::pinnedStateWillChange):
+        (WebKit::PageClient::pinnedStateDidChange):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::didChangeScrollOffsetPinningForMainFrame):
+        * UIProcess/mac/PageClientImplMac.h:
+        * UIProcess/mac/PageClientImplMac.mm:
+        (WebKit::PageClientImpl::pinnedStateWillChange):
+        (WebKit::PageClientImpl::pinnedStateDidChange):
+
 2017-09-06  Brent Fulgham  <[email protected]>
 
         Deny third-party cookie creation for prevalent resources without interaction

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (221693 => 221694)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2017-09-06 20:09:28 UTC (rev 221693)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2017-09-06 20:15:47 UTC (rev 221694)
@@ -5281,6 +5281,21 @@
     return _impl->pageExtendedBackgroundColor();
 }
 
+- (_WKRectEdge)_pinnedState
+{
+    return _impl->pinnedState();
+}
+
+- (_WKRectEdge)_rubberBandingEnabled
+{
+    return _impl->rubberBandingEnabled();
+}
+
+- (void)_setRubberBandingEnabled:(_WKRectEdge)state
+{
+    _impl->setRubberBandingEnabled(state);
+}
+
 - (id)_immediateActionAnimationControllerForHitTestResult:(_WKHitTestResult *)hitTestResult withType:(_WKImmediateActionType)type userData:(id<NSSecureCoding>)userData
 {
     return nil;

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (221693 => 221694)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2017-09-06 20:09:28 UTC (rev 221693)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2017-09-06 20:15:47 UTC (rev 221694)
@@ -80,6 +80,15 @@
     _WKImmediateActionTelLink
 } WK_API_AVAILABLE(macosx(10.12));
 
+typedef NS_OPTIONS(NSInteger, _WKRectEdge) {
+    _WKRectEdgeNone = 0,
+    _WKRectEdgeLeft = 1 << CGRectMinXEdge,
+    _WKRectEdgeTop = 1 << CGRectMinYEdge,
+    _WKRectEdgeRight = 1 << CGRectMaxXEdge,
+    _WKRectEdgeBottom = 1 << CGRectMaxYEdge,
+    _WKRectEdgeAll = _WKRectEdgeLeft | _WKRectEdgeTop | _WKRectEdgeRight | _WKRectEdgeBottom,
+} WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+
 #endif
 
 @class WKBrowsingContextHandle;
@@ -238,6 +247,10 @@
 - (void)_accessibilityDidGetSpeakSelectionContent:(NSString *)content WK_API_AVAILABLE(ios(WK_IOS_TBA));
 
 #else
+
+@property (nonatomic, readonly) _WKRectEdge _pinnedState;
+@property (nonatomic, setter=_setRubberBandingEnabled:) _WKRectEdge _rubberBandingEnabled;
+
 @property (readonly) NSColor *_pageExtendedBackgroundColor;
 @property (nonatomic, setter=_setDrawsBackground:) BOOL _drawsBackground;
 @property (nonatomic, setter=_setTopContentInset:) CGFloat _topContentInset;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h (221693 => 221694)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h	2017-09-06 20:09:28 UTC (rev 221693)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h	2017-09-06 20:15:47 UTC (rev 221694)
@@ -23,8 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef WebViewImpl_h
-#define WebViewImpl_h
+#pragma once
 
 #if PLATFORM(MAC)
 
@@ -42,6 +41,8 @@
 #include <wtf/WeakPtr.h>
 #include <wtf/text/WTFString.h>
 
+using _WKRectEdge = NSInteger;
+
 OBJC_CLASS NSAccessibilityRemoteUIElement;
 OBJC_CLASS NSImmediateActionGestureRecognizer;
 OBJC_CLASS NSTextInputContext;
@@ -236,6 +237,10 @@
     void setUnderlayColor(NSColor *);
     NSColor *underlayColor() const;
     NSColor *pageExtendedBackgroundColor() const;
+    
+    _WKRectEdge pinnedState();
+    _WKRectEdge rubberBandingEnabled();
+    void setRubberBandingEnabled(_WKRectEdge);
 
     void setOverlayScrollbarStyle(std::optional<WebCore::ScrollbarOverlayStyle> scrollbarStyle);
     std::optional<WebCore::ScrollbarOverlayStyle> overlayScrollbarStyle() const;
@@ -732,5 +737,3 @@
 } // namespace WebKit
 
 #endif // PLATFORM(MAC)
-
-#endif // WebViewImpl_h

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (221693 => 221694)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2017-09-06 20:09:28 UTC (rev 221693)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2017-09-06 20:15:47 UTC (rev 221694)
@@ -57,7 +57,7 @@
 #import "WKPrintingView.h"
 #import "WKTextInputWindowController.h"
 #import "WKViewLayoutStrategy.h"
-#import "WKWebView.h"
+#import "WKWebViewPrivate.h"
 #import "WebBackForwardList.h"
 #import "WebEditCommandProxy.h"
 #import "WebEventFactory.h"
@@ -4844,6 +4844,42 @@
     mouseMovedInternal(event);
 }
 
+_WKRectEdge WebViewImpl::pinnedState()
+{
+    _WKRectEdge state = _WKRectEdgeNone;
+    if (m_page->isPinnedToLeftSide())
+        state |= _WKRectEdgeLeft;
+    if (m_page->isPinnedToRightSide())
+        state |= _WKRectEdgeRight;
+    if (m_page->isPinnedToTopSide())
+        state |= _WKRectEdgeTop;
+    if (m_page->isPinnedToBottomSide())
+        state |= _WKRectEdgeBottom;
+    return state;
+}
+
+_WKRectEdge WebViewImpl::rubberBandingEnabled()
+{
+    _WKRectEdge state = _WKRectEdgeNone;
+    if (m_page->rubberBandsAtLeft())
+        state |= _WKRectEdgeLeft;
+    if (m_page->rubberBandsAtRight())
+        state |= _WKRectEdgeRight;
+    if (m_page->rubberBandsAtTop())
+        state |= _WKRectEdgeTop;
+    if (m_page->rubberBandsAtBottom())
+        state |= _WKRectEdgeBottom;
+    return state;
+}
+
+void WebViewImpl::setRubberBandingEnabled(_WKRectEdge state)
+{
+    m_page->setRubberBandsAtLeft(state & _WKRectEdgeLeft);
+    m_page->setRubberBandsAtRight(state & _WKRectEdgeRight);
+    m_page->setRubberBandsAtTop(state & _WKRectEdgeTop);
+    m_page->setRubberBandsAtBottom(state & _WKRectEdgeBottom);
+}
+
 void WebViewImpl::mouseDown(NSEvent *event)
 {
     if (m_ignoresNonWheelEvents)

Modified: trunk/Source/WebKit/UIProcess/PageClient.h (221693 => 221694)


--- trunk/Source/WebKit/UIProcess/PageClient.h	2017-09-06 20:09:28 UTC (rev 221693)
+++ trunk/Source/WebKit/UIProcess/PageClient.h	2017-09-06 20:15:47 UTC (rev 221694)
@@ -346,6 +346,8 @@
     virtual void didChangeBackgroundColor() = 0;
     virtual void isPlayingAudioWillChange() = 0;
     virtual void isPlayingAudioDidChange() = 0;
+    virtual void pinnedStateWillChange() { };
+    virtual void pinnedStateDidChange() { };
 
 #if PLATFORM(MAC)
     virtual void didPerformImmediateActionHitTest(const WebHitTestResultData&, bool contentPreventsDefault, API::Object*) = 0;

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (221693 => 221694)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2017-09-06 20:09:28 UTC (rev 221693)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2017-09-06 20:15:47 UTC (rev 221694)
@@ -5966,10 +5966,12 @@
 
 void WebPageProxy::didChangeScrollOffsetPinningForMainFrame(bool pinnedToLeftSide, bool pinnedToRightSide, bool pinnedToTopSide, bool pinnedToBottomSide)
 {
+    m_pageClient.pinnedStateWillChange();
     m_mainFrameIsPinnedToLeftSide = pinnedToLeftSide;
     m_mainFrameIsPinnedToRightSide = pinnedToRightSide;
     m_mainFrameIsPinnedToTopSide = pinnedToTopSide;
     m_mainFrameIsPinnedToBottomSide = pinnedToBottomSide;
+    m_pageClient.pinnedStateDidChange();
 
     m_uiClient->pinnedStateDidChange(*this);
 }

Modified: trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h (221693 => 221694)


--- trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h	2017-09-06 20:09:28 UTC (rev 221693)
+++ trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h	2017-09-06 20:15:47 UTC (rev 221694)
@@ -117,6 +117,9 @@
     virtual WebCore::IntRect rootViewToAccessibilityScreen(const WebCore::IntRect&) = 0;
 #endif
 
+    void pinnedStateWillChange() final;
+    void pinnedStateDidChange() final;
+
     CGRect boundsOfLayerInLayerBackedWindowCoordinates(CALayer *) const override;
 
     void doneWithKeyEvent(const NativeWebKeyboardEvent&, bool wasEventHandled) override;

Modified: trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm (221693 => 221694)


--- trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm	2017-09-06 20:09:28 UTC (rev 221693)
+++ trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm	2017-09-06 20:15:47 UTC (rev 221694)
@@ -402,6 +402,20 @@
     return toUserSpace(rect, [m_view window]);
 }
 
+void PageClientImpl::pinnedStateWillChange()
+{
+#if WK_API_ENABLED
+    [m_webView willChangeValueForKey:@"_pinnedState"];
+#endif
+}
+
+void PageClientImpl::pinnedStateDidChange()
+{
+#if WK_API_ENABLED
+    [m_webView didChangeValueForKey:@"_pinnedState"];
+#endif
+}
+    
 IntPoint PageClientImpl::screenToRootView(const IntPoint& point)
 {
 #pragma clang diagnostic push

Modified: trunk/Tools/ChangeLog (221693 => 221694)


--- trunk/Tools/ChangeLog	2017-09-06 20:09:28 UTC (rev 221693)
+++ trunk/Tools/ChangeLog	2017-09-06 20:15:47 UTC (rev 221694)
@@ -1,3 +1,15 @@
+2017-09-06  Alex Christensen  <[email protected]>
+
+        Add WKUIDelegatePrivate equivalent of WKPageUIClient's pinnedStateDidChange
+        https://bugs.webkit.org/show_bug.cgi?id=176474
+        <rdar://problem/29270035>
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
+        (-[PinnedStateObserver observeValueForKeyPath:ofObject:change:context:]):
+        (TEST):
+
 2017-09-06  Filip Pizlo  <[email protected]>
 
         WSL: Inliner doesn't allow double-negation

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm (221693 => 221694)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm	2017-09-06 20:09:28 UTC (rev 221693)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm	2017-09-06 20:15:47 UTC (rev 221694)
@@ -249,6 +249,32 @@
     TestWebKitAPI::Util::run(&done);
 }
 
+@interface PinnedStateObserver : NSObject <WKUIDelegatePrivate>
+@end
+
+@implementation PinnedStateObserver
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *, id> *)change context:(void *)context
+{
+    EXPECT_TRUE([keyPath isEqualToString:NSStringFromSelector(@selector(_pinnedState))]);
+    EXPECT_TRUE([[object class] isEqual:[TestWKWebView class]]);
+    EXPECT_EQ([[change objectForKey:NSKeyValueChangeOldKey] integerValue], _WKRectEdgeAll);
+    EXPECT_EQ([[change objectForKey:NSKeyValueChangeNewKey] integerValue], _WKRectEdgeLeft | _WKRectEdgeRight);
+    EXPECT_TRUE(context == nullptr);
+    done = true;
+}
+
+@end
+
+TEST(WebKit, PinnedState)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600)]);
+    auto observer = adoptNS([[PinnedStateObserver alloc] init]);
+    [webView addObserver:observer.get() forKeyPath:@"_pinnedState" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
+    [webView loadHTMLString:@"<body _onload_='scroll(100, 100)' style='height:10000vh;'/>" baseURL:[NSURL URLWithString:@"http://example.com/"]];
+    TestWebKitAPI::Util::run(&done);
+}
+
 static NSEvent *tabEvent(NSWindow *window, NSEventType type, NSEventModifierFlags flags)
 {
     return [NSEvent keyEventWithType:type location:NSMakePoint(5, 5) modifierFlags:flags timestamp:GetCurrentEventTime() windowNumber:[window windowNumber] context:[NSGraphicsContext currentContext] characters:@"\t" charactersIgnoringModifiers:@"\t" isARepeat:NO keyCode:0];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to