OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/cocoa/extensions/browser_action_button.h" | 5 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
16 #import "chrome/browser/ui/cocoa/app_menu/app_menu_controller.h" | |
16 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
17 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" | 18 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" |
18 #import "chrome/browser/ui/cocoa/themed_window.h" | 19 #import "chrome/browser/ui/cocoa/themed_window.h" |
19 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 20 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
20 #import "chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h" | |
21 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 21 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
22 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" | 22 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" |
23 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 23 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
24 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
25 #include "skia/ext/skia_utils_mac.h" | 25 #include "skia/ext/skia_utils_mac.h" |
26 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h " | 26 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h " |
27 #import "ui/base/cocoa/menu_controller.h" | 27 #import "ui/base/cocoa/menu_controller.h" |
28 #include "ui/gfx/canvas_skia_paint.h" | 28 #include "ui/gfx/canvas_skia_paint.h" |
29 #include "ui/gfx/geometry/rect.h" | 29 #include "ui/gfx/geometry/rect.h" |
30 #include "ui/gfx/image/image.h" | 30 #include "ui/gfx/image/image.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 ToolbarActionViewDelegateBridge::~ToolbarActionViewDelegateBridge() { | 106 ToolbarActionViewDelegateBridge::~ToolbarActionViewDelegateBridge() { |
107 viewController_->SetDelegate(nullptr); | 107 viewController_->SetDelegate(nullptr); |
108 } | 108 } |
109 | 109 |
110 void ToolbarActionViewDelegateBridge::ShowContextMenu() { | 110 void ToolbarActionViewDelegateBridge::ShowContextMenu() { |
111 // We should only be showing the context menu in this way if we're doing so | 111 // We should only be showing the context menu in this way if we're doing so |
112 // for an overflowed action. | 112 // for an overflowed action. |
113 DCHECK(![owner_ superview]); | 113 DCHECK(![owner_ superview]); |
114 | 114 |
115 contextMenuRunning_ = true; | 115 contextMenuRunning_ = true; |
116 WrenchMenuController* wrenchMenuController = | 116 AppMenuController* appMenuController = |
117 [[[BrowserWindowController browserWindowControllerForWindow: | 117 [[[BrowserWindowController browserWindowControllerForWindow: |
118 [controller_ browser]->window()->GetNativeWindow()] | 118 [controller_ browser]->window()->GetNativeWindow()] |
119 toolbarController] wrenchMenuController]; | 119 toolbarController] appMenuController]; |
120 // If the wrench menu is open, we have to first close it. Part of this happens | 120 // If the app menu is open, we have to first close it. Part of this happens |
121 // asynchronously, so we have to use a posted task to open the next menu. | 121 // asynchronously, so we have to use a posted task to open the next menu. |
122 if ([wrenchMenuController isMenuOpen]) | 122 if ([appMenuController isMenuOpen]) |
123 [wrenchMenuController cancel]; | 123 [appMenuController cancel]; |
124 | 124 |
125 [controller_ toolbarActionsBar]->PopOutAction( | 125 [controller_ toolbarActionsBar]->PopOutAction( |
126 viewController_, | 126 viewController_, |
127 base::Bind(&ToolbarActionViewDelegateBridge::DoShowContextMenu, | 127 base::Bind(&ToolbarActionViewDelegateBridge::DoShowContextMenu, |
128 weakFactory_.GetWeakPtr())); | 128 weakFactory_.GetWeakPtr())); |
129 } | 129 } |
130 | 130 |
131 content::WebContents* ToolbarActionViewDelegateBridge::GetCurrentWebContents() | 131 content::WebContents* ToolbarActionViewDelegateBridge::GetCurrentWebContents() |
132 const { | 132 const { |
133 return [controller_ currentWebContents]; | 133 return [controller_ currentWebContents]; |
(...skipping 13 matching lines...) Expand all Loading... | |
147 user_shown_popup_visible_ = true; | 147 user_shown_popup_visible_ = true; |
148 [owner_ updateHighlightedState]; | 148 [owner_ updateHighlightedState]; |
149 } | 149 } |
150 | 150 |
151 void ToolbarActionViewDelegateBridge::OnPopupClosed() { | 151 void ToolbarActionViewDelegateBridge::OnPopupClosed() { |
152 user_shown_popup_visible_ = false; | 152 user_shown_popup_visible_ = false; |
153 [owner_ updateHighlightedState]; | 153 [owner_ updateHighlightedState]; |
154 } | 154 } |
155 | 155 |
156 void ToolbarActionViewDelegateBridge::DoShowContextMenu() { | 156 void ToolbarActionViewDelegateBridge::DoShowContextMenu() { |
157 // The point the menu shows matches that of the normal wrench menu - that is, | 157 // The point the menu shows matches that of the normal app menu - that is, |
Peter Kasting
2015/11/06 22:21:28
Nit: Rewrap comment
| |
158 // the right-left most corner of the menu is left-aligned with the wrench | 158 // the right-left most corner of the menu is left-aligned with the app button, |
159 // button, and the menu is displayed "a little bit" lower. It would be nice to | 159 // and the menu is displayed "a little bit" lower. It would be nice to be able |
160 // be able to avoid the magic '5' here, but since it's built into Cocoa, it's | 160 // to avoid the magic '5' here, but since it's built into Cocoa, it's not too |
161 // not too hopeful. | 161 // hopeful. |
162 NSPoint menuPoint = NSMakePoint(0, NSHeight([owner_ bounds]) + 5); | 162 NSPoint menuPoint = NSMakePoint(0, NSHeight([owner_ bounds]) + 5); |
163 [[owner_ cell] setHighlighted:YES]; | 163 [[owner_ cell] setHighlighted:YES]; |
164 [[owner_ menu] popUpMenuPositioningItem:nil | 164 [[owner_ menu] popUpMenuPositioningItem:nil |
165 atLocation:menuPoint | 165 atLocation:menuPoint |
166 inView:owner_]; | 166 inView:owner_]; |
167 [[owner_ cell] setHighlighted:NO]; | 167 [[owner_ cell] setHighlighted:NO]; |
168 contextMenuRunning_ = false; | 168 contextMenuRunning_ = false; |
169 // When the menu closed, the ViewController should have popped itself back in. | 169 // When the menu closed, the ViewController should have popped itself back in. |
170 DCHECK(![controller_ toolbarActionsBar]->popped_out_action()); | 170 DCHECK(![controller_ toolbarActionsBar]->popped_out_action()); |
171 } | 171 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 | 223 |
224 return self; | 224 return self; |
225 } | 225 } |
226 | 226 |
227 - (BOOL)acceptsFirstResponder { | 227 - (BOOL)acceptsFirstResponder { |
228 return YES; | 228 return YES; |
229 } | 229 } |
230 | 230 |
231 - (void)rightMouseDown:(NSEvent*)theEvent { | 231 - (void)rightMouseDown:(NSEvent*)theEvent { |
232 // Cocoa doesn't allow menus-running-in-menus, so in order to show the | 232 // Cocoa doesn't allow menus-running-in-menus, so in order to show the |
233 // context menu for an overflowed action, we close the wrench menu and show | 233 // context menu for an overflowed action, we close the app menu and show |
Peter Kasting
2015/11/06 22:21:28
Nit: Rewrap comment
| |
234 // the context menu over the wrench (similar to what we do for popups). | 234 // the context menu over the app menu (similar to what we do for popups). |
235 // Let the main bar's button handle showing the context menu, since the wrench | 235 // Let the main bar's button handle showing the context menu, since the app |
236 // menu will close.. | 236 // menu will close.. |
237 if ([browserActionsController_ isOverflow]) { | 237 if ([browserActionsController_ isOverflow]) { |
238 [browserActionsController_ mainButtonForId:viewController_->GetId()]-> | 238 [browserActionsController_ mainButtonForId:viewController_->GetId()]-> |
239 viewControllerDelegate_->ShowContextMenu(); | 239 viewControllerDelegate_->ShowContextMenu(); |
240 } else { | 240 } else { |
241 [super rightMouseDown:theEvent]; | 241 [super rightMouseDown:theEvent]; |
242 } | 242 } |
243 } | 243 } |
244 | 244 |
245 - (void)mouseDown:(NSEvent*)theEvent { | 245 - (void)mouseDown:(NSEvent*)theEvent { |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
569 - (ui::ThemeProvider*)themeProviderForWindow:(NSWindow*)window { | 569 - (ui::ThemeProvider*)themeProviderForWindow:(NSWindow*)window { |
570 ui::ThemeProvider* themeProvider = [window themeProvider]; | 570 ui::ThemeProvider* themeProvider = [window themeProvider]; |
571 if (!themeProvider) | 571 if (!themeProvider) |
572 themeProvider = | 572 themeProvider = |
573 [[browserActionsController_ browser]->window()->GetNativeWindow() | 573 [[browserActionsController_ browser]->window()->GetNativeWindow() |
574 themeProvider]; | 574 themeProvider]; |
575 return themeProvider; | 575 return themeProvider; |
576 } | 576 } |
577 | 577 |
578 @end | 578 @end |
OLD | NEW |