Add the ability to create empty contentEditable windows in MiniBrowser
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Jan 2017 21:10:21 +0000 (21:10 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Jan 2017 21:10:21 +0000 (21:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=166801

Reviewed by Wenson Hsieh.

* MiniBrowser/mac/AppDelegate.h:
* MiniBrowser/mac/AppDelegate.m:
(-[BrowserAppDelegate createBrowserWindowController:]):
(-[BrowserAppDelegate newWindow:]):
(-[BrowserAppDelegate newEditorWindow:]):
(-[BrowserAppDelegate openDocument:]):
(-[BrowserAppDelegate _updateNewWindowKeyEquivalents]):
* MiniBrowser/mac/BrowserWindowController.h:
* MiniBrowser/mac/BrowserWindowController.m:
(-[BrowserWindowController loadHTMLString:]):
(-[BrowserWindowController toggleEditable:]):
* MiniBrowser/mac/MainMenu.xib:
* MiniBrowser/mac/WK1BrowserWindowController.m:
(-[WK1BrowserWindowController awakeFromNib]):
(-[WK1BrowserWindowController loadHTMLString:]):
(-[WK1BrowserWindowController validateMenuItem:]):
(-[WK1BrowserWindowController setEditable:]):
(-[WK1BrowserWindowController updateTitle:]):
* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController awakeFromNib]):
(-[WK2BrowserWindowController validateMenuItem:]):
(-[WK2BrowserWindowController setEditable:]):
(-[WK2BrowserWindowController updateTitle:]):
(-[WK2BrowserWindowController loadHTMLString:]):
Merge more functionality from WebEditingTester.
Add two menu items for creating empty editable WebKit1/2 windows.
Add a menu item to the Edit menu to toggle editability on any window.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210483 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 76ca17f..aef3acf 100644 (file)
@@ -1,5 +1,40 @@
 2017-01-07  Tim Horton  <timothy_horton@apple.com>
 
+        Add the ability to create empty contentEditable windows in MiniBrowser
+        https://bugs.webkit.org/show_bug.cgi?id=166801
+
+        Reviewed by Wenson Hsieh.
+
+        * MiniBrowser/mac/AppDelegate.h:
+        * MiniBrowser/mac/AppDelegate.m:
+        (-[BrowserAppDelegate createBrowserWindowController:]):
+        (-[BrowserAppDelegate newWindow:]):
+        (-[BrowserAppDelegate newEditorWindow:]):
+        (-[BrowserAppDelegate openDocument:]):
+        (-[BrowserAppDelegate _updateNewWindowKeyEquivalents]):
+        * MiniBrowser/mac/BrowserWindowController.h:
+        * MiniBrowser/mac/BrowserWindowController.m:
+        (-[BrowserWindowController loadHTMLString:]):
+        (-[BrowserWindowController toggleEditable:]):
+        * MiniBrowser/mac/MainMenu.xib:
+        * MiniBrowser/mac/WK1BrowserWindowController.m:
+        (-[WK1BrowserWindowController awakeFromNib]):
+        (-[WK1BrowserWindowController loadHTMLString:]):
+        (-[WK1BrowserWindowController validateMenuItem:]):
+        (-[WK1BrowserWindowController setEditable:]):
+        (-[WK1BrowserWindowController updateTitle:]):
+        * MiniBrowser/mac/WK2BrowserWindowController.m:
+        (-[WK2BrowserWindowController awakeFromNib]):
+        (-[WK2BrowserWindowController validateMenuItem:]):
+        (-[WK2BrowserWindowController setEditable:]):
+        (-[WK2BrowserWindowController updateTitle:]):
+        (-[WK2BrowserWindowController loadHTMLString:]):
+        Merge more functionality from WebEditingTester.
+        Add two menu items for creating empty editable WebKit1/2 windows.
+        Add a menu item to the Edit menu to toggle editability on any window.
+
+2017-01-07  Tim Horton  <timothy_horton@apple.com>
+
         Implement find-in-page in MiniBrowser
         https://bugs.webkit.org/show_bug.cgi?id=166799
 
index e739ded..565bdd9 100644 (file)
@@ -33,6 +33,8 @@
 
     IBOutlet NSMenuItem *_newWebKit1WindowItem;
     IBOutlet NSMenuItem *_newWebKit2WindowItem;
+    IBOutlet NSMenuItem *_newWebKit1EditorItem;
+    IBOutlet NSMenuItem *_newWebKit2EditorItem;
 }
 
 - (void)browserWindowWillClose:(NSWindow *)window;
index 7811b77..846a76f 100644 (file)
@@ -44,7 +44,9 @@
 
 enum {
     WebKit1NewWindowTag = 1,
-    WebKit2NewWindowTag = 2
+    WebKit2NewWindowTag = 2,
+    WebKit1NewEditorTag = 3,
+    WebKit2NewEditorTag = 4
 };
 
 @interface NSApplication (TouchBar)
@@ -120,30 +122,44 @@ WKPreferences *defaultPreferences()
 
 #endif
 
-
-- (IBAction)newWindow:(id)sender
+- (BrowserWindowController *)createBrowserWindowController:(id)sender
 {
     BrowserWindowController *controller = nil;
-
     BOOL useWebKit2 = NO;
+    BOOL makeEditable = NO;
 
     if (![sender respondsToSelector:@selector(tag)])
         useWebKit2 = [SettingsController shared].useWebKit2ByDefault;
-    else
-        useWebKit2 = [sender tag] == WebKit2NewWindowTag;
-    
+    else {
+        useWebKit2 = [sender tag] == WebKit2NewWindowTag || [sender tag] == WebKit2NewEditorTag;
+        makeEditable = [sender tag] == WebKit1NewEditorTag || [sender tag] == WebKit2NewEditorTag;
+    }
+
     if (!useWebKit2)
         controller = [[WK1BrowserWindowController alloc] initWithWindowNibName:@"BrowserWindow"];
 #if WK_API_ENABLED
     else
         controller = [[WK2BrowserWindowController alloc] initWithConfiguration:defaultConfiguration()];
 #endif
+
+    if (makeEditable)
+        controller.editable = YES;
+
+    if (!controller)
+        return nil;
+
+    [_browserWindowControllers addObject:controller];
+
+    return controller;
+}
+
+- (IBAction)newWindow:(id)sender
+{
+    BrowserWindowController *controller = [self createBrowserWindowController:sender];
     if (!controller)
         return;
 
     [[controller window] makeKeyAndOrderFront:sender];
-    [_browserWindowControllers addObject:controller];
-    
     [controller loadURLString:[SettingsController shared].defaultURL];
 }
 
@@ -163,6 +179,16 @@ WKPreferences *defaultPreferences()
 #endif
 }
 
+- (IBAction)newEditorWindow:(id)sender
+{
+    BrowserWindowController *controller = [self createBrowserWindowController:sender];
+    if (!controller)
+        return;
+
+    [[controller window] makeKeyAndOrderFront:sender];
+    [controller loadHTMLString:@"<html><body></body></html>"];
+}
+
 - (void)browserWindowWillClose:(NSWindow *)window
 {
     [_browserWindowControllers removeObject:window.windowController];
@@ -222,11 +248,11 @@ WKPreferences *defaultPreferences()
         if (result != NSFileHandlingPanelOKButton)
             return;
 
-        BrowserWindowController *newBrowserWindowController = [[WK1BrowserWindowController alloc] initWithWindowNibName:@"BrowserWindow"];
-        [newBrowserWindowController.window makeKeyAndOrderFront:self];
+        BrowserWindowController *controller = [self createBrowserWindowController:nil];
+        [controller.window makeKeyAndOrderFront:self];
 
         NSURL *url = [openPanel.URLs objectAtIndex:0];
-        [newBrowserWindowController loadURLString:[url absoluteString]];
+        [controller loadURLString:[url absoluteString]];
     }];
 }
 
@@ -241,13 +267,13 @@ WKPreferences *defaultPreferences()
 
 - (void)_updateNewWindowKeyEquivalents
 {
-    if ([[SettingsController shared] useWebKit2ByDefault]) {
-        [_newWebKit1WindowItem setKeyEquivalentModifierMask:NSEventModifierFlagCommand | NSEventModifierFlagOption];
-        [_newWebKit2WindowItem setKeyEquivalentModifierMask:NSEventModifierFlagCommand];
-    } else {
-        [_newWebKit1WindowItem setKeyEquivalentModifierMask:NSEventModifierFlagCommand];
-        [_newWebKit2WindowItem setKeyEquivalentModifierMask:NSEventModifierFlagCommand | NSEventModifierFlagOption];
-    }
+    NSEventModifierFlags webKit1Flags = [SettingsController shared].useWebKit2ByDefault ? NSEventModifierFlagOption : 0;
+    NSEventModifierFlags webKit2Flags = [SettingsController shared].useWebKit2ByDefault ? 0 : NSEventModifierFlagOption;
+
+    _newWebKit1WindowItem.keyEquivalentModifierMask = NSEventModifierFlagCommand | webKit1Flags;
+    _newWebKit2WindowItem.keyEquivalentModifierMask = NSEventModifierFlagCommand | webKit2Flags;
+    _newWebKit1EditorItem.keyEquivalentModifierMask = NSEventModifierFlagCommand | webKit1Flags;
+    _newWebKit2EditorItem.keyEquivalentModifierMask = NSEventModifierFlagCommand | webKit2Flags;
 }
 
 - (IBAction)showExtensionsManager:(id)sender
index 5b85ce4..b7aa5cf 100644 (file)
@@ -40,6 +40,7 @@
 }
 
 - (void)loadURLString:(NSString *)urlString;
+- (void)loadHTMLString:(NSString *)HTMLString;
 - (NSString *)addProtocolIfNecessary:(NSString *)address;
 
 - (void)applicationTerminating;
@@ -79,5 +80,8 @@
 
 - (CGFloat)pageScaleForMenuItemTag:(NSInteger)tag;
 
+@property (nonatomic, assign, getter=isEditable) BOOL editable;
+- (IBAction)toggleEditable:(id)sender;
+
 @end
 
index 0c0f548..d96eb51 100644 (file)
 {
 }
 
+- (void)loadHTMLString:(NSString *)HTMLString
+{
+}
+
 - (void)applicationTerminating
 {
 }
     return nil;
 }
 
+- (IBAction)toggleEditable:(id)sender
+{
+    self.editable = !self.isEditable;
+}
+
 #pragma mark -
 #pragma mark NSSharingServicePickerDelegate
 
index 67a945f..1b093de 100644 (file)
                                     <action selector="newPrivateWindow:" target="-1" id="mf5-zi-a5R"/>
                                 </connections>
                             </menuItem>
+                            <menuItem title="New WebKit1 Editor" tag="3" keyEquivalent="N" id="jNR-Z3-YWi" userLabel="New WebKit1 Editor">
+                                <connections>
+                                    <action selector="newEditorWindow:" target="-1" id="Nv5-c0-KRP"/>
+                                </connections>
+                            </menuItem>
+                            <menuItem title="New WebKit2 Editor" tag="4" keyEquivalent="N" id="IdI-wb-1JD" userLabel="New WebKit2 Editor">
+                                <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
+                                <connections>
+                                    <action selector="newEditorWindow:" target="-1" id="kk6-R4-iec"/>
+                                </connections>
+                            </menuItem>
                             <menuItem title="Openโ€ฆ" keyEquivalent="o" id="72">
                                 <connections>
                                     <action selector="openDocument:" target="-1" id="374"/>
                                     <action selector="redo:" target="-1" id="231"/>
                                 </connections>
                             </menuItem>
+                            <menuItem isSeparatorItem="YES" id="fUL-7k-Dqg">
+                                <modifierMask key="keyEquivalentModifierMask" command="YES"/>
+                            </menuItem>
+                            <menuItem title="Editable" id="kG4-hS-JbX">
+                                <modifierMask key="keyEquivalentModifierMask"/>
+                                <connections>
+                                    <action selector="toggleEditable:" target="-1" id="6my-b2-eff"/>
+                                </connections>
+                            </menuItem>
                             <menuItem isSeparatorItem="YES" id="206">
                                 <modifierMask key="keyEquivalentModifierMask" command="YES"/>
                             </menuItem>
         </menu>
         <customObject id="494" customClass="BrowserAppDelegate">
             <connections>
+                <outlet property="_newWebKit1EditorItem" destination="jNR-Z3-YWi" id="6wB-Aa-CK7"/>
                 <outlet property="_newWebKit1WindowItem" destination="573" id="ZCj-u2-PU7"/>
+                <outlet property="_newWebKit2EditorItem" destination="IdI-wb-1JD" id="DIr-pe-XI8"/>
                 <outlet property="_newWebKit2WindowItem" destination="571" id="1Gv-mK-aul"/>
             </connections>
         </customObject>
index bb428b5..f26b419 100644 (file)
@@ -44,6 +44,8 @@
     _webView = [[WebView alloc] initWithFrame:[containerView bounds] frameName:nil groupName:@"MiniBrowser"];
     [_webView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
 
+    _webView.editable = self.isEditable;
+
     [_webView setFrameLoadDelegate:self];
     [_webView setUIDelegate:self];
     [_webView setResourceLoadDelegate:self];
     [self fetch:nil];
 }
 
+- (void)loadHTMLString:(NSString *)HTMLString
+{
+    [_webView.mainFrame loadHTMLString:HTMLString baseURL:nil];
+}
+
 - (IBAction)fetch:(id)sender
 {
     [urlText setStringValue:[self addProtocolIfNecessary:[urlText stringValue]]];
@@ -139,6 +146,8 @@ static BOOL areEssentiallyEqual(double a, double b)
         [menuItem setTitle:[_webView window] ? @"Remove Web View" : @"Insert Web View"];
     else if (action == @selector(toggleZoomMode:))
         [menuItem setState:_zoomTextOnly ? NSOnState : NSOffState];
+    else if (action == @selector(toggleEditable:))
+        [menuItem setState:self.isEditable ? NSOnState : NSOffState];
 
     if (action == @selector(setPageScale:))
         [menuItem setState:areEssentiallyEqual([_webView _viewScaleFactor], [self pageScaleForMenuItemTag:[menuItem tag]])];
@@ -247,6 +256,12 @@ static BOOL areEssentiallyEqual(double a, double b)
     return _webView;
 }
 
+- (void)setEditable:(BOOL)editable
+{
+    [super setEditable:editable];
+    _webView.editable = editable;
+}
+
 - (void)didChangeSettings
 {
     SettingsController *settings = [SettingsController shared];
@@ -317,8 +332,8 @@ static BOOL areEssentiallyEqual(double a, double b)
         NSURL *url = _webView.mainFrame.dataSource.request.URL;
         title = url.lastPathComponent ?: url._web_userVisibleString;
     }
-    
-    [self.window setTitle:[title stringByAppendingString:@" [WK1]"]];
+
+    [self.window setTitle:[title stringByAppendingFormat:@" [WK1]%@", _webView.editable ? @" [Editable]" : @""]];
 }
 
 - (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request
index 1538463..8ede255 100644 (file)
@@ -69,6 +69,7 @@ static const int testFooterBannerHeight = 58;
 
     _webView.allowsMagnification = YES;
     _webView.allowsBackForwardNavigationGestures = YES;
+    _webView._editable = self.isEditable;
 
     [_webView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
     [containerView addSubview:_webView];
@@ -201,6 +202,8 @@ static BOOL areEssentiallyEqual(double a, double b)
         [menuItem setTitle:[_webView window] ? @"Remove Web View" : @"Insert Web View"];
     else if (action == @selector(toggleZoomMode:))
         [menuItem setState:_zoomTextOnly ? NSOnState : NSOffState];
+    else if (action == @selector(toggleEditable:))
+        [menuItem setState:self.isEditable ? NSOnState : NSOffState];
 
     if (action == @selector(setPageScale:))
         [menuItem setState:areEssentiallyEqual([_webView _pageScale], [self pageScaleForMenuItemTag:[menuItem tag]])];
@@ -284,6 +287,12 @@ static BOOL areEssentiallyEqual(double a, double b)
     return _webView;
 }
 
+- (void)setEditable:(BOOL)editable
+{
+    [super setEditable:editable];
+    _webView._editable = editable;
+}
+
 - (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)item
 {
     SEL action = item.action;
@@ -415,7 +424,7 @@ static BOOL areEssentiallyEqual(double a, double b)
         title = url.lastPathComponent ?: url._web_userVisibleString;
     }
 
-    self.window.title = [NSString stringWithFormat:@"%@%@ [WK2 %d]", _isPrivateBrowsingWindow ? @"๐Ÿ™ˆ " : @"", title, _webView._webProcessIdentifier];
+    self.window.title = [NSString stringWithFormat:@"%@%@ [WK2 %d]%@", _isPrivateBrowsingWindow ? @"๐Ÿ™ˆ " : @"", title, _webView._webProcessIdentifier, _webView._editable ? @" [Editable]" : @""];
 }
 
 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
@@ -525,6 +534,11 @@ static BOOL areEssentiallyEqual(double a, double b)
     [self fetch:nil];
 }
 
+- (void)loadHTMLString:(NSString *)HTMLString
+{
+    [_webView loadHTMLString:HTMLString baseURL:nil];
+}
+
 static NSSet *dataTypes()
 {
     return [WKWebsiteDataStore allWebsiteDataTypes];