Changeset 181881 in webkit


Ignore:
Timestamp:
Mar 23, 2015 4:42:40 PM (9 years ago)
Author:
timothy@apple.com
Message:

Web Inspector: Support attaching to another view other than the WKView
https://bugs.webkit.org/show_bug.cgi?id=142892

Reviewed by Tim Horton.

  • UIProcess/API/C/WKInspector.cpp:

(WKInspectorAttach): Drive by fix so it used the last attachment side.

  • UIProcess/API/Cocoa/WKViewPrivate.h:
  • UIProcess/API/mac/WKView.mm:

(-[WKView _inspectorAttachmentView]): Added.
(-[WKView _setInspectorAttachmentView:]): Added.

  • UIProcess/WebInspectorProxy.cpp:

(WebKit::WebInspectorProxy::createInspectorPage):
(WebKit::WebInspectorProxy::attachAvailabilityChanged):
Use platformCanAttach as a final check incase there is a different
attachment view that the platform knows about.

  • UIProcess/WebInspectorProxy.h:

(WebKit::WebInspectorProxy::attachmentSide): Added.
(WebKit::WebInspectorProxy::platformCanAttach): Added.

  • UIProcess/mac/WebInspectorProxyMac.mm:

(WebKit::WebInspectorProxy::attachmentViewDidChange): Added.
(WebKit::WebInspectorProxy::closeTimerFired):
(WebKit::WebInspectorProxy::platformCreateInspectorPage):
(WebKit::WebInspectorProxy::platformCanAttach):
(WebKit::WebInspectorProxy::inspectedViewFrameDidChange):
(WebKit::WebInspectorProxy::platformInspectedWindowHeight):
(WebKit::WebInspectorProxy::platformInspectedWindowWidth):
(WebKit::WebInspectorProxy::platformAttach):
(WebKit::WebInspectorProxy::platformDetach):
Use the _inspectorAttachmentView and change how the frame change notification
is observed and follow the attachment view as it changes.

Location:
trunk/Source/WebKit2
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r181874 r181881  
     12015-03-19  Timothy Hatcher  <timothy@apple.com>
     2
     3        Web Inspector: Support attaching to another view other than the WKView
     4        https://bugs.webkit.org/show_bug.cgi?id=142892
     5
     6        Reviewed by Tim Horton.
     7
     8        * UIProcess/API/C/WKInspector.cpp:
     9        (WKInspectorAttach): Drive by fix so it used the last attachment side.
     10
     11        * UIProcess/API/Cocoa/WKViewPrivate.h:
     12        * UIProcess/API/mac/WKView.mm:
     13        (-[WKView _inspectorAttachmentView]): Added.
     14        (-[WKView _setInspectorAttachmentView:]): Added.
     15
     16        * UIProcess/WebInspectorProxy.cpp:
     17        (WebKit::WebInspectorProxy::createInspectorPage):
     18        (WebKit::WebInspectorProxy::attachAvailabilityChanged):
     19        Use platformCanAttach as a final check incase there is a different
     20        attachment view that the platform knows about.
     21
     22        * UIProcess/WebInspectorProxy.h:
     23        (WebKit::WebInspectorProxy::attachmentSide): Added.
     24        (WebKit::WebInspectorProxy::platformCanAttach): Added.
     25
     26        * UIProcess/mac/WebInspectorProxyMac.mm:
     27        (WebKit::WebInspectorProxy::attachmentViewDidChange): Added.
     28        (WebKit::WebInspectorProxy::closeTimerFired):
     29        (WebKit::WebInspectorProxy::platformCreateInspectorPage):
     30        (WebKit::WebInspectorProxy::platformCanAttach):
     31        (WebKit::WebInspectorProxy::inspectedViewFrameDidChange):
     32        (WebKit::WebInspectorProxy::platformInspectedWindowHeight):
     33        (WebKit::WebInspectorProxy::platformInspectedWindowWidth):
     34        (WebKit::WebInspectorProxy::platformAttach):
     35        (WebKit::WebInspectorProxy::platformDetach):
     36        Use the _inspectorAttachmentView and change how the frame change notification
     37        is observed and follow the attachment view as it changes.
     38
    1392015-03-23  Tim Horton  <timothy_horton@apple.com>
    240
  • trunk/Source/WebKit2/UIProcess/API/C/WKInspector.cpp

    r179705 r181881  
    102102void WKInspectorAttach(WKInspectorRef inspectorRef)
    103103{
    104     toImpl(inspectorRef)->attach();
     104    auto inspector = toImpl(inspectorRef);
     105    inspector->attach(inspector->attachmentSide());
    105106}
    106107
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKViewPrivate.h

    r181039 r181881  
    9898
    9999@property (readonly) NSColor *_pageExtendedBackgroundColor;
    100 @property(copy, nonatomic) NSColor *underlayColor;
     100@property (copy, nonatomic) NSColor *underlayColor;
     101
     102@property (strong, nonatomic, setter=_setInspectorAttachmentView:) NSView *_inspectorAttachmentView WK_AVAILABLE(WK_MAC_TBA, NA);
    101103
    102104- (NSView*)fullScreenPlaceholderView;
  • trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm

    r181866 r181881  
    6969#import "WebBackForwardList.h"
    7070#import "WebEventFactory.h"
     71#import "WebInspectorProxy.h"
    7172#import "WebKit2Initialize.h"
    7273#import "WebPage.h"
     
    192193
    193194    RetainPtr<id> _remoteAccessibilityChild;
    194    
     195
     196    RetainPtr<NSView> _inspectorAttachmentView;
     197
    195198    // For asynchronous validation.
    196199    ValidationMap _validationMap;
     
    41334136}
    41344137
     4138- (NSView *)_inspectorAttachmentView
     4139{
     4140    NSView *attachmentView = _data->_inspectorAttachmentView.get();
     4141    return attachmentView ? attachmentView : self;
     4142}
     4143
     4144- (void)_setInspectorAttachmentView:(NSView *)newView
     4145{
     4146    NSView *oldView = _data->_inspectorAttachmentView.get();
     4147    if (oldView == newView)
     4148        return;
     4149
     4150    _data->_inspectorAttachmentView = newView;
     4151    _data->_page->inspector()->attachmentViewDidChange(oldView ? oldView : self, newView ? newView : self);
     4152}
     4153
    41354154- (NSView *)fullScreenPlaceholderView
    41364155{
  • trunk/Source/WebKit2/UIProcess/WebInspectorProxy.cpp

    r179705 r181881  
    482482
    483483    if (!m_underTest) {
    484         m_canAttach = canAttach;
     484        m_canAttach = platformCanAttach(canAttach);
    485485        m_isAttached = shouldOpenAttached();
    486486        m_attachmentSide = static_cast<AttachmentSide>(inspectorPagePreferences().inspectorAttachmentSide());
     
    556556void WebInspectorProxy::attachAvailabilityChanged(bool available)
    557557{
    558     m_canAttach = available;
    559 
    560     platformAttachAvailabilityChanged(available);
     558    bool previousCanAttach = m_canAttach;
     559
     560    m_canAttach = platformCanAttach(available);
     561
     562    if (previousCanAttach == m_canAttach)
     563        return;
     564
     565    platformAttachAvailabilityChanged(m_canAttach);
    561566}
    562567
  • trunk/Source/WebKit2/UIProcess/WebInspectorProxy.h

    r179705 r181881  
    4343OBJC_CLASS NSButton;
    4444OBJC_CLASS NSURL;
     45OBJC_CLASS NSView;
    4546OBJC_CLASS NSWindow;
    4647OBJC_CLASS WKWebInspectorProxyObjCAdapter;
     
    107108
    108109    void closeTimerFired();
     110
     111    void attachmentViewDidChange(NSView *oldView, NSView *newView);
    109112#endif
    110113
     
    118121    void showMainResourceForFrame(WebFrameProxy*);
    119122
     123    AttachmentSide attachmentSide() const { return m_attachmentSide; }
    120124    bool isAttached() const { return m_isAttached; }
    121125    void attachRight();
     
    173177    void platformSave(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs);
    174178    void platformAppend(const String& filename, const String& content);
     179
     180#if PLATFORM(MAC)
     181    bool platformCanAttach(bool webProcessCanAttach);
     182#else
     183    bool platformCanAttach(bool webProcessCanAttach) { return webProcessCanAttach; }
     184#endif
    175185
    176186    // Called by WebInspectorProxy messages
  • trunk/Source/WebKit2/UIProcess/mac/WebInspectorProxyMac.mm

    r180570 r181881  
    291291}
    292292
     293void WebInspectorProxy::attachmentViewDidChange(NSView *oldView, NSView *newView)
     294{
     295    [[NSNotificationCenter defaultCenter] removeObserver:m_inspectorProxyObjCAdapter.get() name:NSViewFrameDidChangeNotification object:oldView];
     296    [[NSNotificationCenter defaultCenter] addObserver:m_inspectorProxyObjCAdapter.get() selector:@selector(inspectedViewFrameDidChange:) name:NSViewFrameDidChangeNotification object:newView];
     297
     298    if (m_isAttached)
     299        attach(m_attachmentSide);
     300}
     301
    293302void WebInspectorProxy::setInspectorWindowFrame(WKRect& frame)
    294303{
     
    318327        m_inspectorView = nil;
    319328    }
     329
     330    [[NSNotificationCenter defaultCenter] removeObserver:m_inspectorProxyObjCAdapter.get()];
    320331
    321332    [m_inspectorProxyObjCAdapter close];
     
    460471    ASSERT(!m_inspectorProxyObjCAdapter);
    461472
     473    NSView *inspectedView = inspectedPage()->wkView()._inspectorAttachmentView;
     474
    462475    NSRect initialRect;
    463476    if (m_isAttached) {
    464         NSRect inspectedViewFrame = inspectedPage()->wkView().frame;
     477        NSRect inspectedViewFrame = inspectedView.frame;
    465478
    466479        switch (m_attachmentSide) {
     
    508521
    509522    [m_inspectorView setInspectorProxyObjCAdapter:m_inspectorProxyObjCAdapter.get()];
     523
     524    [[NSNotificationCenter defaultCenter] addObserver:m_inspectorProxyObjCAdapter.get() selector:@selector(inspectedViewFrameDidChange:) name:NSViewFrameDidChangeNotification object:inspectedView];
    510525
    511526    WebPageProxy* inspectorPage = m_inspectorView->_page.get();
     
    567582}
    568583
     584bool WebInspectorProxy::platformCanAttach(bool webProcessCanAttach)
     585{
     586    NSView *inspectedView = inspectedPage()->wkView()._inspectorAttachmentView;
     587    if ([inspectedView isKindOfClass:[WKView class]])
     588        return webProcessCanAttach;
     589
     590    static const float minimumAttachedHeight = 250;
     591    static const float maximumAttachedHeightRatio = 0.75;
     592    static const float minimumAttachedWidth = 750;
     593
     594    NSRect inspectedViewFrame = inspectedView.frame;
     595
     596    float maximumAttachedHeight = NSHeight(inspectedViewFrame) * maximumAttachedHeightRatio;
     597    return minimumAttachedHeight <= maximumAttachedHeight && minimumAttachedWidth <= NSWidth(inspectedViewFrame);
     598}
     599
    569600void WebInspectorProxy::platformOpen()
    570601{
     
    728759void WebInspectorProxy::inspectedViewFrameDidChange(CGFloat currentDimension)
    729760{
    730     if (!m_isAttached || !m_isVisible)
    731         return;
    732 
    733     WKView *inspectedView = inspectedPage()->wkView();
     761    if (!m_isVisible)
     762        return;
     763
     764    if (!m_isAttached) {
     765        // Check if the attach avaibility changed. We need to do this here in case
     766        // the attachment view is not the WKView.
     767        attachAvailabilityChanged(platformCanAttach(canAttach()));
     768        return;
     769    }
     770
     771    NSView *inspectedView = inspectedPage()->wkView()._inspectorAttachmentView;
    734772    NSRect inspectedViewFrame = [inspectedView frame];
    735773    NSRect inspectorFrame = NSZeroRect;
     
    761799        // top position for the inspector view since the banners only stretch as wide as the the inspected view.
    762800        inspectedViewFrame = NSMakeRect(0, 0, parentWidth - inspectorWidth, inspectedViewTop);
    763         CGFloat insetExcludingBanners = inspectedView._topContentInset - inspectedView._totalHeightOfBanners;
     801        CGFloat insetExcludingBanners = 0;
     802        if ([inspectedView isKindOfClass:[WKView class]])
     803            insetExcludingBanners = ((WKView *)inspectedView)._topContentInset - ((WKView *)inspectedView)._totalHeightOfBanners;
    764804        inspectorFrame = NSMakeRect(parentWidth - inspectorWidth, 0, inspectorWidth, NSHeight(parentBounds) - insetExcludingBanners);
    765805        break;
     
    781821unsigned WebInspectorProxy::platformInspectedWindowHeight()
    782822{
    783     WKView *inspectedView = inspectedPage()->wkView();
     823    NSView *inspectedView = inspectedPage()->wkView()._inspectorAttachmentView;
    784824    NSRect inspectedViewRect = [inspectedView frame];
    785825    return static_cast<unsigned>(inspectedViewRect.size.height);
     
    788828unsigned WebInspectorProxy::platformInspectedWindowWidth()
    789829{
    790     WKView *inspectedView = inspectedPage()->wkView();
     830    NSView *inspectedView = inspectedPage()->wkView()._inspectorAttachmentView;
    791831    NSRect inspectedViewRect = [inspectedView frame];
    792832    return static_cast<unsigned>(inspectedViewRect.size.width);
     
    795835void WebInspectorProxy::platformAttach()
    796836{
    797     WKView *inspectedView = inspectedPage()->wkView();
    798     [[NSNotificationCenter defaultCenter] addObserver:m_inspectorProxyObjCAdapter.get() selector:@selector(inspectedViewFrameDidChange:) name:NSViewFrameDidChangeNotification object:inspectedView];
     837    NSView *inspectedView = inspectedPage()->wkView()._inspectorAttachmentView;
    799838
    800839    if (m_inspectorWindow) {
     
    828867void WebInspectorProxy::platformDetach()
    829868{
    830     WKView *inspectedView = inspectedPage()->wkView();
    831     [[NSNotificationCenter defaultCenter] removeObserver:m_inspectorProxyObjCAdapter.get() name:NSViewFrameDidChangeNotification object:inspectedView];
     869    NSView *inspectedView = inspectedPage()->wkView()._inspectorAttachmentView;
    832870
    833871    [m_inspectorView removeFromSuperview];
Note: See TracChangeset for help on using the changeset viewer.