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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/browser_action_button.mm

Issue 1105713002: [Extension Toolbar] Slide out overflowed actions for popups (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
OLDNEW
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 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.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 #import "chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h"
21 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" 22 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
22 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" 23 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h"
23 #include "grit/theme_resources.h" 24 #include "grit/theme_resources.h"
24 #include "skia/ext/skia_utils_mac.h" 25 #include "skia/ext/skia_utils_mac.h"
25 #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 "
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // We should only be showing the context menu in this way if we're doing so 105 // We should only be showing the context menu in this way if we're doing so
105 // for an overflowed action. 106 // for an overflowed action.
106 DCHECK(![owner_ superview]); 107 DCHECK(![owner_ superview]);
107 108
108 WrenchMenuController* wrenchMenuController = 109 WrenchMenuController* wrenchMenuController =
109 [[[BrowserWindowController browserWindowControllerForWindow: 110 [[[BrowserWindowController browserWindowControllerForWindow:
110 [controller_ browser]->window()->GetNativeWindow()] 111 [controller_ browser]->window()->GetNativeWindow()]
111 toolbarController] wrenchMenuController]; 112 toolbarController] wrenchMenuController];
112 // If the wrench menu is open, we have to first close it. Part of this happens 113 // If the wrench menu is open, we have to first close it. Part of this happens
113 // asynchronously, so we have to use a posted task to open the next menu. 114 // asynchronously, so we have to use a posted task to open the next menu.
114 if ([wrenchMenuController isMenuOpen]) { 115 if ([wrenchMenuController isMenuOpen])
115 [wrenchMenuController cancel]; 116 [wrenchMenuController cancel];
116 base::MessageLoop::current()->PostTask( 117 [controller_ toolbarActionsBar]->PopOutAction(
117 FROM_HERE, 118 viewController_,
118 base::Bind(&ToolbarActionViewDelegateBridge::DoShowContextMenu, 119 base::Bind(&ToolbarActionViewDelegateBridge::DoShowContextMenu,
119 weakFactory_.GetWeakPtr())); 120 weakFactory_.GetWeakPtr()));
120 } else {
121 DoShowContextMenu();
122 }
123 } 121 }
124 122
125 content::WebContents* ToolbarActionViewDelegateBridge::GetCurrentWebContents() 123 content::WebContents* ToolbarActionViewDelegateBridge::GetCurrentWebContents()
126 const { 124 const {
127 return [controller_ currentWebContents]; 125 return [controller_ currentWebContents];
128 } 126 }
129 127
130 void ToolbarActionViewDelegateBridge::UpdateState() { 128 void ToolbarActionViewDelegateBridge::UpdateState() {
131 [owner_ updateState]; 129 [owner_ updateState];
132 } 130 }
133 131
134 void ToolbarActionViewDelegateBridge::OnPopupShown(bool by_user) { 132 void ToolbarActionViewDelegateBridge::OnPopupShown(bool by_user) {
135 if (by_user) 133 if (by_user)
136 user_shown_popup_visible_ = true; 134 user_shown_popup_visible_ = true;
137 [owner_ updateHighlightedState]; 135 [owner_ updateHighlightedState];
138 } 136 }
139 137
140 void ToolbarActionViewDelegateBridge::OnPopupClosed() { 138 void ToolbarActionViewDelegateBridge::OnPopupClosed() {
141 user_shown_popup_visible_ = false; 139 user_shown_popup_visible_ = false;
142 [owner_ updateHighlightedState]; 140 [owner_ updateHighlightedState];
143 } 141 }
144 142
145 void ToolbarActionViewDelegateBridge::DoShowContextMenu() { 143 void ToolbarActionViewDelegateBridge::DoShowContextMenu() {
146 NSButton* wrenchButton =
147 [[[BrowserWindowController browserWindowControllerForWindow:
148 [controller_ browser]->window()->GetNativeWindow()]
149 toolbarController] wrenchButton];
150 // The point the menu shows matches that of the normal wrench menu - that is, 144 // The point the menu shows matches that of the normal wrench menu - that is,
151 // the right-left most corner of the menu is left-aligned with the wrench 145 // the right-left most corner of the menu is left-aligned with the wrench
152 // button, and the menu is displayed "a little bit" lower. It would be nice to 146 // button, and the menu is displayed "a little bit" lower. It would be nice to
153 // be able to avoid the magic '5' here, but since it's built into Cocoa, it's 147 // be able to avoid the magic '5' here, but since it's built into Cocoa, it's
154 // not too hopeful. 148 // not too hopeful.
155 NSPoint menuPoint = NSMakePoint(0, NSHeight([wrenchButton bounds]) + 5); 149 NSPoint menuPoint = NSMakePoint(0, NSHeight([owner_ bounds]) + 5);
156 150 [[owner_ cell] setHighlighted:YES];
157 // We set the wrench to be highlighted so it remains "pressed" when the menu
158 // is running.
159 [[wrenchButton cell] setHighlighted:YES];
160 [[owner_ menu] popUpMenuPositioningItem:nil 151 [[owner_ menu] popUpMenuPositioningItem:nil
161 atLocation:menuPoint 152 atLocation:menuPoint
162 inView:wrenchButton]; 153 inView:owner_];
163 [[wrenchButton cell] setHighlighted:NO]; 154 [[owner_ cell] setHighlighted:NO];
155 [controller_ toolbarActionsBar]->PopInAction();
164 } 156 }
165 157
166 @interface BrowserActionCell (Internals) 158 @interface BrowserActionCell (Internals)
167 - (void)drawBadgeWithinFrame:(NSRect)frame 159 - (void)drawBadgeWithinFrame:(NSRect)frame
168 forWebContents:(content::WebContents*)webContents; 160 forWebContents:(content::WebContents*)webContents;
169 @end 161 @end
170 162
171 @implementation BrowserActionButton 163 @implementation BrowserActionButton
172 164
173 @synthesize isBeingDragged = isBeingDragged_; 165 @synthesize isBeingDragged = isBeingDragged_;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 337 }
346 338
347 - (void)updateHighlightedState { 339 - (void)updateHighlightedState {
348 // The button's cell is highlighted if either the popup is showing by a user 340 // The button's cell is highlighted if either the popup is showing by a user
349 // action, or the user is about to drag the button, unless the button is 341 // action, or the user is about to drag the button, unless the button is
350 // overflowed (in which case it is never highlighted). 342 // overflowed (in which case it is never highlighted).
351 if ([self superview] && ![browserActionsController_ isOverflow]) { 343 if ([self superview] && ![browserActionsController_ isOverflow]) {
352 BOOL highlighted = viewControllerDelegate_->user_shown_popup_visible() || 344 BOOL highlighted = viewControllerDelegate_->user_shown_popup_visible() ||
353 dragCouldStart_; 345 dragCouldStart_;
354 [[self cell] setHighlighted:highlighted]; 346 [[self cell] setHighlighted:highlighted];
347 } else {
348 [[self cell] setHighlighted:NO];
355 } 349 }
356 } 350 }
357 351
358 - (void)setFrame:(NSRect)frameRect animate:(BOOL)animate { 352 - (void)setFrame:(NSRect)frameRect animate:(BOOL)animate {
359 if (!animate) { 353 if (!animate) {
360 [self setFrame:frameRect]; 354 [self setFrame:frameRect];
361 } else { 355 } else {
362 if ([moveAnimation_ isAnimating]) 356 if ([moveAnimation_ isAnimating])
363 [moveAnimation_ stopAnimation]; 357 [moveAnimation_ stopAnimation];
364 358
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 - (ui::ThemeProvider*)themeProviderForWindow:(NSWindow*)window { 529 - (ui::ThemeProvider*)themeProviderForWindow:(NSWindow*)window {
536 ui::ThemeProvider* themeProvider = [window themeProvider]; 530 ui::ThemeProvider* themeProvider = [window themeProvider];
537 if (!themeProvider) 531 if (!themeProvider)
538 themeProvider = 532 themeProvider =
539 [[browserActionsController_ browser]->window()->GetNativeWindow() 533 [[browserActionsController_ browser]->window()->GetNativeWindow()
540 themeProvider]; 534 themeProvider];
541 return themeProvider; 535 return themeProvider;
542 } 536 }
543 537
544 @end 538 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698