Avoid making a window for the Web Inspector when it is docked.
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Feb 2012 03:20:07 +0000 (03:20 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Feb 2012 03:20:07 +0000 (03:20 +0000)
This also makes sure the inspector WKView is in a window before the page is loaded.
This avoids some redundant work caused by moving it to a window later.

https://webkit.org/b/78064

Reviewed by Brian Weinstein.

* UIProcess/WebInspectorProxy.cpp:
(WebKit::WebInspectorProxy::createInspectorPage): Set m_isAttached here...
(WebKit::WebInspectorProxy::didLoadInspectorPage): ... instead of here.
* UIProcess/WebInspectorProxy.h:
(WebInspectorProxy):
* UIProcess/mac/WebInspectorProxyMac.mm:
(WebKit::WebInspectorProxy::createInspectorWindow): Added. Factored out of platformOpen.
(WebKit::WebInspectorProxy::updateInspectorWindowTitle): Added. Factored out of platformInspectedURLChanged.
(WebKit::WebInspectorProxy::platformCreateInspectorPage): Call platformAttach or createInspectorWindow.
(WebKit::WebInspectorProxy::platformOpen): Make the view or window visible.
(WebKit::WebInspectorProxy::platformDidClose): Only message m_inspectorWindow if it isn't nil.
(WebKit::WebInspectorProxy::platformInspectedURLChanged): Store the urlString and call updateInspectorWindowTitle.
(WebKit::WebInspectorProxy::inspectedViewFrameDidChange): Return early if not visible.
(WebKit::WebInspectorProxy::platformAttach): Start out hidden if we are not visible yet. Destroy the window.
(WebKit::WebInspectorProxy::platformDetach): Use createInspectorWindow to create it again.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/WebInspectorProxy.cpp
Source/WebKit2/UIProcess/WebInspectorProxy.h
Source/WebKit2/UIProcess/mac/WebInspectorProxyMac.mm

index 4c1bebe..b4aa265 100644 (file)
@@ -1,3 +1,30 @@
+2012-02-07  Timothy Hatcher  <timothy@apple.com>
+
+        Avoid making a window for the Web Inspector when it is docked.
+
+        This also makes sure the inspector WKView is in a window before the page is loaded.
+        This avoids some redundant work caused by moving it to a window later.
+
+        https://webkit.org/b/78064
+
+        Reviewed by Brian Weinstein.
+
+        * UIProcess/WebInspectorProxy.cpp:
+        (WebKit::WebInspectorProxy::createInspectorPage): Set m_isAttached here...
+        (WebKit::WebInspectorProxy::didLoadInspectorPage): ... instead of here.
+        * UIProcess/WebInspectorProxy.h:
+        (WebInspectorProxy):
+        * UIProcess/mac/WebInspectorProxyMac.mm:
+        (WebKit::WebInspectorProxy::createInspectorWindow): Added. Factored out of platformOpen.
+        (WebKit::WebInspectorProxy::updateInspectorWindowTitle): Added. Factored out of platformInspectedURLChanged.
+        (WebKit::WebInspectorProxy::platformCreateInspectorPage): Call platformAttach or createInspectorWindow.
+        (WebKit::WebInspectorProxy::platformOpen): Make the view or window visible.
+        (WebKit::WebInspectorProxy::platformDidClose): Only message m_inspectorWindow if it isn't nil.
+        (WebKit::WebInspectorProxy::platformInspectedURLChanged): Store the urlString and call updateInspectorWindowTitle.
+        (WebKit::WebInspectorProxy::inspectedViewFrameDidChange): Return early if not visible.
+        (WebKit::WebInspectorProxy::platformAttach): Start out hidden if we are not visible yet. Destroy the window.
+        (WebKit::WebInspectorProxy::platformDetach): Use createInspectorWindow to create it again.
+
 2012-02-07  Tony Chang  <tony@chromium.org>
 
         merge DashboardSupportCSSPropertyNames.in into CSSPropertyNames.in
index 825420a..cb5df79 100644 (file)
@@ -207,6 +207,8 @@ void WebInspectorProxy::createInspectorPage(uint64_t& inspectorPageID, WebPageCr
     if (!m_page)
         return;
 
+    m_isAttached = shouldOpenAttached();
+
     WebPageProxy* inspectorPage = platformCreateInspectorPage();
     ASSERT(inspectorPage);
     if (!inspectorPage)
@@ -216,7 +218,7 @@ void WebInspectorProxy::createInspectorPage(uint64_t& inspectorPageID, WebPageCr
     inspectorPageParameters = inspectorPage->creationParameters();
 
     String url = inspectorPageURL();
-    if (shouldOpenAttached())
+    if (m_isAttached)
         url += "?docked=true";
     m_page->process()->assumeReadAccessToBaseURL(inspectorBaseURL());
     inspectorPage->loadURL(url);
@@ -225,7 +227,6 @@ void WebInspectorProxy::createInspectorPage(uint64_t& inspectorPageID, WebPageCr
 void WebInspectorProxy::didLoadInspectorPage()
 {
     m_isVisible = true;
-    m_isAttached = shouldOpenAttached();
 
     // platformOpen is responsible for rendering attached mode depending on m_isAttached.
     platformOpen();
index a70ac70..56df78c 100644 (file)
@@ -34,6 +34,7 @@
 #include <wtf/Forward.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
+#include <wtf/text/WTFString.h>
 
 #if PLATFORM(MAC)
 #include <wtf/RetainPtr.h>
@@ -82,6 +83,8 @@ public:
     void close();
     
 #if PLATFORM(MAC)
+    void createInspectorWindow();
+    void updateInspectorWindowTitle() const;
     void inspectedViewFrameDidChange();
 #elif PLATFORM(GTK)
     void windowDestroyed();
@@ -175,6 +178,7 @@ private:
     RetainPtr<WKWebInspectorWKView> m_inspectorView;
     RetainPtr<NSWindow> m_inspectorWindow;
     RetainPtr<WKWebInspectorProxyObjCAdapter> m_inspectorProxyObjCAdapter;
+    String m_urlString;
 #elif PLATFORM(WIN)
     HWND m_inspectorWindow;
     RefPtr<WebView> m_inspectorView;
index d43a2ac..d90ad12 100644 (file)
@@ -99,25 +99,10 @@ static const CGFloat windowContentBorderThickness = 55;
 
 namespace WebKit {
 
-WebPageProxy* WebInspectorProxy::platformCreateInspectorPage()
-{
-    ASSERT(m_page);
-    ASSERT(!m_inspectorView);
-
-    m_inspectorView.adoptNS([[WKWebInspectorWKView alloc] initWithFrame:NSMakeRect(0, 0, initialWindowWidth, initialWindowHeight) contextRef:toAPI(page()->process()->context()) pageGroupRef:toAPI(inspectorPageGroup())]);
-    ASSERT(m_inspectorView);
-
-    [m_inspectorView.get() setDrawsBackground:NO];
-
-    return toImpl(m_inspectorView.get().pageRef);
-}
-
-void WebInspectorProxy::platformOpen()
+void WebInspectorProxy::createInspectorWindow()
 {
     ASSERT(!m_inspectorWindow);
 
-    m_inspectorProxyObjCAdapter.adoptNS([[WKWebInspectorProxyObjCAdapter alloc] initWithWebInspectorProxy:this]);
-
     bool useTexturedWindow = page()->process()->context()->overrideWebInspectorPagePath().isEmpty();
 
     NSUInteger styleMask = (NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask);
@@ -135,31 +120,72 @@ void WebInspectorProxy::platformOpen()
         WKNSWindowMakeBottomCornersSquare(window);
     }
 
+    NSView *contentView = [window contentView];
+    [m_inspectorView.get() setFrame:[contentView bounds]];
+    [contentView addSubview:m_inspectorView.get()];
+
     // Center the window initially before setting the frame autosave name so that the window will be in a good
     // position if there is no saved frame yet.
     [window center];
     [window setFrameAutosaveName:@"Web Inspector 2"];
 
-    NSView *contentView = [window contentView];
-    [m_inspectorView.get() setFrame:[contentView bounds]];
+    m_inspectorWindow.adoptNS(window);
+
+    updateInspectorWindowTitle();
+}
+
+void WebInspectorProxy::updateInspectorWindowTitle() const
+{
+    if (!m_inspectorWindow)
+        return;
+
+    NSString *title = [NSString stringWithFormat:WEB_UI_STRING("Web Inspector — %@", "Web Inspector window title"), (NSString *)m_urlString];
+    [m_inspectorWindow.get() setTitle:title];
+}
+
+WebPageProxy* WebInspectorProxy::platformCreateInspectorPage()
+{
+    ASSERT(m_page);
+    ASSERT(!m_inspectorView);
+
+    m_inspectorView.adoptNS([[WKWebInspectorWKView alloc] initWithFrame:NSMakeRect(0, 0, initialWindowWidth, initialWindowHeight) contextRef:toAPI(page()->process()->context()) pageGroupRef:toAPI(inspectorPageGroup())]);
+    ASSERT(m_inspectorView);
+
+    [m_inspectorView.get() setDrawsBackground:NO];
     [m_inspectorView.get() setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
-    [contentView addSubview:m_inspectorView.get()];
 
-    m_inspectorWindow.adoptNS(window);
+    m_inspectorProxyObjCAdapter.adoptNS([[WKWebInspectorProxyObjCAdapter alloc] initWithWebInspectorProxy:this]);
 
     if (m_isAttached)
         platformAttach();
     else
-        [window makeKeyAndOrderFront:nil];
+        createInspectorWindow();
+
+    return toImpl(m_inspectorView.get().pageRef);
+}
+
+void WebInspectorProxy::platformOpen()
+{
+    if (m_isAttached) {
+        // Make the inspector view visible since it was hidden while loading.
+        [m_inspectorView.get() setHidden:NO];
+
+        // Adjust the frames now that we are visible and inspectedViewFrameDidChange wont return early.
+        inspectedViewFrameDidChange();
+    } else
+        [m_inspectorWindow.get() makeKeyAndOrderFront:nil];
 }
 
 void WebInspectorProxy::platformDidClose()
 {
-    [m_inspectorWindow.get() setDelegate:nil];
-    [m_inspectorWindow.get() orderOut:nil];
+    if (m_inspectorWindow) {
+        [m_inspectorWindow.get() setDelegate:nil];
+        [m_inspectorWindow.get() orderOut:nil];
+        m_inspectorWindow = 0;
+    }
 
-    m_inspectorWindow = 0;
     m_inspectorView = 0;
+
     m_inspectorProxyObjCAdapter = 0;
 }
 
@@ -171,13 +197,14 @@ void WebInspectorProxy::platformBringToFront()
 
 void WebInspectorProxy::platformInspectedURLChanged(const String& urlString)
 {
-    NSString *title = [NSString stringWithFormat:WEB_UI_STRING("Web Inspector — %@", "Web Inspector window title"), (NSString *)urlString];
-    [m_inspectorWindow.get() setTitle:title];
+    m_urlString = urlString;
+
+    updateInspectorWindowTitle();
 }
 
 void WebInspectorProxy::inspectedViewFrameDidChange()
 {
-    if (!m_isAttached)
+    if (!m_isAttached || !m_isVisible)
         return;
 
     WKView *inspectedView = m_page->wkView();
@@ -187,7 +214,7 @@ void WebInspectorProxy::inspectedViewFrameDidChange()
     CGFloat inspectedTop = NSMaxY(inspectedViewFrame);
     CGFloat inspectedWidth = NSWidth(inspectedViewFrame);
     CGFloat inspectorHeight = NSHeight([m_inspectorView.get() frame]);
-    
+
     CGFloat parentHeight = NSHeight([[inspectedView superview] frame]);
     inspectorHeight = InspectorFrontendClientLocal::constrainedAttachedWindowHeight(inspectorHeight, parentHeight);
 
@@ -213,9 +240,16 @@ void WebInspectorProxy::platformAttach()
     NSRect inspectedViewFrame = [inspectedView frame];
     [m_inspectorView.get() setFrame:NSMakeRect(NSMinX(inspectedViewFrame), 0, NSWidth(inspectedViewFrame), inspectorPageGroup()->preferences()->inspectorAttachedHeight())];
 
+    // Start out hidden if we are not visible yet. When platformOpen is called, hidden will be set to NO.
+    [m_inspectorView.get() setHidden:!m_isVisible];
+
     [[inspectedView superview] addSubview:m_inspectorView.get() positioned:NSWindowBelow relativeTo:inspectedView];
 
-    [m_inspectorWindow.get() orderOut:nil];
+    if (m_inspectorWindow) {
+        [m_inspectorWindow.get() setDelegate:nil];
+        [m_inspectorWindow.get() orderOut:nil];
+        m_inspectorWindow = 0;
+    }
 
     inspectedViewFrameDidChange();
 }
@@ -227,10 +261,10 @@ void WebInspectorProxy::platformDetach()
 
     [m_inspectorView.get() removeFromSuperview];
 
-    // Move the inspector view back into the inspector window.
-    NSView *inspectorWindowContentView = [m_inspectorWindow.get() contentView];
-    [m_inspectorView.get() setFrame:[inspectorWindowContentView bounds]];
-    [inspectorWindowContentView addSubview:m_inspectorView.get()];
+    createInspectorWindow();
+
+    // Make the inspector view visible in case it is still hidden from loading while attached.
+    [m_inspectorView.get() setHidden:NO];
 
     // Make sure that we size the inspected view's frame after detaching so that it takes up the space that the
     // attached inspector used to. This assumes the previous height was the Y origin.