Make WebKit2 more accessible in MiniBrowser
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Jun 2014 18:32:59 +0000 (18:32 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Jun 2014 18:32:59 +0000 (18:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=134099

Reviewed by Anders Carlsson.

* MiniBrowser/mac/AppDelegate.h:
* MiniBrowser/mac/AppDelegate.m:
(-[BrowserAppDelegate newWindow:]):
(-[BrowserAppDelegate applicationDidFinishLaunching:]):
(-[BrowserAppDelegate toggleUseWebKit2ByDefault:]):
(-[BrowserAppDelegate _useWebKit2ByDefault]):
(-[BrowserAppDelegate _updateNewWindowKeyEquivalents]):
(-[BrowserAppDelegate validateMenuItem:]):
* MiniBrowser/mac/MainMenu.xib:
Add a "Use WebKit2 By Default" menu item to the top of the Debug menu.
When switched on, Cmd-N will make WebKit2 windows (and the default window will be WebKit2).
Make the non-default new-window menu item always show up, because people often don't find it
when you have to press option to have it show up.

* MiniBrowser/mac/BrowserWindowController.h:
* MiniBrowser/mac/BrowserWindowController.m:
(-[BrowserWindowController initWithWindow:]):

* MiniBrowser/mac/WK1BrowserWindowController.m:
(-[WK1BrowserWindowController validateMenuItem:]):
* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController validateMenuItem:]):
Use the cached [menuItem action] like the earlier cases do.

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

Tools/ChangeLog
Tools/MiniBrowser/mac/AppDelegate.h
Tools/MiniBrowser/mac/AppDelegate.m
Tools/MiniBrowser/mac/BrowserWindowController.h
Tools/MiniBrowser/mac/BrowserWindowController.m
Tools/MiniBrowser/mac/MainMenu.xib
Tools/MiniBrowser/mac/WK1BrowserWindowController.m
Tools/MiniBrowser/mac/WK2BrowserWindowController.m

index 38295de..b330705 100644 (file)
@@ -1,3 +1,34 @@
+2014-06-20  Tim Horton  <timothy_horton@apple.com>
+
+        Make WebKit2 more accessible in MiniBrowser
+        https://bugs.webkit.org/show_bug.cgi?id=134099
+
+        Reviewed by Anders Carlsson.
+
+        * MiniBrowser/mac/AppDelegate.h:
+        * MiniBrowser/mac/AppDelegate.m:
+        (-[BrowserAppDelegate newWindow:]):
+        (-[BrowserAppDelegate applicationDidFinishLaunching:]):
+        (-[BrowserAppDelegate toggleUseWebKit2ByDefault:]):
+        (-[BrowserAppDelegate _useWebKit2ByDefault]):
+        (-[BrowserAppDelegate _updateNewWindowKeyEquivalents]):
+        (-[BrowserAppDelegate validateMenuItem:]):
+        * MiniBrowser/mac/MainMenu.xib:
+        Add a "Use WebKit2 By Default" menu item to the top of the Debug menu.
+        When switched on, Cmd-N will make WebKit2 windows (and the default window will be WebKit2).
+        Make the non-default new-window menu item always show up, because people often don't find it
+        when you have to press option to have it show up.
+
+        * MiniBrowser/mac/BrowserWindowController.h:
+        * MiniBrowser/mac/BrowserWindowController.m:
+        (-[BrowserWindowController initWithWindow:]):
+        
+        * MiniBrowser/mac/WK1BrowserWindowController.m:
+        (-[WK1BrowserWindowController validateMenuItem:]):
+        * MiniBrowser/mac/WK2BrowserWindowController.m:
+        (-[WK2BrowserWindowController validateMenuItem:]):
+        Use the cached [menuItem action] like the earlier cases do.
+
 2014-06-20  Daniel Bates  <dabates@apple.com>
 
         Teach run-{safari, webkit-app} about iOS Simulator
index 46df9b5..8ead0ef 100644 (file)
 
 @interface BrowserAppDelegate : NSObject <NSApplicationDelegate> {
     NSMutableSet *_browserWindowControllers;
+
+    IBOutlet NSMenuItem *_newWebKit1WindowItem;
+    IBOutlet NSMenuItem *_newWebKit2WindowItem;
 }
 
 - (void)browserWindowWillClose:(NSWindow *)window;
 
+- (IBAction)toggleUseWebKit2ByDefault:(id)sender;
+
 @end
index a25375b..524a3cf 100644 (file)
@@ -31,6 +31,7 @@
 #import <WebKit/WebKit2.h>
 
 static NSString *defaultURL = @"http://www.webkit.org/";
+static NSString *useWebKit2ByDefaultPreferenceKey = @"UseWebKit2ByDefault";
 
 enum {
     WebKit1NewWindowTag = 1,
@@ -52,11 +53,18 @@ enum {
 - (IBAction)newWindow:(id)sender
 {
     BrowserWindowController *controller = nil;
+
+    BOOL useWebKit2 = NO;
+
+    if (![sender respondsToSelector:@selector(tag)])
+        useWebKit2 = [self _useWebKit2ByDefault];
+    else
+        useWebKit2 = [sender tag] == WebKit2NewWindowTag;
     
-    if (![sender respondsToSelector:@selector(tag)] || [sender tag] == WebKit1NewWindowTag)
+    if (!useWebKit2)
         controller = [[WK1BrowserWindowController alloc] initWithWindowNibName:@"BrowserWindow"];
 #if WK_API_ENABLED
-    else if ([sender tag] == WebKit2NewWindowTag)
+    else
         controller = [[WK2BrowserWindowController alloc] initWithWindowNibName:@"BrowserWindow"];
 #endif
     if (!controller)
@@ -79,6 +87,7 @@ enum {
     [WebHistory setOptionalSharedHistory:webHistory];
     [webHistory release];
 
+    [self _updateNewWindowKeyEquivalents];
     [self newWindow:self];
 }
 
@@ -133,4 +142,38 @@ enum {
     }];
 }
 
+- (IBAction)toggleUseWebKit2ByDefault:(id)sender
+{
+    BOOL newUseWebKit2ByDefault = ![self _useWebKit2ByDefault];
+    if (!newUseWebKit2ByDefault)
+        [[NSUserDefaults standardUserDefaults] removeObjectForKey:useWebKit2ByDefaultPreferenceKey];
+    else
+        [[NSUserDefaults standardUserDefaults] setBool:newUseWebKit2ByDefault forKey:useWebKit2ByDefaultPreferenceKey];
+    [self _updateNewWindowKeyEquivalents];
+}
+
+- (BOOL)_useWebKit2ByDefault
+{
+    return [[NSUserDefaults standardUserDefaults] boolForKey:useWebKit2ByDefaultPreferenceKey];
+}
+
+- (void)_updateNewWindowKeyEquivalents
+{
+    if ([self _useWebKit2ByDefault]) {
+        [_newWebKit1WindowItem setKeyEquivalentModifierMask:NSCommandKeyMask | NSAlternateKeyMask];
+        [_newWebKit2WindowItem setKeyEquivalentModifierMask:NSCommandKeyMask];
+    } else {
+        [_newWebKit1WindowItem setKeyEquivalentModifierMask:NSCommandKeyMask];
+        [_newWebKit2WindowItem setKeyEquivalentModifierMask:NSCommandKeyMask | NSAlternateKeyMask];
+    }
+}
+
+- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
+{
+    if ([menuItem action] == @selector(toggleUseWebKit2ByDefault:))
+        [menuItem setState:[self _useWebKit2ByDefault] ? NSOnState : NSOffState];
+
+    return YES;
+}
+
 @end
index 7c8ad21..4c9345d 100644 (file)
@@ -66,7 +66,7 @@
     IBOutlet NSView *containerView;
     
     IBOutlet NSWindow *findPanelWindow;
-    
+
     BOOL _zoomTextOnly;
 }
 
index ba38d25..795f2a2 100644 (file)
@@ -34,9 +34,6 @@
 - (id)initWithWindow:(NSWindow *)window
 {
     self = [super initWithWindow:window];
-    if (self) {
-    }
-    
     return self;
 }
 
index dfce6ee..6b53323 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6119.2" systemVersion="13C64" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13D65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
     <dependencies>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6119.2"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
     </dependencies>
     <objects>
         <customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
@@ -75,7 +75,7 @@
                                     <action selector="newWindow:" target="-1" id="574"/>
                                 </connections>
                             </menuItem>
-                            <menuItem title="New WebKit2 Window" tag="2" alternate="YES" keyEquivalent="n" id="571">
+                            <menuItem title="New WebKit2 Window" tag="2" keyEquivalent="n" id="571">
                                 <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
                                 <connections>
                                     <action selector="newWindow:" target="-1" id="572"/>
                     <modifierMask key="keyEquivalentModifierMask"/>
                     <menu key="submenu" title="Debug" id="535">
                         <items>
+                            <menuItem title="Use WebKit2 By Default" id="GmH-08-ZX9">
+                                <modifierMask key="keyEquivalentModifierMask"/>
+                                <connections>
+                                    <action selector="toggleUseWebKit2ByDefault:" target="494" id="xgA-9P-zY6"/>
+                                </connections>
+                            </menuItem>
+                            <menuItem isSeparatorItem="YES" id="kgf-Bs-8S1"/>
                             <menuItem title="Force Repaint" keyEquivalent="r" id="545">
                                 <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
                                 <connections>
                 </menuItem>
             </items>
         </menu>
-        <customObject id="494" customClass="BrowserAppDelegate"/>
+        <customObject id="494" customClass="BrowserAppDelegate">
+            <connections>
+                <outlet property="_newWebKit1WindowItem" destination="573" id="ZCj-u2-PU7"/>
+                <outlet property="_newWebKit2WindowItem" destination="571" id="1Gv-mK-aul"/>
+            </connections>
+        </customObject>
         <customObject id="420" customClass="NSFontManager"/>
     </objects>
 </document>
index 23cb27b..e38f21a 100644 (file)
         [menuItem setTitle:[_webView window] ? @"Remove Web View" : @"Insert Web View"];
     else if (action == @selector(toggleZoomMode:))
         [menuItem setState:_zoomTextOnly ? NSOnState : NSOffState];
-    else if ([menuItem action] == @selector(togglePaginationMode:))
+    else if (action == @selector(togglePaginationMode:))
         [menuItem setState:[self isPaginated] ? NSOnState : NSOffState];
-    else if ([menuItem action] == @selector(toggleTransparentWindow:))
+    else if (action == @selector(toggleTransparentWindow:))
         [menuItem setState:[[self window] isOpaque] ? NSOffState : NSOnState];
-    else if ([menuItem action] == @selector(toggleSubpixelCSSOMElementMetricsEnabled:))
+    else if (action == @selector(toggleSubpixelCSSOMElementMetricsEnabled:))
         [menuItem setState:[self isSubpixelCSSOMElementMetricsEnabled] ? NSOnState : NSOffState];
 
     return YES;
index f70fd90..12ca5ff 100644 (file)
@@ -132,13 +132,13 @@ static NSString * const WebKit2SubpixelCSSOMElementMetricsEnabledKey = @"WebKitS
         [menuItem setTitle:[_webView window] ? @"Remove Web View" : @"Insert Web View"];
     else if (action == @selector(toggleZoomMode:))
         [menuItem setState:_zoomTextOnly ? NSOnState : NSOffState];
-    else if ([menuItem action] == @selector(togglePaginationMode:))
+    else if (action == @selector(togglePaginationMode:))
         [menuItem setState:[self isPaginated] ? NSOnState : NSOffState];
-    else if ([menuItem action] == @selector(toggleTransparentWindow:))
+    else if (action == @selector(toggleTransparentWindow:))
         [menuItem setState:[[self window] isOpaque] ? NSOffState : NSOnState];
-    else if ([menuItem action] == @selector(toggleUISideCompositing:))
+    else if (action == @selector(toggleUISideCompositing:))
         [menuItem setState:[self isUISideCompositingEnabled] ? NSOnState : NSOffState];
-    else if ([menuItem action] == @selector(toggleSubpixelCSSOMElementMetricsEnabled:))
+    else if (action == @selector(toggleSubpixelCSSOMElementMetricsEnabled:))
         [menuItem setState:[self isSubpixelCSSOMElementMetricsEnabled] ? NSOnState : NSOffState];
 
     return YES;