[WebEditingTester] Hook up key equivalents for new window action
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Feb 2015 19:17:51 +0000 (19:17 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Feb 2015 19:17:51 +0000 (19:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=141828

Reviewed by Enrica Casucci.

* WebEditingTester/AppDelegate.h:
* WebEditingTester/AppDelegate.m:
(-[WebEditingAppDelegate applicationDidFinishLaunching:]):
(-[WebEditingAppDelegate newEditor:]):
(-[WebEditingAppDelegate _defaultWebDocumentControllerClass]):
(-[WebEditingAppDelegate toggleUseWK2ByDefault:]):
(-[WebEditingAppDelegate _updateNewWindowKeyEquivalents]):
(defaultConfiguration): Deleted.
(-[WebEditingAppDelegate applicationWillTerminate:]): Deleted.
Move WKWebViewConfiguration setup into WK2WebDocumentController.
Remove unused application termination code.
Update new-window menu item key equivalents when launching and when
changing the use-WebKit2-by-default setting.
Make WebDocumentController subclasses all initialized the same way,
and use that to factor out alloc/init.
Rename loadContent to loadHTMLString for future use.

* WebEditingTester/MainMenu.xib:
Add default key equivalents.
Cmd-N will always make the default kind of window (controlled by the pref).
Cmd-Opt-N will always make the other kind.
The menu items are configured as alternates so they only show up if you
press alt (just like in MiniBrowser).

* WebEditingTester/WK1WebDocumentController.m:
(-[WK1WebDocumentController loadHTMLString:]):
(-[WK1WebDocumentController loadContent]): Deleted.
* WebEditingTester/WK2WebDocumentController.h:
* WebEditingTester/WK2WebDocumentController.m:
(defaultConfiguration):
(-[WK2WebDocumentController awakeFromNib]):
(-[WK2WebDocumentController loadHTMLString:]):
(-[WK2WebDocumentController initWithConfiguration:]): Deleted.
(-[WK2WebDocumentController dealloc]): Deleted.
* WebEditingTester/WebDocumentController.h:
* WebEditingTester/WebDocumentController.m:
(-[WebDocumentController init]):
(-[WebDocumentController initWithWindow:]):
(+[WebDocumentController defaultEditingSource]):
(-[WebDocumentController loadHTMLString:]):
(-[WebDocumentController windowDidLoad]): Deleted.
(-[WebDocumentController defaultEditingSource]): Deleted.
(-[WebDocumentController applicationTerminating]): Deleted.
(-[WebDocumentController loadContent]): Deleted.

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

Tools/ChangeLog
Tools/WebEditingTester/AppDelegate.h
Tools/WebEditingTester/AppDelegate.m
Tools/WebEditingTester/MainMenu.xib
Tools/WebEditingTester/WK1WebDocumentController.m
Tools/WebEditingTester/WK2WebDocumentController.h
Tools/WebEditingTester/WK2WebDocumentController.m
Tools/WebEditingTester/WebDocumentController.h
Tools/WebEditingTester/WebDocumentController.m

index 3245f0d..260eba1 100644 (file)
@@ -1,5 +1,57 @@
 2015-02-20  Timothy Horton  <timothy_horton@apple.com>
 
+        [WebEditingTester] Hook up key equivalents for new window action
+        https://bugs.webkit.org/show_bug.cgi?id=141828
+
+        Reviewed by Enrica Casucci.
+
+        * WebEditingTester/AppDelegate.h:
+        * WebEditingTester/AppDelegate.m:
+        (-[WebEditingAppDelegate applicationDidFinishLaunching:]):
+        (-[WebEditingAppDelegate newEditor:]):
+        (-[WebEditingAppDelegate _defaultWebDocumentControllerClass]):
+        (-[WebEditingAppDelegate toggleUseWK2ByDefault:]):
+        (-[WebEditingAppDelegate _updateNewWindowKeyEquivalents]):
+        (defaultConfiguration): Deleted.
+        (-[WebEditingAppDelegate applicationWillTerminate:]): Deleted.
+        Move WKWebViewConfiguration setup into WK2WebDocumentController.
+        Remove unused application termination code.
+        Update new-window menu item key equivalents when launching and when
+        changing the use-WebKit2-by-default setting.
+        Make WebDocumentController subclasses all initialized the same way,
+        and use that to factor out alloc/init.
+        Rename loadContent to loadHTMLString for future use.
+
+        * WebEditingTester/MainMenu.xib:
+        Add default key equivalents.
+        Cmd-N will always make the default kind of window (controlled by the pref).
+        Cmd-Opt-N will always make the other kind.
+        The menu items are configured as alternates so they only show up if you
+        press alt (just like in MiniBrowser).
+
+        * WebEditingTester/WK1WebDocumentController.m:
+        (-[WK1WebDocumentController loadHTMLString:]):
+        (-[WK1WebDocumentController loadContent]): Deleted.
+        * WebEditingTester/WK2WebDocumentController.h:
+        * WebEditingTester/WK2WebDocumentController.m:
+        (defaultConfiguration):
+        (-[WK2WebDocumentController awakeFromNib]):
+        (-[WK2WebDocumentController loadHTMLString:]):
+        (-[WK2WebDocumentController initWithConfiguration:]): Deleted.
+        (-[WK2WebDocumentController dealloc]): Deleted.
+        * WebEditingTester/WebDocumentController.h:
+        * WebEditingTester/WebDocumentController.m:
+        (-[WebDocumentController init]):
+        (-[WebDocumentController initWithWindow:]):
+        (+[WebDocumentController defaultEditingSource]):
+        (-[WebDocumentController loadHTMLString:]):
+        (-[WebDocumentController windowDidLoad]): Deleted.
+        (-[WebDocumentController defaultEditingSource]): Deleted.
+        (-[WebDocumentController applicationTerminating]): Deleted.
+        (-[WebDocumentController loadContent]): Deleted.
+
+2015-02-20  Timothy Horton  <timothy_horton@apple.com>
+
         [WebEditingTester] ARC-ify WebEditingTester
         https://bugs.webkit.org/show_bug.cgi?id=141827
 
index 38e9e20..1938184 100644 (file)
@@ -31,6 +31,7 @@
     IBOutlet NSMenuItem *_newWK2EditorItem;
     IBOutlet NSPanel *_operationsPanel;
 }
+
 - (IBAction)newEditor:(id)sender;
 - (IBAction)showOperations:(id)sender;
 - (IBAction)toggleUseWK2ByDefault:(id)sender;
index 5295b93..41e216c 100644 (file)
 #import "EditingOperations.h"
 #import "WK1WebDocumentController.h"
 #import "WK2WebDocumentController.h"
-#import <WebKit/WKPreferencesPrivate.h>
-#import <WebKit/WKWebViewConfigurationPrivate.h>
-#import <WebKit/WebKit.h>
-#import <WebKit/_WKWebsiteDataStore.h>
 
 static NSString * const UseWebKit2ByDefaultPreferenceKey = @"UseWebKit2ByDefault";
 
@@ -45,49 +41,27 @@ static NSString * const UseWebKit2ByDefaultPreferenceKey = @"UseWebKit2ByDefault
     return self;
 }
 
-static WKWebViewConfiguration *defaultConfiguration()
-{
-    static WKWebViewConfiguration *configuration;
-    
-    if (!configuration) {
-        configuration = [[WKWebViewConfiguration alloc] init];
-        configuration.preferences._fullScreenEnabled = YES;
-        configuration.preferences._developerExtrasEnabled = YES;
-    }
-    
-    return configuration;
-}
-
-
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
 {
     [self newEditor:self];
-}
-
-- (void)applicationWillTerminate:(NSNotification *)aNotification
-{
-    for (WebDocumentController *documents in _webDocuments)
-        [documents applicationTerminating];
+    [self _updateNewWindowKeyEquivalents];
 }
 
 - (IBAction)newEditor:(id)sender
 {
-    BOOL useWebKit2 = NO;
+    Class controllerClass;
 
     if (sender == self)
-        useWebKit2 = [self useWebKit2ByDefault];
+        controllerClass = self._defaultWebDocumentControllerClass;
     else if (sender == _newWK2EditorItem)
-        useWebKit2 = YES;
-    
-    WebDocumentController *controller = nil;
-    if (useWebKit2)
-        controller = [[WK2WebDocumentController alloc] initWithConfiguration:defaultConfiguration()];
-    else
-        controller = [[WK1WebDocumentController alloc] initWithWindowNibName:@"WebDocument"];
+        controllerClass = [WK2WebDocumentController class];
+    else if (sender == _newWK1EditorItem)
+        controllerClass = [WK1WebDocumentController class];
     
+    WebDocumentController *controller = [[controllerClass alloc] init];
     [[controller window] makeKeyAndOrderFront:sender];
     [_webDocuments addObject:controller];
-    [controller loadContent];
+    [controller loadHTMLString:[WebDocumentController defaultEditingSource]];
 }
 
 - (IBAction)showOperations:(id)sender
@@ -138,6 +112,11 @@ static WKWebViewConfiguration *defaultConfiguration()
     [_operationsPanel orderFront:nil];
 }
 
+- (Class)_defaultWebDocumentControllerClass
+{
+    return self.useWebKit2ByDefault ? [WK2WebDocumentController class] : [WK1WebDocumentController class];
+}
+
 - (BOOL)useWebKit2ByDefault
 {
     return [[NSUserDefaults standardUserDefaults] boolForKey:UseWebKit2ByDefaultPreferenceKey];
@@ -147,6 +126,7 @@ static WKWebViewConfiguration *defaultConfiguration()
 {
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
     [defaults setBool:![defaults boolForKey:UseWebKit2ByDefaultPreferenceKey] forKey:UseWebKit2ByDefaultPreferenceKey];
+    [self _updateNewWindowKeyEquivalents];
 }
 
 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
@@ -159,4 +139,15 @@ static WKWebViewConfiguration *defaultConfiguration()
     return YES;
 }
 
+- (void)_updateNewWindowKeyEquivalents
+{
+    if (self.useWebKit2ByDefault) {
+        [_newWK1EditorItem setKeyEquivalentModifierMask:NSCommandKeyMask | NSAlternateKeyMask];
+        [_newWK2EditorItem setKeyEquivalentModifierMask:NSCommandKeyMask];
+    } else {
+        [_newWK1EditorItem setKeyEquivalentModifierMask:NSCommandKeyMask];
+        [_newWK2EditorItem setKeyEquivalentModifierMask:NSCommandKeyMask | NSAlternateKeyMask];
+    }
+}
+
 @end
index 33a2262..e21b2a9 100644 (file)
                     <modifierMask key="keyEquivalentModifierMask"/>
                     <menu key="submenu" title="File" id="bib-Uj-vzu">
                         <items>
-                            <menuItem title="New WK1 Editor" id="2Pd-3X-Tvf" userLabel="New WK1 Editor">
-                                <modifierMask key="keyEquivalentModifierMask"/>
+                            <menuItem title="New WK1 Editor" keyEquivalent="n" id="2Pd-3X-Tvf" userLabel="New WK1 Editor">
                                 <connections>
                                     <action selector="newEditor:" target="Voe-Tx-rLC" id="21m-3B-oXY"/>
                                 </connections>
                             </menuItem>
-                            <menuItem title="New WK2 Editor" id="kzr-0m-cAu" userLabel="New WK2 Editor">
-                                <modifierMask key="keyEquivalentModifierMask"/>
+                            <menuItem title="New WK2 Editor" alternate="YES" keyEquivalent="n" id="kzr-0m-cAu" userLabel="New WK2 Editor">
+                                <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
                                 <connections>
                                     <action selector="newEditor:" target="Voe-Tx-rLC" id="Za3-gM-3R7"/>
                                 </connections>
index af9ed66..8906075 100644 (file)
@@ -52,9 +52,9 @@
     [containerView addSubview:_webView];
 }
 
-- (void)loadContent
+- (void)loadHTMLString:(NSString *)content
 {
-    [[_webView mainFrame] loadHTMLString:[self defaultEditingSource] baseURL:nil];    
+    [[_webView mainFrame] loadHTMLString:content baseURL:nil];
 }
 
 - (IBAction)pasteAsMarkup:(id)sender
index 52adf0f..b9ddbc3 100644 (file)
@@ -29,7 +29,5 @@
 
 @interface WK2WebDocumentController : WebDocumentController<WebDocument>
 
-- (instancetype)initWithConfiguration:(WKWebViewConfiguration *)configuration;
-
 @end
 
index 56f1bbe..9abff20 100644 (file)
 @end
 
 @implementation WK2WebDocumentController {
-    WKWebViewConfiguration *_configuration;
     WKWebView *_webView;
 }
 
-- (instancetype)initWithConfiguration:(WKWebViewConfiguration *)configuration
+static WKWebViewConfiguration *defaultConfiguration()
 {
-    if (!(self = [super initWithWindowNibName:@"WebDocument"]))
-        return nil;
-    _configuration = [configuration copy];
-    
-    return self;
-    
+    static WKWebViewConfiguration *configuration;
+
+    if (!configuration) {
+        configuration = [[WKWebViewConfiguration alloc] init];
+        configuration.preferences._fullScreenEnabled = YES;
+        configuration.preferences._developerExtrasEnabled = YES;
+    }
+
+    return configuration;
 }
 
 - (IBAction)pasteAsMarkup:(id)sender
@@ -59,7 +61,7 @@
 
 - (void)awakeFromNib
 {
-    _webView = [[WKWebView alloc] initWithFrame:[containerView bounds] configuration:_configuration];
+    _webView = [[WKWebView alloc] initWithFrame:[containerView bounds] configuration:defaultConfiguration()];
     [_webView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
     [_webView _setEditable:YES];
     [_webView setUIDelegate:self];
@@ -68,9 +70,9 @@
     [self.window setTitle:@"WebEditor [WK2]"];
 }
 
-- (void)loadContent
+- (void)loadHTMLString:(NSString *)content
 {
-    [_webView loadHTMLString:[self defaultEditingSource] baseURL:nil];
+    [_webView loadHTMLString:content baseURL:nil];
 }
 
 @end
index d7fbf96..1b931b7 100644 (file)
 {
     IBOutlet NSView *containerView;
 }
-- (NSString *)defaultEditingSource;
-- (void)applicationTerminating;
-- (void)loadContent;
+
++ (NSString *)defaultEditingSource;
+
+- (void)loadHTMLString:(NSString *)content;
 
 @end
 
index f54ca78..6314efd 100644 (file)
 
 @implementation WebDocumentController
 
-- (id)initWithWindow:(NSWindow *)window
+- (instancetype)init
 {
-    self = [super initWithWindow:window];
+    if (!(self = [super initWithWindowNibName:@"WebDocument"]))
+        return nil;
+
     return self;
 }
 
-- (void)windowDidLoad
-{    
-    [super windowDidLoad];
+- (id)initWithWindow:(NSWindow *)window
+{
+    self = [super initWithWindow:window];
+    return self;
 }
 
-- (const NSString *)defaultEditingSource
++ (const NSString *)defaultEditingSource
 {
     const static NSString *source = @"<html><body></body></html>";
     return source;
 }
 
-- (void)applicationTerminating
-{
-}
-
-- (void)loadContent
+- (void)loadHTMLString:(NSString *)content
 {
 }