Diff
Modified: trunk/Source/WebKit2/ChangeLog (181880 => 181881)
--- trunk/Source/WebKit2/ChangeLog 2015-03-23 22:56:58 UTC (rev 181880)
+++ trunk/Source/WebKit2/ChangeLog 2015-03-23 23:42:40 UTC (rev 181881)
@@ -1,3 +1,41 @@
+2015-03-19 Timothy Hatcher <[email protected]>
+
+ 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.
+
2015-03-23 Tim Horton <[email protected]>
Images shared to photos via action menu are padded with zeroes at the end
Modified: trunk/Source/WebKit2/UIProcess/API/C/WKInspector.cpp (181880 => 181881)
--- trunk/Source/WebKit2/UIProcess/API/C/WKInspector.cpp 2015-03-23 22:56:58 UTC (rev 181880)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKInspector.cpp 2015-03-23 23:42:40 UTC (rev 181881)
@@ -101,7 +101,8 @@
void WKInspectorAttach(WKInspectorRef inspectorRef)
{
- toImpl(inspectorRef)->attach();
+ auto inspector = toImpl(inspectorRef);
+ inspector->attach(inspector->attachmentSide());
}
void WKInspectorDetach(WKInspectorRef inspectorRef)
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKViewPrivate.h (181880 => 181881)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKViewPrivate.h 2015-03-23 22:56:58 UTC (rev 181880)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKViewPrivate.h 2015-03-23 23:42:40 UTC (rev 181881)
@@ -97,8 +97,10 @@
#endif
@property (readonly) NSColor *_pageExtendedBackgroundColor;
-@property(copy, nonatomic) NSColor *underlayColor;
+@property (copy, nonatomic) NSColor *underlayColor;
+@property (strong, nonatomic, setter=_setInspectorAttachmentView:) NSView *_inspectorAttachmentView WK_AVAILABLE(WK_MAC_TBA, NA);
+
- (NSView*)fullScreenPlaceholderView;
- (NSWindow*)createFullScreenWindow;
Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (181880 => 181881)
--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm 2015-03-23 22:56:58 UTC (rev 181880)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm 2015-03-23 23:42:40 UTC (rev 181881)
@@ -68,6 +68,7 @@
#import "WKViewPrivate.h"
#import "WebBackForwardList.h"
#import "WebEventFactory.h"
+#import "WebInspectorProxy.h"
#import "WebKit2Initialize.h"
#import "WebPage.h"
#import "WebPageGroup.h"
@@ -191,7 +192,9 @@
RetainPtr<NSView> _layerHostingView;
RetainPtr<id> _remoteAccessibilityChild;
-
+
+ RetainPtr<NSView> _inspectorAttachmentView;
+
// For asynchronous validation.
ValidationMap _validationMap;
@@ -4132,6 +4135,22 @@
_data->_page->setUnderlayColor(colorFromNSColor(underlayColor));
}
+- (NSView *)_inspectorAttachmentView
+{
+ NSView *attachmentView = _data->_inspectorAttachmentView.get();
+ return attachmentView ? attachmentView : self;
+}
+
+- (void)_setInspectorAttachmentView:(NSView *)newView
+{
+ NSView *oldView = _data->_inspectorAttachmentView.get();
+ if (oldView == newView)
+ return;
+
+ _data->_inspectorAttachmentView = newView;
+ _data->_page->inspector()->attachmentViewDidChange(oldView ? oldView : self, newView ? newView : self);
+}
+
- (NSView *)fullScreenPlaceholderView
{
#if ENABLE(FULLSCREEN_API)
Modified: trunk/Source/WebKit2/UIProcess/WebInspectorProxy.cpp (181880 => 181881)
--- trunk/Source/WebKit2/UIProcess/WebInspectorProxy.cpp 2015-03-23 22:56:58 UTC (rev 181880)
+++ trunk/Source/WebKit2/UIProcess/WebInspectorProxy.cpp 2015-03-23 23:42:40 UTC (rev 181881)
@@ -481,7 +481,7 @@
m_inspectorPage->process().send(Messages::WebInspectorUI::EstablishConnection(m_connectionIdentifier, m_inspectedPage->pageID(), m_underTest), m_inspectorPage->pageID());
if (!m_underTest) {
- m_canAttach = canAttach;
+ m_canAttach = platformCanAttach(canAttach);
m_isAttached = shouldOpenAttached();
m_attachmentSide = static_cast<AttachmentSide>(inspectorPagePreferences().inspectorAttachmentSide());
@@ -555,9 +555,14 @@
void WebInspectorProxy::attachAvailabilityChanged(bool available)
{
- m_canAttach = available;
+ bool previousCanAttach = m_canAttach;
- platformAttachAvailabilityChanged(available);
+ m_canAttach = platformCanAttach(available);
+
+ if (previousCanAttach == m_canAttach)
+ return;
+
+ platformAttachAvailabilityChanged(m_canAttach);
}
void WebInspectorProxy::inspectedURLChanged(const String& urlString)
Modified: trunk/Source/WebKit2/UIProcess/WebInspectorProxy.h (181880 => 181881)
--- trunk/Source/WebKit2/UIProcess/WebInspectorProxy.h 2015-03-23 22:56:58 UTC (rev 181880)
+++ trunk/Source/WebKit2/UIProcess/WebInspectorProxy.h 2015-03-23 23:42:40 UTC (rev 181881)
@@ -42,6 +42,7 @@
OBJC_CLASS NSButton;
OBJC_CLASS NSURL;
+OBJC_CLASS NSView;
OBJC_CLASS NSWindow;
OBJC_CLASS WKWebInspectorProxyObjCAdapter;
OBJC_CLASS WKWebInspectorWKWebView;
@@ -106,6 +107,8 @@
WKRect inspectorWindowFrame();
void closeTimerFired();
+
+ void attachmentViewDidChange(NSView *oldView, NSView *newView);
#endif
#if PLATFORM(GTK)
@@ -117,6 +120,7 @@
void showResources();
void showMainResourceForFrame(WebFrameProxy*);
+ AttachmentSide attachmentSide() const { return m_attachmentSide; }
bool isAttached() const { return m_isAttached; }
void attachRight();
void attachBottom();
@@ -173,6 +177,12 @@
void platformSave(const String& filename, const String& content, bool base64Encoded, bool forceSaveAs);
void platformAppend(const String& filename, const String& content);
+#if PLATFORM(MAC)
+ bool platformCanAttach(bool webProcessCanAttach);
+#else
+ bool platformCanAttach(bool webProcessCanAttach) { return webProcessCanAttach; }
+#endif
+
// Called by WebInspectorProxy messages
void createInspectorPage(IPC::Attachment, bool canAttach, bool underTest);
void didClose();
Modified: trunk/Source/WebKit2/UIProcess/mac/WebInspectorProxyMac.mm (181880 => 181881)
--- trunk/Source/WebKit2/UIProcess/mac/WebInspectorProxyMac.mm 2015-03-23 22:56:58 UTC (rev 181880)
+++ trunk/Source/WebKit2/UIProcess/mac/WebInspectorProxyMac.mm 2015-03-23 23:42:40 UTC (rev 181881)
@@ -290,6 +290,15 @@
}];
}
+void WebInspectorProxy::attachmentViewDidChange(NSView *oldView, NSView *newView)
+{
+ [[NSNotificationCenter defaultCenter] removeObserver:m_inspectorProxyObjCAdapter.get() name:NSViewFrameDidChangeNotification object:oldView];
+ [[NSNotificationCenter defaultCenter] addObserver:m_inspectorProxyObjCAdapter.get() selector:@selector(inspectedViewFrameDidChange:) name:NSViewFrameDidChangeNotification object:newView];
+
+ if (m_isAttached)
+ attach(m_attachmentSide);
+}
+
void WebInspectorProxy::setInspectorWindowFrame(WKRect& frame)
{
if (m_isAttached)
@@ -318,6 +327,8 @@
m_inspectorView = nil;
}
+ [[NSNotificationCenter defaultCenter] removeObserver:m_inspectorProxyObjCAdapter.get()];
+
[m_inspectorProxyObjCAdapter close];
m_inspectorProxyObjCAdapter = nil;
}
@@ -459,9 +470,11 @@
ASSERT(!m_inspectorView);
ASSERT(!m_inspectorProxyObjCAdapter);
+ NSView *inspectedView = inspectedPage()->wkView()._inspectorAttachmentView;
+
NSRect initialRect;
if (m_isAttached) {
- NSRect inspectedViewFrame = inspectedPage()->wkView().frame;
+ NSRect inspectedViewFrame = inspectedView.frame;
switch (m_attachmentSide) {
case AttachmentSide::Bottom:
@@ -508,6 +521,8 @@
[m_inspectorView setInspectorProxyObjCAdapter:m_inspectorProxyObjCAdapter.get()];
+ [[NSNotificationCenter defaultCenter] addObserver:m_inspectorProxyObjCAdapter.get() selector:@selector(inspectedViewFrameDidChange:) name:NSViewFrameDidChangeNotification object:inspectedView];
+
WebPageProxy* inspectorPage = m_inspectorView->_page.get();
ASSERT(inspectorPage);
@@ -566,6 +581,22 @@
return inspectorPage;
}
+bool WebInspectorProxy::platformCanAttach(bool webProcessCanAttach)
+{
+ NSView *inspectedView = inspectedPage()->wkView()._inspectorAttachmentView;
+ if ([inspectedView isKindOfClass:[WKView class]])
+ return webProcessCanAttach;
+
+ static const float minimumAttachedHeight = 250;
+ static const float maximumAttachedHeightRatio = 0.75;
+ static const float minimumAttachedWidth = 750;
+
+ NSRect inspectedViewFrame = inspectedView.frame;
+
+ float maximumAttachedHeight = NSHeight(inspectedViewFrame) * maximumAttachedHeightRatio;
+ return minimumAttachedHeight <= maximumAttachedHeight && minimumAttachedWidth <= NSWidth(inspectedViewFrame);
+}
+
void WebInspectorProxy::platformOpen()
{
if (m_isAttached)
@@ -727,10 +758,17 @@
void WebInspectorProxy::inspectedViewFrameDidChange(CGFloat currentDimension)
{
- if (!m_isAttached || !m_isVisible)
+ if (!m_isVisible)
return;
- WKView *inspectedView = inspectedPage()->wkView();
+ if (!m_isAttached) {
+ // Check if the attach avaibility changed. We need to do this here in case
+ // the attachment view is not the WKView.
+ attachAvailabilityChanged(platformCanAttach(canAttach()));
+ return;
+ }
+
+ NSView *inspectedView = inspectedPage()->wkView()._inspectorAttachmentView;
NSRect inspectedViewFrame = [inspectedView frame];
NSRect inspectorFrame = NSZeroRect;
NSRect parentBounds = [[inspectedView superview] bounds];
@@ -760,7 +798,9 @@
// Preserve the top position of the inspected view so banners in Safari still work. But don't use that
// top position for the inspector view since the banners only stretch as wide as the the inspected view.
inspectedViewFrame = NSMakeRect(0, 0, parentWidth - inspectorWidth, inspectedViewTop);
- CGFloat insetExcludingBanners = inspectedView._topContentInset - inspectedView._totalHeightOfBanners;
+ CGFloat insetExcludingBanners = 0;
+ if ([inspectedView isKindOfClass:[WKView class]])
+ insetExcludingBanners = ((WKView *)inspectedView)._topContentInset - ((WKView *)inspectedView)._totalHeightOfBanners;
inspectorFrame = NSMakeRect(parentWidth - inspectorWidth, 0, inspectorWidth, NSHeight(parentBounds) - insetExcludingBanners);
break;
}
@@ -780,22 +820,21 @@
unsigned WebInspectorProxy::platformInspectedWindowHeight()
{
- WKView *inspectedView = inspectedPage()->wkView();
+ NSView *inspectedView = inspectedPage()->wkView()._inspectorAttachmentView;
NSRect inspectedViewRect = [inspectedView frame];
return static_cast<unsigned>(inspectedViewRect.size.height);
}
unsigned WebInspectorProxy::platformInspectedWindowWidth()
{
- WKView *inspectedView = inspectedPage()->wkView();
+ NSView *inspectedView = inspectedPage()->wkView()._inspectorAttachmentView;
NSRect inspectedViewRect = [inspectedView frame];
return static_cast<unsigned>(inspectedViewRect.size.width);
}
void WebInspectorProxy::platformAttach()
{
- WKView *inspectedView = inspectedPage()->wkView();
- [[NSNotificationCenter defaultCenter] addObserver:m_inspectorProxyObjCAdapter.get() selector:@selector(inspectedViewFrameDidChange:) name:NSViewFrameDidChangeNotification object:inspectedView];
+ NSView *inspectedView = inspectedPage()->wkView()._inspectorAttachmentView;
if (m_inspectorWindow) {
[m_inspectorWindow setDelegate:nil];
@@ -827,8 +866,7 @@
void WebInspectorProxy::platformDetach()
{
- WKView *inspectedView = inspectedPage()->wkView();
- [[NSNotificationCenter defaultCenter] removeObserver:m_inspectorProxyObjCAdapter.get() name:NSViewFrameDidChangeNotification object:inspectedView];
+ NSView *inspectedView = inspectedPage()->wkView()._inspectorAttachmentView;
[m_inspectorView removeFromSuperview];