Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Unified Diff: ui/base/cocoa/appkit_utils.mm

Issue 1588073005: Follow El Capitan Dock settings for double-click in window title bar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change constants to enums. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ce672699f5d16a602aa511987a549b75a9967ddd 100644
--- a/ui/base/cocoa/appkit_utils.mm
+++ b/ui/base/cocoa/appkit_utils.mm
@@ -15,18 +15,45 @@ 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.
+enum class DoubleClickAction {
+ NONE,
+ MINIMIZE,
+ MAXIMIZE,
+};
+
+// The action to take when the user double-clicks in the window title bar.
+DoubleClickAction 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 DoubleClickAction::MINIMIZE;
+ } else if ([doubleClickAction isEqualToString:@"Maximize"]) {
+ return DoubleClickAction::MAXIMIZE;
+ }
+
+ return DoubleClickAction::NONE;
+ }
+
+ // 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 DoubleClickAction::MINIMIZE;
+ }
+
+ // 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() ? DoubleClickAction::MAXIMIZE
+ : DoubleClickAction::NONE;
}
} // namespace
@@ -54,10 +81,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 DoubleClickAction::MINIMIZE:
+ [window performMiniaturize:sender];
+ break;
+
+ case DoubleClickAction::MAXIMIZE:
+ [window performZoom:sender];
+ break;
+
+ case DoubleClickAction::NONE:
+ break;
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698