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

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

Issue 1784533003: [Extensions UI Cocoa] Make disabled actions respond to the keyboard (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Linux compile fix Created 4 years, 9 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"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 contextMenuRunning_(false), 104 contextMenuRunning_(false),
105 weakFactory_(this) { 105 weakFactory_(this) {
106 viewController_->SetDelegate(this); 106 viewController_->SetDelegate(this);
107 } 107 }
108 108
109 ToolbarActionViewDelegateBridge::~ToolbarActionViewDelegateBridge() { 109 ToolbarActionViewDelegateBridge::~ToolbarActionViewDelegateBridge() {
110 viewController_->SetDelegate(nullptr); 110 viewController_->SetDelegate(nullptr);
111 } 111 }
112 112
113 void ToolbarActionViewDelegateBridge::ShowContextMenu() { 113 void ToolbarActionViewDelegateBridge::ShowContextMenu() {
114 // We should only be showing the context menu in this way if we're doing so 114 DCHECK(![controller_ toolbarActionsBar]->in_overflow_mode());
115 // for an overflowed action. 115 if ([owner_ superview]) {
116 DCHECK(![owner_ superview]); 116 // If the button is already visible on the toolbar, we can skip ahead to
117 // just showing the menu.
118 DoShowContextMenu();
119 return;
120 }
117 121
122 // Otherwise, we have to slide the button out.
118 contextMenuRunning_ = true; 123 contextMenuRunning_ = true;
119 AppMenuController* appMenuController = 124 AppMenuController* appMenuController =
120 [[[BrowserWindowController browserWindowControllerForWindow: 125 [[[BrowserWindowController browserWindowControllerForWindow:
121 [controller_ browser]->window()->GetNativeWindow()] 126 [controller_ browser]->window()->GetNativeWindow()]
122 toolbarController] appMenuController]; 127 toolbarController] appMenuController];
123 // If the app menu is open, we have to first close it. Part of this happens 128 // If the app menu is open, we have to first close it. Part of this happens
124 // asynchronously, so we have to use a posted task to open the next menu. 129 // asynchronously, so we have to use a posted task to open the next menu.
125 if ([appMenuController isMenuOpen]) 130 if ([appMenuController isMenuOpen])
126 [appMenuController cancel]; 131 [appMenuController cancel];
127 132
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 329
325 - (void)mouseUp:(NSEvent*)theEvent { 330 - (void)mouseUp:(NSEvent*)theEvent {
326 dragCouldStart_ = NO; 331 dragCouldStart_ = NO;
327 // There are non-drag cases where a mouseUp: may happen 332 // There are non-drag cases where a mouseUp: may happen
328 // (e.g. mouse-down, cmd-tab to another application, move mouse, 333 // (e.g. mouse-down, cmd-tab to another application, move mouse,
329 // mouse-up). 334 // mouse-up).
330 NSPoint location = [self convertPoint:[theEvent locationInWindow] 335 NSPoint location = [self convertPoint:[theEvent locationInWindow]
331 fromView:nil]; 336 fromView:nil];
332 // Only perform the click if we didn't drag the button. 337 // Only perform the click if we didn't drag the button.
333 if (NSPointInRect(location, [self bounds]) && !isBeingDragged_) { 338 if (NSPointInRect(location, [self bounds]) && !isBeingDragged_) {
334 // There's also a chance that the action is disabled, and the left click 339 [self performClick:self];
335 // should show the context menu.
336 if (!viewController_->IsEnabled(
337 [browserActionsController_ currentWebContents]) &&
338 viewController_->DisabledClickOpensMenu()) {
339 // No menus-in-menus; see comment in -rightMouseDown:.
340 if ([browserActionsController_ isOverflow]) {
341 [browserActionsController_ mainButtonForId:viewController_->GetId()]->
342 viewControllerDelegate_->ShowContextMenu();
343 } else {
344 [NSMenu popUpContextMenu:[self menu] withEvent:theEvent forView:self];
345 }
346 } else {
347 [self performClick:self];
348 }
349 } else { 340 } else {
350 // Make sure an ESC to end a drag doesn't trigger 2 endDrags. 341 // Make sure an ESC to end a drag doesn't trigger 2 endDrags.
351 if (isBeingDragged_) { 342 if (isBeingDragged_) {
352 [self endDrag]; 343 [self endDrag];
353 } else { 344 } else {
354 [super mouseUp:theEvent]; 345 [super mouseUp:theEvent];
355 } 346 }
356 } 347 }
357 [self updateHighlightedState]; 348 [self updateHighlightedState];
358 } 349 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 fromRect:NSZeroRect 473 fromRect:NSZeroRect
483 operation:NSCompositeSourceOver 474 operation:NSCompositeSourceOver
484 fraction:1.0 475 fraction:1.0
485 respectFlipped:YES 476 respectFlipped:YES
486 hints:nil]; 477 hints:nil];
487 478
488 [image unlockFocus]; 479 [image unlockFocus];
489 return image; 480 return image;
490 } 481 }
491 482
483 - (void)showContextMenu {
484 viewControllerDelegate_->ShowContextMenu();
485 }
486
492 - (NSMenu*)menu { 487 - (NSMenu*)menu {
493 // Hack: Since Cocoa doesn't support menus-running-in-menus (see also comment 488 // Hack: Since Cocoa doesn't support menus-running-in-menus (see also comment
494 // in -rightMouseDown:), it doesn't launch the menu for an overflowed action 489 // in -rightMouseDown:), it doesn't launch the menu for an overflowed action
495 // on a Control-click. Even more unfortunate, it doesn't even pass us the 490 // on a Control-click. Even more unfortunate, it doesn't even pass us the
496 // mouseDown event for control clicks. However, it does call -menuForEvent:, 491 // mouseDown event for control clicks. However, it does call -menuForEvent:,
497 // which in turn calls -menu:, so we can tap in here and show the menu 492 // which in turn calls -menu:, so we can tap in here and show the menu
498 // programmatically for the Control-click case. 493 // programmatically for the Control-click case.
499 if ([browserActionsController_ isOverflow] && 494 if ([browserActionsController_ isOverflow] &&
500 ([NSEvent modifierFlags] & NSControlKeyMask)) { 495 ([NSEvent modifierFlags] & NSControlKeyMask)) {
501 [browserActionsController_ mainButtonForId:viewController_->GetId()]-> 496 [browserActionsController_ mainButtonForId:viewController_->GetId()]->
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 - (const ui::ThemeProvider*)themeProviderForWindow:(NSWindow*)window { 570 - (const ui::ThemeProvider*)themeProviderForWindow:(NSWindow*)window {
576 const ui::ThemeProvider* themeProvider = [window themeProvider]; 571 const ui::ThemeProvider* themeProvider = [window themeProvider];
577 if (!themeProvider) 572 if (!themeProvider)
578 themeProvider = 573 themeProvider =
579 [[browserActionsController_ browser]->window()->GetNativeWindow() 574 [[browserActionsController_ browser]->window()->GetNativeWindow()
580 themeProvider]; 575 themeProvider];
581 return themeProvider; 576 return themeProvider;
582 } 577 }
583 578
584 @end 579 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698