Title: [107028] trunk/Source/WebKit2
Revision
107028
Author
timo...@apple.com
Date
2012-02-07 19:20:07 -0800 (Tue, 07 Feb 2012)

Log Message

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.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (107027 => 107028)


--- trunk/Source/WebKit2/ChangeLog	2012-02-08 03:10:38 UTC (rev 107027)
+++ trunk/Source/WebKit2/ChangeLog	2012-02-08 03:20:07 UTC (rev 107028)
@@ -1,3 +1,30 @@
+2012-02-07  Timothy Hatcher  <timo...@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  <t...@chromium.org>
 
         merge DashboardSupportCSSPropertyNames.in into CSSPropertyNames.in

Modified: trunk/Source/WebKit2/UIProcess/WebInspectorProxy.cpp (107027 => 107028)


--- trunk/Source/WebKit2/UIProcess/WebInspectorProxy.cpp	2012-02-08 03:10:38 UTC (rev 107027)
+++ trunk/Source/WebKit2/UIProcess/WebInspectorProxy.cpp	2012-02-08 03:20:07 UTC (rev 107028)
@@ -207,6 +207,8 @@
     if (!m_page)
         return;
 
+    m_isAttached = shouldOpenAttached();
+
     WebPageProxy* inspectorPage = platformCreateInspectorPage();
     ASSERT(inspectorPage);
     if (!inspectorPage)
@@ -216,7 +218,7 @@
     inspectorPageParameters = inspectorPage->creationParameters();
 
     String url = ""
-    if (shouldOpenAttached())
+    if (m_isAttached)
         url += "?docked=true";
     m_page->process()->assumeReadAccessToBaseURL(inspectorBaseURL());
     inspectorPage->loadURL(url);
@@ -225,7 +227,6 @@
 void WebInspectorProxy::didLoadInspectorPage()
 {
     m_isVisible = true;
-    m_isAttached = shouldOpenAttached();
 
     // platformOpen is responsible for rendering attached mode depending on m_isAttached.
     platformOpen();

Modified: trunk/Source/WebKit2/UIProcess/WebInspectorProxy.h (107027 => 107028)


--- trunk/Source/WebKit2/UIProcess/WebInspectorProxy.h	2012-02-08 03:10:38 UTC (rev 107027)
+++ trunk/Source/WebKit2/UIProcess/WebInspectorProxy.h	2012-02-08 03:20:07 UTC (rev 107028)
@@ -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 @@
     void close();
     
 #if PLATFORM(MAC)
+    void createInspectorWindow();
+    void updateInspectorWindowTitle() const;
     void inspectedViewFrameDidChange();
 #elif PLATFORM(GTK)
     void windowDestroyed();
@@ -175,6 +178,7 @@
     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;

Modified: trunk/Source/WebKit2/UIProcess/mac/WebInspectorProxyMac.mm (107027 => 107028)


--- trunk/Source/WebKit2/UIProcess/mac/WebInspectorProxyMac.mm	2012-02-08 03:10:38 UTC (rev 107027)
+++ trunk/Source/WebKit2/UIProcess/mac/WebInspectorProxyMac.mm	2012-02-08 03:20:07 UTC (rev 107028)
@@ -99,25 +99,10 @@
 
 namespace WebKit {
 
-WebPageProxy* WebInspectorProxy::platformCreateInspectorPage()
+void WebInspectorProxy::createInspectorWindow()
 {
-    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()
-{
     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 @@
         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::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 @@
     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 @@
     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,11 +261,11 @@
 
     [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.
     NSRect inspectedViewRect = [inspectedView frame];
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to