+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
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);
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;
}
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();
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);
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();
}
[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.