Changeset 221694 in webkit


Ignore:
Timestamp:
Sep 6, 2017 1:15:47 PM (7 years ago)
Author:
achristensen@apple.com
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):

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r221683 r221694  
     12017-09-06  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add WKUIDelegatePrivate equivalent of WKPageUIClient's pinnedStateDidChange
     4        https://bugs.webkit.org/show_bug.cgi?id=176474
     5        <rdar://problem/29270035>
     6
     7        Reviewed by Tim Horton.
     8
     9        Rather than telling the UIClient that the pinned state changed and having the application check 4 bools
     10        like we do with WKPage, I made a KVO property on the WKWebView.  I introduce _WKRectEdge for this purpose,
     11        which is like UIRectEdge but unfortunately NSRectEdge and CGRectEdge cannot be used as NS_OPTIONS/flags.
     12        This same structure is used for rubber band state.
     13       
     14        Covered by a new API test.
     15
     16        * UIProcess/API/Cocoa/WKWebView.mm:
     17        (-[WKWebView _pinnedState]):
     18        (-[WKWebView _rubberBandState]):
     19        (-[WKWebView _setRubberBandState:]):
     20        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
     21        * UIProcess/Cocoa/WebViewImpl.h:
     22        * UIProcess/Cocoa/WebViewImpl.mm:
     23        (WebKit::WebViewImpl::pinnedState):
     24        (WebKit::WebViewImpl::rubberBandState):
     25        (WebKit::WebViewImpl::setRubberBandState):
     26        * UIProcess/PageClient.h:
     27        (WebKit::PageClient::pinnedStateWillChange):
     28        (WebKit::PageClient::pinnedStateDidChange):
     29        * UIProcess/WebPageProxy.cpp:
     30        (WebKit::WebPageProxy::didChangeScrollOffsetPinningForMainFrame):
     31        * UIProcess/mac/PageClientImplMac.h:
     32        * UIProcess/mac/PageClientImplMac.mm:
     33        (WebKit::PageClientImpl::pinnedStateWillChange):
     34        (WebKit::PageClientImpl::pinnedStateDidChange):
     35
    1362017-09-06  Brent Fulgham  <bfulgham@apple.com>
    237
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r221660 r221694  
    52825282}
    52835283
     5284- (_WKRectEdge)_pinnedState
     5285{
     5286    return _impl->pinnedState();
     5287}
     5288
     5289- (_WKRectEdge)_rubberBandingEnabled
     5290{
     5291    return _impl->rubberBandingEnabled();
     5292}
     5293
     5294- (void)_setRubberBandingEnabled:(_WKRectEdge)state
     5295{
     5296    _impl->setRubberBandingEnabled(state);
     5297}
     5298
    52845299- (id)_immediateActionAnimationControllerForHitTestResult:(_WKHitTestResult *)hitTestResult withType:(_WKImmediateActionType)type userData:(id<NSSecureCoding>)userData
    52855300{
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h

    r221660 r221694  
    8181} WK_API_AVAILABLE(macosx(10.12));
    8282
     83typedef NS_OPTIONS(NSInteger, _WKRectEdge) {
     84    _WKRectEdgeNone = 0,
     85    _WKRectEdgeLeft = 1 << CGRectMinXEdge,
     86    _WKRectEdgeTop = 1 << CGRectMinYEdge,
     87    _WKRectEdgeRight = 1 << CGRectMaxXEdge,
     88    _WKRectEdgeBottom = 1 << CGRectMaxYEdge,
     89    _WKRectEdgeAll = _WKRectEdgeLeft | _WKRectEdgeTop | _WKRectEdgeRight | _WKRectEdgeBottom,
     90} WK_API_AVAILABLE(macosx(WK_MAC_TBA));
     91
    8392#endif
    8493
     
    239248
    240249#else
     250
     251@property (nonatomic, readonly) _WKRectEdge _pinnedState;
     252@property (nonatomic, setter=_setRubberBandingEnabled:) _WKRectEdge _rubberBandingEnabled;
     253
    241254@property (readonly) NSColor *_pageExtendedBackgroundColor;
    242255@property (nonatomic, setter=_setDrawsBackground:) BOOL _drawsBackground;
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h

    r221381 r221694  
    2424 */
    2525
    26 #ifndef WebViewImpl_h
    27 #define WebViewImpl_h
     26#pragma once
    2827
    2928#if PLATFORM(MAC)
     
    4241#include <wtf/WeakPtr.h>
    4342#include <wtf/text/WTFString.h>
     43
     44using _WKRectEdge = NSInteger;
    4445
    4546OBJC_CLASS NSAccessibilityRemoteUIElement;
     
    237238    NSColor *underlayColor() const;
    238239    NSColor *pageExtendedBackgroundColor() const;
     240   
     241    _WKRectEdge pinnedState();
     242    _WKRectEdge rubberBandingEnabled();
     243    void setRubberBandingEnabled(_WKRectEdge);
    239244
    240245    void setOverlayScrollbarStyle(std::optional<WebCore::ScrollbarOverlayStyle> scrollbarStyle);
     
    733738
    734739#endif // PLATFORM(MAC)
    735 
    736 #endif // WebViewImpl_h
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm

    r221502 r221694  
    5858#import "WKTextInputWindowController.h"
    5959#import "WKViewLayoutStrategy.h"
    60 #import "WKWebView.h"
     60#import "WKWebViewPrivate.h"
    6161#import "WebBackForwardList.h"
    6262#import "WebEditCommandProxy.h"
     
    48454845}
    48464846
     4847_WKRectEdge WebViewImpl::pinnedState()
     4848{
     4849    _WKRectEdge state = _WKRectEdgeNone;
     4850    if (m_page->isPinnedToLeftSide())
     4851        state |= _WKRectEdgeLeft;
     4852    if (m_page->isPinnedToRightSide())
     4853        state |= _WKRectEdgeRight;
     4854    if (m_page->isPinnedToTopSide())
     4855        state |= _WKRectEdgeTop;
     4856    if (m_page->isPinnedToBottomSide())
     4857        state |= _WKRectEdgeBottom;
     4858    return state;
     4859}
     4860
     4861_WKRectEdge WebViewImpl::rubberBandingEnabled()
     4862{
     4863    _WKRectEdge state = _WKRectEdgeNone;
     4864    if (m_page->rubberBandsAtLeft())
     4865        state |= _WKRectEdgeLeft;
     4866    if (m_page->rubberBandsAtRight())
     4867        state |= _WKRectEdgeRight;
     4868    if (m_page->rubberBandsAtTop())
     4869        state |= _WKRectEdgeTop;
     4870    if (m_page->rubberBandsAtBottom())
     4871        state |= _WKRectEdgeBottom;
     4872    return state;
     4873}
     4874
     4875void WebViewImpl::setRubberBandingEnabled(_WKRectEdge state)
     4876{
     4877    m_page->setRubberBandsAtLeft(state & _WKRectEdgeLeft);
     4878    m_page->setRubberBandsAtRight(state & _WKRectEdgeRight);
     4879    m_page->setRubberBandsAtTop(state & _WKRectEdgeTop);
     4880    m_page->setRubberBandsAtBottom(state & _WKRectEdgeBottom);
     4881}
     4882
    48474883void WebViewImpl::mouseDown(NSEvent *event)
    48484884{
  • trunk/Source/WebKit/UIProcess/PageClient.h

    r221660 r221694  
    347347    virtual void isPlayingAudioWillChange() = 0;
    348348    virtual void isPlayingAudioDidChange() = 0;
     349    virtual void pinnedStateWillChange() { };
     350    virtual void pinnedStateDidChange() { };
    349351
    350352#if PLATFORM(MAC)
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r221658 r221694  
    59675967void WebPageProxy::didChangeScrollOffsetPinningForMainFrame(bool pinnedToLeftSide, bool pinnedToRightSide, bool pinnedToTopSide, bool pinnedToBottomSide)
    59685968{
     5969    m_pageClient.pinnedStateWillChange();
    59695970    m_mainFrameIsPinnedToLeftSide = pinnedToLeftSide;
    59705971    m_mainFrameIsPinnedToRightSide = pinnedToRightSide;
    59715972    m_mainFrameIsPinnedToTopSide = pinnedToTopSide;
    59725973    m_mainFrameIsPinnedToBottomSide = pinnedToBottomSide;
     5974    m_pageClient.pinnedStateDidChange();
    59735975
    59745976    m_uiClient->pinnedStateDidChange(*this);
  • trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h

    r221502 r221694  
    118118#endif
    119119
     120    void pinnedStateWillChange() final;
     121    void pinnedStateDidChange() final;
     122
    120123    CGRect boundsOfLayerInLayerBackedWindowCoordinates(CALayer *) const override;
    121124
  • trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm

    r221543 r221694  
    403403}
    404404
     405void PageClientImpl::pinnedStateWillChange()
     406{
     407#if WK_API_ENABLED
     408    [m_webView willChangeValueForKey:@"_pinnedState"];
     409#endif
     410}
     411
     412void PageClientImpl::pinnedStateDidChange()
     413{
     414#if WK_API_ENABLED
     415    [m_webView didChangeValueForKey:@"_pinnedState"];
     416#endif
     417}
     418   
    405419IntPoint PageClientImpl::screenToRootView(const IntPoint& point)
    406420{
  • trunk/Tools/ChangeLog

    r221692 r221694  
     12017-09-06  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add WKUIDelegatePrivate equivalent of WKPageUIClient's pinnedStateDidChange
     4        https://bugs.webkit.org/show_bug.cgi?id=176474
     5        <rdar://problem/29270035>
     6
     7        Reviewed by Tim Horton.
     8
     9        * TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
     10        (-[PinnedStateObserver observeValueForKeyPath:ofObject:change:context:]):
     11        (TEST):
     12
    1132017-09-06  Filip Pizlo  <fpizlo@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm

    r221658 r221694  
    250250}
    251251
     252@interface PinnedStateObserver : NSObject <WKUIDelegatePrivate>
     253@end
     254
     255@implementation PinnedStateObserver
     256
     257- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *, id> *)change context:(void *)context
     258{
     259    EXPECT_TRUE([keyPath isEqualToString:NSStringFromSelector(@selector(_pinnedState))]);
     260    EXPECT_TRUE([[object class] isEqual:[TestWKWebView class]]);
     261    EXPECT_EQ([[change objectForKey:NSKeyValueChangeOldKey] integerValue], _WKRectEdgeAll);
     262    EXPECT_EQ([[change objectForKey:NSKeyValueChangeNewKey] integerValue], _WKRectEdgeLeft | _WKRectEdgeRight);
     263    EXPECT_TRUE(context == nullptr);
     264    done = true;
     265}
     266
     267@end
     268
     269TEST(WebKit, PinnedState)
     270{
     271    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600)]);
     272    auto observer = adoptNS([[PinnedStateObserver alloc] init]);
     273    [webView addObserver:observer.get() forKeyPath:@"_pinnedState" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
     274    [webView loadHTMLString:@"<body onload='scroll(100, 100)' style='height:10000vh;'/>" baseURL:[NSURL URLWithString:@"http://example.com/"]];
     275    TestWebKitAPI::Util::run(&done);
     276}
     277
    252278static NSEvent *tabEvent(NSWindow *window, NSEventType type, NSEventModifierFlags flags)
    253279{
Note: See TracChangeset for help on using the changeset viewer.