Change Page, FocusController to use ViewState
authorbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Feb 2014 08:23:15 +0000 (08:23 +0000)
committerbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Feb 2014 08:23:15 +0000 (08:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=126533

Reviewed by Tim Horton.

These classes currently maintain a set of separate fields to represent the view state;
combine these into a single field, and allow WebPage to send the combined update rather
than individual changes.

Maintain existing interface for WebKit1 clients.

Source/WebCore:

* WebCore.exp.in:
    - Added WebCore::setViewState, removed WebCore::setIsVisuallyIdle.
* page/FocusController.cpp:
(WebCore::FocusController::FocusController):
    - Initialize combined m_viewState.
(WebCore::FocusController::setFocused):
    - Calls setViewState.
(WebCore::FocusController::setFocusedInternal):
    - setFocused -> setFocusedInternal.
(WebCore::FocusController::setViewState):
    - Added, update all ViewState flags.
(WebCore::FocusController::setActive):
    - Calls setViewState.
(WebCore::FocusController::setActiveInternal):
    - setActive -> setActiveInternal.
(WebCore::FocusController::setContentIsVisible):
    - Calls setViewState.
(WebCore::FocusController::setContentIsVisibleInternal):
    - setContentIsVisible -> setContentIsVisibleInternal.
* page/FocusController.h:
(WebCore::FocusController::isActive):
(WebCore::FocusController::isFocused):
(WebCore::FocusController::contentIsVisible):
    - Implemented in terms of ViewState.
* page/Page.cpp:
(WebCore::Page::Page):
    - Initialize using PageInitialViewState.
(WebCore::Page::setIsInWindow):
    - Calls setViewState.
(WebCore::Page::setIsInWindowInternal):
    - setIsInWindow -> setIsInWindowInternal.
(WebCore::Page::setIsVisuallyIdleInternal):
    - setIsVisuallyIdle -> setIsVisuallyIdleInternal.
(WebCore::Page::setViewState):
    - Added, update all ViewState flags, including FocusController.
(WebCore::Page::setIsVisible):
    - Calls setViewState.
(WebCore::Page::setIsVisibleInternal):
    - setIsVisible -> setIsVisibleInternal.
(WebCore::Page::visibilityState):
    - m_isVisible -> isVisible()
(WebCore::Page::hiddenPageCSSAnimationSuspensionStateChanged):
    - m_isVisible -> isVisible()
* page/Page.h:
(WebCore::Page::isVisible):
(WebCore::Page::isInWindow):
    - Implemented in terms of ViewState.
(WebCore::Page::scriptedAnimationsSuspended):
    - Combined member fields into ViewState::Flags.

Source/WebKit/mac:

* WebView/WebView.mm:
(-[WebView _windowWillOrderOnScreen:]):
(-[WebView _windowWillOrderOffScreen:]):
    - remove calls to FocusController::setContentIsVisible, these are redundant
      (this is handled when page visibility is set).

Source/WebKit2:

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage):
    - Combined separate calls to Page::setViewState.
(WebKit::WebPage::updateIsInWindow):
    - Simplied from setIsInWindow.
(WebKit::WebPage::setViewState):
    - Combined separate calls to Page::setViewState.
* WebProcess/WebPage/WebPage.h:
    - Declare updateIsInWindow.

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

Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/page/FocusController.cpp
Source/WebCore/page/FocusController.h
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebView.mm
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h

index ee6578d..f76df29 100644 (file)
@@ -1,3 +1,66 @@
+2014-02-05  Gavin Barraclough  <barraclough@apple.com>
+
+        Change Page, FocusController to use ViewState
+        https://bugs.webkit.org/show_bug.cgi?id=126533
+
+        Reviewed by Tim Horton.
+
+        These classes currently maintain a set of separate fields to represent the view state;
+        combine these into a single field, and allow WebPage to send the combined update rather
+        than individual changes.
+
+        Maintain existing interface for WebKit1 clients.
+
+        * WebCore.exp.in:
+            - Added WebCore::setViewState, removed WebCore::setIsVisuallyIdle.
+        * page/FocusController.cpp:
+        (WebCore::FocusController::FocusController):
+            - Initialize combined m_viewState.
+        (WebCore::FocusController::setFocused):
+            - Calls setViewState.
+        (WebCore::FocusController::setFocusedInternal):
+            - setFocused -> setFocusedInternal.
+        (WebCore::FocusController::setViewState):
+            - Added, update all ViewState flags.
+        (WebCore::FocusController::setActive):
+            - Calls setViewState.
+        (WebCore::FocusController::setActiveInternal):
+            - setActive -> setActiveInternal.
+        (WebCore::FocusController::setContentIsVisible):
+            - Calls setViewState.
+        (WebCore::FocusController::setContentIsVisibleInternal):
+            - setContentIsVisible -> setContentIsVisibleInternal.
+        * page/FocusController.h:
+        (WebCore::FocusController::isActive):
+        (WebCore::FocusController::isFocused):
+        (WebCore::FocusController::contentIsVisible):
+            - Implemented in terms of ViewState.
+        * page/Page.cpp:
+        (WebCore::Page::Page):
+            - Initialize using PageInitialViewState.
+        (WebCore::Page::setIsInWindow):
+            - Calls setViewState.
+        (WebCore::Page::setIsInWindowInternal):
+            - setIsInWindow -> setIsInWindowInternal.
+        (WebCore::Page::setIsVisuallyIdleInternal):
+            - setIsVisuallyIdle -> setIsVisuallyIdleInternal.
+        (WebCore::Page::setViewState):
+            - Added, update all ViewState flags, including FocusController.
+        (WebCore::Page::setIsVisible):
+            - Calls setViewState.
+        (WebCore::Page::setIsVisibleInternal):
+            - setIsVisible -> setIsVisibleInternal.
+        (WebCore::Page::visibilityState):
+            - m_isVisible -> isVisible()
+        (WebCore::Page::hiddenPageCSSAnimationSuspensionStateChanged):
+            - m_isVisible -> isVisible()
+        * page/Page.h:
+        (WebCore::Page::isVisible):
+        (WebCore::Page::isInWindow):
+            - Implemented in terms of ViewState.
+        (WebCore::Page::scriptedAnimationsSuspended):
+            - Combined member fields into ViewState::Flags.
+
 2014-02-05  Simon Fraser  <simon.fraser@apple.com>
 
         Transfer the non-fast-scrollable region to the UI process for iOS
index e4df2fc..8ae2709 100644 (file)
@@ -483,7 +483,6 @@ __ZN7WebCore15FocusController10setFocusedEb
 __ZN7WebCore15FocusController15setFocusedFrameEN3WTF10PassRefPtrINS_5FrameEEE
 __ZN7WebCore15FocusController15setInitialFocusENS_14FocusDirectionEPNS_13KeyboardEventE
 __ZN7WebCore15FocusController17setFocusedElementEPNS_7ElementEN3WTF10PassRefPtrINS_5FrameEEENS_14FocusDirectionE
-__ZN7WebCore15FocusController19setContentIsVisibleEb
 __ZN7WebCore15FocusController9setActiveEb
 __ZN7WebCore15GraphicsContext10strokeRectERKNS_9FloatRectEf
 __ZN7WebCore15GraphicsContext11clearShadowEv
@@ -991,6 +990,7 @@ __ZN7WebCore4Page11PageClientsC1Ev
 __ZN7WebCore4Page11PageClientsD1Ev
 __ZN7WebCore4Page12setGroupNameERKN3WTF6StringE
 __ZN7WebCore4Page12setIsVisibleEbb
+__ZN7WebCore4Page12setViewStateEjb
 __ZN7WebCore4Page13rangeOfStringERKN3WTF6StringEPNS_5RangeEj
 __ZN7WebCore4Page13setIsInWindowEb
 __ZN7WebCore4Page13setPaginationERKNS_10PaginationE
@@ -1000,7 +1000,6 @@ __ZN7WebCore4Page15addSchedulePairEN3WTF10PassRefPtrINS1_12SchedulePairEEE
 __ZN7WebCore4Page16countFindMatchesERKN3WTF6StringEjj
 __ZN7WebCore4Page16setCanStartMediaEb
 __ZN7WebCore4Page16setDefersLoadingEb
-__ZN7WebCore4Page17setIsVisuallyIdleEb
 __ZN7WebCore4Page18removeSchedulePairEN3WTF10PassRefPtrINS1_12SchedulePairEEE
 __ZN7WebCore4Page18setPageScaleFactorEfRKNS_8IntPointE
 #if ENABLE(RUBBER_BANDING)
index 4b88dbd..69c4229 100644 (file)
@@ -158,12 +158,10 @@ static inline bool shouldVisit(Element& element, KeyboardEvent& event)
     return element.isKeyboardFocusable(&event) || isNonFocusableShadowHost(element, event);
 }
 
-FocusController::FocusController(Page& page)
+FocusController::FocusController(Page& page, ViewState::Flags viewState)
     : m_page(page)
-    , m_isActive(false)
-    , m_isFocused(false)
     , m_isChangingFocusedFrame(false)
-    , m_contentIsVisible(false)
+    , m_viewState(viewState)
 {
 }
 
@@ -205,12 +203,12 @@ Frame& FocusController::focusedOrMainFrame() const
 
 void FocusController::setFocused(bool focused)
 {
-    if (isFocused() == focused)
-        return;
-    
-    m_isFocused = focused;
+    m_page.setViewState(focused ? m_viewState | ViewState::IsFocused : m_viewState & ~ViewState::IsFocused);
+}
 
-    if (!m_isFocused)
+void FocusController::setFocusedInternal(bool focused)
+{
+    if (!isFocused())
         focusedOrMainFrame().eventHandler().stopAutoscrollTimer();
 
     if (!m_focusedFrame)
@@ -635,13 +633,26 @@ bool FocusController::setFocusedElement(Element* element, PassRefPtr<Frame> newF
     return true;
 }
 
-void FocusController::setActive(bool active)
+void FocusController::setViewState(ViewState::Flags viewState)
 {
-    if (m_isActive == active)
-        return;
+    ViewState::Flags changed = m_viewState ^ viewState;
+    m_viewState = viewState;
 
-    m_isActive = active;
+    if (changed & ViewState::IsFocused)
+        setFocusedInternal(viewState & ViewState::IsFocused);
+    if (changed & ViewState::WindowIsActive)
+        setActiveInternal(viewState & ViewState::WindowIsActive);
+    if (changed & ViewState::IsVisible)
+        setIsVisibleInternal(viewState & ViewState::IsVisible);
+}
 
+void FocusController::setActive(bool active)
+{
+    m_page.setViewState(active ? m_viewState | ViewState::WindowIsActive : m_viewState & ~ViewState::WindowIsActive);
+}
+
+void FocusController::setActiveInternal(bool active)
+{
     if (FrameView* view = m_page.mainFrame().view()) {
         if (!view->platformWidget()) {
             view->updateLayoutAndStyleIfNeededRecursive();
@@ -663,13 +674,8 @@ static void contentAreaDidShowOrHide(ScrollableArea* scrollableArea, bool didSho
         scrollableArea->contentAreaDidHide();
 }
 
-void FocusController::setContentIsVisible(bool contentIsVisible)
+void FocusController::setIsVisibleInternal(bool contentIsVisible)
 {
-    if (m_contentIsVisible == contentIsVisible)
-        return;
-
-    m_contentIsVisible = contentIsVisible;
-
     FrameView* view = m_page.mainFrame().view();
     if (!view)
         return;
index b991130..c6c2d47 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "FocusDirection.h"
 #include "LayoutRect.h"
+#include "ViewState.h"
 #include <wtf/Forward.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/RefPtr.h>
@@ -62,7 +63,7 @@ private:
 class FocusController {
     WTF_MAKE_NONCOPYABLE(FocusController); WTF_MAKE_FAST_ALLOCATED;
 public:
-    explicit FocusController(Page&);
+    explicit FocusController(Page&, ViewState::Flags);
 
     void setFocusedFrame(PassRefPtr<Frame>);
     Frame* focusedFrame() const { return m_focusedFrame.get(); }
@@ -73,19 +74,25 @@ public:
 
     bool setFocusedElement(Element*, PassRefPtr<Frame>, FocusDirection = FocusDirectionNone);
 
+    void setViewState(ViewState::Flags);
+
     void setActive(bool);
-    bool isActive() const { return m_isActive; }
+    bool isActive() const { return m_viewState & ViewState::WindowIsActive; }
 
     void setFocused(bool);
-    bool isFocused() const { return m_isFocused; }
+    bool isFocused() const { return m_viewState & ViewState::IsFocused; }
 
-    void setContentIsVisible(bool);
+    bool contentIsVisible() const { return m_viewState & ViewState::IsVisible; }
 
     // These methods are used in WebCore/bindings/objc/DOM.mm.
     Element* nextFocusableElement(FocusNavigationScope, Node* start, KeyboardEvent*);
     Element* previousFocusableElement(FocusNavigationScope, Node* start, KeyboardEvent*);
 
 private:
+    void setActiveInternal(bool);
+    void setFocusedInternal(bool);
+    void setIsVisibleInternal(bool);
+
     bool advanceFocusDirectionally(FocusDirection, KeyboardEvent*);
     bool advanceFocusInDocumentOrder(FocusDirection, KeyboardEvent*, bool initialFocus);
 
@@ -111,11 +118,8 @@ private:
 
     Page& m_page;
     RefPtr<Frame> m_focusedFrame;
-    bool m_isActive;
-    bool m_isFocused;
     bool m_isChangingFocusedFrame;
-    bool m_contentIsVisible;
-
+    ViewState::Flags m_viewState;
 };
 
 } // namespace WebCore
index 0058872..7854e5e 100644 (file)
@@ -124,13 +124,15 @@ float deviceScaleFactor(Frame* frame)
     return page->deviceScaleFactor();
 }
 
+static const ViewState::Flags PageInitialViewState = ViewState::IsVisible | ViewState::IsInWindow;
+
 Page::Page(PageClients& pageClients)
     : m_chrome(std::make_unique<Chrome>(*this, *pageClients.chromeClient))
     , m_dragCaretController(std::make_unique<DragCaretController>())
 #if ENABLE(DRAG_SUPPORT)
     , m_dragController(std::make_unique<DragController>(*this, *pageClients.dragClient))
 #endif
-    , m_focusController(std::make_unique<FocusController>(*this))
+    , m_focusController(std::make_unique<FocusController>(*this, PageInitialViewState))
 #if ENABLE(CONTEXT_MENUS)
     , m_contextMenuController(std::make_unique<ContextMenuController>(*this, *pageClients.contextMenuClient))
 #endif
@@ -172,9 +174,8 @@ Page::Page(PageClients& pageClients)
     , m_minimumTimerInterval(Settings::defaultMinDOMTimerInterval())
     , m_timerAlignmentInterval(Settings::defaultDOMTimerAlignmentInterval())
     , m_isEditable(false)
-    , m_isInWindow(true)
-    , m_isVisible(true)
     , m_isPrerender(false)
+    , m_viewState(PageInitialViewState)
     , m_requestedLayoutMilestones(0)
     , m_headerHeight(0)
     , m_footerHeight(0)
@@ -812,11 +813,11 @@ unsigned Page::pageCount() const
 
 void Page::setIsInWindow(bool isInWindow)
 {
-    if (m_isInWindow == isInWindow)
-        return;
-
-    m_isInWindow = isInWindow;
+    setViewState(isInWindow ? m_viewState | ViewState::IsInWindow : m_viewState & ~ViewState::IsInWindow);
+}
 
+void Page::setIsInWindowInternal(bool isInWindow)
+{
     for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
         if (FrameView* frameView = frame->view())
             frameView->setIsInWindow(isInWindow);
@@ -844,7 +845,7 @@ void Page::resumeScriptedAnimations()
     }
 }
 
-void Page::setIsVisuallyIdle(bool isVisuallyIdle)
+void Page::setIsVisuallyIdleInternal(bool isVisuallyIdle)
 {
     m_pageThrottler->setIsVisuallyIdle(isVisuallyIdle);
 }
@@ -1147,15 +1148,33 @@ void Page::resumeAnimatingImages()
         CachedImage::resumeAnimatingImagesForLoader(frame->document()->cachedResourceLoader());
 }
 
+void Page::setViewState(ViewState::Flags viewState, bool isInitialState)
+{
+    ViewState::Flags changed = m_viewState ^ viewState;
+    if (!changed)
+        return;
+
+    m_viewState = viewState;
+    m_focusController->setViewState(viewState);
+
+    if (changed & ViewState::IsVisible)
+        setIsVisibleInternal(viewState & ViewState::IsVisible, isInitialState);
+    if (changed & ViewState::IsInWindow)
+        setIsInWindowInternal(viewState & ViewState::IsInWindow);
+    if (changed & ViewState::IsVisuallyIdle)
+        setIsVisuallyIdleInternal(viewState & ViewState::IsVisuallyIdle);
+}
+
 void Page::setIsVisible(bool isVisible, bool isInitialState)
 {
+    setViewState(isVisible ? m_viewState | ViewState::IsVisible : m_viewState & ~ViewState::IsVisible, isInitialState);
+}
+
+void Page::setIsVisibleInternal(bool isVisible, bool isInitialState)
+{
     // FIXME: The visibility state should be stored on the top-level document.
     // https://bugs.webkit.org/show_bug.cgi?id=116769
 
-    if (m_isVisible == isVisible)
-        return;
-    m_isVisible = isVisible;
-
     if (isVisible) {
         m_isPrerender = false;
 
@@ -1221,7 +1240,7 @@ void Page::setIsPrerender()
 #if ENABLE(PAGE_VISIBILITY_API)
 PageVisibilityState Page::visibilityState() const
 {
-    if (m_isVisible)
+    if (isVisible())
         return PageVisibilityStateVisible;
     if (m_isPrerender)
         return PageVisibilityStatePrerender;
@@ -1483,7 +1502,7 @@ void Page::hiddenPageDOMTimerThrottlingStateChanged()
 #if (ENABLE_PAGE_VISIBILITY_API)
 void Page::hiddenPageCSSAnimationSuspensionStateChanged()
 {
-    if (!m_isVisible) {
+    if (!isVisible()) {
         if (m_settings->hiddenPageCSSAnimationSuspensionEnabled())
             mainFrame().animation().suspendAnimations();
         else
index f0b3317..6f48257 100644 (file)
@@ -31,6 +31,7 @@
 #include "PlatformScreen.h"
 #include "Region.h"
 #include "Supplementable.h"
+#include "ViewState.h"
 #include "ViewportArguments.h"
 #include <wtf/Forward.h>
 #include <wtf/HashMap.h>
@@ -289,18 +290,18 @@ public:
     unsigned pageCount() const;
 
     // Notifications when the Page starts and stops being presented via a native window.
+    void setViewState(ViewState::Flags, bool isInitial = false);
     void setIsVisible(bool isVisible, bool isInitial);
     void setIsPrerender();
-    bool isVisible() const { return m_isVisible; }
+    bool isVisible() const { return m_viewState & ViewState::IsVisible; }
 
     // Notification that this Page was moved into or out of a native window.
     void setIsInWindow(bool);
-    bool isInWindow() const { return m_isInWindow; }
+    bool isInWindow() const { return m_viewState & ViewState::IsInWindow; }
 
     void suspendScriptedAnimations();
     void resumeScriptedAnimations();
     bool scriptedAnimationsSuspended() const { return m_scriptedAnimationsSuspended; }
-    void setIsVisuallyIdle(bool);
 
     void userStyleSheetLocationChanged();
     const String& userStyleSheet() const;
@@ -417,6 +418,10 @@ public:
 private:
     void initGroup();
 
+    void setIsInWindowInternal(bool);
+    void setIsVisibleInternal(bool isVisible, bool isInitial);
+    void setIsVisuallyIdleInternal(bool);
+
 #if ASSERT_DISABLED
     void checkSubframeCountConsistency() const { }
 #else
@@ -520,9 +525,8 @@ private:
     double m_timerAlignmentInterval;
 
     bool m_isEditable;
-    bool m_isInWindow;
-    bool m_isVisible;
     bool m_isPrerender;
+    ViewState::Flags m_viewState;
 
     LayoutMilestones m_requestedLayoutMilestones;
 
index f8ae6cf..f556665 100644 (file)
@@ -1,3 +1,22 @@
+2014-02-05  Gavin Barraclough  <barraclough@apple.com>
+
+        Change Page, FocusController to use ViewState
+        https://bugs.webkit.org/show_bug.cgi?id=126533
+
+        Reviewed by Tim Horton.
+
+        These classes currently maintain a set of separate fields to represent the view state;
+        combine these into a single field, and allow WebPage to send the combined update rather
+        than individual changes.
+
+        Maintain existing interface for WebKit1 clients.
+
+        * WebView/WebView.mm:
+        (-[WebView _windowWillOrderOnScreen:]):
+        (-[WebView _windowWillOrderOffScreen:]):
+            - remove calls to FocusController::setContentIsVisible, these are redundant
+              (this is handled when page visibility is set).
+
 2014-02-05  Andreas Kling  <akling@apple.com>
 
         Remove ENABLE(DIRECTORY_UPLOAD).
index d50487c..6f6000e 100644 (file)
@@ -5352,7 +5352,7 @@ static NSString * const backingPropertyOldScaleFactorKey = @"NSBackingPropertyOl
 
     if (_private && _private->page) {
         _private->page->resumeScriptedAnimations();
-        _private->page->focusController().setContentIsVisible(true);
+        _private->page->setIsVisible(true, false);
     }
 }
 
@@ -5365,7 +5365,7 @@ static NSString * const backingPropertyOldScaleFactorKey = @"NSBackingPropertyOl
 {
     if (_private && _private->page) {
         _private->page->suspendScriptedAnimations();
-        _private->page->focusController().setContentIsVisible(false);
+        _private->page->setIsVisible(false, false);
     }
 }
 
index 2c2ad76..3986284 100644 (file)
@@ -1,3 +1,26 @@
+2014-02-05  Gavin Barraclough  <barraclough@apple.com>
+
+        Change Page, FocusController to use ViewState
+        https://bugs.webkit.org/show_bug.cgi?id=126533
+
+        Reviewed by Tim Horton.
+
+        These classes currently maintain a set of separate fields to represent the view state;
+        combine these into a single field, and allow WebPage to send the combined update rather
+        than individual changes.
+
+        Maintain existing interface for WebKit1 clients.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::WebPage):
+            - Combined separate calls to Page::setViewState.
+        (WebKit::WebPage::updateIsInWindow):
+            - Simplied from setIsInWindow.
+        (WebKit::WebPage::setViewState):
+            - Combined separate calls to Page::setViewState.
+        * WebProcess/WebPage/WebPage.h:
+            - Declare updateIsInWindow.
+
 2014-02-05  Zan Dobersek  <zdobersek@igalia.com>
 
         Unreviewed GTK build fix after r163480.
index 82635d1..2890598 100644 (file)
@@ -379,17 +379,8 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
 
     setMemoryCacheMessagesEnabled(parameters.areMemoryCacheClientCallsEnabled);
 
-    setActive(parameters.viewState & ViewState::WindowIsActive);
-    setFocused(parameters.viewState & ViewState::IsFocused);
-
-    // Page defaults to in-window, but setIsInWindow depends on it being a valid indicator of actually having been put into a window.
-    bool isInWindow = parameters.viewState & ViewState::IsInWindow;
-    if (!isInWindow)
-        m_page->setIsInWindow(false);
-    else
-        WebProcess::shared().pageDidEnterWindow(m_pageID);
-
-    setIsInWindow(isInWindow);
+    m_page->setViewState(m_viewState, true);
+    updateIsInWindow(true);
 
     setMinimumLayoutSize(parameters.minimumLayoutSize);
     setAutoSizingShouldExpandToViewHeight(parameters.autoSizingShouldExpandToViewHeight);
@@ -433,9 +424,6 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
     if (m_useAsyncScrolling)
         WebProcess::shared().eventDispatcher().addScrollingTreeForPage(this);
 #endif
-
-    m_page->setIsVisible(m_viewState & ViewState::IsVisible, true);
-    setIsVisuallyIdle(m_viewState & ViewState::IsVisuallyIdle);
 }
 
 void WebPage::reinitializeWebPage(const WebPageCreationParameters& parameters)
@@ -1934,18 +1922,6 @@ void WebPage::centerSelectionInVisibleArea()
     m_findController.showFindIndicatorInSelection();
 }
 
-void WebPage::setActive(bool isActive)
-{
-    m_page->focusController().setActive(isActive);
-}
-
-void WebPage::setViewIsVisible(bool isVisible)
-{
-    corePage()->focusController().setContentIsVisible(isVisible);
-
-    m_page->setIsVisible(m_viewState & ViewState::IsVisible, false);
-}
-
 void WebPage::setDrawsBackground(bool drawsBackground)
 {
     if (m_drawsBackground == drawsBackground)
@@ -2001,11 +1977,6 @@ void WebPage::viewWillEndLiveResize()
         view->willEndLiveResize();
 }
 
-void WebPage::setFocused(bool isFocused)
-{
-    m_page->focusController().setFocused(isFocused);
-}
-
 void WebPage::setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent& event)
 {
     if (!m_page)
@@ -2060,15 +2031,16 @@ inline bool WebPage::canHandleUserEvents() const
     return true;
 }
 
-void WebPage::setIsInWindow(bool isInWindow)
+void WebPage::updateIsInWindow(bool isInitialState)
 {
-    bool pageWasInWindow = m_page->isInWindow();
-    
+    bool isInWindow = m_viewState & WebCore::ViewState::IsInWindow;
+
     if (!isInWindow) {
         m_setCanStartMediaTimer.stop();
         m_page->setCanStartMedia(false);
         
-        if (pageWasInWindow)
+        // The WebProcess does not yet know about this page; no need to tell it we're leaving the window.
+        if (!isInitialState)
             WebProcess::shared().pageWillLeaveWindow(m_pageID);
     } else {
         // Defer the call to Page::setCanStartMedia() since it ends up sending a synchronous message to the UI process
@@ -2077,12 +2049,9 @@ void WebPage::setIsInWindow(bool isInWindow)
         if (m_mayStartMediaWhenInWindow)
             m_setCanStartMediaTimer.startOneShot(0);
 
-        if (!pageWasInWindow)
-            WebProcess::shared().pageDidEnterWindow(m_pageID);
+        WebProcess::shared().pageDidEnterWindow(m_pageID);
     }
 
-    m_page->setIsInWindow(isInWindow);
-
     if (isInWindow)
         layoutIfNeeded();
 }
@@ -2101,24 +2070,12 @@ void WebPage::setViewStateInternal(ViewState::Flags viewState, bool isInitialSta
     m_viewState = viewState;
 
     m_drawingArea->viewStateDidChange(changed);
-
-    // We want to make sure to update the active state while hidden, so if the view is hidden then update the active state
-    // early (in case it becomes visible), and if the view was visible then update active state later (in case it hides).
-    if (changed & ViewState::IsFocused)
-        setFocused(viewState & ViewState::IsFocused);
-    if (changed & ViewState::WindowIsActive && !(m_viewState & ViewState::IsVisible))
-        setActive(viewState & ViewState::WindowIsActive);
-    if (changed & ViewState::IsVisible)
-        setViewIsVisible(viewState & ViewState::IsVisible);
-    if (changed & ViewState::WindowIsActive && m_viewState & ViewState::IsVisible)
-        setActive(viewState & ViewState::WindowIsActive);
-    if (changed & ViewState::IsInWindow)
-         setIsInWindow(viewState & ViewState::IsInWindow);
-    if (changed & ViewState::IsVisuallyIdle)
-        setIsVisuallyIdle(viewState & ViewState::IsVisuallyIdle);
-
+    m_page->setViewState(viewState, isInitialState);
     for (auto* pluginView : m_pluginViews)
         pluginView->viewStateDidChange(changed);
+
+    if (changed & ViewState::IsInWindow)
+        updateIsInWindow();
 }
 
 void WebPage::setLayerHostingMode(unsigned layerHostingMode)
@@ -3749,11 +3706,6 @@ void WebPage::setVisibilityStatePrerender()
         m_page->setIsPrerender();
 }
 
-void WebPage::setIsVisuallyIdle(bool isVisuallyIdle)
-{
-    m_page->setIsVisuallyIdle(isVisuallyIdle);
-}
-
 void WebPage::setScrollingPerformanceLoggingEnabled(bool enabled)
 {
     m_scrollingPerformanceLoggingEnabled = enabled;
index c6fa990..f5490c1 100644 (file)
@@ -754,8 +754,7 @@ private:
     void setViewIsVisible(bool);
     void setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent&);
     void setWindowResizerSize(const WebCore::IntSize&);
-    void setIsInWindow(bool);
-    void setIsVisuallyIdle(bool);
+    void updateIsInWindow(bool isInitialState = false);
     void setViewState(WebCore::ViewState::Flags, bool wantsDidUpdateViewState);
     void setViewStateInternal(WebCore::ViewState::Flags, bool isInitialState);
     void validateCommand(const String&, uint64_t);