viewStateDidChange should always fully update ViewState
authorbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 May 2014 01:41:22 +0000 (01:41 +0000)
committerbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 May 2014 01:41:22 +0000 (01:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=133159

Reviewed by Anders Carlson.

Currently WebPageProxy::viewStateDidChange is passed a mask of bits to update.

This has the following negative consequences:
 – WKWebView implicitly requires more detailed knowledge of the internal implementation of the PageClient.
 – Updates may unnecessarily be split over multiple IPC messages.
 – In order to support partial updates we make multiple virtual function calls to PageClient, which then makes duplicate objc calls.

Better to just always update the entire ViewState.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView didMoveToWindow]):
    - removed argument to viewStateDidChange.
* UIProcess/API/gtk/PageClientImpl.cpp:
(WebKit::PageClientImpl::viewState):
(WebKit::PageClientImpl::isViewWindowActive): Deleted.
(WebKit::PageClientImpl::isViewFocused): Deleted.
(WebKit::PageClientImpl::isViewVisible): Deleted.
(WebKit::PageClientImpl::isViewInWindow): Deleted.
* UIProcess/API/gtk/PageClientImpl.h:
    - merged isViewWindowActive/isViewFocused/isViewVisible/isViewInWindow to viewState.
* UIProcess/API/mac/WKView.mm:
(-[WKView becomeFirstResponder]):
(-[WKView resignFirstResponder]):
(-[WKView viewDidMoveToWindow]):
(-[WKView _windowDidBecomeKey:]):
(-[WKView _windowDidResignKey:]):
(-[WKView _windowDidMiniaturize:]):
(-[WKView _windowDidDeminiaturize:]):
(-[WKView _windowDidOrderOffScreen:]):
(-[WKView _windowDidOrderOnScreen:]):
(-[WKView _windowDidChangeOcclusionState:]):
(-[WKView viewDidHide]):
(-[WKView viewDidUnhide]):
(-[WKView _activeSpaceDidChange:]):
(-[WKView _setThumbnailView:]):
(-[WKView endDeferringViewInWindowChanges]):
(-[WKView endDeferringViewInWindowChangesSync]):
    - removed argument to viewStateDidChange.
* UIProcess/CoordinatedGraphics/WebView.cpp:
(WebKit::WebView::viewState):
(WebKit::WebView::isViewWindowActive): Deleted.
(WebKit::WebView::isViewFocused): Deleted.
(WebKit::WebView::isViewVisible): Deleted.
(WebKit::WebView::isViewInWindow): Deleted.
* UIProcess/CoordinatedGraphics/WebView.h:
    - merged isViewWindowActive/isViewFocused/isViewVisible/isViewInWindow to viewState.
* UIProcess/PageClient.h:
(WebKit::PageClient::isViewVisibleOrOccluded): Deleted.
(WebKit::PageClient::isVisuallyIdle): Deleted.
    - merged isViewVisibleOrOccluded/isVisuallyIdle to subclass viewState methods.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::WebPageProxy):
(WebKit::WebPageProxy::reattachToWebProcess):
    - updateViewState -> PageClient::viewState
(WebKit::WebPageProxy::viewStateDidChange):
    - argument removed; updateViewState -> PageClient::viewState.
(WebKit::WebPageProxy::setCursor):
    - call isViewWindowActive on WebPageProxy, rather than PageClient.
(WebKit::WebPageProxy::updateBackingStoreDiscardableState):
    - call isViewWindowActive on WebPageProxy, rather than PageClient.
(WebKit::WebPageProxy::updateViewState): Deleted.
    - removed - viewState method moved to PageClient.
* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::isViewWindowActive):
    - added missing implementation.
(WebKit::WebPageProxy::isViewVisible):
    - removed argument to viewStateDidChange.
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::windowServerConnectionStateChanged):
    - removed argument to viewStateDidChange.
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::viewState):
(WebKit::PageClientImpl::isViewWindowActive): Deleted.
(WebKit::PageClientImpl::isViewFocused): Deleted.
(WebKit::PageClientImpl::isViewVisible): Deleted.
(WebKit::PageClientImpl::isViewInWindow): Deleted.
(WebKit::PageClientImpl::isViewVisibleOrOccluded): Deleted.
(WebKit::PageClientImpl::isVisuallyIdle): Deleted.
    - merged isViewWindowActive/isViewFocused/isViewVisible/isViewInWindow to viewState.
* UIProcess/ios/WKContentView.mm:
(-[WKContentView didMoveToWindow]):
(-[WKContentView _applicationDidEnterBackground:]):
(-[WKContentView _applicationWillEnterForeground:]):
    - removed argument to viewStateDidChange.
* UIProcess/mac/PageClientImpl.h:
* UIProcess/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::viewState):
(WebKit::PageClientImpl::showCorrectionPanel):
(WebKit::PageClientImpl::showDictationAlternativeUI):
(WebKit::PageClientImpl::isViewWindowActive): Deleted.
(WebKit::PageClientImpl::isViewFocused): Deleted.
(WebKit::PageClientImpl::isViewVisibleOrOccluded): Deleted.
(WebKit::PageClientImpl::isVisuallyIdle): Deleted.
    - merged isViewWindowActive/isViewFocused/isViewVisible/isViewInWindow to viewState.

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

17 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp
Source/WebKit2/UIProcess/API/gtk/PageClientImpl.h
Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/CoordinatedGraphics/WebView.cpp
Source/WebKit2/UIProcess/CoordinatedGraphics/WebView.h
Source/WebKit2/UIProcess/PageClient.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebProcessProxy.cpp
Source/WebKit2/UIProcess/ios/PageClientImplIOS.h
Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm
Source/WebKit2/UIProcess/ios/WKContentView.mm
Source/WebKit2/UIProcess/mac/PageClientImpl.h
Source/WebKit2/UIProcess/mac/PageClientImpl.mm

index f62eb7a..8e72bf0 100644 (file)
@@ -1,3 +1,106 @@
+2014-05-28  Gavin Barraclough  <baraclough@apple.com>
+
+        viewStateDidChange should always fully update ViewState
+        https://bugs.webkit.org/show_bug.cgi?id=133159
+
+        Reviewed by Anders Carlson.
+
+        Currently WebPageProxy::viewStateDidChange is passed a mask of bits to update.
+
+        This has the following negative consequences:
+         – WKWebView implicitly requires more detailed knowledge of the internal implementation of the PageClient.
+         – Updates may unnecessarily be split over multiple IPC messages.
+         – In order to support partial updates we make multiple virtual function calls to PageClient, which then makes duplicate objc calls.
+
+        Better to just always update the entire ViewState.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView didMoveToWindow]):
+            - removed argument to viewStateDidChange.
+        * UIProcess/API/gtk/PageClientImpl.cpp:
+        (WebKit::PageClientImpl::viewState):
+        (WebKit::PageClientImpl::isViewWindowActive): Deleted.
+        (WebKit::PageClientImpl::isViewFocused): Deleted.
+        (WebKit::PageClientImpl::isViewVisible): Deleted.
+        (WebKit::PageClientImpl::isViewInWindow): Deleted.
+        * UIProcess/API/gtk/PageClientImpl.h:
+            - merged isViewWindowActive/isViewFocused/isViewVisible/isViewInWindow to viewState.
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView becomeFirstResponder]):
+        (-[WKView resignFirstResponder]):
+        (-[WKView viewDidMoveToWindow]):
+        (-[WKView _windowDidBecomeKey:]):
+        (-[WKView _windowDidResignKey:]):
+        (-[WKView _windowDidMiniaturize:]):
+        (-[WKView _windowDidDeminiaturize:]):
+        (-[WKView _windowDidOrderOffScreen:]):
+        (-[WKView _windowDidOrderOnScreen:]):
+        (-[WKView _windowDidChangeOcclusionState:]):
+        (-[WKView viewDidHide]):
+        (-[WKView viewDidUnhide]):
+        (-[WKView _activeSpaceDidChange:]):
+        (-[WKView _setThumbnailView:]):
+        (-[WKView endDeferringViewInWindowChanges]):
+        (-[WKView endDeferringViewInWindowChangesSync]):
+            - removed argument to viewStateDidChange.
+        * UIProcess/CoordinatedGraphics/WebView.cpp:
+        (WebKit::WebView::viewState):
+        (WebKit::WebView::isViewWindowActive): Deleted.
+        (WebKit::WebView::isViewFocused): Deleted.
+        (WebKit::WebView::isViewVisible): Deleted.
+        (WebKit::WebView::isViewInWindow): Deleted.
+        * UIProcess/CoordinatedGraphics/WebView.h:
+            - merged isViewWindowActive/isViewFocused/isViewVisible/isViewInWindow to viewState.
+        * UIProcess/PageClient.h:
+        (WebKit::PageClient::isViewVisibleOrOccluded): Deleted.
+        (WebKit::PageClient::isVisuallyIdle): Deleted.
+            - merged isViewVisibleOrOccluded/isVisuallyIdle to subclass viewState methods.
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::WebPageProxy):
+        (WebKit::WebPageProxy::reattachToWebProcess):
+            - updateViewState -> PageClient::viewState
+        (WebKit::WebPageProxy::viewStateDidChange):
+            - argument removed; updateViewState -> PageClient::viewState.
+        (WebKit::WebPageProxy::setCursor):
+            - call isViewWindowActive on WebPageProxy, rather than PageClient.
+        (WebKit::WebPageProxy::updateBackingStoreDiscardableState):
+            - call isViewWindowActive on WebPageProxy, rather than PageClient.
+        (WebKit::WebPageProxy::updateViewState): Deleted.
+            - removed - viewState method moved to PageClient.
+        * UIProcess/WebPageProxy.h:
+        (WebKit::WebPageProxy::isViewWindowActive):
+            - added missing implementation.
+        (WebKit::WebPageProxy::isViewVisible):
+            - removed argument to viewStateDidChange.
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::windowServerConnectionStateChanged):
+            - removed argument to viewStateDidChange.
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::viewState):
+        (WebKit::PageClientImpl::isViewWindowActive): Deleted.
+        (WebKit::PageClientImpl::isViewFocused): Deleted.
+        (WebKit::PageClientImpl::isViewVisible): Deleted.
+        (WebKit::PageClientImpl::isViewInWindow): Deleted.
+        (WebKit::PageClientImpl::isViewVisibleOrOccluded): Deleted.
+        (WebKit::PageClientImpl::isVisuallyIdle): Deleted.
+            - merged isViewWindowActive/isViewFocused/isViewVisible/isViewInWindow to viewState.
+        * UIProcess/ios/WKContentView.mm:
+        (-[WKContentView didMoveToWindow]):
+        (-[WKContentView _applicationDidEnterBackground:]):
+        (-[WKContentView _applicationWillEnterForeground:]):
+            - removed argument to viewStateDidChange.
+        * UIProcess/mac/PageClientImpl.h:
+        * UIProcess/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::viewState):
+        (WebKit::PageClientImpl::showCorrectionPanel):
+        (WebKit::PageClientImpl::showDictationAlternativeUI):
+        (WebKit::PageClientImpl::isViewWindowActive): Deleted.
+        (WebKit::PageClientImpl::isViewFocused): Deleted.
+        (WebKit::PageClientImpl::isViewVisibleOrOccluded): Deleted.
+        (WebKit::PageClientImpl::isVisuallyIdle): Deleted.
+            - merged isViewWindowActive/isViewFocused/isViewVisible/isViewInWindow to viewState.
+
 2014-05-28  Jeffrey Pfau  <jpfau@apple.com>
 
         Add Obj-C API for cache partitioned URL schemes
index cb528a0..c0ae710 100644 (file)
@@ -918,7 +918,7 @@ static WebCore::FloatPoint constrainContentOffset(WebCore::FloatPoint contentOff
 
 - (void)didMoveToWindow
 {
-    _page->viewStateDidChange(WebCore::ViewState::IsInWindow);
+    _page->viewStateDidChange();
 }
 
 #pragma mark - UIScrollViewDelegate
index c6fc610..7431158 100644 (file)
@@ -97,26 +97,25 @@ WebCore::IntSize PageClientImpl::viewSize()
     return IntSize(allocation.width, allocation.height);
 }
 
-bool PageClientImpl::isViewWindowActive()
-{
-    return webkitWebViewBaseIsInWindowActive(WEBKIT_WEB_VIEW_BASE(m_viewWidget));
-}
-
-bool PageClientImpl::isViewFocused()
-{
-    return webkitWebViewBaseIsFocused(WEBKIT_WEB_VIEW_BASE(m_viewWidget));
-}
-
-bool PageClientImpl::isViewVisible()
-{
-    return webkitWebViewBaseIsVisible(WEBKIT_WEB_VIEW_BASE(m_viewWidget));
-}
-
-bool PageClientImpl::isViewInWindow()
-{
-    return webkitWebViewBaseIsInWindow(WEBKIT_WEB_VIEW_BASE(m_viewWidget));
-}
-
+ViewState::Flags PageClientImpl::viewState()
+{
+    WebKitWebViewBase* webView = WEBKIT_WEB_VIEW_BASE(m_viewWidget);
+    ViewState::Flags viewState = ViewState::NoFlags;
+    
+    if (webkitWebViewBaseIsFocused(webView))
+        viewState |= ViewState::IsFocused;
+    if (webkitWebViewBaseIsInWindowActive(webView))
+        viewState |= ViewState::WindowIsActive;
+    if (webkitWebViewBaseIsInWindow(webView))
+        viewState |= ViewState::IsInWindow;
+    if (webkitWebViewBaseIsVisible(webView))
+        viewState |= (ViewState::IsVisible | ViewState::IsVisibleOrOccluded);
+    else
+        viewState |= ViewState::IsVisuallyIdle;
+    
+    return viewState;
+}
+    
 void PageClientImpl::PageClientImpl::processDidExit()
 {
     notImplemented();
index a4142fa..054a971 100644 (file)
@@ -67,10 +67,7 @@ private:
     virtual void scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset) override;
     virtual void requestScroll(const WebCore::FloatPoint& scrollPosition, bool isProgrammaticScroll) override;
     virtual WebCore::IntSize viewSize() override;
-    virtual bool isViewWindowActive() override;
-    virtual bool isViewFocused() override;
-    virtual bool isViewVisible() override;
-    virtual bool isViewInWindow() override;
+    virtual WebCore::ViewState::Flags viewState() override;
     virtual void processDidExit() override;
     virtual void didRelaunchProcess() override;
     virtual void pageClosed() override;
index 946fb54..c98d66d 100644 (file)
@@ -170,7 +170,7 @@ static gboolean toplevelWindowFocusInEvent(GtkWidget*, GdkEventFocus*, WebKitWeb
     WebKitWebViewBasePrivate* priv = webViewBase->priv;
     if (!priv->isInWindowActive) {
         priv->isInWindowActive = true;
-        priv->pageProxy->viewStateDidChange(ViewState::WindowIsActive);
+        priv->pageProxy->viewStateDidChange();
     }
 
     return FALSE;
@@ -181,7 +181,7 @@ static gboolean toplevelWindowFocusOutEvent(GtkWidget*, GdkEventFocus*, WebKitWe
     WebKitWebViewBasePrivate* priv = webViewBase->priv;
     if (priv->isInWindowActive) {
         priv->isInWindowActive = false;
-        priv->pageProxy->viewStateDidChange(ViewState::WindowIsActive);
+        priv->pageProxy->viewStateDidChange();
     }
 
     return FALSE;
@@ -193,7 +193,7 @@ static gboolean toplevelWindowVisibilityEvent(GtkWidget*, GdkEventVisibility* vi
     bool isWindowVisible = visibilityEvent->state != GDK_VISIBILITY_FULLY_OBSCURED;
     if (priv->isWindowVisible != isWindowVisible) {
         priv->isWindowVisible = isWindowVisible;
-        priv->pageProxy->viewStateDidChange(ViewState::IsVisible);
+        priv->pageProxy->viewStateDidChange();
     }
 
     return FALSE;
@@ -223,7 +223,7 @@ static void webkitWebViewBaseSetToplevelOnScreenWindow(WebKitWebViewBase* webVie
     }
 
     priv->toplevelOnScreenWindow = window;
-    priv->pageProxy->viewStateDidChange(ViewState::IsInWindow);
+    priv->pageProxy->viewStateDidChange();
     if (!priv->toplevelOnScreenWindow)
         return;
 
@@ -564,7 +564,7 @@ static void webkitWebViewBaseMap(GtkWidget* widget)
     WebKitWebViewBasePrivate* priv = webViewBase->priv;
     if (!priv->isVisible) {
         priv->isVisible = true;
-        priv->pageProxy->viewStateDidChange(ViewState::IsVisible);
+        priv->pageProxy->viewStateDidChange();
     }
 
     if (!priv->needsResizeOnMap)
@@ -583,7 +583,7 @@ static void webkitWebViewBaseUnmap(GtkWidget* widget)
     WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv;
     if (priv->isVisible) {
         priv->isVisible = false;
-        priv->pageProxy->viewStateDidChange(ViewState::IsVisible);
+        priv->pageProxy->viewStateDidChange();
     }
 }
 
@@ -1124,7 +1124,6 @@ void webkitWebViewBaseSetFocus(WebKitWebViewBase* webViewBase, bool focused)
     if (priv->isFocused == focused)
         return;
 
-    unsigned viewStateFlags = ViewState::IsFocused;
     priv->isFocused = focused;
 
     // If the view has received the focus and the window is not active
@@ -1132,11 +1131,9 @@ void webkitWebViewBaseSetFocus(WebKitWebViewBase* webViewBase, bool focused)
     // toplevel window is a GTK_WINDOW_POPUP and the focus has been
     // set programatically like WebKitTestRunner does, because POPUP
     // can't be focused.
-    if (priv->isFocused && !priv->isInWindowActive) {
+    if (priv->isFocused && !priv->isInWindowActive)
         priv->isInWindowActive = true;
-        viewStateFlags |= ViewState::WindowIsActive;
-    }
-    priv->pageProxy->viewStateDidChange(viewStateFlags);
+    priv->pageProxy->viewStateDidChange();
 }
 
 bool webkitWebViewBaseIsInWindowActive(WebKitWebViewBase* webViewBase)
index 00f0912..f88c2c6 100644 (file)
@@ -353,7 +353,7 @@ struct WKViewInterpretKeyEventsParameters {
     _data->_inBecomeFirstResponder = true;
     
     [self _updateSecureInputState];
-    _data->_page->viewStateDidChange(ViewState::IsFocused);
+    _data->_page->viewStateDidChange();
 
     _data->_inBecomeFirstResponder = false;
     
@@ -385,7 +385,7 @@ struct WKViewInterpretKeyEventsParameters {
     if (!_data->_page->maintainsInactiveSelection())
         _data->_page->clearSelection();
     
-    _data->_page->viewStateDidChange(ViewState::IsFocused);
+    _data->_page->viewStateDidChange();
 
     _data->_inResignFirstResponder = false;
 
@@ -2448,12 +2448,9 @@ static void createSandboxExtensionsForFileUpload(NSPasteboard *pasteboard, Sandb
     if ([self window]) {
         [self doWindowDidChangeScreen];
 
-        ViewState::Flags viewStateChanges = ViewState::WindowIsActive | ViewState::IsVisible;
         if ([self isDeferringViewInWindowChanges])
             _data->_viewInWindowChangeWasDeferred = YES;
-        else
-            viewStateChanges |= ViewState::IsInWindow;
-        _data->_page->viewStateDidChange(viewStateChanges);
+        _data->_page->viewStateDidChange();
 
         [self _updateWindowAndViewFrames];
 
@@ -2466,12 +2463,9 @@ static void createSandboxExtensionsForFileUpload(NSPasteboard *pasteboard, Sandb
 
         [self _accessibilityRegisterUIProcessTokens];
     } else {
-        ViewState::Flags viewStateChanges = ViewState::WindowIsActive | ViewState::IsVisible;
         if ([self isDeferringViewInWindowChanges])
             _data->_viewInWindowChangeWasDeferred = YES;
-        else
-            viewStateChanges |= ViewState::IsInWindow;
-        _data->_page->viewStateDidChange(viewStateChanges);
+        _data->_page->viewStateDidChange();
 
         [NSEvent removeMonitor:_data->_flagsChangedEventMonitor];
         _data->_flagsChangedEventMonitor = nil;
@@ -2492,7 +2486,7 @@ static void createSandboxExtensionsForFileUpload(NSPasteboard *pasteboard, Sandb
     NSWindow *keyWindow = [notification object];
     if (keyWindow == [self window] || keyWindow == [[self window] attachedSheet]) {
         [self _updateSecureInputState];
-        _data->_page->viewStateDidChange(ViewState::WindowIsActive);
+        _data->_page->viewStateDidChange();
     }
 }
 
@@ -2511,18 +2505,18 @@ static void createSandboxExtensionsForFileUpload(NSPasteboard *pasteboard, Sandb
     NSWindow *formerKeyWindow = [notification object];
     if (formerKeyWindow == [self window] || formerKeyWindow == [[self window] attachedSheet]) {
         [self _updateSecureInputState];
-        _data->_page->viewStateDidChange(ViewState::WindowIsActive);
+        _data->_page->viewStateDidChange();
     }
 }
 
 - (void)_windowDidMiniaturize:(NSNotification *)notification
 {
-    _data->_page->viewStateDidChange(ViewState::IsVisible);
+    _data->_page->viewStateDidChange();
 }
 
 - (void)_windowDidDeminiaturize:(NSNotification *)notification
 {
-    _data->_page->viewStateDidChange(ViewState::IsVisible);
+    _data->_page->viewStateDidChange();
 }
 
 - (void)_windowDidMove:(NSNotification *)notification
@@ -2537,12 +2531,12 @@ static void createSandboxExtensionsForFileUpload(NSPasteboard *pasteboard, Sandb
 
 - (void)_windowDidOrderOffScreen:(NSNotification *)notification
 {
-    _data->_page->viewStateDidChange(ViewState::IsVisible | ViewState::WindowIsActive);
+    _data->_page->viewStateDidChange();
 }
 
 - (void)_windowDidOrderOnScreen:(NSNotification *)notification
 {
-    _data->_page->viewStateDidChange(ViewState::IsVisible | ViewState::WindowIsActive);
+    _data->_page->viewStateDidChange();
 }
 
 - (void)_windowDidChangeBackingProperties:(NSNotification *)notification
@@ -2558,7 +2552,7 @@ static void createSandboxExtensionsForFileUpload(NSPasteboard *pasteboard, Sandb
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
 - (void)_windowDidChangeOcclusionState:(NSNotification *)notification
 {
-    _data->_page->viewStateDidChange(ViewState::IsVisible);
+    _data->_page->viewStateDidChange();
 }
 #endif
 
@@ -2582,12 +2576,12 @@ static void createSandboxExtensionsForFileUpload(NSPasteboard *pasteboard, Sandb
 
 - (void)viewDidHide
 {
-    _data->_page->viewStateDidChange(ViewState::IsVisible);
+    _data->_page->viewStateDidChange();
 }
 
 - (void)viewDidUnhide
 {
-    _data->_page->viewStateDidChange(ViewState::IsVisible);
+    _data->_page->viewStateDidChange();
 }
 
 - (void)viewDidChangeBackingProperties
@@ -2603,7 +2597,7 @@ static void createSandboxExtensionsForFileUpload(NSPasteboard *pasteboard, Sandb
 
 - (void)_activeSpaceDidChange:(NSNotification *)notification
 {
-    _data->_page->viewStateDidChange(ViewState::IsVisible);
+    _data->_page->viewStateDidChange();
 }
 
 - (void)_accessibilityRegisterUIProcessTokens
@@ -3490,7 +3484,7 @@ static NSString *pathWithUniqueFilenameForPath(NSString *path)
     else
         [self _setAcceleratedCompositingModeRootLayer:_data->_rootLayer.get()];
 
-    _data->_page->viewStateDidChange(ViewState::WindowIsActive | ViewState::IsInWindow | ViewState::IsVisible);
+    _data->_page->viewStateDidChange();
 }
 
 - (_WKThumbnailView *)_thumbnailView
@@ -3748,7 +3742,7 @@ static NSString *pathWithUniqueFilenameForPath(NSString *path)
     _data->_shouldDeferViewInWindowChanges = NO;
 
     if (_data->_viewInWindowChangeWasDeferred) {
-        _data->_page->viewStateDidChange(ViewState::IsInWindow);
+        _data->_page->viewStateDidChange();
         _data->_viewInWindowChangeWasDeferred = NO;
     }
 }
@@ -3766,7 +3760,7 @@ static NSString *pathWithUniqueFilenameForPath(NSString *path)
     _data->_shouldDeferViewInWindowChanges = NO;
 
     if (_data->_viewInWindowChangeWasDeferred) {
-        _data->_page->viewStateDidChange(ViewState::IsInWindow, hasPendingViewInWindowChange ? WebPageProxy::WantsReplyOrNot::DoesWantReply : WebPageProxy::WantsReplyOrNot::DoesNotWantReply);
+        _data->_page->viewStateDidChange(hasPendingViewInWindowChange ? WebPageProxy::WantsReplyOrNot::DoesWantReply : WebPageProxy::WantsReplyOrNot::DoesNotWantReply);
         _data->_viewInWindowChangeWasDeferred = NO;
     }
 
index d23e496..45794b7 100644 (file)
@@ -92,7 +92,7 @@ void WebView::setActive(bool active)
         return;
 
     scene->setActive(active);
-    m_page->viewStateDidChange(ViewState::WindowIsActive);
+    m_page->viewStateDidChange();
 }
 
 void WebView::setSize(const WebCore::IntSize& size)
@@ -111,7 +111,7 @@ void WebView::setFocused(bool focused)
         return;
 
     m_focused = focused;
-    m_page->viewStateDidChange(ViewState::IsFocused | ViewState::WindowIsActive);
+    m_page->viewStateDidChange();
 }
 
 void WebView::setVisible(bool visible)
@@ -120,12 +120,27 @@ void WebView::setVisible(bool visible)
         return;
 
     m_visible = visible;
-    m_page->viewStateDidChange(ViewState::IsVisible);
+    m_page->viewStateDidChange();
 
     if (CoordinatedDrawingAreaProxy* drawingArea = static_cast<CoordinatedDrawingAreaProxy*>(page()->drawingArea()))
         drawingArea->visibilityDidChange();
 }
 
+ViewState::Flags WebView::viewState()
+{
+    ViewState::Flags viewState = ViewState::IsInWindow | ViewState::WindowIsActive;
+    
+    if (isFocused())
+        viewState |= ViewState::IsFocused;
+    
+    if (isVisible())
+        viewState |= (ViewState::IsVisible | ViewState::IsVisibleOrOccluded);
+    else
+        viewState |= ViewState::IsVisuallyIdle;
+    
+    return viewState;
+}
+    
 void WebView::setUserViewportTranslation(double tx, double ty)
 {
     m_userViewportTransform = TransformationMatrix().translate(tx, ty);
@@ -323,28 +338,6 @@ bool WebView::isActive() const
     return scene->isActive();
 }
 
-bool WebView::isViewWindowActive()
-{
-    notImplemented();
-    return true;
-}
-
-bool WebView::isViewFocused()
-{
-    return isFocused();
-}
-
-bool WebView::isViewVisible()
-{
-    return isVisible();
-}
-
-bool WebView::isViewInWindow()
-{
-    notImplemented();
-    return true;
-}
-
 void WebView::processDidExit()
 {
     m_client.webProcessCrashed(this, m_page->urlAtProcessExit());
index 754fa2a..4ade7b7 100644 (file)
@@ -135,10 +135,7 @@ protected:
 
     virtual WebCore::IntSize viewSize() override;
 
-    virtual bool isViewWindowActive() override;
-    virtual bool isViewFocused() override;
-    virtual bool isViewVisible() override;
-    virtual bool isViewInWindow() override;
+    virtual WebCore::ViewState::Flags viewState() override;
 
     virtual void processDidExit() override;
     virtual void didRelaunchProcess() override;
index e53a094..20465c8 100644 (file)
@@ -32,6 +32,7 @@
 #include "WebPopupMenuProxy.h"
 #include <WebCore/AlternativeTextClient.h>
 #include <WebCore/EditorClient.h>
+#include <WebCore/ViewState.h>
 #include <wtf/Forward.h>
 
 #if PLATFORM(COCOA)
@@ -100,23 +101,12 @@ public:
     // Return the size of the view the page is associated with.
     virtual WebCore::IntSize viewSize() = 0;
 
-    // Return whether the view's containing window is active.
-    virtual bool isViewWindowActive() = 0;
-
-    // Return whether the view is focused.
-    virtual bool isViewFocused() = 0;
-
-    // Return whether the view is visible.
-    virtual bool isViewVisible() = 0;
-
-    // Return whether the view is visible, or occluded by another window.
-    virtual bool isViewVisibleOrOccluded() { return isViewVisible(); }
-
+#if PLATFORM(MAC)
     // Return whether the view is in a window.
     virtual bool isViewInWindow() = 0;
+#endif
 
-    // Return whether the view is visually idle.
-    virtual bool isVisuallyIdle() { return !isViewVisible(); }
+    virtual WebCore::ViewState::Flags viewState() = 0;
 
     // Return the layer hosting mode for the view.
     virtual LayerHostingMode viewLayerHostingMode() { return LayerHostingMode::InProcess; }
index e92868a..6cd4594 100644 (file)
@@ -270,7 +270,7 @@ WebPageProxy::WebPageProxy(PageClient& pageClient, WebProcessProxy& process, uin
     , m_userAgent(standardUserAgent())
     , m_geolocationPermissionRequestManager(*this)
     , m_notificationPermissionRequestManager(*this)
-    , m_viewState(ViewState::NoFlags)
+    , m_viewState(m_pageClient.viewState())
     , m_backForwardList(WebBackForwardList::create(*this))
     , m_loadStateAtProcessExit(FrameLoadState::State::Finished)
 #if PLATFORM(MAC) && !USE(ASYNC_NSTEXTINPUTCLIENT)
@@ -362,8 +362,7 @@ WebPageProxy::WebPageProxy(PageClient& pageClient, WebProcessProxy& process, uin
             m_userContentController->addProcess(m_process.get());
         m_visitedLinkProvider->addProcess(m_process.get());
     }
-
-    updateViewState();
+    
     updateActivityToken();
     
 #if HAVE(OUT_OF_PROCESS_LAYER_HOSTING)
@@ -530,7 +529,7 @@ void WebPageProxy::reattachToWebProcess()
     m_process->addExistingWebPage(this, m_pageID);
     m_process->addMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID, *this);
 
-    updateViewState();
+    m_viewState = m_pageClient.viewState();
     updateActivityToken();
 
 #if ENABLE(INSPECTOR)
@@ -1050,36 +1049,15 @@ void WebPageProxy::requestScroll(const FloatPoint& scrollPosition, bool isProgra
     m_pageClient.requestScroll(scrollPosition, isProgrammaticScroll);
 }
 
-void WebPageProxy::updateViewState(ViewState::Flags flagsToUpdate)
-{
-    m_viewState &= ~flagsToUpdate;
-    if (flagsToUpdate & ViewState::IsFocused && m_pageClient.isViewFocused())
-        m_viewState |= ViewState::IsFocused;
-    if (flagsToUpdate & ViewState::WindowIsActive && m_pageClient.isViewWindowActive())
-        m_viewState |= ViewState::WindowIsActive;
-    if (flagsToUpdate & ViewState::IsVisible && m_pageClient.isViewVisible())
-        m_viewState |= ViewState::IsVisible;
-    if (flagsToUpdate & ViewState::IsVisibleOrOccluded && m_pageClient.isViewVisibleOrOccluded())
-        m_viewState |= ViewState::IsVisibleOrOccluded;
-    if (flagsToUpdate & ViewState::IsInWindow && m_pageClient.isViewInWindow())
-        m_viewState |= ViewState::IsInWindow;
-    if (flagsToUpdate & ViewState::IsVisuallyIdle && m_pageClient.isVisuallyIdle())
-        m_viewState |= ViewState::IsVisuallyIdle;
-}
-
-void WebPageProxy::viewStateDidChange(ViewState::Flags mayHaveChanged, WantsReplyOrNot wantsReply)
+void WebPageProxy::viewStateDidChange(WantsReplyOrNot wantsReply)
 {
     if (!isValid())
         return;
 
-    // If the visibility state may have changed, then so may the visually idle & occluded agnostic state.
-    if (mayHaveChanged & ViewState::IsVisible)
-        mayHaveChanged |= ViewState::IsVisibleOrOccluded | ViewState::IsVisuallyIdle;
-
     // Record the prior view state, update the flags that may have changed,
     // and check which flags have actually changed.
     ViewState::Flags previousViewState = m_viewState;
-    updateViewState(mayHaveChanged);
+    m_viewState = m_pageClient.viewState();
     ViewState::Flags changed = m_viewState ^ previousViewState;
 
     if (changed)
@@ -1097,7 +1075,7 @@ void WebPageProxy::viewStateDidChange(ViewState::Flags mayHaveChanged, WantsRepl
     if ((changed & ViewState::IsVisible) && !isViewVisible())
         m_process->responsivenessTimer()->stop();
 
-    if ((mayHaveChanged & ViewState::IsInWindow) && (m_viewState & ViewState::IsInWindow)) {
+    if ((changed & ViewState::IsInWindow) && (m_viewState & ViewState::IsInWindow)) {
         LayerHostingMode layerHostingMode = m_pageClient.viewLayerHostingMode();
         if (m_layerHostingMode != layerHostingMode) {
             m_layerHostingMode = layerHostingMode;
@@ -1105,7 +1083,7 @@ void WebPageProxy::viewStateDidChange(ViewState::Flags mayHaveChanged, WantsRepl
         }
     }
 
-    if ((mayHaveChanged & ViewState::IsInWindow) && !(m_viewState & ViewState::IsInWindow)) {
+    if ((changed & ViewState::IsInWindow) && !(m_viewState & ViewState::IsInWindow)) {
 #if ENABLE(INPUT_TYPE_COLOR_POPOVER)
         // When leaving the current page, close the popover color well.
         if (m_colorPicker)
@@ -3801,7 +3779,7 @@ void WebPageProxy::setCursor(const WebCore::Cursor& cursor)
 {
     // The Web process may have asked to change the cursor when the view was in an active window, but
     // if it is no longer in a window or the window is not active, then the cursor should not change.
-    if (m_pageClient.isViewWindowActive())
+    if (isViewWindowActive())
         m_pageClient.setCursor(cursor);
 }
 
@@ -4689,7 +4667,7 @@ void WebPageProxy::updateBackingStoreDiscardableState()
     if (!m_process->responsivenessTimer()->isResponsive())
         isDiscardable = false;
     else
-        isDiscardable = !m_pageClient.isViewWindowActive() || !isViewVisible();
+        isDiscardable = !isViewWindowActive() || !isViewVisible();
 
     m_drawingArea->setBackingStoreIsDiscardable(isDiscardable);
 }
index cc3946c..38d67ea 100644 (file)
@@ -568,15 +568,15 @@ public:
     bool delegatesScrolling() const { return m_delegatesScrolling; }
 
     enum class WantsReplyOrNot { DoesNotWantReply, DoesWantReply };
-    void viewStateDidChange(WebCore::ViewState::Flags mayHaveChanged, WantsReplyOrNot = WantsReplyOrNot::DoesNotWantReply);
+    void viewStateDidChange(WantsReplyOrNot = WantsReplyOrNot::DoesNotWantReply);
     bool isInWindow() const { return m_viewState & WebCore::ViewState::IsInWindow; }
     void waitForDidUpdateViewState();
 
     void layerHostingModeDidChange();
 
     WebCore::IntSize viewSize() const;
+    bool isViewWindowActive() const { return m_viewState & WebCore::ViewState::WindowIsActive; }
     bool isViewVisible() const { return m_viewState & WebCore::ViewState::IsVisible; }
-    bool isViewWindowActive() const;
     bool isProcessSuppressible() const;
 
     void addMIMETypeWithCustomContentProvider(const String& mimeType);
@@ -1102,7 +1102,6 @@ private:
     WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, const WebPageConfiguration&);
     void platformInitialize();
 
-    void updateViewState(WebCore::ViewState::Flags flagsToUpdate = WebCore::ViewState::AllFlags);
     void updateActivityToken();
         
     void resetState();
index b45c527..5e97615 100644 (file)
@@ -669,7 +669,7 @@ void WebProcessProxy::releasePageCache()
 void WebProcessProxy::windowServerConnectionStateChanged()
 {
     for (const auto& page : m_pageMap.values())
-        page->viewStateDidChange(ViewState::IsVisuallyIdle);
+        page->viewStateDidChange();
 }
 
 void WebProcessProxy::requestTermination()
index 0565fb8..4863854 100644 (file)
@@ -55,12 +55,8 @@ private:
     virtual void scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset) override;
     virtual void requestScroll(const WebCore::FloatPoint& scrollPosition, bool isProgrammaticScroll) override;
     virtual WebCore::IntSize viewSize() override;
-    virtual bool isViewWindowActive() override;
-    virtual bool isViewFocused() override;
-    virtual bool isViewVisible() override;
-    virtual bool isViewInWindow() override;
-    virtual bool isViewVisibleOrOccluded() override;
-    virtual bool isVisuallyIdle() override;
+    virtual WebCore::ViewState::Flags viewState() override;
+        
     virtual void processDidExit() override;
     virtual void didRelaunchProcess() override;
     virtual void pageClosed() override;
index b2c870b..b42148e 100644 (file)
@@ -110,38 +110,25 @@ IntSize PageClientImpl::viewSize()
     return IntSize(m_contentView.bounds.size);
 }
 
-bool PageClientImpl::isViewWindowActive()
+// FIXME: https://bugs.webkit.org/show_bug.cgi?id=133098
+ViewState::Flags PageClientImpl::viewState()
 {
-    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=133098
-    return isViewVisible();
-}
-
-bool PageClientImpl::isViewFocused()
-{
-    // FIXME: https://bugs.webkit.org/show_bug.cgi?id=133098
-    return isViewWindowActive();
-}
-
-bool PageClientImpl::isViewVisible()
-{
-    return [m_webView window] && [UIApplication sharedApplication].applicationState != UIApplicationStateBackground;
-}
-
-bool PageClientImpl::isViewInWindow()
-{
-    return [m_webView window];
-}
-
-bool PageClientImpl::isViewVisibleOrOccluded()
-{
-    return isViewVisible();
-}
-
-bool PageClientImpl::isVisuallyIdle()
-{
-    return !isViewVisible();
+    ViewState::Flags viewState = ViewState::NoFlags;
+    
+    bool isInWindow = [m_webView window];
+    bool isVisible = isInWindow && [UIApplication sharedApplication].applicationState != UIApplicationStateBackground;
+    
+    if (isInWindow)
+        viewState |= ViewState::IsInWindow;
+    
+    if (isVisible)
+        viewState |= ViewState::WindowIsActive | ViewState::IsFocused | ViewState::IsVisible | ViewState::IsVisibleOrOccluded;
+    else
+        viewState |= ViewState::IsVisuallyIdle;
+    
+    return viewState;
 }
-
+    
 void PageClientImpl::processDidExit()
 {
     [m_contentView _processDidExit];
index b6fd761..0c2cf42 100644 (file)
@@ -250,7 +250,7 @@ private:
 {
     if (self.window)
         [self _updateForScreen:self.window.screen];
-    _page->viewStateDidChange(ViewState::AllFlags);
+    _page->viewStateDidChange();
 }
 
 - (WKBrowsingContextController *)browsingContextController
@@ -451,13 +451,13 @@ private:
 
 - (void)_applicationDidEnterBackground:(NSNotification*)notification
 {
-    _page->viewStateDidChange(ViewState::AllFlags & ~ViewState::IsInWindow);
+    _page->viewStateDidChange();
 }
 
 - (void)_applicationWillEnterForeground:(NSNotification*)notification
 {
     _page->applicationWillEnterForeground();
-    _page->viewStateDidChange(ViewState::AllFlags & ~ViewState::IsInWindow);
+    _page->viewStateDidChange();
 }
 
 - (void)_applicationDidBecomeActive:(NSNotification*)notification
index 0dae87c..b253939 100644 (file)
@@ -65,12 +65,10 @@ private:
     virtual void requestScroll(const WebCore::FloatPoint& scrollPosition, bool isProgrammaticScroll);
 
     virtual WebCore::IntSize viewSize();
-    virtual bool isViewWindowActive();
-    virtual bool isViewFocused();
-    virtual bool isViewVisible();
-    virtual bool isViewVisibleOrOccluded();
+    bool isViewVisible();
     virtual bool isViewInWindow();
-    virtual bool isVisuallyIdle();
+    virtual WebCore::ViewState::Flags viewState() override;
+        
     virtual LayerHostingMode viewLayerHostingMode() override;
     virtual ColorSpaceData colorSpace() override;
     virtual void setAcceleratedCompositingRootLayer(LayerOrView *) override;
index a84f94b..513eb50 100644 (file)
@@ -190,17 +190,6 @@ NSView *PageClientImpl::activeView() const
 #endif
 }
 
-bool PageClientImpl::isViewWindowActive()
-{
-    NSWindow *activeViewWindow = activeView().window;
-    return activeViewWindow.isKeyWindow || [NSApp keyWindow] == activeViewWindow;
-}
-
-bool PageClientImpl::isViewFocused()
-{
-    return [m_wkView _isFocused];
-}
-
 void PageClientImpl::makeFirstResponder()
 {
      [[m_wkView window] makeFirstResponder:m_wkView];
@@ -235,21 +224,34 @@ bool PageClientImpl::isViewVisible()
     return true;
 }
 
-bool PageClientImpl::isViewVisibleOrOccluded()
-{
-    return activeView().window.isVisible;
-}
-
 bool PageClientImpl::isViewInWindow()
 {
     return activeView().window;
 }
 
-bool PageClientImpl::isVisuallyIdle()
+ViewState::Flags PageClientImpl::viewState()
 {
-    return WindowServerConnection::shared().applicationWindowModificationsHaveStopped() || !isViewVisible();
+    ViewState::Flags viewState = ViewState::NoFlags;
+    
+    NSWindow *activeViewWindow = activeView().window;
+    bool isVisible = isViewVisible();
+    
+    if (activeViewWindow)
+        viewState |= ViewState::IsInWindow;
+    if (activeViewWindow.isKeyWindow || [NSApp keyWindow] == activeViewWindow)
+        viewState |= ViewState::WindowIsActive;
+    if ([m_wkView _isFocused])
+        viewState |= ViewState::IsFocused;
+    if (isVisible)
+        viewState |= ViewState::IsVisible;
+    if (activeViewWindow.isVisible)
+        viewState |= ViewState::IsVisibleOrOccluded;
+    if (!isVisible || WindowServerConnection::shared().applicationWindowModificationsHaveStopped())
+        viewState |= ViewState::IsVisuallyIdle;
+    
+    return viewState;
 }
-
+    
 LayerHostingMode PageClientImpl::viewLayerHostingMode()
 {
 #if HAVE(OUT_OF_PROCESS_LAYER_HOSTING)
@@ -540,8 +542,9 @@ void PageClientImpl::dismissDictionaryLookupPanel()
 void PageClientImpl::showCorrectionPanel(AlternativeTextType type, const FloatRect& boundingBoxOfReplacedString, const String& replacedString, const String& replacementString, const Vector<String>& alternativeReplacementStrings)
 {
 #if USE(AUTOCORRECTION_PANEL)
-    if (!isViewVisible() || !isViewInWindow())
+    if (!isViewVisible())
         return;
+    ASSERT(isViewInWindow());
     m_correctionPanel.show(m_wkView, type, boundingBoxOfReplacedString, replacedString, replacementString, alternativeReplacementStrings);
 #endif
 }
@@ -620,8 +623,9 @@ void PageClientImpl::removeDictationAlternatives(uint64_t dictationContext)
 
 void PageClientImpl::showDictationAlternativeUI(const WebCore::FloatRect& boundingBoxOfDictatedText, uint64_t dictationContext)
 {
-    if (!isViewVisible() || !isViewInWindow())
+    if (!isViewVisible())
         return;
+    ASSERT(isViewInWindow());
     m_alternativeTextUIController->showAlternatives(m_wkView, boundingBoxOfDictatedText, dictationContext, ^(NSString* acceptedAlternative){
         [m_wkView handleAcceptedAlternativeText:acceptedAlternative];
     });