Give the fake Carbon window the right bounds
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Dec 2010 01:55:38 +0000 (01:55 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Dec 2010 01:55:38 +0000 (01:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=50361

Reviewed by Sam Weinig.

* PluginProcess/PluginControllerProxy.cpp:
(WebKit::PluginControllerProxy::windowAndViewFramesChanged):
* PluginProcess/PluginControllerProxy.h:
* PluginProcess/PluginControllerProxy.messages.in:
* UIProcess/API/mac/WKView.mm:
(-[WKView _updateWindowAndViewFrames]):
Pass both the window frame and view frame along.

(-[WKView renewGState]):
Call _updateWindowAndViewFrames.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::windowAndViewFramesChanged):
Pass both the window frame and view frame along.

* UIProcess/WebPageProxy.h:
* WebProcess/Plugins/Netscape/NetscapePlugin.h:
* WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm:
(WebKit::NetscapePlugin::platformPostInitialize):
We don't want a title bar in our fake window.

(WebKit::computeFakeWindowBoundsRect):
Compute the fake window bounds.

(WebKit::NetscapePlugin::windowAndViewFramesChanged):
Update the fake window bounds.

* WebProcess/Plugins/Plugin.h:
* WebProcess/Plugins/PluginProxy.cpp:
(WebKit::PluginProxy::windowAndViewFramesChanged):
* WebProcess/Plugins/PluginProxy.h:
* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::windowAndViewFramesChanged):
(WebKit::PluginView::initializePlugin):
* WebProcess/Plugins/PluginView.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::windowAndViewFramesChanged):
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::windowFrameInScreenCoordinates):
(WebKit::WebPage::viewFrameInWindowCoordinates):
* WebProcess/WebPage/WebPage.messages.in:
Pass both the window frame and view frame along.

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

17 files changed:
WebKit2/ChangeLog
WebKit2/PluginProcess/PluginControllerProxy.cpp
WebKit2/PluginProcess/PluginControllerProxy.h
WebKit2/PluginProcess/PluginControllerProxy.messages.in
WebKit2/UIProcess/API/mac/WKView.mm
WebKit2/UIProcess/WebPageProxy.cpp
WebKit2/UIProcess/WebPageProxy.h
WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h
WebKit2/WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm
WebKit2/WebProcess/Plugins/Plugin.h
WebKit2/WebProcess/Plugins/PluginProxy.cpp
WebKit2/WebProcess/Plugins/PluginProxy.h
WebKit2/WebProcess/Plugins/PluginView.cpp
WebKit2/WebProcess/Plugins/PluginView.h
WebKit2/WebProcess/WebPage/WebPage.cpp
WebKit2/WebProcess/WebPage/WebPage.h
WebKit2/WebProcess/WebPage/WebPage.messages.in

index ad60ab3..2189e1a 100644 (file)
@@ -1,3 +1,53 @@
+2010-12-01  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Give the fake Carbon window the right bounds
+        https://bugs.webkit.org/show_bug.cgi?id=50361
+
+        * PluginProcess/PluginControllerProxy.cpp:
+        (WebKit::PluginControllerProxy::windowAndViewFramesChanged):
+        * PluginProcess/PluginControllerProxy.h:
+        * PluginProcess/PluginControllerProxy.messages.in:
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView _updateWindowAndViewFrames]):
+        Pass both the window frame and view frame along.
+
+        (-[WKView renewGState]):
+        Call _updateWindowAndViewFrames.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::windowAndViewFramesChanged):
+        Pass both the window frame and view frame along.
+
+        * UIProcess/WebPageProxy.h:
+        * WebProcess/Plugins/Netscape/NetscapePlugin.h:
+        * WebProcess/Plugins/Netscape/mac/NetscapePluginMac.mm:
+        (WebKit::NetscapePlugin::platformPostInitialize):
+        We don't want a title bar in our fake window.
+    
+        (WebKit::computeFakeWindowBoundsRect):
+        Compute the fake window bounds.
+
+        (WebKit::NetscapePlugin::windowAndViewFramesChanged):
+        Update the fake window bounds.
+
+        * WebProcess/Plugins/Plugin.h:
+        * WebProcess/Plugins/PluginProxy.cpp:
+        (WebKit::PluginProxy::windowAndViewFramesChanged):
+        * WebProcess/Plugins/PluginProxy.h:
+        * WebProcess/Plugins/PluginView.cpp:
+        (WebKit::PluginView::windowAndViewFramesChanged):
+        (WebKit::PluginView::initializePlugin):
+        * WebProcess/Plugins/PluginView.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::windowAndViewFramesChanged):
+        * WebProcess/WebPage/WebPage.h:
+        (WebKit::WebPage::windowFrameInScreenCoordinates):
+        (WebKit::WebPage::viewFrameInWindowCoordinates):
+        * WebProcess/WebPage/WebPage.messages.in:
+        Pass both the window frame and view frame along.
+
 2010-12-01  Jia Pu  <jpu@apple.com>
 
         Reviewed by Darin Adler.
index 9e1b64e..bb4844e 100644 (file)
@@ -391,9 +391,9 @@ void PluginControllerProxy::windowFocusChanged(bool hasFocus)
     m_plugin->windowFocusChanged(hasFocus);
 }
 
-void PluginControllerProxy::windowFrameChanged(const IntRect& windowFrame)
+void PluginControllerProxy::windowAndViewFramesChanged(const IntRect& windowFrameInScreenCoordinates, const IntRect& viewFrameInWindowCoordinates)
 {
-    m_plugin->windowFrameChanged(windowFrame);
+    m_plugin->windowAndViewFramesChanged(windowFrameInScreenCoordinates, viewFrameInWindowCoordinates);
 }
 
 void PluginControllerProxy::windowVisibilityChanged(bool isVisible)
index 9e76813..0ac1266 100644 (file)
@@ -117,7 +117,7 @@ private:
 
 #if PLATFORM(MAC)
     void windowFocusChanged(bool);
-    void windowFrameChanged(const WebCore::IntRect&);
+    void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates);
     void windowVisibilityChanged(bool);
 #endif
     void privateBrowsingStateChanged(bool);
index 0ddef49..b3727aa 100644 (file)
@@ -90,8 +90,8 @@ messages -> PluginControllerProxy {
     # Sent when the containing NSWindow's focus changes
     WindowFocusChanged(bool hasFocus)
 
-    # Sent when the containing NSWindow's frame changes
-    WindowFrameChanged(WebCore::IntRect windowFrame)
+    # Sent when the containing NSWindow or NSView frame changes
+    WindowAndViewFramesChanged(WebCore::IntRect windowFrameInScreenCoordinates, WebCore::IntRect viewFrameInWindowCoordinates)
 
     # Sent when the containing NSWindow's visibility changes
     WindowVisibilityChanged(bool isVisible)
index f35997e..3f28f99 100644 (file)
@@ -202,13 +202,29 @@ struct EditCommandState {
     _data->_page->drawingArea()->setSize(IntSize(size));
 }
 
+- (void)_updateWindowAndViewFrames
+{
+    NSWindow *window = [self window];
+    ASSERT(window);
+    
+    NSRect windowFrameInScreenCoordinates = [window frame];
+    NSRect viewFrameInWindowCoordinates = [self convertRect:[self frame] toView:nil];
+    
+    _data->_page->windowAndViewFramesChanged(enclosingIntRect(windowFrameInScreenCoordinates), enclosingIntRect(viewFrameInWindowCoordinates));
+}
+
 - (void)renewGState
 {
     // Hide the find indicator.
     _data->_findIndicatorWindow = nullptr;
 
+    // Update the view frame.
+    if ([self window])
+        [self _updateWindowAndViewFrames];
+
     [super renewGState];
 }
+
 typedef HashMap<SEL, String> SelectorNameMap;
 
 // Map selectors into Editor command names.
@@ -598,31 +614,6 @@ static bool isViewVisible(NSView *view)
         area->setPageIsVisible(isViewVisible(self));
 }
 
-static NSScreen *screenForWindow(NSWindow *window)
-{
-    if (NSScreen *screen = [window screen]) // nil if the window is off-screen
-        return screen;
-    
-    NSArray *screens = [NSScreen screens];
-    if ([screens count] > 0)
-        return [screens objectAtIndex:0]; // screen containing the menubar
-    
-    return nil;
-}
-
-- (void)_updateWindowFrame
-{
-    NSWindow *window = [self window];
-    ASSERT(window);
-
-    // We want the window frame in Carbon coordinates, so flip the Y coordinate.
-    NSRect windowFrame = [window frame];
-    NSScreen *screen = ::screenForWindow(window);
-    windowFrame.origin.y = NSMaxY([screen frame]) - windowFrame.origin.y;
-
-    _data->_page->updateWindowFrame(enclosingIntRect(windowFrame));
-}
-
 - (void)viewWillMoveToWindow:(NSWindow *)window
 {
     if (window != [self window]) {
@@ -640,7 +631,7 @@ static NSScreen *screenForWindow(NSWindow *window)
         [self _updateActiveState];
         [self _updateVisibility];
         [self _updateWindowVisibility];
-        [self _updateWindowFrame];
+        [self _updateWindowAndViewFrames];
     } else {
         [self _updateVisibility];
         [self _updateActiveState];
@@ -674,7 +665,7 @@ static NSScreen *screenForWindow(NSWindow *window)
 
 - (void)_windowFrameDidChange:(NSNotification *)notification
 {
-    [self _updateWindowFrame];
+    [self _updateWindowAndViewFrames];
 }
 
 - (void)drawRect:(NSRect)rect
index f0d5735..1e65bd0 100644 (file)
@@ -446,11 +446,12 @@ void WebPageProxy::updateWindowIsVisible(bool windowIsVisible)
     process()->send(Messages::WebPage::SetWindowIsVisible(windowIsVisible), m_pageID);
 }
 
-void WebPageProxy::updateWindowFrame(const IntRect& windowFrame)
+void WebPageProxy::windowAndViewFramesChanged(const IntRect& windowFrameInScreenCoordinates, const IntRect& viewFrameInWindowCoordinates)
 {
     if (!isValid())
         return;
-    process()->send(Messages::WebPage::SetWindowFrame(windowFrame), m_pageID);
+
+    process()->send(Messages::WebPage::WindowAndViewFramesChanged(windowFrameInScreenCoordinates, viewFrameInWindowCoordinates), m_pageID);
 }
 #endif
 
index aa49255..2851351 100644 (file)
@@ -167,7 +167,7 @@ public:
 // These are only used on Mac currently.
 #if PLATFORM(MAC)
     void updateWindowIsVisible(bool windowIsVisible);
-    void updateWindowFrame(const WebCore::IntRect&);
+    void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates);
 #endif
 
 #if ENABLE(TILED_BACKING_STORE)
index bafa3fa..fc2d6c7 100644 (file)
@@ -157,7 +157,7 @@ private:
 
 #if PLATFORM(MAC)
     virtual void windowFocusChanged(bool);
-    virtual void windowFrameChanged(const WebCore::IntRect&);
+    virtual void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates);
     virtual void windowVisibilityChanged(bool);
 #endif
 
index 51911b5..525751a 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "NetscapePlugin.h"
 
-#include "NotImplemented.h"
 #include "WebEvent.h"
 #include <WebCore/GraphicsContext.h>
 
@@ -131,7 +130,7 @@ bool NetscapePlugin::platformPostInitialize()
     if (m_eventModel == NPEventModelCarbon) {
         // Initialize the fake Carbon window.
         ::Rect bounds = { 0, 0, 0, 0 };
-        CreateNewWindow(kDocumentWindowClass, 0, &bounds, reinterpret_cast<WindowRef*>(&m_npCGContext.window));
+        CreateNewWindow(kDocumentWindowClass, kWindowNoTitleBarAttribute, &bounds, reinterpret_cast<WindowRef*>(&m_npCGContext.window));
         ASSERT(m_npCGContext.window);
 
         // FIXME: Disable the backing store.
@@ -602,7 +601,27 @@ void NetscapePlugin::windowFocusChanged(bool hasFocus)
     }
 }
 
-void NetscapePlugin::windowFrameChanged(const IntRect& windowFrame)
+#ifndef NP_NO_CARBON
+static Rect computeFakeWindowBoundsRect(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates)
+{
+    // Carbon global coordinates has the origin set at the top left corner of the main viewing screen, so we want to flip the y coordinate.
+    CGFloat maxY = NSMaxY([[[NSScreen screens] objectAtIndex:0] frame]);
+
+    int flippedWindowFrameYCoordinate = maxY - windowFrameInScreenCoordinates.bottom();
+    int flippedViewFrameYCoordinate = windowFrameInScreenCoordinates.height() - viewFrameInWindowCoordinates.bottom();
+
+    Rect bounds;
+    
+    bounds.top = flippedWindowFrameYCoordinate + flippedViewFrameYCoordinate;
+    bounds.left = windowFrameInScreenCoordinates.x();
+    bounds.right = bounds.left + viewFrameInWindowCoordinates.width();
+    bounds.bottom = bounds.top + viewFrameInWindowCoordinates.height();
+    
+    return bounds;
+}
+#endif
+
+void NetscapePlugin::windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates)
 {
     switch (m_eventModel) {
         case NPEventModelCocoa:
@@ -611,16 +630,12 @@ void NetscapePlugin::windowFrameChanged(const IntRect& windowFrame)
 
 #ifndef NP_NO_CARBON
         case NPEventModelCarbon: {
-            ::Rect bounds;
-            bounds.top = windowFrame.y() + windowFrame.height();
-            bounds.left = windowFrame.x();
-            bounds.right = windowFrame.right();
-            bounds.bottom = windowFrame.y();
+            Rect bounds = computeFakeWindowBoundsRect(windowFrameInScreenCoordinates, viewFrameInWindowCoordinates);
 
             ::SetWindowBounds(windowRef(), kWindowStructureRgn, &bounds);
+#endif
             break;
         }
-#endif
 
         default:
             ASSERT_NOT_REACHED();
index 825eddc..fd0c09a 100644 (file)
@@ -145,8 +145,8 @@ public:
     // Tells the plug-in about window focus changes.
     virtual void windowFocusChanged(bool) = 0;
 
-    // Tells the plug-in about window frame changes.
-    virtual void windowFrameChanged(const WebCore::IntRect&) = 0;
+    // Tells the plug-in about window and plug-in frame changes.
+    virtual void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates) = 0;
 
     // Tells the plug-in about window visibility changes.
     virtual void windowVisibilityChanged(bool) = 0;
index 1330065..b1da783 100644 (file)
@@ -308,9 +308,9 @@ void PluginProxy::windowFocusChanged(bool hasFocus)
     m_connection->connection()->send(Messages::PluginControllerProxy::WindowFocusChanged(hasFocus), m_pluginInstanceID);
 }
 
-void PluginProxy::windowFrameChanged(const IntRect& windowFrame)
+void PluginProxy::windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates)
 {
-    m_connection->connection()->send(Messages::PluginControllerProxy::WindowFrameChanged(windowFrame), m_pluginInstanceID);
+    m_connection->connection()->send(Messages::PluginControllerProxy::WindowAndViewFramesChanged(windowFrameInScreenCoordinates, viewFrameInWindowCoordinates), m_pluginInstanceID);
 }
 
 void PluginProxy::windowVisibilityChanged(bool isVisible)
index 94956da..dc69737 100644 (file)
@@ -93,7 +93,7 @@ private:
     virtual NPObject* pluginScriptableNPObject();
 #if PLATFORM(MAC)
     virtual void windowFocusChanged(bool);
-    virtual void windowFrameChanged(const WebCore::IntRect&);
+    virtual void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates);
     virtual void windowVisibilityChanged(bool);
 #endif
 
index 778619a..8d9b9b2 100644 (file)
@@ -353,12 +353,12 @@ void PluginView::setWindowIsFocused(bool windowIsFocused)
     m_plugin->windowFocusChanged(windowIsFocused);    
 }
 
-void PluginView::setWindowFrame(const IntRect& windowFrame)
+void PluginView::windowAndViewFramesChanged(const IntRect& windowFrameInScreenCoordinates, const IntRect& viewFrameInWindowCoordinates)
 {
     if (!m_plugin)
         return;
 
-    m_plugin->windowFrameChanged(windowFrame);
+    m_plugin->windowAndViewFramesChanged(windowFrameInScreenCoordinates, viewFrameInWindowCoordinates);
 }
 
 #endif
@@ -407,7 +407,7 @@ void PluginView::initializePlugin()
         }
     }
 
-    setWindowFrame(m_webPage->windowFrame());
+    windowAndViewFramesChanged(m_webPage->windowFrameInScreenCoordinates(), m_webPage->viewFrameInWindowCoordinates());
     setWindowIsVisible(m_webPage->windowIsVisible());
     setWindowIsFocused(m_webPage->windowIsFocused());
 #endif
index 5346297..9d64859 100644 (file)
@@ -61,7 +61,7 @@ public:
 #if PLATFORM(MAC)
     void setWindowIsVisible(bool);
     void setWindowIsFocused(bool);
-    void setWindowFrame(const WebCore::IntRect&);
+    void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates);
 #endif
 
 private:
index 39c2767..255ef69 100644 (file)
@@ -1065,13 +1065,14 @@ void WebPage::setWindowIsVisible(bool windowIsVisible)
         (*it)->setWindowIsVisible(windowIsVisible);
 }
 
-void WebPage::setWindowFrame(const IntRect& windowFrame)
+void WebPage::windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates)
 {
-    m_windowFrame = windowFrame;
+    m_windowFrameInScreenCoordinates = windowFrameInScreenCoordinates;
+    m_viewFrameInWindowCoordinates = viewFrameInWindowCoordinates;
 
-    // Tell all our plug-in views that the window frame changed.
+    // Tell all our plug-in views that the window and view frames have changed.
     for (HashSet<PluginView*>::const_iterator it = m_pluginViews.begin(), end = m_pluginViews.end(); it != end; ++it)
-        (*it)->setWindowFrame(windowFrame);
+        (*it)->windowAndViewFramesChanged(windowFrameInScreenCoordinates, viewFrameInWindowCoordinates);
 }
 
 bool WebPage::windowIsFocused() const
index 5c0b72d..6c9495a 100644 (file)
@@ -185,7 +185,8 @@ public:
     void removePluginView(PluginView*);
 
     bool windowIsVisible() const { return m_windowIsVisible; }
-    const WebCore::IntRect& windowFrame() const { return m_windowFrame; }
+    const WebCore::IntRect& windowFrameInScreenCoordinates() const { return m_windowFrameInScreenCoordinates; }
+    const WebCore::IntRect& viewFrameInWindowCoordinates() const { return m_viewFrameInWindowCoordinates; }
     bool windowIsFocused() const;
     bool interceptEditingKeyboardEvent(WebCore::KeyboardEvent*, bool);
 #elif PLATFORM(WIN)
@@ -288,7 +289,7 @@ private:
 
 #if PLATFORM(MAC)
     void setWindowIsVisible(bool windowIsVisible);
-    void setWindowFrame(const WebCore::IntRect&);
+    void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates);
 #endif
 
     void unapplyEditCommand(uint64_t commandID);
@@ -327,8 +328,11 @@ private:
     // Whether the containing window is visible or not.
     bool m_windowIsVisible;
 
-    // The frame of the containing window.
-    WebCore::IntRect m_windowFrame;
+    // The frame of the containing window in screen coordinates.
+    WebCore::IntRect m_windowFrameInScreenCoordinates;
+
+    // The frame of the view in window coordinates.
+    WebCore::IntRect m_viewFrameInWindowCoordinates;
 
     // All plug-in views on this web page.
     HashSet<PluginView*> m_pluginViews;
index ef86ad1..7156a3c 100644 (file)
@@ -92,7 +92,7 @@ messages -> WebPage {
 
 #if PLATFORM(MAC)
     SetWindowIsVisible(bool windowIsVisible)
-    SetWindowFrame(WebCore::IntRect windowFrame)
+    WindowAndViewFramesChanged(WebCore::IntRect windowFrameInScreenCoordinates, WebCore::IntRect viewFrameInWindowCoordinates)
 #endif
 
 #if PLATFORM(QT)