diff options
Diffstat (limited to 'chrome/browser/cocoa/reload_button.mm')
-rw-r--r-- | chrome/browser/cocoa/reload_button.mm | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/chrome/browser/cocoa/reload_button.mm b/chrome/browser/cocoa/reload_button.mm index c1379ed..9975db7 100644 --- a/chrome/browser/cocoa/reload_button.mm +++ b/chrome/browser/cocoa/reload_button.mm @@ -7,7 +7,7 @@ #include "app/l10n_util.h" #include "app/l10n_util_mac.h" #include "base/nsimage_cache_mac.h" -#include "chrome/app/chrome_dll_resource.h" +#include "chrome/app/chrome_command_ids.h" #import "chrome/browser/cocoa/gradient_button_cell.h" #import "chrome/browser/cocoa/view_id_util.h" #include "grit/generated_resources.h" @@ -17,6 +17,9 @@ namespace { NSString* const kReloadImageName = @"reload_Template.pdf"; NSString* const kStopImageName = @"stop_Template.pdf"; +// Constant matches Windows. +NSTimeInterval kPendingReloadTimeout = 1.35; + } // namespace @implementation ReloadButton @@ -58,17 +61,17 @@ NSString* const kStopImageName = @"stop_Template.pdf"; } - (void)setIsLoading:(BOOL)isLoading force:(BOOL)force { - pendingReloadMode_ = NO; - // Can always transition to stop mode. Only transition to reload // mode if forced or if the mouse isn't hovering. Otherwise, note // that reload mode is desired and disable the button. if (isLoading) { + pendingReloadTimer_.reset(); [self setImage:nsimage_cache::ImageNamed(kStopImageName)]; [self setTag:IDC_STOP]; [self setToolTip:l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_STOP)]; [self setEnabled:YES]; } else if (force || ![self isMouseInside]) { + pendingReloadTimer_.reset(); [self setImage:nsimage_cache::ImageNamed(kReloadImageName)]; [self setTag:IDC_RELOAD]; [self setToolTip:l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_RELOAD)]; @@ -81,26 +84,34 @@ NSString* const kStopImageName = @"stop_Template.pdf"; if ([cell respondsToSelector:@selector(setMouseInside:animate:)]) [cell setMouseInside:[self isMouseInside] animate:NO]; [self setEnabled:YES]; - } else if ([self tag] == IDC_STOP) { - pendingReloadMode_ = YES; + } else if ([self tag] == IDC_STOP && !pendingReloadTimer_) { [self setEnabled:NO]; + pendingReloadTimer_.reset( + [[NSTimer scheduledTimerWithTimeInterval:kPendingReloadTimeout + target:self + selector:@selector(forceReloadState) + userInfo:nil + repeats:NO] retain]); } } +- (void)forceReloadState { + [self setIsLoading:NO force:YES]; +} + - (BOOL)sendAction:(SEL)theAction to:(id)theTarget { if ([self tag] == IDC_STOP) { - // The stop command won't be valid after the attempt to change - // back to reload. But it "worked", so short-circuit it. - const BOOL ret = - pendingReloadMode_ ? YES : [super sendAction:theAction to:theTarget]; + // When the timer is started, the button is disabled, so this + // should not be possible. + DCHECK(!pendingReloadTimer_.get()); // When the stop is processed, immediately change to reload mode, // even though the IPC still has to bounce off the renderer and // back before the regular |-setIsLoaded:force:| will be called. // [This is how views and gtk do it.] + const BOOL ret = [super sendAction:theAction to:theTarget]; if (ret) - [self setIsLoading:NO force:YES]; - + [self forceReloadState]; return ret; } @@ -115,12 +126,12 @@ NSString* const kStopImageName = @"stop_Template.pdf"; isMouseInside_ = NO; // Reload mode was requested during the hover. - if (pendingReloadMode_) - [self setIsLoading:NO force:YES]; + if (pendingReloadTimer_) + [self forceReloadState]; } - (BOOL)isMouseInside { - return trackingArea_ && isMouseInside_; + return isMouseInside_; } - (ViewID)viewID { @@ -131,6 +142,10 @@ NSString* const kStopImageName = @"stop_Template.pdf"; @implementation ReloadButton (Testing) ++ (void)setPendingReloadTimeout:(NSTimeInterval)seconds { + kPendingReloadTimeout = seconds; +} + - (NSTrackingArea*)trackingArea { return trackingArea_; } |