OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ui/base/cocoa/appkit_utils.h" | 5 #import "ui/base/cocoa/appkit_utils.h" |
6 | 6 |
7 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
8 #include "ui/base/resource/resource_bundle.h" | 8 #include "ui/base/resource/resource_bundle.h" |
9 | 9 |
10 namespace { | 10 namespace { |
11 | 11 |
12 // Gets an NSImage given an image id. | 12 // Gets an NSImage given an image id. |
13 NSImage* GetImage(int image_id) { | 13 NSImage* GetImage(int image_id) { |
14 return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(image_id) | 14 return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(image_id) |
15 .ToNSImage(); | 15 .ToNSImage(); |
16 } | 16 } |
17 | 17 |
18 // Whether windows should miniaturize on a double-click on the title bar. | 18 // Double-click in window title bar actions. |
19 bool ShouldWindowsMiniaturizeOnDoubleClick() { | 19 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
| |
20 // We use an undocumented method in Cocoa; if it doesn't exist, default to | 20 const int kMinimize = 1; |
21 // |true|. If it ever goes away, we can do (using an undocumented pref key): | 21 const int kMaximize = 2; |
22 // NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | 22 |
23 // return ![defaults objectForKey:@"AppleMiniaturizeOnDoubleClick"] || | 23 // The action to take when the user double-clicks in the window title bar. |
24 // [defaults boolForKey:@"AppleMiniaturizeOnDoubleClick"]; | 24 int WindowTitleBarDoubleClickAction() { |
25 // El Capitan introduced a Dock preference to configure the window title bar | |
26 // double-click action (Minimize, Maximize, or nothing). | |
27 if (base::mac::IsOSElCapitanOrLater()) { | |
28 NSString* doubleClickAction = [[NSUserDefaults standardUserDefaults] | |
29 objectForKey:@"AppleActionOnDoubleClick"]; | |
30 | |
31 if ([doubleClickAction isEqualToString:@"Minimize"]) { | |
32 return kMinimize; | |
33 } else if ([doubleClickAction isEqualToString:@"Maximize"]) { | |
34 return kMaximize; | |
35 } | |
36 | |
37 return kNoAction; | |
38 } | |
39 | |
40 // Determine minimize using an undocumented method in Cocoa. If we're | |
41 // running on an earlier version of the OS that doesn't implement it, | |
42 // just default to the minimize action. | |
25 BOOL methodImplemented = | 43 BOOL methodImplemented = |
26 [NSWindow respondsToSelector:@selector(_shouldMiniaturizeOnDoubleClick)]; | 44 [NSWindow respondsToSelector:@selector(_shouldMiniaturizeOnDoubleClick)]; |
27 DCHECK(methodImplemented); | 45 if (!methodImplemented || |
28 return !methodImplemented || | 46 [NSWindow performSelector:@selector(_shouldMiniaturizeOnDoubleClick)]) { |
29 [NSWindow performSelector:@selector(_shouldMiniaturizeOnDoubleClick)]; | 47 return kMinimize; |
48 } | |
49 | |
50 // At this point _shouldMiniaturizeOnDoubleClick has returned |NO|. On | |
51 // Yosemite, that means a double-click should Maximize the window, and on | |
52 // all prior OSes a double-click should do nothing. | |
53 return base::mac::IsOSYosemite() ? kMaximize : kNoAction; | |
30 } | 54 } |
31 | 55 |
32 } // namespace | 56 } // namespace |
33 | 57 |
34 namespace ui { | 58 namespace ui { |
35 | 59 |
36 void DrawNinePartImage(NSRect frame, | 60 void DrawNinePartImage(NSRect frame, |
37 const NinePartImageIds& image_ids, | 61 const NinePartImageIds& image_ids, |
38 NSCompositingOperation operation, | 62 NSCompositingOperation operation, |
39 CGFloat alpha, | 63 CGFloat alpha, |
40 BOOL flipped) { | 64 BOOL flipped) { |
41 NSDrawNinePartImage(frame, | 65 NSDrawNinePartImage(frame, |
42 GetImage(image_ids.top_left), | 66 GetImage(image_ids.top_left), |
43 GetImage(image_ids.top), | 67 GetImage(image_ids.top), |
44 GetImage(image_ids.top_right), | 68 GetImage(image_ids.top_right), |
45 GetImage(image_ids.left), | 69 GetImage(image_ids.left), |
46 GetImage(image_ids.center), | 70 GetImage(image_ids.center), |
47 GetImage(image_ids.right), | 71 GetImage(image_ids.right), |
48 GetImage(image_ids.bottom_left), | 72 GetImage(image_ids.bottom_left), |
49 GetImage(image_ids.bottom), | 73 GetImage(image_ids.bottom), |
50 GetImage(image_ids.bottom_right), | 74 GetImage(image_ids.bottom_right), |
51 operation, | 75 operation, |
52 alpha, | 76 alpha, |
53 flipped); | 77 flipped); |
54 } | 78 } |
55 | 79 |
56 void WindowTitlebarReceivedDoubleClick(NSWindow* window, id sender) { | 80 void WindowTitlebarReceivedDoubleClick(NSWindow* window, id sender) { |
57 if (ShouldWindowsMiniaturizeOnDoubleClick()) { | 81 switch (WindowTitleBarDoubleClickAction()) { |
58 [window performMiniaturize:sender]; | 82 case kMinimize: |
59 } else if (base::mac::IsOSYosemiteOrLater()) { | 83 [window performMiniaturize:sender]; |
60 [window performZoom:sender]; | 84 break; |
85 | |
86 case kMaximize: | |
87 [window performZoom:sender]; | |
88 break; | |
89 | |
90 default: | |
91 break; | |
61 } | 92 } |
62 } | 93 } |
63 | 94 |
64 } // namespace ui | 95 } // namespace ui |
OLD | NEW |