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
3 // found in the LICENSE file.
5 #import "ui/base/cocoa/appkit_utils.h"
7 #include "base/mac/mac_util.h"
8 #include "ui/base/resource/resource_bundle.h"
12 // Gets an NSImage given an image id.
13 NSImage* GetImage(int image_id) {
14 return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(image_id)
18 // Whether windows should miniaturize on a double-click on the title bar.
19 bool ShouldWindowsMiniaturizeOnDoubleClick() {
20 // We use an undocumented method in Cocoa; if it doesn't exist, default to
21 // |true|. If it ever goes away, we can do (using an undocumented pref key):
22 // NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
23 // return ![defaults objectForKey:@"AppleMiniaturizeOnDoubleClick"] ||
24 // [defaults boolForKey:@"AppleMiniaturizeOnDoubleClick"];
25 BOOL methodImplemented =
26 [NSWindow respondsToSelector:@selector(_shouldMiniaturizeOnDoubleClick)];
27 DCHECK(methodImplemented);
28 return !methodImplemented ||
29 [NSWindow performSelector:@selector(_shouldMiniaturizeOnDoubleClick)];
36 void DrawNinePartImage(NSRect frame,
37 const NinePartImageIds& image_ids,
38 NSCompositingOperation operation,
41 NSDrawNinePartImage(frame,
42 GetImage(image_ids.top_left),
43 GetImage(image_ids.top),
44 GetImage(image_ids.top_right),
45 GetImage(image_ids.left),
46 GetImage(image_ids.center),
47 GetImage(image_ids.right),
48 GetImage(image_ids.bottom_left),
49 GetImage(image_ids.bottom),
50 GetImage(image_ids.bottom_right),
56 void WindowTitlebarReceivedDoubleClick(NSWindow* window, id sender) {
57 if (ShouldWindowsMiniaturizeOnDoubleClick()) {
58 [window performMiniaturize:sender];
59 } else if (base::mac::IsOSYosemiteOrLater()) {
60 [window performZoom:sender];