- Revision
- 199630
- Author
- wei...@apple.com
- Date
- 2016-04-16 17:10:45 -0700 (Sat, 16 Apr 2016)
Log Message
Add support for NSSharingService to MiniBrowser, for no great reasons
https://bugs.webkit.org/show_bug.cgi?id=156658
Reviewed by Darin Adler.
* MiniBrowser/mac/BrowserWindow.xib:
* MiniBrowser/mac/BrowserWindowController.h:
Add the share button.
* MiniBrowser/mac/BrowserWindowController.m:
(-[BrowserWindowController windowDidLoad]):
Set the share button to fire it's actions on mouse down, as it is supposed to act like a menu.
(-[BrowserWindowController share:]):
Show the picker when the button is pressed.
(-[BrowserWindowController mainContentView]):
Add a new override to get the main content view of derived classes (either a WKWebView or the WebView).
(-[BrowserWindowController sharingServicePicker:sharingServicesForItems:proposedSharingServices:]):
(-[BrowserWindowController sharingServicePicker:delegateForSharingService:]):
(-[BrowserWindowController sharingServicePicker:didChooseSharingService:]):
(-[BrowserWindowController sharingService:sourceFrameOnScreenForShareItem:]):
(-[BrowserWindowController sharingService:transitionImageForShareItem:contentRect:]):
(-[BrowserWindowController sharingService:sourceWindowForShareItems:sharingContentScope:]):
Add delegate methods.
* MiniBrowser/mac/WK1BrowserWindowController.m:
(-[WK1BrowserWindowController mainContentView]):
* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController mainContentView]):
Implement to return the web view.
Modified Paths
Diff
Modified: trunk/Tools/ChangeLog (199629 => 199630)
--- trunk/Tools/ChangeLog 2016-04-16 22:52:48 UTC (rev 199629)
+++ trunk/Tools/ChangeLog 2016-04-17 00:10:45 UTC (rev 199630)
@@ -1,3 +1,37 @@
+2016-04-15 Sam Weinig <s...@webkit.org>
+
+ Add support for NSSharingService to MiniBrowser, for no great reasons
+ https://bugs.webkit.org/show_bug.cgi?id=156658
+
+ Reviewed by Darin Adler.
+
+ * MiniBrowser/mac/BrowserWindow.xib:
+ * MiniBrowser/mac/BrowserWindowController.h:
+ Add the share button.
+
+ * MiniBrowser/mac/BrowserWindowController.m:
+ (-[BrowserWindowController windowDidLoad]):
+ Set the share button to fire it's actions on mouse down, as it is supposed to act like a menu.
+
+ (-[BrowserWindowController share:]):
+ Show the picker when the button is pressed.
+ (-[BrowserWindowController mainContentView]):
+ Add a new override to get the main content view of derived classes (either a WKWebView or the WebView).
+
+ (-[BrowserWindowController sharingServicePicker:sharingServicesForItems:proposedSharingServices:]):
+ (-[BrowserWindowController sharingServicePicker:delegateForSharingService:]):
+ (-[BrowserWindowController sharingServicePicker:didChooseSharingService:]):
+ (-[BrowserWindowController sharingService:sourceFrameOnScreenForShareItem:]):
+ (-[BrowserWindowController sharingService:transitionImageForShareItem:contentRect:]):
+ (-[BrowserWindowController sharingService:sourceWindowForShareItems:sharingContentScope:]):
+ Add delegate methods.
+
+ * MiniBrowser/mac/WK1BrowserWindowController.m:
+ (-[WK1BrowserWindowController mainContentView]):
+ * MiniBrowser/mac/WK2BrowserWindowController.m:
+ (-[WK2BrowserWindowController mainContentView]):
+ Implement to return the web view.
+
2016-04-16 Alexey Proskuryakov <a...@apple.com>
Build fix.
Modified: trunk/Tools/MiniBrowser/mac/BrowserWindow.xib (199629 => 199630)
--- trunk/Tools/MiniBrowser/mac/BrowserWindow.xib 2016-04-16 22:52:48 UTC (rev 199629)
+++ trunk/Tools/MiniBrowser/mac/BrowserWindow.xib 2016-04-17 00:10:45 UTC (rev 199630)
@@ -1,17 +1,21 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="8068.4" systemVersion="14D136" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
+<?xml version="1.0" encoding="UTF-8"?>
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11085" systemVersion="16A167" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
- <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="8068.4"/>
+ <deployment identifier="macosx"/>
+ <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11085"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="BrowserWindowController">
<connections>
+ <outlet property="Share" destination="dJx-dw-gcC" id="j0J-ps-exa"/>
<outlet property="backButton" destination="40" id="46"/>
<outlet property="containerView" destination="9" id="37"/>
<outlet property="findPanelWindow" destination="70" id="77"/>
<outlet property="forwardButton" destination="42" id="47"/>
<outlet property="progressIndicator" destination="21" id="33"/>
<outlet property="reloadButton" destination="23" id="34"/>
+ <outlet property="share" destination="1hB-AH-eUl" id="si4-8e-DsM"/>
+ <outlet property="shareButton" destination="S1v-UD-QhI" id="t4L-Uq-paq"/>
<outlet property="toggleUseShrinkToFitButton" destination="82" id="9w7-AB-Ye3"/>
<outlet property="toolbar" destination="48" id="67"/>
<outlet property="urlText" destination="10" id="32"/>
@@ -39,10 +43,10 @@
<allowedToolbarItems>
<toolbarItem implicitItemIdentifier="73DE9F4B-73E2-4036-A134-2D9E029DA980" label="Go Back" paletteLabel="Go Back" image="NSGoLeftTemplate" id="56" customClass="MBToolbarItem">
<nil key="toolTip"/>
- <size key="minSize" width="32" height="25"/>
+ <size key="minSize" width="32" height="27"/>
<size key="maxSize" width="32" height="25"/>
<button key="view" verticalHuggingPriority="750" id="40">
- <rect key="frame" x="11" y="14" width="32" height="25"/>
+ <rect key="frame" x="10" y="14" width="32" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" image="NSGoLeftTemplate" imagePosition="overlaps" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="41">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -55,10 +59,10 @@
</toolbarItem>
<toolbarItem implicitItemIdentifier="E1A9D32A-59E3-467B-9ABA-A95780416E69" label="Go Forward" paletteLabel="Go Forward" image="NSGoRightTemplate" id="57" customClass="MBToolbarItem">
<nil key="toolTip"/>
- <size key="minSize" width="32" height="25"/>
- <size key="maxSize" width="32" height="25"/>
+ <size key="minSize" width="32" height="27"/>
+ <size key="maxSize" width="32" height="27"/>
<button key="view" verticalHuggingPriority="750" id="42">
- <rect key="frame" x="19" y="14" width="32" height="25"/>
+ <rect key="frame" x="18" y="14" width="32" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" image="NSGoRightTemplate" imagePosition="overlaps" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="43">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -71,8 +75,8 @@
</toolbarItem>
<toolbarItem implicitItemIdentifier="88C16109-D40F-4682-BCE4-CBEE2EDE32D2" label="Refresh" paletteLabel="Refresh" image="NSRefreshTemplate" id="58" customClass="MBToolbarItem">
<nil key="toolTip"/>
- <size key="minSize" width="29" height="25"/>
- <size key="maxSize" width="29" height="25"/>
+ <size key="minSize" width="29" height="27"/>
+ <size key="maxSize" width="29" height="27"/>
<button key="view" verticalHuggingPriority="750" id="23">
<rect key="frame" x="10" y="14" width="29" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
@@ -87,10 +91,10 @@
</toolbarItem>
<toolbarItem implicitItemIdentifier="76DCF2B0-1DDE-47D2-9212-705E6E310CCE" label="Use Shrink To Fit" paletteLabel="Use Shrink To Fit" image="NSEnterFullScreenTemplate" id="81" customClass="MBToolbarItem">
<nil key="toolTip"/>
- <size key="minSize" width="29" height="25"/>
- <size key="maxSize" width="29" height="25"/>
+ <size key="minSize" width="29" height="27"/>
+ <size key="maxSize" width="29" height="27"/>
<button key="view" verticalHuggingPriority="750" id="82">
- <rect key="frame" x="19" y="14" width="29" height="25"/>
+ <rect key="frame" x="34" y="14" width="29" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" image="NSEnterFullScreenTemplate" imagePosition="overlaps" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="83">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@@ -101,14 +105,21 @@
</connections>
</button>
</toolbarItem>
- <toolbarItem implicitItemIdentifier="6BDC61B7-F1A8-425A-A212-9CAC59C56385" label="Progress" paletteLabel="Progress" tag="-1" id="60">
+ <toolbarItem implicitItemIdentifier="F1738B7F-895C-48F7-955D-0915E150BE1B" label="Share" paletteLabel="Share" image="NSShareTemplate" id="dJx-dw-gcC" customClass="MBToolbarItem">
<nil key="toolTip"/>
- <size key="minSize" width="16" height="16"/>
- <size key="maxSize" width="16" height="16"/>
- <progressIndicator key="view" horizontalHuggingPriority="750" verticalHuggingPriority="750" maxValue="1" displayedWhenStopped="NO" bezeled="NO" controlSize="small" style="spinning" id="21">
- <rect key="frame" x="19" y="14" width="16" height="16"/>
- <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
- </progressIndicator>
+ <size key="minSize" width="29" height="27"/>
+ <size key="maxSize" width="29" height="27"/>
+ <button key="view" verticalHuggingPriority="750" id="1hB-AH-eUl">
+ <rect key="frame" x="5" y="14" width="29" height="25"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <buttonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" image="NSShareTemplate" imagePosition="overlaps" alignment="center" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="S1v-UD-QhI">
+ <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+ <font key="font" metaFont="system"/>
+ <connections>
+ <action selector="share:" target="-2" id="5e3-hg-bKN"/>
+ </connections>
+ </buttonCell>
+ </button>
</toolbarItem>
<toolbarItem implicitItemIdentifier="255D29F2-C9AA-4B4B-BB43-B38FCD6A0BBB" label="Location" paletteLabel="Location" id="59">
<nil key="toolTip"/>
@@ -127,6 +138,15 @@
</connections>
</textField>
</toolbarItem>
+ <toolbarItem implicitItemIdentifier="86912BAA-B8D0-400F-BFEE-71FC166986E6" label="Progress" paletteLabel="Progress" tag="-1" id="60">
+ <nil key="toolTip"/>
+ <size key="minSize" width="16" height="16"/>
+ <size key="maxSize" width="16" height="16"/>
+ <progressIndicator key="view" horizontalHuggingPriority="750" verticalHuggingPriority="750" maxValue="1" displayedWhenStopped="NO" bezeled="NO" controlSize="small" style="spinning" id="21">
+ <rect key="frame" x="19" y="14" width="16" height="16"/>
+ <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
+ </progressIndicator>
+ </toolbarItem>
</allowedToolbarItems>
<defaultToolbarItems>
<toolbarItem reference="56"/>
@@ -134,6 +154,7 @@
<toolbarItem reference="58"/>
<toolbarItem reference="59"/>
<toolbarItem reference="60"/>
+ <toolbarItem reference="dJx-dw-gcC"/>
</defaultToolbarItems>
</toolbar>
<connections>
@@ -170,5 +191,6 @@
<image name="NSGoLeftTemplate" width="9" height="12"/>
<image name="NSGoRightTemplate" width="9" height="12"/>
<image name="NSRefreshTemplate" width="11" height="15"/>
+ <image name="NSShareTemplate" width="11" height="16"/>
</resources>
</document>
Modified: trunk/Tools/MiniBrowser/mac/BrowserWindowController.h (199629 => 199630)
--- trunk/Tools/MiniBrowser/mac/BrowserWindowController.h 2016-04-16 22:52:48 UTC (rev 199629)
+++ trunk/Tools/MiniBrowser/mac/BrowserWindowController.h 2016-04-17 00:10:45 UTC (rev 199630)
@@ -30,6 +30,7 @@
IBOutlet NSButton *reloadButton;
IBOutlet NSButton *backButton;
IBOutlet NSButton *forwardButton;
+ IBOutlet NSButton *share;
IBOutlet NSToolbar *toolbar;
IBOutlet NSTextField *urlText;
IBOutlet NSView *containerView;
@@ -48,6 +49,7 @@
- (IBAction)openLocation:(id)sender;
- (IBAction)fetch:(id)sender;
+- (IBAction)share:(id)sender;
- (IBAction)reload:(id)sender;
- (IBAction)forceRepaint:(id)sender;
- (IBAction)goBack:(id)sender;
@@ -75,6 +77,7 @@
- (void)didChangeSettings;
- (NSURL *)currentURL;
+- (NSView *)mainContentView;
@end
Modified: trunk/Tools/MiniBrowser/mac/BrowserWindowController.m (199629 => 199630)
--- trunk/Tools/MiniBrowser/mac/BrowserWindowController.m 2016-04-16 22:52:48 UTC (rev 199629)
+++ trunk/Tools/MiniBrowser/mac/BrowserWindowController.m 2016-04-17 00:10:45 UTC (rev 199630)
@@ -25,8 +25,7 @@
#import "BrowserWindowController.h"
-@interface BrowserWindowController ()
-
+@interface BrowserWindowController () <NSSharingServicePickerDelegate, NSSharingServiceDelegate>
@end
@implementation BrowserWindowController
@@ -41,6 +40,12 @@
{
self.window.styleMask |= NSWindowStyleMaskFullSizeContentView;
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
+ [share sendActionOn:NSEventMaskLeftMouseDown];
+#else
+ [share sendActionOn:NSLeftMouseDownMask];
+#endif
+
[super windowDidLoad];
}
@@ -68,6 +73,13 @@
return [@"http://" stringByAppendingString:address];
}
+- (IBAction)share:(id)sender
+{
+ NSSharingServicePicker *picker = [[NSSharingServicePicker alloc] initWithItems:@[ self.currentURL ]];
+ picker.delegate = self;
+ [picker showRelativeToRect:CGRectZero ofView:sender preferredEdge:NSRectEdgeMinY];
+}
+
- (IBAction)fetch:(id)sender
{
[self doesNotRecognizeSelector:_cmd];
@@ -172,4 +184,65 @@
return nil;
}
+- (NSView *)mainContentView
+{
+ [self doesNotRecognizeSelector:_cmd];
+ return nil;
+}
+
+#pragma mark -
+#pragma mark NSSharingServicePickerDelegate
+
+- (NSArray<NSSharingService *> *)sharingServicePicker:(NSSharingServicePicker *)sharingServicePicker sharingServicesForItems:(NSArray *)items proposedSharingServices:(NSArray<NSSharingService *> *)proposedServices
+{
+ return proposedServices;
+}
+
+- (nullable id <NSSharingServiceDelegate>)sharingServicePicker:(NSSharingServicePicker *)sharingServicePicker delegateForSharingService:(NSSharingService *)sharingService
+{
+ return self;
+}
+
+- (void)sharingServicePicker:(NSSharingServicePicker *)sharingServicePicker didChooseSharingService:(nullable NSSharingService *)service
+{
+}
+
+#pragma mark -
+#pragma mark NSSharingServiceDelegate
+
+- (NSRect)sharingService:(NSSharingService *)sharingService sourceFrameOnScreenForShareItem:(id)item
+{
+ NSRect rect = [self.window convertRectToScreen:self.mainContentView.bounds];
+
+ return rect;
+}
+
+static CGRect coreGraphicsScreenRectForAppKitScreenRect(NSRect rect)
+{
+ NSScreen *firstScreen = [NSScreen screens][0];
+ return CGRectMake(NSMinX(rect), NSHeight(firstScreen.frame) - NSMinY(rect) - NSHeight(rect), NSWidth(rect), NSHeight(rect));
+}
+
+- (NSImage *)sharingService:(NSSharingService *)sharingService transitionImageForShareItem:(id)item contentRect:(NSRect *)contentRect
+{
+ NSRect contentFrame = [self.window convertRectToScreen:self.mainContentView.bounds];
+
+ CGRect frame = coreGraphicsScreenRectForAppKitScreenRect(NSRectToCGRect(contentFrame));
+ CGImageRef imageRef = CGWindowListCreateImage(frame, kCGWindowListOptionIncludingWindow, (CGWindowID)[self.window windowNumber], kCGWindowImageBoundsIgnoreFraming);
+
+ if (!imageRef)
+ return nil;
+
+ NSImage *image = [[NSImage alloc] initWithCGImage:imageRef size:NSZeroSize];
+ CGImageRelease(imageRef);
+
+ return image;
+}
+
+- (nullable NSWindow *)sharingService:(NSSharingService *)sharingService sourceWindowForShareItems:(NSArray *)items sharingContentScope:(NSSharingContentScope *)sharingContentScope
+{
+ *sharingContentScope = NSSharingContentScopeFull;
+ return self.window;
+}
+
@end
Modified: trunk/Tools/MiniBrowser/mac/WK1BrowserWindowController.m (199629 => 199630)
--- trunk/Tools/MiniBrowser/mac/WK1BrowserWindowController.m 2016-04-16 22:52:48 UTC (rev 199629)
+++ trunk/Tools/MiniBrowser/mac/WK1BrowserWindowController.m 2016-04-17 00:10:45 UTC (rev 199630)
@@ -250,6 +250,11 @@
return _webView.mainFrame.dataSource.request.URL;
}
+- (NSView *)mainContentView
+{
+ return _webView;
+}
+
- (void)didChangeSettings
{
SettingsController *settings = [SettingsController shared];
Modified: trunk/Tools/MiniBrowser/mac/WK2BrowserWindowController.m (199629 => 199630)
--- trunk/Tools/MiniBrowser/mac/WK2BrowserWindowController.m 2016-04-16 22:52:48 UTC (rev 199629)
+++ trunk/Tools/MiniBrowser/mac/WK2BrowserWindowController.m 2016-04-17 00:10:45 UTC (rev 199630)
@@ -260,6 +260,11 @@
return _webView.URL;
}
+- (NSView *)mainContentView
+{
+ return _webView;
+}
+
- (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)item
{
SEL action = ""