Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / base / cocoa / appkit_utils.mm
blob6aa90ae6789d1dcb58f9b87ee753d1576db4f1f0
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"
10 namespace {
12 // Gets an NSImage given an image id.
13 NSImage* GetImage(int image_id) {
14   return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(image_id)
15       .ToNSImage();
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)];
32 }  // namespace
34 namespace ui {
36 void DrawNinePartImage(NSRect frame,
37                        const NinePartImageIds& image_ids,
38                        NSCompositingOperation operation,
39                        CGFloat alpha,
40                        BOOL flipped) {
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),
51                       operation,
52                       alpha,
53                       flipped);
56 void WindowTitlebarReceivedDoubleClick(NSWindow* window, id sender) {
57   if (ShouldWindowsMiniaturizeOnDoubleClick()) {
58     [window performMiniaturize:sender];
59   } else if (base::mac::IsOSYosemiteOrLater()) {
60     [window performZoom:sender];
61   }
64 }  // namespace ui