| Index: chrome/browser/ui/cocoa/toolbar/reload_button.mm
|
| diff --git a/chrome/browser/ui/cocoa/toolbar/reload_button.mm b/chrome/browser/ui/cocoa/toolbar/reload_button.mm
|
| index 1ac51bccdcf5ffb4a625dc4e2e20b6c2ddf7fd8d..0231579ce9f1b9105096e456ac332cda4d8f45aa 100644
|
| --- a/chrome/browser/ui/cocoa/toolbar/reload_button.mm
|
| +++ b/chrome/browser/ui/cocoa/toolbar/reload_button.mm
|
| @@ -5,28 +5,46 @@
|
| #import "chrome/browser/ui/cocoa/toolbar/reload_button.h"
|
|
|
| #include "chrome/app/chrome_command_ids.h"
|
| +#import "chrome/browser/ui/cocoa/accelerators_cocoa.h"
|
| #import "chrome/browser/ui/cocoa/view_id_util.h"
|
| +#include "chrome/browser/command_updater.h"
|
| #include "chrome/grit/generated_resources.h"
|
| #include "grit/theme_resources.h"
|
| +#include "ui/base/accelerators/platform_accelerator_cocoa.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| #include "ui/base/l10n/l10n_util_mac.h"
|
| +#import "ui/events/event_utils.h"
|
|
|
| namespace {
|
|
|
| // Constant matches Windows.
|
| NSTimeInterval kPendingReloadTimeout = 1.35;
|
|
|
| +// Contents of the Reload drop-down menu.
|
| +const int kReloadMenuItems[] = {
|
| + IDS_RELOAD_MENU_NORMAL_RELOAD_ITEM,
|
| + IDS_RELOAD_MENU_HARD_RELOAD_ITEM,
|
| + IDS_RELOAD_MENU_EMPTY_AND_HARD_RELOAD_ITEM,
|
| +};
|
| +// Note: must have the same size as |kReloadMenuItems|.
|
| +const int kReloadMenuCommands[] = {
|
| + IDC_RELOAD,
|
| + IDC_RELOAD_IGNORING_CACHE,
|
| + IDC_RELOAD_CLEARING_CACHE,
|
| +};
|
| +
|
| } // namespace
|
|
|
| @interface ReloadButton ()
|
| - (void)invalidatePendingReloadTimer;
|
| - (void)forceReloadState:(NSTimer *)timer;
|
| +- (void)populateMenu;
|
| @end
|
|
|
| @implementation ReloadButton
|
|
|
| + (Class)cellClass {
|
| - return [ImageButtonCell class];
|
| + return [ClickHoldButtonCell class];
|
| }
|
|
|
| - (id)initWithFrame:(NSRect)frameRect {
|
| @@ -47,6 +65,12 @@ NSTimeInterval kPendingReloadTimeout = 1.35;
|
| // Don't allow multi-clicks, because the user probably wouldn't ever
|
| // want to stop+reload or reload+stop.
|
| [self setIgnoresMultiClick:YES];
|
| +
|
| + [self setOpenMenuOnRightClick:YES];
|
| + [self setOpenMenuOnClick:NO];
|
| +
|
| + menu_.reset([[NSMenu alloc] initWithTitle:@""]);
|
| + [self populateMenu];
|
| }
|
|
|
| - (void)invalidatePendingReloadTimer {
|
| @@ -138,6 +162,14 @@ NSTimeInterval kPendingReloadTimeout = 1.35;
|
| [self setEnabled:pendingReloadTimer_ == nil];
|
| }
|
|
|
| +- (void)setMenuEnabled:(BOOL)enabled {
|
| + [self setAttachedMenu:(enabled ? menu_ : nil)];
|
| +}
|
| +
|
| +- (void)setCommandUpdater:(CommandUpdater*)commandUpdater {
|
| + commandUpdater_ = commandUpdater;
|
| +}
|
| +
|
| - (void)forceReloadState:(NSTimer *)timer {
|
| DCHECK_EQ(timer, pendingReloadTimer_);
|
| [self setIsLoading:NO force:YES];
|
| @@ -176,6 +208,52 @@ NSTimeInterval kPendingReloadTimeout = 1.35;
|
| [pendingReloadTimer_ fire];
|
| }
|
|
|
| +- (void)populateMenu {
|
| + [menu_ setAutoenablesItems:NO];
|
| + // 0-th item must be blank. (This is because we use a pulldown list, for which
|
| + // Cocoa uses the 0-th item as "title" in the button.)
|
| + [menu_ addItemWithTitle:@""
|
| + action:nil
|
| + keyEquivalent:@""];
|
| + AcceleratorsCocoa* keymap = AcceleratorsCocoa::GetInstance();
|
| + for (size_t i = 0; i < arraysize(kReloadMenuItems); ++i) {
|
| + NSString* title = l10n_util::GetNSStringWithFixup(kReloadMenuItems[i]);
|
| + base::scoped_nsobject<NSMenuItem> item(
|
| + [[NSMenuItem alloc] initWithTitle:title
|
| + action:@selector(executeMenuItem:)
|
| + keyEquivalent:@""]);
|
| +
|
| + const ui::Accelerator* accelerator =
|
| + keymap->GetAcceleratorForCommand(kReloadMenuCommands[i]);
|
| + if (accelerator) {
|
| + const ui::PlatformAcceleratorCocoa* platform =
|
| + static_cast<const ui::PlatformAcceleratorCocoa*>(
|
| + accelerator->platform_accelerator());
|
| + if (platform) {
|
| + [item setKeyEquivalent:platform->characters()];
|
| + [item setKeyEquivalentModifierMask:platform->modifier_mask()];
|
| + }
|
| + }
|
| +
|
| + [item setTag:kReloadMenuCommands[i]];
|
| + [item setTarget:self];
|
| + [item setEnabled:YES];
|
| +
|
| + [menu_ addItem:item];
|
| + }
|
| +}
|
| +
|
| +// Action for menu items.
|
| +- (void)executeMenuItem:(id)sender {
|
| + if (!commandUpdater_)
|
| + return;
|
| + DCHECK([sender isKindOfClass:[NSMenuItem class]]);
|
| + int command = [sender tag];
|
| + int event_flags = ui::EventFlagsFromNative([NSApp currentEvent]);
|
| + commandUpdater_->ExecuteCommandWithDisposition(
|
| + command, ui::DispositionFromEventFlags(event_flags));
|
| +}
|
| +
|
| @end // ReloadButton
|
|
|
| @implementation ReloadButton (Testing)
|
|
|