Make it easer to add switches to MiniBrowser
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Aug 2014 18:21:11 +0000 (18:21 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Aug 2014 18:21:11 +0000 (18:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=135499

Reviewed by Simon Fraser.

Add a single class to manage a set of persistent, global settings for MiniBrowser.
Add a new menu that contains items to toggle the aforementioned settings (moving them out of the Debug menu).

* MiniBrowser/MiniBrowser.xcodeproj/project.pbxproj:
Add SettingsController.{m, h}.

* MiniBrowser/mac/AppDelegate.h:
Move _browserWindowControllers to the implementation.
Get rid of toggleUseWebKit2ByDefault, because SettingsController now takes care
of that; instead, we'll receive didChangeSettings.

* MiniBrowser/mac/AppDelegate.m:
Move the default URL, default URL preference key, and use-WebKit2-by-default
preference key into SettingsController.

(-[BrowserAppDelegate awakeFromNib]):
Add the dynamically-generated SettingsController menu just to the left of the Debug menu.

(-[BrowserAppDelegate newWindow:]):
Ask SettingsController if we should use WebKit2 by default, and what the initial URL to load is.

(-[BrowserAppDelegate applicationDidFinishLaunching:]):
SettingsController now takes care of reading the default URL preference.
WK1BrowserWindowController now takes care of enabling the developer extras, via WebPreferences.

(-[BrowserAppDelegate didChangeSettings]):
When settings change, update the key equivalents for the new-window menu items, as they
might have changed (as use-WebKit2-by-default is one of the settings).

Dispatch settings change notifications to all live BrowserControllers.

(-[BrowserAppDelegate _updateNewWindowKeyEquivalents]):
(-[BrowserAppDelegate toggleUseWebKit2ByDefault:]): Deleted.
(-[BrowserAppDelegate _useWebKit2ByDefault]): Deleted.
(-[BrowserAppDelegate validateMenuItem:]): Deleted.
All menu item validation for settings is moved into SettingsController.

* MiniBrowser/mac/BrowserWindowController.h:
Simplify the BrowserWindowController interface; "toggling" settings will happen inside SettingsController,
the BrowserWindowController subclasses will be able to a) know when any setting changes, b) query the current setting state.

* MiniBrowser/mac/MainMenu.xib:
Remove the settings menu items from the "Debug" menu.

* MiniBrowser/mac/SettingsController.h: Added.
* MiniBrowser/mac/SettingsController.m: Added.
(+[SettingsController shared]):
(-[SettingsController menu]):

(-[SettingsController _addItemWithTitle:action:indented:]):
(-[SettingsController _addHeaderWithTitle:]):
NSMenuItem-creating helpers.

(-[SettingsController _populateMenu]):
Build the menu. Ideally this and the validation step would eventually be made more dynamic.

(-[SettingsController validateMenuItem:]):
Validate menu items; since they can be used to toggle the default state of a setting,
we'll always return YES. However, we will use this opportunity to set the 'checked' state
of each item.

(-[SettingsController _toggleBooleanDefault:]):
Toggle the given boolean default, and notify BrowserAppDelegate that something changed.

(-[SettingsController toggleUseWebKit2ByDefault:]):
(-[SettingsController useWebKit2ByDefault]):
(-[SettingsController toggleUseTransparentWindows:]):
(-[SettingsController useTransparentWindows]):
(-[SettingsController toggleUsePaginatedMode:]):
(-[SettingsController usePaginatedMode]):
(-[SettingsController toggleUseUISideCompositing:]):
(-[SettingsController useUISideCompositing]):
(-[SettingsController toggleShowLayerBorders:]):
(-[SettingsController layerBordersVisible]):
(-[SettingsController toggleShowTiledScrollingIndicator:]):
(-[SettingsController tiledScrollingIndicatorVisible]):
(-[SettingsController toggleEnableSubPixelCSSOMMetrics:]):
(-[SettingsController subPixelCSSOMMetricsEnabled]):
(-[SettingsController defaultURL]):
Toggle or return the current state of each preference.

* MiniBrowser/mac/WK1BrowserWindowController.m:
(-[WK1BrowserWindowController awakeFromNib]):
(-[WK1BrowserWindowController validateMenuItem:]):
(-[WK1BrowserWindowController windowWillClose:]):
(-[WK1BrowserWindowController find:]):
(-[WK1BrowserWindowController dumpSourceToConsole:]):
(-[WK1BrowserWindowController didChangeSettings]):
(-[WK1BrowserWindowController webView:didReceiveTitle:forFrame:]):
(-[WK1BrowserWindowController isPaginated]): Deleted.
(-[WK1BrowserWindowController togglePaginationMode:]): Deleted.
(-[WK1BrowserWindowController toggleTransparentWindow:]): Deleted.
(-[WK1BrowserWindowController isSubpixelCSSOMElementMetricsEnabled]): Deleted.
(-[WK1BrowserWindowController toggleSubpixelCSSOMElementMetricsEnabled:]): Deleted.
(-[WK1BrowserWindowController layerBordersVisible]): Deleted.
(-[WK1BrowserWindowController toggleLayerBordersVisibility:]): Deleted.
* MiniBrowser/mac/WK2BrowserWindowController.m:
(-[WK2BrowserWindowController awakeFromNib]):
(-[WK2BrowserWindowController validateMenuItem:]):
(-[WK2BrowserWindowController forceRepaint:]):
(-[WK2BrowserWindowController windowWillClose:]):
(-[WK2BrowserWindowController didChangeSettings]):
(-[WK2BrowserWindowController isPaginated]): Deleted.
(-[WK2BrowserWindowController togglePaginationMode:]): Deleted.
(-[WK2BrowserWindowController toggleTransparentWindow:]): Deleted.
(-[WK2BrowserWindowController isUISideCompositingEnabled]): Deleted.
(-[WK2BrowserWindowController toggleUISideCompositing:]): Deleted.
(-[WK2BrowserWindowController layerBordersVisible]): Deleted.
(-[WK2BrowserWindowController toggleLayerBordersVisibility:]): Deleted.
(-[WK2BrowserWindowController tiledScrollingIndicatorVisible]): Deleted.
(-[WK2BrowserWindowController toggleTiledScrollingIndicatorVisibility:]): Deleted.

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

Tools/ChangeLog
Tools/MiniBrowser/MiniBrowser.xcodeproj/project.pbxproj
Tools/MiniBrowser/mac/AppDelegate.h
Tools/MiniBrowser/mac/AppDelegate.m
Tools/MiniBrowser/mac/BrowserWindowController.h
Tools/MiniBrowser/mac/MainMenu.xib
Tools/MiniBrowser/mac/SettingsController.h [new file with mode: 0644]
Tools/MiniBrowser/mac/SettingsController.m [new file with mode: 0644]
Tools/MiniBrowser/mac/WK1BrowserWindowController.m
Tools/MiniBrowser/mac/WK2BrowserWindowController.m

index 34e33e0..55e595c 100644 (file)
@@ -1,5 +1,125 @@
 2014-08-01  Tim Horton  <timothy_horton@apple.com>
 
+        Make it easer to add switches to MiniBrowser
+        https://bugs.webkit.org/show_bug.cgi?id=135499
+
+        Reviewed by Simon Fraser.
+
+        Add a single class to manage a set of persistent, global settings for MiniBrowser.
+        Add a new menu that contains items to toggle the aforementioned settings (moving them out of the Debug menu).
+
+        * MiniBrowser/MiniBrowser.xcodeproj/project.pbxproj:
+        Add SettingsController.{m, h}.
+
+        * MiniBrowser/mac/AppDelegate.h:
+        Move _browserWindowControllers to the implementation.
+        Get rid of toggleUseWebKit2ByDefault, because SettingsController now takes care
+        of that; instead, we'll receive didChangeSettings.
+
+        * MiniBrowser/mac/AppDelegate.m:
+        Move the default URL, default URL preference key, and use-WebKit2-by-default
+        preference key into SettingsController.
+
+        (-[BrowserAppDelegate awakeFromNib]):
+        Add the dynamically-generated SettingsController menu just to the left of the Debug menu.
+
+        (-[BrowserAppDelegate newWindow:]):
+        Ask SettingsController if we should use WebKit2 by default, and what the initial URL to load is.
+
+        (-[BrowserAppDelegate applicationDidFinishLaunching:]):
+        SettingsController now takes care of reading the default URL preference.
+        WK1BrowserWindowController now takes care of enabling the developer extras, via WebPreferences.
+
+        (-[BrowserAppDelegate didChangeSettings]):
+        When settings change, update the key equivalents for the new-window menu items, as they
+        might have changed (as use-WebKit2-by-default is one of the settings).
+
+        Dispatch settings change notifications to all live BrowserControllers.
+
+        (-[BrowserAppDelegate _updateNewWindowKeyEquivalents]):
+        (-[BrowserAppDelegate toggleUseWebKit2ByDefault:]): Deleted.
+        (-[BrowserAppDelegate _useWebKit2ByDefault]): Deleted.
+        (-[BrowserAppDelegate validateMenuItem:]): Deleted.
+        All menu item validation for settings is moved into SettingsController.
+
+        * MiniBrowser/mac/BrowserWindowController.h:
+        Simplify the BrowserWindowController interface; "toggling" settings will happen inside SettingsController,
+        the BrowserWindowController subclasses will be able to a) know when any setting changes, b) query the current setting state.
+
+        * MiniBrowser/mac/MainMenu.xib:
+        Remove the settings menu items from the "Debug" menu.
+
+        * MiniBrowser/mac/SettingsController.h: Added.
+        * MiniBrowser/mac/SettingsController.m: Added.
+        (+[SettingsController shared]):
+        (-[SettingsController menu]):
+
+        (-[SettingsController _addItemWithTitle:action:indented:]):
+        (-[SettingsController _addHeaderWithTitle:]):
+        NSMenuItem-creating helpers.
+
+        (-[SettingsController _populateMenu]):
+        Build the menu. Ideally this and the validation step would eventually be made more dynamic.
+
+        (-[SettingsController validateMenuItem:]):
+        Validate menu items; since they can be used to toggle the default state of a setting,
+        we'll always return YES. However, we will use this opportunity to set the 'checked' state
+        of each item.
+
+
+        (-[SettingsController _toggleBooleanDefault:]):
+        Toggle the given boolean default, and notify BrowserAppDelegate that something changed.
+
+        (-[SettingsController toggleUseWebKit2ByDefault:]):
+        (-[SettingsController useWebKit2ByDefault]):
+        (-[SettingsController toggleUseTransparentWindows:]):
+        (-[SettingsController useTransparentWindows]):
+        (-[SettingsController toggleUsePaginatedMode:]):
+        (-[SettingsController usePaginatedMode]):
+        (-[SettingsController toggleUseUISideCompositing:]):
+        (-[SettingsController useUISideCompositing]):
+        (-[SettingsController toggleShowLayerBorders:]):
+        (-[SettingsController layerBordersVisible]):
+        (-[SettingsController toggleShowTiledScrollingIndicator:]):
+        (-[SettingsController tiledScrollingIndicatorVisible]):
+        (-[SettingsController toggleEnableSubPixelCSSOMMetrics:]):
+        (-[SettingsController subPixelCSSOMMetricsEnabled]):
+        (-[SettingsController defaultURL]):
+        Toggle or return the current state of each preference.
+
+        * MiniBrowser/mac/WK1BrowserWindowController.m:
+        (-[WK1BrowserWindowController awakeFromNib]):
+        (-[WK1BrowserWindowController validateMenuItem:]):
+        (-[WK1BrowserWindowController windowWillClose:]):
+        (-[WK1BrowserWindowController find:]):
+        (-[WK1BrowserWindowController dumpSourceToConsole:]):
+        (-[WK1BrowserWindowController didChangeSettings]):
+        (-[WK1BrowserWindowController webView:didReceiveTitle:forFrame:]):
+        (-[WK1BrowserWindowController isPaginated]): Deleted.
+        (-[WK1BrowserWindowController togglePaginationMode:]): Deleted.
+        (-[WK1BrowserWindowController toggleTransparentWindow:]): Deleted.
+        (-[WK1BrowserWindowController isSubpixelCSSOMElementMetricsEnabled]): Deleted.
+        (-[WK1BrowserWindowController toggleSubpixelCSSOMElementMetricsEnabled:]): Deleted.
+        (-[WK1BrowserWindowController layerBordersVisible]): Deleted.
+        (-[WK1BrowserWindowController toggleLayerBordersVisibility:]): Deleted.
+        * MiniBrowser/mac/WK2BrowserWindowController.m:
+        (-[WK2BrowserWindowController awakeFromNib]):
+        (-[WK2BrowserWindowController validateMenuItem:]):
+        (-[WK2BrowserWindowController forceRepaint:]):
+        (-[WK2BrowserWindowController windowWillClose:]):
+        (-[WK2BrowserWindowController didChangeSettings]):
+        (-[WK2BrowserWindowController isPaginated]): Deleted.
+        (-[WK2BrowserWindowController togglePaginationMode:]): Deleted.
+        (-[WK2BrowserWindowController toggleTransparentWindow:]): Deleted.
+        (-[WK2BrowserWindowController isUISideCompositingEnabled]): Deleted.
+        (-[WK2BrowserWindowController toggleUISideCompositing:]): Deleted.
+        (-[WK2BrowserWindowController layerBordersVisible]): Deleted.
+        (-[WK2BrowserWindowController toggleLayerBordersVisibility:]): Deleted.
+        (-[WK2BrowserWindowController tiledScrollingIndicatorVisible]): Deleted.
+        (-[WK2BrowserWindowController toggleTiledScrollingIndicatorVisibility:]): Deleted.
+
+2014-08-01  Tim Horton  <timothy_horton@apple.com>
+
         MiniBrowser doesn't support data URLs
         https://bugs.webkit.org/show_bug.cgi?id=135492
 
index a2e35ed..418a114 100644 (file)
@@ -14,6 +14,7 @@
                1AFFEF8818611C3D00DA465E /* MiniBrowserWebProcessPlugIn.m in Sources */ = {isa = PBXBuildFile; fileRef = 1AFFEF8618611C3D00DA465E /* MiniBrowserWebProcessPlugIn.m */; };
                1AFFEF8B18611D8A00DA465E /* MiniBrowser.wkbundle in Copy Bundle */ = {isa = PBXBuildFile; fileRef = 1AFFEF751860EE6700DA465E /* MiniBrowser.wkbundle */; };
                256AC3DA0F4B6AC300CF3369 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 256AC3D90F4B6AC300CF3369 /* AppDelegate.m */; };
+               2DC37343198B62D300EC33E9 /* SettingsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DC37342198B62D300EC33E9 /* SettingsController.m */; };
                51E244FA11EFCE07008228D1 /* MBToolbarItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 51E244F911EFCE07008228D1 /* MBToolbarItem.m */; };
                8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
                BC329487116A92E2008635D0 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = BC329486116A92E2008635D0 /* main.m */; };
@@ -68,6 +69,8 @@
                256AC3F00F4B6AF500CF3369 /* MiniBrowser_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MiniBrowser_Prefix.pch; path = mac/MiniBrowser_Prefix.pch; sourceTree = "<group>"; };
                29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
                29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
+               2DC37341198B62D300EC33E9 /* SettingsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SettingsController.h; path = mac/SettingsController.h; sourceTree = "<group>"; };
+               2DC37342198B62D300EC33E9 /* SettingsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SettingsController.m; path = mac/SettingsController.m; sourceTree = "<group>"; };
                51E244F811EFCE07008228D1 /* MBToolbarItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBToolbarItem.h; sourceTree = "<group>"; };
                51E244F911EFCE07008228D1 /* MBToolbarItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBToolbarItem.m; sourceTree = "<group>"; };
                8D1107320486CEB800E47090 /* MiniBrowser.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MiniBrowser.app; sourceTree = BUILT_PRODUCTS_DIR; };
                                0FE643A3161FAC660059E3FF /* WK1BrowserWindowController.m */,
                                BC329496116A941B008635D0 /* WK2BrowserWindowController.h */,
                                BC329497116A941B008635D0 /* WK2BrowserWindowController.m */,
+                               2DC37341198B62D300EC33E9 /* SettingsController.h */,
+                               2DC37342198B62D300EC33E9 /* SettingsController.m */,
                        );
                        name = MiniBrowser;
                        sourceTree = "<group>";
                        files = (
                                256AC3DA0F4B6AC300CF3369 /* AppDelegate.m in Sources */,
                                0FE643A1161FA8940059E3FF /* BrowserWindowController.m in Sources */,
+                               2DC37343198B62D300EC33E9 /* SettingsController.m in Sources */,
                                BC329487116A92E2008635D0 /* main.m in Sources */,
                                51E244FA11EFCE07008228D1 /* MBToolbarItem.m in Sources */,
                                0FE643A4161FAC660059E3FF /* WK1BrowserWindowController.m in Sources */,
index 8ead0ef..382c090 100644 (file)
  */
 
 @interface BrowserAppDelegate : NSObject <NSApplicationDelegate> {
-    NSMutableSet *_browserWindowControllers;
-
     IBOutlet NSMenuItem *_newWebKit1WindowItem;
     IBOutlet NSMenuItem *_newWebKit2WindowItem;
 }
 
 - (void)browserWindowWillClose:(NSWindow *)window;
 
-- (IBAction)toggleUseWebKit2ByDefault:(id)sender;
+- (void)didChangeSettings;
 
 @end
index b0b4d76..cf4b474 100644 (file)
 
 #import "AppDelegate.h"
 
+#import "SettingsController.h"
 #import "WK1BrowserWindowController.h"
 #import "WK2BrowserWindowController.h"
 #import <WebKit/WebHistory.h>
 #import <WebKit/WebKit2.h>
 
-static NSString *defaultURL = @"http://www.webkit.org/";
-static NSString *useWebKit2ByDefaultPreferenceKey = @"UseWebKit2ByDefault";
-static NSString *defaultURLPreferenceKey = @"DefaultURL";
-
 enum {
     WebKit1NewWindowTag = 1,
     WebKit2NewWindowTag = 2
 };
 
-@implementation BrowserAppDelegate
+@implementation BrowserAppDelegate {
+    NSMutableSet *_browserWindowControllers;
+}
 
 - (id)init
 {
@@ -51,6 +50,13 @@ enum {
     return self;
 }
 
+- (void)awakeFromNib
+{
+    NSMenuItem *item = [[NSMenuItem alloc] init];
+    [item setSubmenu:[[SettingsController shared] menu]];
+    [[NSApp mainMenu] insertItem:[item autorelease] atIndex:[[NSApp mainMenu] indexOfItemWithTitle:@"Debug"]];
+}
+
 - (IBAction)newWindow:(id)sender
 {
     BrowserWindowController *controller = nil;
@@ -58,7 +64,7 @@ enum {
     BOOL useWebKit2 = NO;
 
     if (![sender respondsToSelector:@selector(tag)])
-        useWebKit2 = [self _useWebKit2ByDefault];
+        useWebKit2 = [SettingsController shared].useWebKit2ByDefault;
     else
         useWebKit2 = [sender tag] == WebKit2NewWindowTag;
     
@@ -74,7 +80,7 @@ enum {
     [[controller window] makeKeyAndOrderFront:sender];
     [_browserWindowControllers addObject:controller];
     
-    [controller loadURLString:defaultURL];
+    [controller loadURLString:[SettingsController shared].defaultURL];
 }
 
 - (void)browserWindowWillClose:(NSWindow *)window
@@ -89,11 +95,6 @@ enum {
     [webHistory release];
 
     [self _updateNewWindowKeyEquivalents];
-    
-    [[NSUserDefaults standardUserDefaults] setBool:@YES forKey:@"WebKitDeveloperExtrasEnabled"];
-    NSString *newDefaultURL = [[NSUserDefaults standardUserDefaults] stringForKey:defaultURLPreferenceKey];
-    if (newDefaultURL)
-        defaultURL = [newDefaultURL retain];
 
     [self newWindow:self];
 }
@@ -149,24 +150,18 @@ enum {
     }];
 }
 
-- (IBAction)toggleUseWebKit2ByDefault:(id)sender
+- (void)didChangeSettings
 {
-    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];
+    // Let all of the BrowserWindowControllers know that a setting changed, so they can attempt to dynamically update.
+    for (BrowserWindowController<BrowserController> *browserWindowController in _browserWindowControllers)
+        [browserWindowController didChangeSettings];
 }
 
 - (void)_updateNewWindowKeyEquivalents
 {
-    if ([self _useWebKit2ByDefault]) {
+    if ([[SettingsController shared] useWebKit2ByDefault]) {
         [_newWebKit1WindowItem setKeyEquivalentModifierMask:NSCommandKeyMask | NSAlternateKeyMask];
         [_newWebKit2WindowItem setKeyEquivalentModifierMask:NSCommandKeyMask];
     } else {
@@ -175,12 +170,4 @@ enum {
     }
 }
 
-- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
-{
-    if ([menuItem action] == @selector(toggleUseWebKit2ByDefault:))
-        [menuItem setState:[self _useWebKit2ByDefault] ? NSOnState : NSOffState];
-
-    return YES;
-}
-
 @end
index 9634679..1d8ad76 100644 (file)
 - (BOOL)canResetZoom;
 
 - (IBAction)toggleZoomMode:(id)sender;
-- (IBAction)togglePaginationMode:(id)sender;
-- (IBAction)toggleTransparentWindow:(id)sender;
-- (IBAction)toggleLayerBordersVisibility:(id)sender;
 
 - (IBAction)dumpSourceToConsole:(id)sender;
 - (IBAction)find:(id)sender;
 
-@optional
-- (IBAction)toggleSubpixelCSSOMElementMetricsEnabled:(id)sender;
-- (IBAction)toggleUISideCompositing:(id)sender;
-- (IBAction)toggleTiledScrollingIndicatorVisibility:(id)sender;
+- (void)didChangeSettings;
 
 @end
 
index 99d651c..c5df401 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13D65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13E28" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
     <dependencies>
         <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
     </dependencies>
                     <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>
                                 </connections>
                             </menuItem>
                             <menuItem isSeparatorItem="YES" id="553"/>
-                            <menuItem title="Paginated Mode" id="569">
-                                <modifierMask key="keyEquivalentModifierMask"/>
-                                <connections>
-                                    <action selector="togglePaginationMode:" target="-1" id="570"/>
-                                </connections>
-                            </menuItem>
-                            <menuItem title="Transparent Window" id="576">
-                                <modifierMask key="keyEquivalentModifierMask"/>
-                                <connections>
-                                    <action selector="toggleTransparentWindow:" target="-1" id="578"/>
-                                </connections>
-                            </menuItem>
-                            <menuItem title="UI-Side Compositing" id="BDx-He-jOK">
-                                <modifierMask key="keyEquivalentModifierMask"/>
-                                <connections>
-                                    <action selector="toggleUISideCompositing:" target="-1" id="1Ed-C5-0po"/>
-                                </connections>
-                            </menuItem>
-                            <menuItem title="Layer Borders" id="00T-EI-Wqj">
-                                <modifierMask key="keyEquivalentModifierMask"/>
-                                <connections>
-                                    <action selector="toggleLayerBordersVisibility:" target="-1" id="gmt-1Z-XcQ"/>
-                                </connections>
-                            </menuItem>
-                            <menuItem title="Tiled Scrolling Indicator" id="iBU-Yy-GuV">
-                                <modifierMask key="keyEquivalentModifierMask"/>
-                                <connections>
-                                    <action selector="toggleTiledScrollingIndicatorVisibility:" target="-1" id="RJB-dt-xSR"/>
-                                </connections>
-                            </menuItem>
-                            <menuItem title="Enable Sub-Pixel offsetWidth etc." state="on" id="8X5-i6-t2d">
-                                <modifierMask key="keyEquivalentModifierMask"/>
-                                <connections>
-                                    <action selector="toggleSubpixelCSSOMElementMetricsEnabled:" target="-1" id="Lbe-UQ-A9U"/>
-                                </connections>
-                            </menuItem>
-                            <menuItem isSeparatorItem="YES" id="568"/>
                             <menuItem title="Dump Source To Console" id="566">
                                 <modifierMask key="keyEquivalentModifierMask"/>
                                 <connections>
diff --git a/Tools/MiniBrowser/mac/SettingsController.h b/Tools/MiniBrowser/mac/SettingsController.h
new file mode 100644 (file)
index 0000000..d4dd3f1
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+@interface SettingsController : NSObject
+
++ (instancetype)shared;
+
+@property (nonatomic, readonly) NSMenu *menu;
+
+@property (nonatomic, readonly) BOOL useWebKit2ByDefault;
+@property (nonatomic, readonly) BOOL useTransparentWindows;
+@property (nonatomic, readonly) BOOL usePaginatedMode;
+@property (nonatomic, readonly) BOOL layerBordersVisible;
+@property (nonatomic, readonly) BOOL tiledScrollingIndicatorVisible;
+@property (nonatomic, readonly) BOOL useUISideCompositing;
+@property (nonatomic, readonly) BOOL subPixelCSSOMMetricsEnabled;
+@property (nonatomic, readonly) NSString *defaultURL;
+
+@end
diff --git a/Tools/MiniBrowser/mac/SettingsController.m b/Tools/MiniBrowser/mac/SettingsController.m
new file mode 100644 (file)
index 0000000..dbe955b
--- /dev/null
@@ -0,0 +1,212 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "SettingsController.h"
+
+#import "AppDelegate.h"
+#import "BrowserWindowController.h"
+
+static NSString * const defaultURL = @"http://www.webkit.org/";
+static NSString * const DefaultURLPreferenceKey = @"DefaultURL";
+
+static NSString * const UseWebKit2ByDefaultPreferenceKey = @"UseWebKit2ByDefault";
+static NSString * const LayerBordersVisiblePreferenceKey = @"LayerBordersVisible";
+static NSString * const TiledScrollingIndicatorVisiblePreferenceKey = @"TiledScrollingIndicatorVisible";
+
+static NSString * const UseTransparentWindowsPreferenceKey = @"UseTransparentWindows";
+static NSString * const UsePaginatedModePreferenceKey = @"UsePaginatedMode";
+static NSString * const EnableSubPixelCSSOMMetricsPreferenceKey = @"EnableSubPixelCSSOMMetrics";
+
+// This default name intentionally overlaps with the key that WebKit2 checks when creating a view.
+static NSString * const UseRemoteLayerTreeDrawingAreaPreferenceKey = @"WebKit2UseRemoteLayerTreeDrawingArea";
+
+@implementation SettingsController
+
+@synthesize menu=_menu;
+
++ (instancetype)shared
+{
+    static SettingsController *sharedSettingsController;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
+        sharedSettingsController = [[super alloc] init];
+    });
+
+    return sharedSettingsController;
+}
+
+- (NSMenu *)menu
+{
+    if (!_menu)
+        [self _populateMenu];
+
+    return _menu;
+}
+
+- (void)_addItemWithTitle:(NSString *)title action:(SEL)action indented:(BOOL)indented
+{
+    NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:title action:action keyEquivalent:@""];
+    [item setTarget:self];
+    if (indented)
+        [item setIndentationLevel:1];
+    [_menu addItem:item];
+    [item release];
+}
+
+- (void)_addHeaderWithTitle:(NSString *)title
+{
+    [_menu addItem:[NSMenuItem separatorItem]];
+    [_menu addItem:[[[NSMenuItem alloc] initWithTitle:title action:nil keyEquivalent:@""] autorelease]];
+}
+
+- (void)_populateMenu
+{
+    _menu = [[NSMenu alloc] initWithTitle:@"Settings"];
+
+    [self _addItemWithTitle:@"Use WebKit2 By Default" action:@selector(toggleUseWebKit2ByDefault:) indented:NO];
+
+    [_menu addItem:[NSMenuItem separatorItem]];
+
+    [self _addItemWithTitle:@"Use Transparent Windows" action:@selector(toggleUseTransparentWindows:) indented:NO];
+    [self _addItemWithTitle:@"Use Paginated Mode" action:@selector(toggleUsePaginatedMode:) indented:NO];
+    [self _addItemWithTitle:@"Show Layer Borders" action:@selector(toggleShowLayerBorders:) indented:NO];
+
+    [self _addHeaderWithTitle:@"WebKit2-only Settings"];
+    [self _addItemWithTitle:@"Show Tiled Scrolling Indicator" action:@selector(toggleShowTiledScrollingIndicator:) indented:YES];
+    [self _addItemWithTitle:@"Use UI-Side Compositing" action:@selector(toggleUseUISideCompositing:) indented:YES];
+
+    [self _addHeaderWithTitle:@"WebKit1-only Settings"];
+    [self _addItemWithTitle:@"Enable Subpixel CSSOM Metrics" action:@selector(toggleEnableSubPixelCSSOMMetrics:) indented:YES];
+}
+
+- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
+{
+    SEL action = [menuItem action];
+
+    if (action == @selector(toggleUseWebKit2ByDefault:))
+        [menuItem setState:[self useWebKit2ByDefault] ? NSOnState : NSOffState];
+    else if (action == @selector(toggleUseTransparentWindows:))
+        [menuItem setState:[self useTransparentWindows] ? NSOnState : NSOffState];
+    else if (action == @selector(toggleUsePaginatedMode:))
+        [menuItem setState:[self usePaginatedMode] ? NSOnState : NSOffState];
+    else if (action == @selector(toggleShowLayerBorders:))
+        [menuItem setState:[self layerBordersVisible] ? NSOnState : NSOffState];
+    else if (action == @selector(toggleShowTiledScrollingIndicator:))
+        [menuItem setState:[self tiledScrollingIndicatorVisible] ? NSOnState : NSOffState];
+    else if (action == @selector(toggleUseUISideCompositing:))
+        [menuItem setState:[self useUISideCompositing] ? NSOnState : NSOffState];
+    else if (action == @selector(toggleEnableSubPixelCSSOMMetrics:))
+        [menuItem setState:[self subPixelCSSOMMetricsEnabled] ? NSOnState : NSOffState];
+
+    return YES;
+}
+
+- (void)_toggleBooleanDefault:(NSString *)defaultName
+{
+    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+    [defaults setBool:![defaults boolForKey:defaultName] forKey:defaultName];
+
+    [(BrowserAppDelegate *)[NSApp delegate] didChangeSettings];
+}
+
+- (void)toggleUseWebKit2ByDefault:(id)sender
+{
+    [self _toggleBooleanDefault:UseWebKit2ByDefaultPreferenceKey];
+}
+
+- (BOOL)useWebKit2ByDefault
+{
+    return [[NSUserDefaults standardUserDefaults] boolForKey:UseWebKit2ByDefaultPreferenceKey];
+}
+
+- (void)toggleUseTransparentWindows:(id)sender
+{
+    [self _toggleBooleanDefault:UseTransparentWindowsPreferenceKey];
+}
+
+- (BOOL)useTransparentWindows
+{
+    return [[NSUserDefaults standardUserDefaults] boolForKey:UseTransparentWindowsPreferenceKey];
+}
+
+- (void)toggleUsePaginatedMode:(id)sender
+{
+    [self _toggleBooleanDefault:UsePaginatedModePreferenceKey];
+}
+
+- (BOOL)usePaginatedMode
+{
+    return [[NSUserDefaults standardUserDefaults] boolForKey:UsePaginatedModePreferenceKey];
+}
+
+- (void)toggleUseUISideCompositing:(id)sender
+{
+    [self _toggleBooleanDefault:UseRemoteLayerTreeDrawingAreaPreferenceKey];
+}
+
+- (BOOL)useUISideCompositing
+{
+    return [[NSUserDefaults standardUserDefaults] boolForKey:UseRemoteLayerTreeDrawingAreaPreferenceKey];
+}
+
+- (void)toggleShowLayerBorders:(id)sender
+{
+    [self _toggleBooleanDefault:LayerBordersVisiblePreferenceKey];
+}
+
+- (BOOL)layerBordersVisible
+{
+    return [[NSUserDefaults standardUserDefaults] boolForKey:LayerBordersVisiblePreferenceKey];
+}
+
+- (void)toggleShowTiledScrollingIndicator:(id)sender
+{
+    [self _toggleBooleanDefault:TiledScrollingIndicatorVisiblePreferenceKey];
+}
+
+- (BOOL)tiledScrollingIndicatorVisible
+{
+    return [[NSUserDefaults standardUserDefaults] boolForKey:TiledScrollingIndicatorVisiblePreferenceKey];
+}
+
+- (void)toggleEnableSubPixelCSSOMMetrics:(id)sender
+{
+    [self _toggleBooleanDefault:EnableSubPixelCSSOMMetricsPreferenceKey];
+}
+
+- (BOOL)subPixelCSSOMMetricsEnabled
+{
+    return [[NSUserDefaults standardUserDefaults] boolForKey:EnableSubPixelCSSOMMetricsPreferenceKey];
+}
+
+- (NSString *)defaultURL
+{
+    NSString *customDefaultURL = [[NSUserDefaults standardUserDefaults] stringForKey:DefaultURLPreferenceKey];
+    if (customDefaultURL)
+        return customDefaultURL;
+    return defaultURL;
+}
+
+@end
index a3c8709..4da5c5d 100644 (file)
 
 #import "WK1BrowserWindowController.h"
 
-#import <WebKit/WebKit.h>
-#import <WebKit/WebViewPrivate.h>
 #import "AppDelegate.h"
+#import "SettingsController.h"
+#import <WebKit/WebKit.h>
 #import <WebKit/WebPreferences.h>
 #import <WebKit/WebPreferencesPrivate.h>
 #import <WebKit/WebPreferenceKeysPrivate.h>
+#import <WebKit/WebViewPrivate.h>
 
 @interface WK1BrowserWindowController ()
 @end
     _webView = [[WebView alloc] initWithFrame:[containerView bounds] frameName:nil groupName:@"MiniBrowser"];
     [_webView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
 
-    // Set the WebView delegates
     [_webView setFrameLoadDelegate:self];
     [_webView setUIDelegate:self];
     [_webView setResourceLoadDelegate:self];
     [_webView setPolicyDelegate:self];
+
     [[WebPreferences standardPreferences] setFullScreenEnabled:YES];
+    [[WebPreferences standardPreferences] setDeveloperExtrasEnabled:YES];
 
     [containerView addSubview:_webView];
 }
         [menuItem setTitle:[_webView window] ? @"Remove Web View" : @"Insert Web View"];
     else if (action == @selector(toggleZoomMode:))
         [menuItem setState:_zoomTextOnly ? NSOnState : NSOffState];
-    else if (action == @selector(togglePaginationMode:))
-        [menuItem setState:[self isPaginated] ? NSOnState : NSOffState];
-    else if (action == @selector(toggleTransparentWindow:))
-        [menuItem setState:[[self window] isOpaque] ? NSOffState : NSOnState];
-    else if (action == @selector(toggleSubpixelCSSOMElementMetricsEnabled:))
-        [menuItem setState:[self isSubpixelCSSOMElementMetricsEnabled] ? NSOnState : NSOffState];
-    else if (action == @selector(toggleLayerBordersVisibility:))
-        [menuItem setState:[self layerBordersVisible] ? NSOnState : NSOffState];
 
     return YES;
 }
 
 - (void)windowWillClose:(NSNotification *)notification
 {
-    [(BrowserAppDelegate *)[NSApp delegate] browserWindowWillClose:[self window]];
+    [(BrowserAppDelegate *)[NSApp delegate] browserWindowWillClose:self.window];
     [self autorelease];
 }
 
     _zoomTextOnly = !_zoomTextOnly;
 }
 
-- (BOOL)isPaginated
+- (IBAction)find:(id)sender
 {
-    return [_webView _paginationMode] != WebPaginationModeUnpaginated;
 }
 
-- (IBAction)togglePaginationMode:(id)sender
+- (IBAction)dumpSourceToConsole:(id)sender
 {
-    if ([self isPaginated]) {
-        [_webView _setPaginationMode:WebPaginationModeUnpaginated];
-    } else {
-        [_webView _setPaginationMode:WebPaginationModeRightToLeft];
-        [_webView _setPageLength:_webView.bounds.size.width / 2];
-        [_webView _setGapBetweenPages:10];
-    }
 }
 
-- (IBAction)toggleTransparentWindow:(id)sender
+- (void)didChangeSettings
 {
-    BOOL isTransparent = ![[self window] isOpaque];
-    isTransparent = !isTransparent;
-    
-    [[self window] setOpaque:!isTransparent];
-    [[self window] setHasShadow:!isTransparent];
+    SettingsController *settings = [SettingsController shared];
 
-    if (isTransparent)
-        [_webView setBackgroundColor:[NSColor clearColor]];
-    else
-        [_webView setBackgroundColor:[NSColor whiteColor]];
+    [[WebPreferences standardPreferences] setSubpixelCSSOMElementMetricsEnabled:settings.subPixelCSSOMMetricsEnabled];
+    [[WebPreferences standardPreferences] setShowDebugBorders:settings.layerBordersVisible];
+    [[WebPreferences standardPreferences] setShowRepaintCounter:settings.layerBordersVisible];
 
-    [[self window] display];
-}
+    BOOL useTransparentWindows = settings.useTransparentWindows;
+    if (useTransparentWindows != !self.window.isOpaque) {
+        [self.window setOpaque:!useTransparentWindows];
+        [self.window setHasShadow:!useTransparentWindows];
 
-- (BOOL)isSubpixelCSSOMElementMetricsEnabled
-{
-    return [[WebPreferences standardPreferences] subpixelCSSOMElementMetricsEnabled];
-}
+        [_webView setBackgroundColor:useTransparentWindows ? [NSColor clearColor] : [NSColor whiteColor]];
 
-- (IBAction)toggleSubpixelCSSOMElementMetricsEnabled:(id)sender
-{
-    [[WebPreferences standardPreferences] setSubpixelCSSOMElementMetricsEnabled:![self isSubpixelCSSOMElementMetricsEnabled]];
-}
-
-- (BOOL)layerBordersVisible
-{
-    return [[WebPreferences standardPreferences] showDebugBorders];
-}
-
-- (IBAction)toggleLayerBordersVisibility:(id)sender
-{
-    BOOL newValue = ![self layerBordersVisible];
-    [[WebPreferences standardPreferences] setShowDebugBorders:newValue];
-    [[WebPreferences standardPreferences] setShowRepaintCounter:newValue];
-}
-
-- (IBAction)find:(id)sender
-{
-}
+        [self.window display];
+    }
 
-- (IBAction)dumpSourceToConsole:(id)sender
-{
+    BOOL usePaginatedMode = settings.usePaginatedMode;
+    if (usePaginatedMode != (_webView._paginationMode != WebPaginationModeUnpaginated)) {
+        if (usePaginatedMode) {
+            [_webView _setPaginationMode:WebPaginationModeLeftToRight];
+            [_webView _setPageLength:_webView.bounds.size.width / 2];
+            [_webView _setGapBetweenPages:10];
+        } else
+            [_webView _setPaginationMode:WebPaginationModeUnpaginated];
+    }
 }
 
 - (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener
     if (frame != [sender mainFrame])
         return;
 
-    [[self window] setTitle:[title stringByAppendingString:@" [WK1]"]];
+    [self.window setTitle:[title stringByAppendingString:@" [WK1]"]];
 }
 
 - (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
index a97b3d2..47dcd97 100644 (file)
@@ -28,6 +28,7 @@
 #if WK_API_ENABLED
 
 #import "AppDelegate.h"
+#import "SettingsController.h"
 #import <WebKit/WKFrameInfo.h>
 #import <WebKit/WKNavigationDelegate.h>
 #import <WebKit/WKPreferencesPrivate.h>
 #import <WebKit/WKWebViewPrivate.h>
 
 static void* keyValueObservingContext = &keyValueObservingContext;
-static NSString * const WebKit2UseRemoteLayerTreeDrawingAreaKey = @"WebKit2UseRemoteLayerTreeDrawingArea";
-
-static NSString * const LayerBordersVisiblePreferenceKey = @"LayerBordersVisible";
-static NSString * const TiledScrollingIndicatorVisiblePreferenceKey = @"TiledScrollingIndicatorVisibleKey";
 
 @interface WK2BrowserWindowController () <WKNavigationDelegate, WKUIDelegate>
 @end
@@ -55,13 +52,10 @@ static NSString * const TiledScrollingIndicatorVisiblePreferenceKey = @"TiledScr
     static WKWebViewConfiguration *configuration;
     if (!configuration) {
         configuration = [[WKWebViewConfiguration alloc] init];
-
-        configuration.preferences._tiledScrollingIndicatorVisible = [self tiledScrollingIndicatorVisible];
-        configuration.preferences._compositingBordersVisible = [self layerBordersVisible];
-        configuration.preferences._compositingRepaintCountersVisible = [self layerBordersVisible];
         configuration.preferences._fullScreenEnabled = YES;
     }
     _webView = [[WKWebView alloc] initWithFrame:[containerView bounds] configuration:configuration];
+    [self didChangeSettings];
 
     _webView.allowsMagnification = YES;
     _webView.allowsBackForwardNavigationGestures = YES;
@@ -132,7 +126,8 @@ static NSString * const TiledScrollingIndicatorVisiblePreferenceKey = @"TiledScr
     
     // Disabled until missing WK2 functionality is exposed via API/SPI.
     if (action == @selector(dumpSourceToConsole:)
-        || action == @selector(find:))
+        || action == @selector(find:)
+        || action == @selector(forceRepaint:))
         return NO;
     
     if (action == @selector(showHideWebView:))
@@ -141,16 +136,6 @@ static NSString * const TiledScrollingIndicatorVisiblePreferenceKey = @"TiledScr
         [menuItem setTitle:[_webView window] ? @"Remove Web View" : @"Insert Web View"];
     else if (action == @selector(toggleZoomMode:))
         [menuItem setState:_zoomTextOnly ? NSOnState : NSOffState];
-    else if (action == @selector(togglePaginationMode:))
-        [menuItem setState:[self isPaginated] ? NSOnState : NSOffState];
-    else if (action == @selector(toggleTransparentWindow:))
-        [menuItem setState:[[self window] isOpaque] ? NSOffState : NSOnState];
-    else if (action == @selector(toggleUISideCompositing:))
-        [menuItem setState:[self isUISideCompositingEnabled] ? NSOnState : NSOffState];
-    else if (action == @selector(toggleLayerBordersVisibility:))
-        [menuItem setState:[self layerBordersVisible] ? NSOnState : NSOffState];
-    else if (action == @selector(toggleTiledScrollingIndicatorVisibility:))
-        [menuItem setState:[self tiledScrollingIndicatorVisible] ? NSOnState : NSOffState];
 
     return YES;
 }
@@ -162,6 +147,7 @@ static NSString * const TiledScrollingIndicatorVisiblePreferenceKey = @"TiledScr
 
 - (IBAction)forceRepaint:(id)sender
 {
+    // FIXME: This doesn't actually force a repaint.
     [_webView setNeedsDisplay:YES];
 }
 
@@ -232,7 +218,7 @@ static NSString * const TiledScrollingIndicatorVisiblePreferenceKey = @"TiledScr
 
 - (void)windowWillClose:(NSNotification *)notification
 {
-    [(BrowserAppDelegate *)[NSApp delegate] browserWindowWillClose:[self window]];
+    [(BrowserAppDelegate *)[NSApp delegate] browserWindowWillClose:self.window];
     [self autorelease];
 }
 
@@ -283,68 +269,34 @@ static NSString * const TiledScrollingIndicatorVisiblePreferenceKey = @"TiledScr
     self.currentZoomFactor /= DefaultZoomFactorRatio;
 }
 
-- (BOOL)isPaginated
-{
-    return _webView._paginationMode != _WKPaginationModeUnpaginated;
-}
-
-- (IBAction)togglePaginationMode:(id)sender
-{
-    if (self.isPaginated)
-        _webView._paginationMode = _WKPaginationModeUnpaginated;
-    else {
-        _webView._paginationMode = _WKPaginationModeLeftToRight;
-        _webView._pageLength = _webView.bounds.size.width / 2;
-        _webView._gapBetweenPages = 10;
-    }
-}
-
-- (IBAction)toggleTransparentWindow:(id)sender
+- (void)didChangeSettings
 {
-    BOOL isTransparent = _webView._drawsTransparentBackground;
-    isTransparent = !isTransparent;
+    SettingsController *settings = [SettingsController shared];
+    WKPreferences *preferences = _webView.configuration.preferences;
 
-    [[self window] setOpaque:!isTransparent];
-    [[self window] setHasShadow:!isTransparent];
+    preferences._tiledScrollingIndicatorVisible = settings.tiledScrollingIndicatorVisible;
+    preferences._compositingBordersVisible = settings.layerBordersVisible;
+    preferences._compositingRepaintCountersVisible = settings.layerBordersVisible;
 
-    _webView._drawsTransparentBackground = isTransparent;
+    BOOL useTransparentWindows = settings.useTransparentWindows;
+    if (useTransparentWindows != _webView._drawsTransparentBackground) {
+        [self.window setOpaque:!useTransparentWindows];
+        [self.window setHasShadow:!useTransparentWindows];
 
-    [[self window] display];    
-}
+        _webView._drawsTransparentBackground = useTransparentWindows;
 
-- (BOOL)isUISideCompositingEnabled
-{
-    return [[NSUserDefaults standardUserDefaults] boolForKey:WebKit2UseRemoteLayerTreeDrawingAreaKey];
-}
-
-- (IBAction)toggleUISideCompositing:(id)sender
-{
-    [[NSUserDefaults standardUserDefaults] setBool:![self isUISideCompositingEnabled] forKey:WebKit2UseRemoteLayerTreeDrawingAreaKey];
-}
-
-- (BOOL)layerBordersVisible
-{
-    return [[NSUserDefaults standardUserDefaults] boolForKey:LayerBordersVisiblePreferenceKey];
-}
-
-- (IBAction)toggleLayerBordersVisibility:(id)sender
-{
-    BOOL newState = ![self layerBordersVisible];
-    [[NSUserDefaults standardUserDefaults] setBool:newState forKey:LayerBordersVisiblePreferenceKey];
-    _webView.configuration.preferences._compositingBordersVisible = newState;
-    _webView.configuration.preferences._compositingRepaintCountersVisible = newState;
-}
-
-- (BOOL)tiledScrollingIndicatorVisible
-{
-    return [[NSUserDefaults standardUserDefaults] boolForKey:TiledScrollingIndicatorVisiblePreferenceKey];
-}
+        [self.window display];
+    }
 
-- (IBAction)toggleTiledScrollingIndicatorVisibility:(id)sender
-{
-    BOOL newState = ![self tiledScrollingIndicatorVisible];
-    [[NSUserDefaults standardUserDefaults] setBool:newState forKey:TiledScrollingIndicatorVisiblePreferenceKey];
-    _webView.configuration.preferences._tiledScrollingIndicatorVisible = newState;
+    BOOL usePaginatedMode = settings.usePaginatedMode;
+    if (usePaginatedMode != (_webView._paginationMode != _WKPaginationModeUnpaginated)) {
+        if (usePaginatedMode) {
+            _webView._paginationMode = _WKPaginationModeLeftToRight;
+            _webView._pageLength = _webView.bounds.size.width / 2;
+            _webView._gapBetweenPages = 10;
+        } else
+            _webView._paginationMode = _WKPaginationModeUnpaginated;
+    }
 }
 
 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context