Changeset 107028 in webkit


Ignore:
Timestamp:
Feb 7, 2012 7:20:07 PM (12 years ago)
Author:
timothy@apple.com
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.

Location:
trunk/Source/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r107026 r107028  
     12012-02-07  Timothy Hatcher  <timothy@apple.com>
     2
     3        Avoid making a window for the Web Inspector when it is docked.
     4
     5        This also makes sure the inspector WKView is in a window before the page is loaded.
     6        This avoids some redundant work caused by moving it to a window later.
     7
     8        https://webkit.org/b/78064
     9
     10        Reviewed by Brian Weinstein.
     11
     12        * UIProcess/WebInspectorProxy.cpp:
     13        (WebKit::WebInspectorProxy::createInspectorPage): Set m_isAttached here...
     14        (WebKit::WebInspectorProxy::didLoadInspectorPage): ... instead of here.
     15        * UIProcess/WebInspectorProxy.h:
     16        (WebInspectorProxy):
     17        * UIProcess/mac/WebInspectorProxyMac.mm:
     18        (WebKit::WebInspectorProxy::createInspectorWindow): Added. Factored out of platformOpen.
     19        (WebKit::WebInspectorProxy::updateInspectorWindowTitle): Added. Factored out of platformInspectedURLChanged.
     20        (WebKit::WebInspectorProxy::platformCreateInspectorPage): Call platformAttach or createInspectorWindow.
     21        (WebKit::WebInspectorProxy::platformOpen): Make the view or window visible.
     22        (WebKit::WebInspectorProxy::platformDidClose): Only message m_inspectorWindow if it isn't nil.
     23        (WebKit::WebInspectorProxy::platformInspectedURLChanged): Store the urlString and call updateInspectorWindowTitle.
     24        (WebKit::WebInspectorProxy::inspectedViewFrameDidChange): Return early if not visible.
     25        (WebKit::WebInspectorProxy::platformAttach): Start out hidden if we are not visible yet. Destroy the window.
     26        (WebKit::WebInspectorProxy::platformDetach): Use createInspectorWindow to create it again.
     27
    1282012-02-07  Tony Chang  <tony@chromium.org>
    229
  • trunk/Source/WebKit2/UIProcess/WebInspectorProxy.cpp

    r105571 r107028  
    208208        return;
    209209
     210    m_isAttached = shouldOpenAttached();
     211
    210212    WebPageProxy* inspectorPage = platformCreateInspectorPage();
    211213    ASSERT(inspectorPage);
     
    217219
    218220    String url = inspectorPageURL();
    219     if (shouldOpenAttached())
     221    if (m_isAttached)
    220222        url += "?docked=true";
    221223    m_page->process()->assumeReadAccessToBaseURL(inspectorBaseURL());
     
    226228{
    227229    m_isVisible = true;
    228     m_isAttached = shouldOpenAttached();
    229230
    230231    // platformOpen is responsible for rendering attached mode depending on m_isAttached.
  • trunk/Source/WebKit2/UIProcess/WebInspectorProxy.h

    r96383 r107028  
    3535#include <wtf/PassRefPtr.h>
    3636#include <wtf/RefPtr.h>
     37#include <wtf/text/WTFString.h>
    3738
    3839#if PLATFORM(MAC)
     
    8384   
    8485#if PLATFORM(MAC)
     86    void createInspectorWindow();
     87    void updateInspectorWindowTitle() const;
    8588    void inspectedViewFrameDidChange();
    8689#elif PLATFORM(GTK)
     
    176179    RetainPtr<NSWindow> m_inspectorWindow;
    177180    RetainPtr<WKWebInspectorProxyObjCAdapter> m_inspectorProxyObjCAdapter;
     181    String m_urlString;
    178182#elif PLATFORM(WIN)
    179183    HWND m_inspectorWindow;
  • trunk/Source/WebKit2/UIProcess/mac/WebInspectorProxyMac.mm

    r105571 r107028  
    100100namespace WebKit {
    101101
    102 WebPageProxy* WebInspectorProxy::platformCreateInspectorPage()
    103 {
    104     ASSERT(m_page);
    105     ASSERT(!m_inspectorView);
    106 
    107     m_inspectorView.adoptNS([[WKWebInspectorWKView alloc] initWithFrame:NSMakeRect(0, 0, initialWindowWidth, initialWindowHeight) contextRef:toAPI(page()->process()->context()) pageGroupRef:toAPI(inspectorPageGroup())]);
    108     ASSERT(m_inspectorView);
    109 
    110     [m_inspectorView.get() setDrawsBackground:NO];
    111 
    112     return toImpl(m_inspectorView.get().pageRef);
    113 }
    114 
    115 void WebInspectorProxy::platformOpen()
     102void WebInspectorProxy::createInspectorWindow()
    116103{
    117104    ASSERT(!m_inspectorWindow);
    118 
    119     m_inspectorProxyObjCAdapter.adoptNS([[WKWebInspectorProxyObjCAdapter alloc] initWithWebInspectorProxy:this]);
    120105
    121106    bool useTexturedWindow = page()->process()->context()->overrideWebInspectorPagePath().isEmpty();
     
    136121    }
    137122
     123    NSView *contentView = [window contentView];
     124    [m_inspectorView.get() setFrame:[contentView bounds]];
     125    [contentView addSubview:m_inspectorView.get()];
     126
    138127    // Center the window initially before setting the frame autosave name so that the window will be in a good
    139128    // position if there is no saved frame yet.
     
    141130    [window setFrameAutosaveName:@"Web Inspector 2"];
    142131
    143     NSView *contentView = [window contentView];
    144     [m_inspectorView.get() setFrame:[contentView bounds]];
     132    m_inspectorWindow.adoptNS(window);
     133
     134    updateInspectorWindowTitle();
     135}
     136
     137void WebInspectorProxy::updateInspectorWindowTitle() const
     138{
     139    if (!m_inspectorWindow)
     140        return;
     141
     142    NSString *title = [NSString stringWithFormat:WEB_UI_STRING("Web Inspector — %@", "Web Inspector window title"), (NSString *)m_urlString];
     143    [m_inspectorWindow.get() setTitle:title];
     144}
     145
     146WebPageProxy* WebInspectorProxy::platformCreateInspectorPage()
     147{
     148    ASSERT(m_page);
     149    ASSERT(!m_inspectorView);
     150
     151    m_inspectorView.adoptNS([[WKWebInspectorWKView alloc] initWithFrame:NSMakeRect(0, 0, initialWindowWidth, initialWindowHeight) contextRef:toAPI(page()->process()->context()) pageGroupRef:toAPI(inspectorPageGroup())]);
     152    ASSERT(m_inspectorView);
     153
     154    [m_inspectorView.get() setDrawsBackground:NO];
    145155    [m_inspectorView.get() setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
    146     [contentView addSubview:m_inspectorView.get()];
    147 
    148     m_inspectorWindow.adoptNS(window);
     156
     157    m_inspectorProxyObjCAdapter.adoptNS([[WKWebInspectorProxyObjCAdapter alloc] initWithWebInspectorProxy:this]);
    149158
    150159    if (m_isAttached)
    151160        platformAttach();
    152161    else
    153         [window makeKeyAndOrderFront:nil];
     162        createInspectorWindow();
     163
     164    return toImpl(m_inspectorView.get().pageRef);
     165}
     166
     167void WebInspectorProxy::platformOpen()
     168{
     169    if (m_isAttached) {
     170        // Make the inspector view visible since it was hidden while loading.
     171        [m_inspectorView.get() setHidden:NO];
     172
     173        // Adjust the frames now that we are visible and inspectedViewFrameDidChange wont return early.
     174        inspectedViewFrameDidChange();
     175    } else
     176        [m_inspectorWindow.get() makeKeyAndOrderFront:nil];
    154177}
    155178
    156179void WebInspectorProxy::platformDidClose()
    157180{
    158     [m_inspectorWindow.get() setDelegate:nil];
    159     [m_inspectorWindow.get() orderOut:nil];
    160 
    161     m_inspectorWindow = 0;
     181    if (m_inspectorWindow) {
     182        [m_inspectorWindow.get() setDelegate:nil];
     183        [m_inspectorWindow.get() orderOut:nil];
     184        m_inspectorWindow = 0;
     185    }
     186
    162187    m_inspectorView = 0;
     188
    163189    m_inspectorProxyObjCAdapter = 0;
    164190}
     
    172198void WebInspectorProxy::platformInspectedURLChanged(const String& urlString)
    173199{
    174     NSString *title = [NSString stringWithFormat:WEB_UI_STRING("Web Inspector — %@", "Web Inspector window title"), (NSString *)urlString];
    175     [m_inspectorWindow.get() setTitle:title];
     200    m_urlString = urlString;
     201
     202    updateInspectorWindowTitle();
    176203}
    177204
    178205void WebInspectorProxy::inspectedViewFrameDidChange()
    179206{
    180     if (!m_isAttached)
     207    if (!m_isAttached || !m_isVisible)
    181208        return;
    182209
     
    188215    CGFloat inspectedWidth = NSWidth(inspectedViewFrame);
    189216    CGFloat inspectorHeight = NSHeight([m_inspectorView.get() frame]);
    190    
     217
    191218    CGFloat parentHeight = NSHeight([[inspectedView superview] frame]);
    192219    inspectorHeight = InspectorFrontendClientLocal::constrainedAttachedWindowHeight(inspectorHeight, parentHeight);
     
    214241    [m_inspectorView.get() setFrame:NSMakeRect(NSMinX(inspectedViewFrame), 0, NSWidth(inspectedViewFrame), inspectorPageGroup()->preferences()->inspectorAttachedHeight())];
    215242
     243    // Start out hidden if we are not visible yet. When platformOpen is called, hidden will be set to NO.
     244    [m_inspectorView.get() setHidden:!m_isVisible];
     245
    216246    [[inspectedView superview] addSubview:m_inspectorView.get() positioned:NSWindowBelow relativeTo:inspectedView];
    217247
    218     [m_inspectorWindow.get() orderOut:nil];
     248    if (m_inspectorWindow) {
     249        [m_inspectorWindow.get() setDelegate:nil];
     250        [m_inspectorWindow.get() orderOut:nil];
     251        m_inspectorWindow = 0;
     252    }
    219253
    220254    inspectedViewFrameDidChange();
     
    228262    [m_inspectorView.get() removeFromSuperview];
    229263
    230     // Move the inspector view back into the inspector window.
    231     NSView *inspectorWindowContentView = [m_inspectorWindow.get() contentView];
    232     [m_inspectorView.get() setFrame:[inspectorWindowContentView bounds]];
    233     [inspectorWindowContentView addSubview:m_inspectorView.get()];
     264    createInspectorWindow();
     265
     266    // Make the inspector view visible in case it is still hidden from loading while attached.
     267    [m_inspectorView.get() setHidden:NO];
    234268
    235269    // Make sure that we size the inspected view's frame after detaching so that it takes up the space that the
Note: See TracChangeset for help on using the changeset viewer.