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

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

Issue 1216053013: [Extension Toolbar Redesign] Wants to act treatment, redux - left click (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/ui/extensions/extension_action_view_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 object:self]; 318 object:self];
319 } 319 }
320 320
321 - (void)mouseUp:(NSEvent*)theEvent { 321 - (void)mouseUp:(NSEvent*)theEvent {
322 dragCouldStart_ = NO; 322 dragCouldStart_ = NO;
323 // There are non-drag cases where a mouseUp: may happen 323 // There are non-drag cases where a mouseUp: may happen
324 // (e.g. mouse-down, cmd-tab to another application, move mouse, 324 // (e.g. mouse-down, cmd-tab to another application, move mouse,
325 // mouse-up). 325 // mouse-up).
326 NSPoint location = [self convertPoint:[theEvent locationInWindow] 326 NSPoint location = [self convertPoint:[theEvent locationInWindow]
327 fromView:nil]; 327 fromView:nil];
328 // Only perform the click if we didn't drag the button.
328 if (NSPointInRect(location, [self bounds]) && !isBeingDragged_) { 329 if (NSPointInRect(location, [self bounds]) && !isBeingDragged_) {
329 // Only perform the click if we didn't drag the button. 330 // There's also a chance that the action is disabled, and the left click
330 [self performClick:self]; 331 // should show the context menu.
332 if (!viewController_->IsEnabled(
333 [browserActionsController_ currentWebContents]) &&
334 viewController_->DisabledClickOpensMenu()) {
335 // No menus-in-menus; see comment in -rightMouseDown:.
336 if ([browserActionsController_ isOverflow]) {
337 [browserActionsController_ mainButtonForId:viewController_->GetId()]->
338 viewControllerDelegate_->ShowContextMenu();
339 } else {
340 [NSMenu popUpContextMenu:[self menu] withEvent:theEvent forView:self];
341 }
342 } else {
343 [self performClick:self];
344 }
331 } else { 345 } else {
332 // Make sure an ESC to end a drag doesn't trigger 2 endDrags. 346 // Make sure an ESC to end a drag doesn't trigger 2 endDrags.
333 if (isBeingDragged_) { 347 if (isBeingDragged_) {
334 [self endDrag]; 348 [self endDrag];
335 } else { 349 } else {
336 [super mouseUp:theEvent]; 350 [super mouseUp:theEvent];
337 } 351 }
338 } 352 }
339 [self updateHighlightedState]; 353 [self updateHighlightedState];
340 } 354 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 413
400 base::string16 tooltip = viewController_->GetTooltip(webContents); 414 base::string16 tooltip = viewController_->GetTooltip(webContents);
401 [self setToolTip:(tooltip.empty() ? nil : base::SysUTF16ToNSString(tooltip))]; 415 [self setToolTip:(tooltip.empty() ? nil : base::SysUTF16ToNSString(tooltip))];
402 416
403 gfx::Image image = 417 gfx::Image image =
404 viewController_->GetIcon(webContents, gfx::Size([self frame].size)); 418 viewController_->GetIcon(webContents, gfx::Size([self frame].size));
405 419
406 if (!image.IsEmpty()) 420 if (!image.IsEmpty())
407 [self setImage:image.ToNSImage()]; 421 [self setImage:image.ToNSImage()];
408 422
409 [self setEnabled:viewController_->IsEnabled(webContents)]; 423 BOOL enabled = viewController_->IsEnabled(webContents) ||
424 viewController_->DisabledClickOpensMenu();
425 [self setEnabled:enabled];
410 426
411 [self setNeedsDisplay:YES]; 427 [self setNeedsDisplay:YES];
412 } 428 }
413 429
414 - (void)onRemoved { 430 - (void)onRemoved {
415 // The button is being removed from the toolbar, and the backing controller 431 // The button is being removed from the toolbar, and the backing controller
416 // will also be removed. Destroy the delegate. 432 // will also be removed. Destroy the delegate.
417 // We only need to do this because in Cocoa's memory management, removing the 433 // We only need to do this because in Cocoa's memory management, removing the
418 // button from the toolbar doesn't synchronously dealloc it. 434 // button from the toolbar doesn't synchronously dealloc it.
419 viewControllerDelegate_.reset(); 435 viewControllerDelegate_.reset();
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 - (ui::ThemeProvider*)themeProviderForWindow:(NSWindow*)window { 555 - (ui::ThemeProvider*)themeProviderForWindow:(NSWindow*)window {
540 ui::ThemeProvider* themeProvider = [window themeProvider]; 556 ui::ThemeProvider* themeProvider = [window themeProvider];
541 if (!themeProvider) 557 if (!themeProvider)
542 themeProvider = 558 themeProvider =
543 [[browserActionsController_ browser]->window()->GetNativeWindow() 559 [[browserActionsController_ browser]->window()->GetNativeWindow()
544 themeProvider]; 560 themeProvider];
545 return themeProvider; 561 return themeProvider;
546 } 562 }
547 563
548 @end 564 @end
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/extensions/extension_action_view_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698