2011-01-10 Anders Carlsson <andersca@apple.com>
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Jan 2011 00:45:52 +0000 (00:45 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Jan 2011 00:45:52 +0000 (00:45 +0000)
        Reviewed by Sam Weinig.

        Use a pull model for view state changes
        https://bugs.webkit.org/show_bug.cgi?id=52175

        Instead of having the WKView call setFocused, setActive etc on the WebPageProxy, the
        WKView now simply informs the WebPageProxy what has changed, using the WebPageProxy::viewStateDidChange
        function. The WebPageProxy can then fetch the relevant information using newly added PageClient functions.

        * UIProcess/API/mac/PageClientImpl.h:
        * UIProcess/API/mac/PageClientImpl.mm:
        (WebKit::PageClientImpl::viewSize):
        (WebKit::PageClientImpl::isViewWindowActive):
        (WebKit::PageClientImpl::isViewFocused):
        (WebKit::PageClientImpl::isViewVisible):
        (WebKit::PageClientImpl::isViewInWindow):
        * UIProcess/API/mac/WKView.mm:
        (-[WKView initWithFrame:contextRef:pageGroupRef:]):
        (-[WKView becomeFirstResponder]):
        (-[WKView resignFirstResponder]):
        (-[WKView viewDidMoveToWindow]):
        (-[WKView _windowDidBecomeKey:]):
        (-[WKView _windowDidResignKey:]):
        (-[WKView viewDidHide]):
        (-[WKView viewDidUnhide]):
        (-[WKView _isFocused]):
        (-[WKView _didRelaunchProcess]):
        * UIProcess/API/mac/WKViewInternal.h:
        * UIProcess/API/qt/qgraphicswkview.cpp:
        (QGraphicsWKView::focusInEvent):
        (QGraphicsWKView::focusOutEvent):
        * UIProcess/API/qt/qwkpage.cpp:
        (QWKPagePrivate::QWKPagePrivate):
        (QWKPagePrivate::viewSize):
        (QWKPagePrivate::isViewWindowActive):
        (QWKPagePrivate::isViewFocused):
        (QWKPagePrivate::isViewVisible):
        (QWKPagePrivate::isViewInWindow):
        * UIProcess/API/qt/qwkpage_p.h:
        * UIProcess/PageClient.h:
        * UIProcess/WebContext.cpp:
        (WebKit::WebContext::createWebPage):
        * UIProcess/WebContext.h:
        * UIProcess/WebPageProxy.cpp:
        (WebKit::WebPageProxy::create):
        (WebKit::WebPageProxy::WebPageProxy):
        (WebKit::WebPageProxy::viewStateDidChange):
        * UIProcess/WebPageProxy.h:
        * UIProcess/WebProcessProxy.cpp:
        (WebKit::WebProcessProxy::createWebPage):
        * UIProcess/WebProcessProxy.h:
        * UIProcess/win/WebView.cpp:
        (WebKit::WebView::WebView):
        (WebKit::WebView::onSetFocusEvent):
        (WebKit::WebView::onKillFocusEvent):
        (WebKit::WebView::onShowWindowEvent):
        (WebKit::WebView::updateActiveState):
        (WebKit::WebView::viewSize):
        (WebKit::WebView::isViewWindowActive):
        (WebKit::WebView::isViewFocused):
        (WebKit::WebView::isViewVisible):
        (WebKit::WebView::isViewInWindow):
        (WebKit::WebView::didRelaunchProcess):
        (WebKit::WebView::setIsInWindow):
        * UIProcess/win/WebView.h:

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

17 files changed:
WebKit2/ChangeLog
WebKit2/UIProcess/API/mac/PageClientImpl.h
WebKit2/UIProcess/API/mac/PageClientImpl.mm
WebKit2/UIProcess/API/mac/WKView.mm
WebKit2/UIProcess/API/mac/WKViewInternal.h
WebKit2/UIProcess/API/qt/qgraphicswkview.cpp
WebKit2/UIProcess/API/qt/qwkpage.cpp
WebKit2/UIProcess/API/qt/qwkpage_p.h
WebKit2/UIProcess/PageClient.h
WebKit2/UIProcess/WebContext.cpp
WebKit2/UIProcess/WebContext.h
WebKit2/UIProcess/WebPageProxy.cpp
WebKit2/UIProcess/WebPageProxy.h
WebKit2/UIProcess/WebProcessProxy.cpp
WebKit2/UIProcess/WebProcessProxy.h
WebKit2/UIProcess/win/WebView.cpp
WebKit2/UIProcess/win/WebView.h

index 963274c..6cee045 100644 (file)
@@ -1,3 +1,71 @@
+2011-01-10  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Use a pull model for view state changes
+        https://bugs.webkit.org/show_bug.cgi?id=52175
+
+        Instead of having the WKView call setFocused, setActive etc on the WebPageProxy, the
+        WKView now simply informs the WebPageProxy what has changed, using the WebPageProxy::viewStateDidChange
+        function. The WebPageProxy can then fetch the relevant information using newly added PageClient functions.
+
+        * UIProcess/API/mac/PageClientImpl.h:
+        * UIProcess/API/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::viewSize):
+        (WebKit::PageClientImpl::isViewWindowActive):
+        (WebKit::PageClientImpl::isViewFocused):
+        (WebKit::PageClientImpl::isViewVisible):
+        (WebKit::PageClientImpl::isViewInWindow):
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView initWithFrame:contextRef:pageGroupRef:]):
+        (-[WKView becomeFirstResponder]):
+        (-[WKView resignFirstResponder]):
+        (-[WKView viewDidMoveToWindow]):
+        (-[WKView _windowDidBecomeKey:]):
+        (-[WKView _windowDidResignKey:]):
+        (-[WKView viewDidHide]):
+        (-[WKView viewDidUnhide]):
+        (-[WKView _isFocused]):
+        (-[WKView _didRelaunchProcess]):
+        * UIProcess/API/mac/WKViewInternal.h:
+        * UIProcess/API/qt/qgraphicswkview.cpp:
+        (QGraphicsWKView::focusInEvent):
+        (QGraphicsWKView::focusOutEvent):
+        * UIProcess/API/qt/qwkpage.cpp:
+        (QWKPagePrivate::QWKPagePrivate):
+        (QWKPagePrivate::viewSize):
+        (QWKPagePrivate::isViewWindowActive):
+        (QWKPagePrivate::isViewFocused):
+        (QWKPagePrivate::isViewVisible):
+        (QWKPagePrivate::isViewInWindow):
+        * UIProcess/API/qt/qwkpage_p.h:
+        * UIProcess/PageClient.h:
+        * UIProcess/WebContext.cpp:
+        (WebKit::WebContext::createWebPage):
+        * UIProcess/WebContext.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::create):
+        (WebKit::WebPageProxy::WebPageProxy):
+        (WebKit::WebPageProxy::viewStateDidChange):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::createWebPage):
+        * UIProcess/WebProcessProxy.h:
+        * UIProcess/win/WebView.cpp:
+        (WebKit::WebView::WebView):
+        (WebKit::WebView::onSetFocusEvent):
+        (WebKit::WebView::onKillFocusEvent):
+        (WebKit::WebView::onShowWindowEvent):
+        (WebKit::WebView::updateActiveState):
+        (WebKit::WebView::viewSize):
+        (WebKit::WebView::isViewWindowActive):
+        (WebKit::WebView::isViewFocused):
+        (WebKit::WebView::isViewVisible):
+        (WebKit::WebView::isViewInWindow):
+        (WebKit::WebView::didRelaunchProcess):
+        (WebKit::WebView::setIsInWindow):
+        * UIProcess/win/WebView.h:
+
 2011-01-10  Adam Roben  <aroben@apple.com>
 
         Don't pass a reference type to va_start
index 888129c..a8752c0 100644 (file)
@@ -48,6 +48,12 @@ public:
 private:
     PageClientImpl(WKView*);
 
+    virtual WebCore::IntSize viewSize();
+    virtual bool isViewWindowActive();
+    virtual bool isViewFocused();
+    virtual bool isViewVisible();
+    virtual bool isViewInWindow();
+    
     virtual void processDidCrash();
     virtual void didRelaunchProcess();
     virtual void takeFocus(bool direction);
index b401078..8779f2f 100644 (file)
@@ -118,6 +118,37 @@ PageClientImpl::~PageClientImpl()
 {
 }
 
+IntSize PageClientImpl::viewSize()
+{
+    return IntSize([m_wkView bounds].size);
+}
+
+bool PageClientImpl::isViewWindowActive()
+{
+    return [[m_wkView window] isKeyWindow];
+}
+
+bool PageClientImpl::isViewFocused()
+{
+    return [m_wkView _isFocused];
+}
+
+bool PageClientImpl::isViewVisible()
+{
+    if (![m_wkView window])
+        return false;
+
+    if ([m_wkView isHiddenOrHasHiddenAncestor])
+        return false;
+
+    return true;
+}
+
+bool PageClientImpl::isViewInWindow()
+{
+    return [m_wkView window];
+}
+
 void PageClientImpl::processDidCrash()
 {
     [m_wkView _processDidCrash];
index 1186d55..401a034 100644 (file)
@@ -120,6 +120,9 @@ typedef HashMap<String, ValidationVector> ValidationMap;
     Vector<CompositionUnderline> _underlines;
     unsigned _selectionStart;
     unsigned _selectionEnd;
+
+    bool _inBecomeFirstResponder;
+    bool _inResignFirstResponder;
 }
 @end
 
@@ -162,11 +165,9 @@ typedef HashMap<String, ValidationVector> ValidationMap;
     _data = [[WKViewData alloc] init];
 
     _data->_pageClient = PageClientImpl::create(self);
-    _data->_page = toImpl(contextRef)->createWebPage(toImpl(pageGroupRef));
-    _data->_page->setPageClient(_data->_pageClient.get());
+    _data->_page = toImpl(contextRef)->createWebPage(_data->_pageClient.get(), toImpl(pageGroupRef));
     _data->_page->setDrawingArea(ChunkedUpdateDrawingAreaProxy::create(self, _data->_page.get()));
     _data->_page->initializeWebPage(IntSize(frame.size));
-    _data->_page->setIsInWindow([self window]);
 
     WebContext::statistics().wkViewCount++;
 
@@ -224,7 +225,9 @@ typedef HashMap<String, ValidationVector> ValidationMap;
 {
     NSSelectionDirection direction = [[self window] keyViewSelectionDirection];
 
-    _data->_page->setFocused(true);
+    _data->_inBecomeFirstResponder = true;
+    _data->_page->viewStateDidChange(WebPageProxy::ViewIsFocused);
+    _data->_inBecomeFirstResponder = false;
 
     if (direction != NSDirectSelection)
         _data->_page->setInitialFocus(direction == NSSelectingNext);
@@ -234,7 +237,10 @@ typedef HashMap<String, ValidationVector> ValidationMap;
 
 - (BOOL)resignFirstResponder
 {
-    _data->_page->setFocused(false);
+    _data->_inResignFirstResponder = true;
+    _data->_page->viewStateDidChange(WebPageProxy::ViewIsFocused);
+    _data->_inResignFirstResponder = false;
+
     return YES;
 }
 
@@ -961,11 +967,6 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde
     return resultRect;
 }
 
-- (void)_updateActiveState
-{
-    _data->_page->setActive([[self window] isKeyWindow]);
-}
-
 - (void)_updateWindowVisibility
 {
     _data->_page->updateWindowIsVisible(![[self window] isMiniaturized]);
@@ -1045,24 +1046,6 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde
     [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidResizeNotification object:window];
 }
 
-static bool isViewVisible(NSView *view)
-{
-    if (![view window])
-        return false;
-    
-    if ([view isHiddenOrHasHiddenAncestor])
-        return false;
-    
-    return true;
-}
-
-- (void)_updateVisibility
-{
-    _data->_page->setIsInWindow([self window]);
-    if (DrawingAreaProxy* area = _data->_page->drawingArea())
-        area->setPageIsVisible(isViewVisible(self));
-}
-
 - (void)viewWillMoveToWindow:(NSWindow *)window
 {
     if (window != [self window]) {
@@ -1077,13 +1060,13 @@ static bool isViewVisible(NSView *view)
     // update the active state first and then make it visible. If the view is about to be hidden, we hide it first and then
     // update the active state.
     if ([self window]) {
-        [self _updateActiveState];
-        [self _updateVisibility];
+        _data->_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive);
+        _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible | WebPageProxy::ViewIsInWindow);
         [self _updateWindowVisibility];
         [self _updateWindowAndViewFrames];
     } else {
-        [self _updateVisibility];
-        [self _updateActiveState];
+        _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible);
+        _data->_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive | WebPageProxy::ViewIsInWindow);
     }
 
 }
@@ -1092,14 +1075,14 @@ static bool isViewVisible(NSView *view)
 {
     NSWindow *keyWindow = [notification object];
     if (keyWindow == [self window] || keyWindow == [[self window] attachedSheet])
-        [self _updateActiveState];
+        _data->_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive);
 }
 
 - (void)_windowDidResignKey:(NSNotification *)notification
 {
     NSWindow *formerKeyWindow = [notification object];
     if (formerKeyWindow == [self window] || formerKeyWindow == [[self window] attachedSheet])
-        [self _updateActiveState];
+        _data->_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive);
 }
 
 - (void)_windowDidMiniaturize:(NSNotification *)notification
@@ -1136,12 +1119,12 @@ static bool isViewVisible(NSView *view)
 
 - (void)viewDidHide
 {
-    [self _updateVisibility];
+    _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible);
 }
 
 - (void)viewDidUnhide
 {
-    [self _updateVisibility];
+    _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible);
 }
 
 - (void)_setAccessibilityChildToken:(NSData *)data
@@ -1216,6 +1199,15 @@ static bool isViewVisible(NSView *view)
 
 @implementation WKView (Internal)
 
+- (BOOL)_isFocused
+{
+    if (_data->_inBecomeFirstResponder)
+        return YES;
+    if (_data->_inResignFirstResponder)
+        return NO;
+    return [[self window] firstResponder] == self;
+}
+
 - (void)_processDidCrash
 {
     [self setNeedsDisplay:YES];
@@ -1224,9 +1216,6 @@ static bool isViewVisible(NSView *view)
 - (void)_didRelaunchProcess
 {
     _data->_page->reinitializeWebPage(IntSize([self bounds].size));
-
-    _data->_page->setActive([[self window] isKeyWindow]);
-    _data->_page->setFocused([[self window] firstResponder] == self);
     
     [self setNeedsDisplay:YES];
 }
index 8cc72d6..4939d91 100644 (file)
@@ -32,6 +32,7 @@ namespace WebKit {
 }
 
 @interface WKView (Internal)
+- (BOOL)_isFocused;
 - (void)_processDidCrash;
 - (void)_didRelaunchProcess;
 - (void)_takeFocus:(BOOL)direction;
index 9f15717..4a2e6b1 100644 (file)
@@ -328,14 +328,12 @@ void QGraphicsWKView::touchEvent(QTouchEvent* ev)
 
 void QGraphicsWKView::focusInEvent(QFocusEvent*)
 {
-    page()->d->page->setActive(true);
-    page()->d->page->setFocused(true);
+    page()->d->page->viewStateDidChange(WebPageProxy::ViewIsFocused | WebPageProxy::ViewWindowIsActive);
 }
 
 void QGraphicsWKView::focusOutEvent(QFocusEvent*)
 {
-    page()->d->page->setFocused(false);
-    page()->d->page->setActive(false);
+    page()->d->page->viewStateDidChange(WebPageProxy::ViewIsFocused | WebPageProxy::ViewWindowIsActive);
 }
 
 void QGraphicsWKView::showContextMenu(QMenu* menu)
index f0a0c56..fa8f8ee 100644 (file)
@@ -86,8 +86,7 @@ QWKPagePrivate::QWKPagePrivate(QWKPage* qq, QWKContext* c)
     , createNewPageFn(0)
 {
     memset(actions, 0, sizeof(actions));
-    page = context->d->context->createWebPage(0);
-    page->setPageClient(this);
+    page = context->d->context->createWebPage(this, 0);
     history = QWKHistoryPrivate::createHistory(page->backForwardList());
 }
 
@@ -121,6 +120,36 @@ void QWKPagePrivate::takeFocus(bool direction)
     emit q->focusNextPrevChild(direction);
 }
 
+WebCore::IntSize QWKPagePrivate::viewSize()
+{
+    // FIXME: Implement.
+    return WebCore::IntSize();
+}
+
+bool QWKPagePrivate::isViewWindowActive()
+{
+    // FIXME: Implement.
+    return true;
+}
+
+bool QWKPagePrivate::isViewFocused()
+{
+    // FIXME: Implement.
+    return true;
+}
+
+bool QWKPagePrivate::isViewVisible()
+{
+    // FIXME: Implement.
+    return true;
+}
+
+bool QWKPagePrivate::isViewInWindow()
+{
+    // FIXME: Implement.
+    return true;
+}
+
 void QWKPagePrivate::pageDidRequestScroll(const IntSize& delta)
 {
     emit q->scrollRequested(delta.width(), delta.height());
index b0d0a30..bbae5d6 100644 (file)
@@ -43,6 +43,12 @@ public:
     void init(const QSize& viewportSize, WTF::PassOwnPtr<WebKit::DrawingAreaProxy>);
 
     // PageClient
+    virtual WebCore::IntSize viewSize();
+    virtual bool isViewWindowActive();
+    virtual bool isViewFocused();
+    virtual bool isViewVisible();
+    virtual bool isViewInWindow();
+
 #if USE(ACCELERATED_COMPOSITING)
     void pageDidEnterAcceleratedCompositing() { }
     void pageDidLeaveAcceleratedCompositing() { }
index 40decc1..2af6677 100644 (file)
@@ -48,6 +48,21 @@ class PageClient {
 public:
     virtual ~PageClient() { }
 
+    // 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 in a window.
+    virtual bool isViewInWindow() = 0;
+    
     virtual void processDidCrash() = 0;
     virtual void didRelaunchProcess() = 0;
 
index 84b8eac..2c75cf2 100644 (file)
@@ -242,14 +242,14 @@ void WebContext::processDidClose(WebProcessProxy* process)
     m_process = 0;
 }
 
-WebPageProxy* WebContext::createWebPage(WebPageGroup* pageGroup)
+WebPageProxy* WebContext::createWebPage(PageClient* pageClient, WebPageGroup* pageGroup)
 {
     ensureWebProcess();
 
     if (!pageGroup)
         pageGroup = m_defaultPageGroup.get();
 
-    return m_process->createWebPage(this, pageGroup);
+    return m_process->createWebPage(pageClient, this, pageGroup);
 }
 
 void WebContext::relaunchProcessIfNecessary()
index 1217e0a..9996198 100644 (file)
@@ -71,7 +71,7 @@ public:
     void processDidFinishLaunching(WebProcessProxy*);
     void processDidClose(WebProcessProxy*);
 
-    WebPageProxy* createWebPage(WebPageGroup* = 0);
+    WebPageProxy* createWebPage(PageClient*, WebPageGroup*);
 
     void relaunchProcessIfNecessary();
 
index a5985dd..f232fb9 100644 (file)
@@ -85,19 +85,20 @@ namespace WebKit {
 static WTF::RefCountedLeakCounter webPageProxyCounter("WebPageProxy");
 #endif
 
-PassRefPtr<WebPageProxy> WebPageProxy::create(WebContext* context, WebPageGroup* pageGroup, uint64_t pageID)
+PassRefPtr<WebPageProxy> WebPageProxy::create(PageClient* pageClient, WebContext* context, WebPageGroup* pageGroup, uint64_t pageID)
 {
-    return adoptRef(new WebPageProxy(context, pageGroup, pageID));
+    return adoptRef(new WebPageProxy(pageClient, context, pageGroup, pageID));
 }
 
-WebPageProxy::WebPageProxy(WebContext* context, WebPageGroup* pageGroup, uint64_t pageID)
-    : m_pageClient(0)
+WebPageProxy::WebPageProxy(PageClient* pageClient, WebContext* context, WebPageGroup* pageGroup, uint64_t pageID)
+    : m_pageClient(pageClient)
     , m_context(context)
     , m_pageGroup(pageGroup)
     , m_mainFrame(0)
     , m_userAgent(standardUserAgent())
     , m_estimatedProgress(0)
-    , m_isInWindow(false)
+    , m_isInWindow(m_pageClient->isViewInWindow())
+    , m_isVisible(m_pageClient->isViewVisible())
     , m_backForwardList(WebBackForwardList::create(this))
     , m_textZoomFactor(1)
     , m_pageZoomFactor(1)
@@ -158,11 +159,6 @@ bool WebPageProxy::isValid()
     return m_isValid;
 }
 
-void WebPageProxy::setPageClient(PageClient* pageClient)
-{
-    m_pageClient = pageClient;
-}
-
 void WebPageProxy::setDrawingArea(PassOwnPtr<DrawingAreaProxy> drawingArea)
 {
     if (drawingArea == m_drawingArea)
@@ -445,11 +441,32 @@ void WebPageProxy::setDrawsTransparentBackground(bool drawsTransparentBackground
         process()->send(Messages::WebPage::SetDrawsTransparentBackground(drawsTransparentBackground), m_pageID);
 }
 
-void WebPageProxy::setFocused(bool isFocused)
+void WebPageProxy::viewStateDidChange(ViewStateFlags flags)
 {
     if (!isValid())
         return;
-    process()->send(Messages::WebPage::SetFocused(isFocused), m_pageID);
+
+    if (flags & ViewIsFocused)
+        process()->send(Messages::WebPage::SetFocused(m_pageClient->isViewFocused()), m_pageID);
+
+    if (flags & ViewWindowIsActive)
+        process()->send(Messages::WebPage::SetActive(m_pageClient->isViewWindowActive()), m_pageID);
+
+    if (flags & ViewIsVisible) {
+        bool isVisible = m_pageClient->isViewVisible();
+        if (isVisible != m_isVisible) {
+            m_isVisible = isVisible;
+            m_drawingArea->setPageIsVisible(isVisible);
+        }
+    }
+
+    if (flags & ViewIsInWindow) {
+        bool isInWindow = m_pageClient->isViewInWindow();
+        if (m_isInWindow != isInWindow) {
+            m_isInWindow = isInWindow;
+            process()->send(Messages::WebPage::SetIsInWindow(isInWindow), m_pageID);
+        }
+    }
 }
 
 void WebPageProxy::setInitialFocus(bool forward)
@@ -459,13 +476,6 @@ void WebPageProxy::setInitialFocus(bool forward)
     process()->send(Messages::WebPage::SetInitialFocus(forward), m_pageID);
 }
 
-void WebPageProxy::setActive(bool active)
-{
-    if (!isValid())
-        return;
-    process()->send(Messages::WebPage::SetActive(active), m_pageID);
-}
-
 void WebPageProxy::setWindowResizerSize(const IntSize& windowResizerSize)
 {
     if (!isValid())
@@ -488,17 +498,6 @@ void WebPageProxy::executeEditCommand(const String& commandName)
     process()->send(Messages::WebPage::ExecuteEditCommand(commandName), m_pageID);
 }
     
-void WebPageProxy::setIsInWindow(bool isInWindow)
-{
-    if (m_isInWindow == isInWindow)
-        return;
-    
-    m_isInWindow = isInWindow;
-    if (!isValid())
-        return;
-    process()->send(Messages::WebPage::SetIsInWindow(isInWindow), m_pageID);
-}
-
 #if PLATFORM(MAC)
 void WebPageProxy::updateWindowIsVisible(bool windowIsVisible)
 {
index e3d7ffe..193d3e3 100644 (file)
@@ -106,8 +106,7 @@ class WebPageProxy : public APIObject, public WebPopupMenuProxy::Client {
 public:
     static const Type APIType = TypePage;
 
-    static PassRefPtr<WebPageProxy> create(WebContext*, WebPageGroup*, uint64_t pageID);
-
+    static PassRefPtr<WebPageProxy> create(PageClient*, WebContext*, WebPageGroup*, uint64_t pageID);
     virtual ~WebPageProxy();
 
     uint64_t pageID() const { return m_pageID; }
@@ -125,7 +124,6 @@ public:
     WebInspectorProxy* inspector();
 #endif
 
-    void setPageClient(PageClient*);
     void initializeContextMenuClient(const WKPageContextMenuClient*);
     void initializeFindClient(const WKPageFindClient*);
     void initializeFormClient(const WKPageFormClient*);
@@ -167,12 +165,18 @@ public:
     bool drawsTransparentBackground() const { return m_drawsTransparentBackground; }
     void setDrawsTransparentBackground(bool);
 
-    void setFocused(bool);
     void setInitialFocus(bool);
-    void setActive(bool);
-    void setIsInWindow(bool);
     void setWindowResizerSize(const WebCore::IntSize&);
 
+    enum {
+        ViewWindowIsActive = 1 << 0,
+        ViewIsFocused = 1 << 1,
+        ViewIsVisible = 1 << 2,
+        ViewIsInWindow = 1 << 3
+    };
+    typedef unsigned ViewStateFlags;
+    void viewStateDidChange(ViewStateFlags flags);
+
     void executeEditCommand(const String& commandName);
     void validateMenuItem(const String& commandName);
 
@@ -318,7 +322,7 @@ public:
 #endif
 
 private:
-    WebPageProxy(WebContext*, WebPageGroup*, uint64_t pageID);
+    WebPageProxy(PageClient*, WebContext*, WebPageGroup*, uint64_t pageID);
 
     virtual Type type() const { return APIType; }
 
@@ -520,6 +524,9 @@ private:
     // Whether the web page is contained in a top-level window.
     bool m_isInWindow;
 
+    // Whether the page is visible; if the backing view is visible and inserted into a window.
+    bool m_isVisible;
+
     bool m_canGoBack;
     bool m_canGoForward;
     RefPtr<WebBackForwardList> m_backForwardList;
index 063bbcc..c7e9382 100644 (file)
@@ -144,12 +144,12 @@ WebPageProxy* WebProcessProxy::webPage(uint64_t pageID) const
     return m_pageMap.get(pageID).get();
 }
 
-WebPageProxy* WebProcessProxy::createWebPage(WebContext* context, WebPageGroup* pageGroup)
+WebPageProxy* WebProcessProxy::createWebPage(PageClient* pageClient, WebContext* context, WebPageGroup* pageGroup)
 {
     ASSERT(context->process() == this);
 
     unsigned pageID = generatePageID();
-    RefPtr<WebPageProxy> webPage = WebPageProxy::create(context, pageGroup, pageID);
+    RefPtr<WebPageProxy> webPage = WebPageProxy::create(pageClient, context, pageGroup, pageID);
     m_pageMap.set(pageID, webPage);
     return webPage.get();
 }
index 44ab918..531d7fe 100644 (file)
@@ -79,7 +79,7 @@ public:
     PlatformProcessIdentifier processIdentifier() const { return m_processLauncher->processIdentifier(); }
 
     WebPageProxy* webPage(uint64_t pageID) const;
-    WebPageProxy* createWebPage(WebContext*, WebPageGroup*);
+    WebPageProxy* createWebPage(PageClient*, WebContext*, WebPageGroup*);
     void addExistingWebPage(WebPageProxy*, uint64_t pageID);
     void removeWebPage(uint64_t pageID);
 
index 092826a..45589dc 100644 (file)
@@ -227,14 +227,15 @@ WebView::WebView(RECT rect, WebContext* context, WebPageGroup* pageGroup, HWND p
     , m_webCoreCursor(0)
     , m_overrideCursor(0)
     , m_trackingMouseLeave(false)
+    , m_isInWindow(false)
+    , m_isVisible(false)
     , m_wasActivatedByMouseEvent(false)
     , m_isBeingDestroyed(false)
     , m_inIMEComposition(0)
 {
     registerWebViewWindowClass();
 
-    m_page = context->createWebPage(pageGroup);
-    m_page->setPageClient(this);
+    m_page = context->createWebPage(this, pageGroup);
     m_page->setDrawingArea(ChunkedUpdateDrawingAreaProxy::create(this, m_page.get()));
 
     m_window = ::CreateWindowEx(0, kWebKit2WebViewWindowClassName, 0, WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
@@ -437,16 +438,14 @@ LRESULT WebView::onWindowPositionChangedEvent(HWND, UINT, WPARAM, LPARAM lParam,
 
 LRESULT WebView::onSetFocusEvent(HWND, UINT, WPARAM, LPARAM lParam, bool& handled)
 {
-    m_page->setFocused(true);
-
+    m_page->viewStateDidChange(WebPageProxy::ViewIsFocused);
     handled = true;
     return 0;
 }
 
 LRESULT WebView::onKillFocusEvent(HWND, UINT, WPARAM, LPARAM lParam, bool& handled)
 {
-    m_page->setFocused(false);
-
+    m_page->viewStateDidChange(WebPageProxy::ViewIsFocused);
     handled = true;
     return 0;
 }
@@ -469,10 +468,8 @@ LRESULT WebView::onShowWindowEvent(HWND hWnd, UINT message, WPARAM wParam, LPARA
     // lParam is 0 when the message is sent because of a ShowWindow call.
     // FIXME: Is WM_SHOWWINDOW sent when ShowWindow is called on an ancestor of our window?
     if (!lParam) {
-        bool isVisible = wParam;
-
-        // Notify the drawing area that the visibility changed.
-        m_page->drawingArea()->setPageIsVisible(isVisible);
+        m_isVisible = wParam;
+        m_page->viewStateDidChange(WebPageProxy::IsViewVisible);
 
         handled = true;
     }
@@ -491,15 +488,9 @@ LRESULT WebView::onSetCursor(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPar
     return 0;
 }
 
-bool WebView::isActive()
-{
-    HWND activeWindow = ::GetActiveWindow();
-    return (activeWindow && m_topLevelParentWindow == findTopLevelParentWindow(activeWindow));
-}
-
 void WebView::updateActiveState()
 {
-    m_page->setActive(isActive());
+    m_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive);
 }
 
 void WebView::updateActiveStateSoon()
@@ -584,6 +575,35 @@ void WebView::close()
 
 // PageClient
 
+WebCore::IntSize WebView::viewSize()
+{
+    RECT clientRect;
+    GetClientRect(m_window, &clientRect);
+
+    return IntRect(clientRect).size();
+}
+
+bool WebView::ViewWindowIsActive()
+{    
+    HWND activeWindow = ::GetActiveWindow();
+    return (activeWindow && m_topLevelParentWindow == findTopLevelParentWindow(activeWindow));
+}
+
+bool WebView::isViewFocused()
+{
+    return ::GetFocus() == m_window;
+}
+
+bool WebView::isViewVisible()
+{
+    return m_isVisible;
+}
+
+bool WebView::isViewInWindow()
+{
+    return m_isInWindow;
+}
+
 void WebView::processDidCrash()
 {
     updateNativeCursor();
@@ -597,8 +617,6 @@ void WebView::didRelaunchProcess()
         return;
 
     m_page->reinitializeWebPage(IntRect(clientRect).size());
-    updateActiveState();
-    m_page->setFocused(::GetFocus() == m_window);
     updateNativeCursor();
 
     ::InvalidateRect(m_window, 0, TRUE);
@@ -992,7 +1010,8 @@ void WebView::setCustomRepresentationZoomFactor(double)
 
 void WebView::setIsInWindow(bool isInWindow)
 {
-    m_page->setIsInWindow(isInWindow);
+    m_isInWindow = isInWindow;
+    m_page->viewStateDidChange(WebPageProxy::ViewIsInWindow);
 }
 
 #if USE(ACCELERATED_COMPOSITING)
index f502973..bfff344 100644 (file)
@@ -90,7 +90,6 @@ private:
     LRESULT onIMERequestCharPosition(IMECHARPOSITION*);
     LRESULT onIMERequestReconvertString(RECONVERTSTRING*);
 
-    bool isActive();
     void updateActiveState();
     void updateActiveStateSoon();
 
@@ -105,6 +104,11 @@ private:
     void updateNativeCursor();
 
     // PageClient
+    virtual WebCore::IntSize viewSize();
+    virtual bool isViewWindowActive();
+    virtual bool isViewFocused();
+    virtual bool isViewVisible();
+    virtual bool isViewInWindow();
     virtual void processDidCrash();
     virtual void didRelaunchProcess();
     virtual void takeFocus(bool direction);
@@ -146,6 +150,8 @@ private:
     HCURSOR m_webCoreCursor;
     HCURSOR m_overrideCursor;
 
+    bool m_isInWindow;
+    bool m_isVisible;
     bool m_wasActivatedByMouseEvent;
     bool m_trackingMouseLeave;
     bool m_isBeingDestroyed;