Add a dock button to the top right corner of the Web Inspector window (similar to...
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Nov 2012 04:05:18 +0000 (04:05 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Nov 2012 04:05:18 +0000 (04:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=102025

Reviewed by Joseph Pecoraro.

Source/WebKit:

* WebKit.xcodeproj/project.pbxproj: Added Dock.pdf.

Source/WebKit/mac:

* Resources/Dock.pdf: Added.
* WebCoreSupport/WebInspectorClient.h:
* WebCoreSupport/WebInspectorClient.mm:
(-[WebInspectorWindow _cursorForResizeDirection:]): Added.
(WebInspectorClient::didResizeMainFrame): Call attachAvailabilityChanged instead.
(WebInspectorFrontendClient::attachAvailabilityChanged): Added.
(-[WebInspectorWindowController window]): Create the dock button and add it.
(-[WebInspectorWindowController attachWindow:]): Added.
(-[WebInspectorWindowController attach]): Call setAttachedWindow.
(-[WebInspectorWindowController detach]): Ditto.
(-[WebInspectorWindowController setDockingUnavailable:]): Added. Update hidden state of the dock button.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@134347 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/WebKit.xcodeproj/project.pbxproj
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/Resources/Dock.pdf [new file with mode: 0644]
Source/WebKit/mac/WebCoreSupport/WebInspectorClient.h
Source/WebKit/mac/WebCoreSupport/WebInspectorClient.mm

index 60f1889..85393cf 100644 (file)
@@ -1,3 +1,13 @@
+2012-11-12  Timothy Hatcher  <timothy@apple.com>
+
+        Add a dock button to the top right corner of the Web Inspector window (similar to the full screen button).
+
+        https://bugs.webkit.org/show_bug.cgi?id=102025
+
+        Reviewed by Joseph Pecoraro.
+
+        * WebKit.xcodeproj/project.pbxproj: Added Dock.pdf.
+
 2012-11-08  Laszlo Gombos  <l.gombos@samsung.com>
 
         [EFL] Remove non-variable options from the build system
index d33b741..019cbd4 100644 (file)
@@ -64,6 +64,7 @@
                1C68F672095B5FC100C2984E /* WebNodeHighlightView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C68F666095B5FC100C2984E /* WebNodeHighlightView.mm */; };
                1C7B0C660EB2464D00A28502 /* WebInspectorClientCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C7B0C650EB2464D00A28502 /* WebInspectorClientCF.cpp */; };
                1C8CB07A0AE9830C00B1F6E9 /* WebEditingDelegatePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C8CB0790AE9830C00B1F6E9 /* WebEditingDelegatePrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               1C9F5EFC1651CDF700C480F8 /* Dock.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 1C9F5EFB1651CDF700C480F8 /* Dock.pdf */; };
                1CCFFD130B1F81F2002EE926 /* OldWebAssertions.c in Sources */ = {isa = PBXBuildFile; fileRef = 1CCFFD120B1F81F2002EE926 /* OldWebAssertions.c */; };
                224100F3091818D900D2D266 /* WebPluginsPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 224100F2091818D900D2D266 /* WebPluginsPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
                224100F90918190100D2D266 /* WebPluginsPrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = 224100F80918190100D2D266 /* WebPluginsPrivate.m */; };
                1C904FD30BA9DD0F0081E9D0 /* Version.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Version.xcconfig; sourceTree = "<group>"; };
                1C904FD40BA9DD0F0081E9D0 /* DebugRelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = DebugRelease.xcconfig; sourceTree = "<group>"; };
                1C904FD50BA9DD0F0081E9D0 /* Base.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Base.xcconfig; sourceTree = "<group>"; };
+               1C9F5EFB1651CDF700C480F8 /* Dock.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = Dock.pdf; sourceTree = "<group>"; };
                1CCFFD120B1F81F2002EE926 /* OldWebAssertions.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = OldWebAssertions.c; sourceTree = "<group>"; };
                224100F2091818D900D2D266 /* WebPluginsPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebPluginsPrivate.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                224100F80918190100D2D266 /* WebPluginsPrivate.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = WebPluginsPrivate.m; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                089C1665FE841158C02AAC07 /* Resources */ = {
                        isa = PBXGroup;
                        children = (
+                               1C9F5EFB1651CDF700C480F8 /* Dock.pdf */,
                                9325FBDC07D829AE00159862 /* IDNScriptWhiteList.txt */,
                                939811320824BF01008DF038 /* Info.plist */,
                                F5B67130023EDF8901C1A525 /* url_icon.tiff */,
                                939810B70824BF01008DF038 /* url_icon.tiff in Resources */,
                                939810B50824BF01008DF038 /* WebAuthenticationPanel.nib in Resources */,
                                5DE83A7A0D0F7F9400CAD12A /* WebJavaScriptTextInputPanel.nib in Resources */,
+                               1C9F5EFC1651CDF700C480F8 /* Dock.pdf in Resources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 639d102..8d45435 100644 (file)
@@ -1,3 +1,23 @@
+2012-11-12  Timothy Hatcher  <timothy@apple.com>
+
+        Add a dock button to the top right corner of the Web Inspector window (similar to the full screen button).
+
+        https://bugs.webkit.org/show_bug.cgi?id=102025
+
+        Reviewed by Joseph Pecoraro.
+
+        * Resources/Dock.pdf: Added.
+        * WebCoreSupport/WebInspectorClient.h:
+        * WebCoreSupport/WebInspectorClient.mm:
+        (-[WebInspectorWindow _cursorForResizeDirection:]): Added.
+        (WebInspectorClient::didResizeMainFrame): Call attachAvailabilityChanged instead.
+        (WebInspectorFrontendClient::attachAvailabilityChanged): Added.
+        (-[WebInspectorWindowController window]): Create the dock button and add it.
+        (-[WebInspectorWindowController attachWindow:]): Added.
+        (-[WebInspectorWindowController attach]): Call setAttachedWindow.
+        (-[WebInspectorWindowController detach]): Ditto.
+        (-[WebInspectorWindowController setDockingUnavailable:]): Added. Update hidden state of the dock button.
+
 2012-11-08  Timothy Hatcher  <timothy@apple.com>
 
         Always use a textured window for the Web Inspector.
diff --git a/Source/WebKit/mac/Resources/Dock.pdf b/Source/WebKit/mac/Resources/Dock.pdf
new file mode 100644 (file)
index 0000000..11ff0e0
Binary files /dev/null and b/Source/WebKit/mac/Resources/Dock.pdf differ
index 8069334..cb2f917 100644 (file)
@@ -90,6 +90,8 @@ class WebInspectorFrontendClient : public WebCore::InspectorFrontendClientLocal
 public:
     WebInspectorFrontendClient(WebView*, WebInspectorWindowController*, WebCore::InspectorController*, WebCore::Page*, PassOwnPtr<Settings>);
 
+    void attachAvailabilityChanged(bool);
+
     virtual void frontendLoaded();
 
     virtual String localizedStringsURL();
index 0b9041d..a3f822a 100644 (file)
 
 SOFT_LINK_STAGED_FRAMEWORK_OPTIONAL(WebInspector, PrivateFrameworks, A)
 
+// The margin from the top and right of the dock button (same as the full screen button).
+static const CGFloat dockButtonMargin = 3;
+
 using namespace WebCore;
 
+@interface NSWindow (AppKitDetails)
+- (NSCursor *)_cursorForResizeDirection:(NSInteger)direction;
+@end
+
+@interface WebInspectorWindow : NSWindow {
+@public
+    RetainPtr<NSButton> _dockButton;
+}
+@end
+
+@implementation WebInspectorWindow
+
+- (NSCursor *)_cursorForResizeDirection:(NSInteger)direction
+{
+    // Don't show a resize cursor for the northeast (top right) direction if the dock button is visible.
+    // This matches what happens when the full screen button is visible.
+    if (direction == 1 && ![_dockButton isHidden])
+        return nil;
+    return [super _cursorForResizeDirection:direction];
+}
+
+@end
+
 @interface WebInspectorWindowController : NSWindowController <NSWindowDelegate> {
 @private
     RetainPtr<WebView> _inspectedWebView;
+    RetainPtr<NSButton> _dockButton;
     WebView *_webView;
     WebInspectorFrontendClient* _frontendClient;
     WebInspectorClient* _inspectorClient;
@@ -72,6 +99,7 @@ using namespace WebCore;
 - (void)setInspectorClient:(WebInspectorClient*)inspectorClient;
 - (WebInspectorClient*)inspectorClient;
 - (void)setAttachedWindowHeight:(unsigned)height;
+- (void)setDockingUnavailable:(BOOL)unavailable;
 - (void)destroyInspectorView:(bool)notifyInspectorController;
 @end
 
@@ -120,7 +148,7 @@ void WebInspectorClient::bringFrontendToFront()
 void WebInspectorClient::didResizeMainFrame(Frame*)
 {
     if (m_frontendClient)
-        m_frontendClient->setDockingUnavailable(!m_frontendClient->canAttachWindow());
+        m_frontendClient->attachAvailabilityChanged(m_frontendClient->canAttachWindow());
 }
 
 void WebInspectorClient::highlight()
@@ -147,6 +175,12 @@ WebInspectorFrontendClient::WebInspectorFrontendClient(WebView* inspectedWebView
     [windowController setFrontendClient:this];
 }
 
+void WebInspectorFrontendClient::attachAvailabilityChanged(bool available)
+{
+    setDockingUnavailable(!available);
+    [m_windowController.get() setDockingUnavailable:!available];
+}
+
 void WebInspectorFrontendClient::frontendLoaded()
 {
     [m_windowController.get() showWindow:nil];
@@ -332,18 +366,57 @@ void WebInspectorFrontendClient::updateWindowTitle() const
 
 - (NSWindow *)window
 {
-    NSWindow *window = [super window];
+    WebInspectorWindow *window = (WebInspectorWindow *)[super window];
     if (window)
         return window;
 
     NSUInteger styleMask = (NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask | NSTexturedBackgroundWindowMask);
-    window = [[NSWindow alloc] initWithContentRect:NSMakeRect(60.0, 200.0, 750.0, 650.0) styleMask:styleMask backing:NSBackingStoreBuffered defer:NO];
+    window = [[WebInspectorWindow alloc] initWithContentRect:NSMakeRect(60.0, 200.0, 750.0, 650.0) styleMask:styleMask backing:NSBackingStoreBuffered defer:NO];
     [window setDelegate:self];
     [window setMinSize:NSMakeSize(400.0, 400.0)];
     [window setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge];
     [window setContentBorderThickness:55. forEdge:NSMaxYEdge];
     WKNSWindowMakeBottomCornersSquare(window);
 
+    // Create a full screen button so we can turn it into a dock button.
+    _dockButton = [NSWindow standardWindowButton:NSWindowFullScreenButton forStyleMask:styleMask];
+    _dockButton.get().target = self;
+    _dockButton.get().action = @selector(attachWindow:);
+
+    // Store the dock button on the window too so it can check its visibility.
+    window->_dockButton = _dockButton;
+
+    // Get the dock image and make it a template so the button cell effects will apply.
+    NSImage *dockImage = [[NSBundle bundleForClass:[self class]] imageForResource:@"Dock"];
+    [dockImage setTemplate:YES];
+
+    // Set the dock image on the button cell.
+    NSCell *dockButtonCell = _dockButton.get().cell;
+    dockButtonCell.image = dockImage;
+
+    // Get the frame view, the superview of the content view, and its frame.
+    // This will be the superview of the dock button too.
+    NSView *contentView = window.contentView;
+    NSView *frameView = contentView.superview;
+    NSRect frameViewBounds = frameView.bounds;
+    NSSize dockButtonSize = _dockButton.get().frame.size;
+
+    ASSERT(!frameView.flipped);
+
+    // Position the dock button in the corner to match where the full screen button is normally.
+    NSPoint dockButtonOrigin;
+    dockButtonOrigin.x = NSMaxX(frameViewBounds) - dockButtonSize.width - dockButtonMargin;
+    dockButtonOrigin.y = NSMaxY(frameViewBounds) - dockButtonSize.height - dockButtonMargin;
+    _dockButton.get().frameOrigin = dockButtonOrigin;
+
+    // Set the autoresizing mask to keep the dock button pinned to the top right corner.
+    _dockButton.get().autoresizingMask = NSViewMinXMargin | NSViewMinYMargin;
+
+    [frameView addSubview:_dockButton.get()];
+
+    // Hide the dock button if we can't attach.
+    _dockButton.get().hidden = !_frontendClient->canAttachWindow();
+
     [self setWindow:window];
     [window release];
 
@@ -388,6 +461,11 @@ void WebInspectorFrontendClient::updateWindowTitle() const
         [super close];
 }
 
+- (IBAction)attachWindow:(id)sender
+{
+    _frontendClient->attachWindow();
+}
+
 - (IBAction)showWindow:(id)sender
 {
     if (_visible) {
@@ -435,6 +513,7 @@ void WebInspectorFrontendClient::updateWindowTitle() const
         return;
 
     _inspectorClient->setInspectorStartsAttached(true);
+    _frontendClient->setAttachedWindow(true);
 
     [self close];
     [self showWindow:nil];
@@ -446,6 +525,7 @@ void WebInspectorFrontendClient::updateWindowTitle() const
         return;
 
     _inspectorClient->setInspectorStartsAttached(false);
+    _frontendClient->setAttachedWindow(false);
 
     [self close];
     [self showWindow:nil];
@@ -489,6 +569,11 @@ void WebInspectorFrontendClient::updateWindowTitle() const
     [frameView setFrame:frameViewRect];
 }
 
+- (void)setDockingUnavailable:(BOOL)unavailable
+{
+    _dockButton.get().hidden = unavailable;
+}
+
 - (void)destroyInspectorView:(bool)notifyInspectorController
 {
     [[_inspectedWebView.get() inspector] releaseFrontend];