1// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_UI_COCOA_TOOLBAR_RELOAD_BUTTON_H_
6#define CHROME_BROWSER_UI_COCOA_TOOLBAR_RELOAD_BUTTON_H_
7#pragma once
8
9#import <Cocoa/Cocoa.h>
10
11#import "base/memory/scoped_nsobject.h"
12#import "chrome/browser/ui/cocoa/toolbar/toolbar_button.h"
13
14// ToolbarButton subclass which defers certain state changes when the mouse
15// is hovering over it.
16
17@interface ReloadButton : ToolbarButton {
18 @private
19  // Tracks whether the mouse is hovering for purposes of not making
20  // unexpected state changes.
21  BOOL isMouseInside_;
22  scoped_nsobject<NSTrackingArea> trackingArea_;
23
24  // Timer used when setting reload mode while the mouse is hovered.
25  scoped_nsobject<NSTimer> pendingReloadTimer_;
26}
27
28// Returns YES if the mouse is currently inside the bounds.
29- (BOOL)isMouseInside;
30
31// Update the tag, and the image and tooltip to match.  If |anInt|
32// matches the current tag, no action is taken.  |anInt| must be
33// either |IDC_STOP| or |IDC_RELOAD|.
34- (void)updateTag:(NSInteger)anInt;
35
36// Update the button to be a reload button or stop button depending on
37// |isLoading|.  If |force|, always sets the indicated mode.  If
38// |!force|, and the mouse is over the button, defer the transition
39// from stop button to reload button until the mouse has left the
40// button, or until |pendingReloadTimer_| fires.  This prevents an
41// inadvertent click _just_ as the state changes.
42- (void)setIsLoading:(BOOL)isLoading force:(BOOL)force;
43
44@end
45
46@interface ReloadButton (PrivateTestingMethods)
47+ (void)setPendingReloadTimeout:(NSTimeInterval)seconds;
48- (NSTrackingArea*)trackingArea;
49@end
50
51#endif  // CHROME_BROWSER_UI_COCOA_TOOLBAR_RELOAD_BUTTON_H_
52