Index: ui/base/cocoa/appkit_utils.mm |
diff --git a/ui/base/cocoa/appkit_utils.mm b/ui/base/cocoa/appkit_utils.mm |
index 6aa90ae6789d1dcb58f9b87ee753d1576db4f1f0..234db3e0f260f2536c12b77de141428efba444ed 100644 |
--- a/ui/base/cocoa/appkit_utils.mm |
+++ b/ui/base/cocoa/appkit_utils.mm |
@@ -15,18 +15,42 @@ NSImage* GetImage(int image_id) { |
.ToNSImage(); |
} |
-// Whether windows should miniaturize on a double-click on the title bar. |
-bool ShouldWindowsMiniaturizeOnDoubleClick() { |
- // We use an undocumented method in Cocoa; if it doesn't exist, default to |
- // |true|. If it ever goes away, we can do (using an undocumented pref key): |
- // NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
- // return ![defaults objectForKey:@"AppleMiniaturizeOnDoubleClick"] || |
- // [defaults boolForKey:@"AppleMiniaturizeOnDoubleClick"]; |
+// Double-click in window title bar actions. |
+const int kNoAction = 0; |
tapted
2016/01/21 00:27:20
enum class DoubleClickAction {
NONE,
MINIMIZE,
shrike
2016/01/21 00:52:50
This is great, actually. I wasn't sure of the righ
|
+const int kMinimize = 1; |
+const int kMaximize = 2; |
+ |
+// The action to take when the user double-clicks in the window title bar. |
+int WindowTitleBarDoubleClickAction() { |
+ // El Capitan introduced a Dock preference to configure the window title bar |
+ // double-click action (Minimize, Maximize, or nothing). |
+ if (base::mac::IsOSElCapitanOrLater()) { |
+ NSString* doubleClickAction = [[NSUserDefaults standardUserDefaults] |
+ objectForKey:@"AppleActionOnDoubleClick"]; |
+ |
+ if ([doubleClickAction isEqualToString:@"Minimize"]) { |
+ return kMinimize; |
+ } else if ([doubleClickAction isEqualToString:@"Maximize"]) { |
+ return kMaximize; |
+ } |
+ |
+ return kNoAction; |
+ } |
+ |
+ // Determine minimize using an undocumented method in Cocoa. If we're |
+ // running on an earlier version of the OS that doesn't implement it, |
+ // just default to the minimize action. |
BOOL methodImplemented = |
[NSWindow respondsToSelector:@selector(_shouldMiniaturizeOnDoubleClick)]; |
- DCHECK(methodImplemented); |
- return !methodImplemented || |
- [NSWindow performSelector:@selector(_shouldMiniaturizeOnDoubleClick)]; |
+ if (!methodImplemented || |
+ [NSWindow performSelector:@selector(_shouldMiniaturizeOnDoubleClick)]) { |
+ return kMinimize; |
+ } |
+ |
+ // At this point _shouldMiniaturizeOnDoubleClick has returned |NO|. On |
+ // Yosemite, that means a double-click should Maximize the window, and on |
+ // all prior OSes a double-click should do nothing. |
+ return base::mac::IsOSYosemite() ? kMaximize : kNoAction; |
} |
} // namespace |
@@ -54,10 +78,17 @@ void DrawNinePartImage(NSRect frame, |
} |
void WindowTitlebarReceivedDoubleClick(NSWindow* window, id sender) { |
- if (ShouldWindowsMiniaturizeOnDoubleClick()) { |
- [window performMiniaturize:sender]; |
- } else if (base::mac::IsOSYosemiteOrLater()) { |
- [window performZoom:sender]; |
+ switch (WindowTitleBarDoubleClickAction()) { |
+ case kMinimize: |
+ [window performMiniaturize:sender]; |
+ break; |
+ |
+ case kMaximize: |
+ [window performZoom:sender]; |
+ break; |
+ |
+ default: |
+ break; |
} |
} |