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" |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |