OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/reload_button.h" | 5 #import "chrome/browser/cocoa/reload_button.h" |
6 | 6 |
7 #include "base/nsimage_cache_mac.h" | 7 #include "base/nsimage_cache_mac.h" |
8 #include "chrome/app/chrome_dll_resource.h" | 8 #include "chrome/app/chrome_dll_resource.h" |
9 #import "chrome/browser/cocoa/view_id_util.h" | 9 #import "chrome/browser/cocoa/view_id_util.h" |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // Don't allow multi-clicks, because the user probably wouldn't ever | 51 // Don't allow multi-clicks, because the user probably wouldn't ever |
52 // want to stop+reload or reload+stop. | 52 // want to stop+reload or reload+stop. |
53 [self setIgnoresMultiClick:YES]; | 53 [self setIgnoresMultiClick:YES]; |
54 } | 54 } |
55 | 55 |
56 - (void)setIsLoading:(BOOL)isLoading force:(BOOL)force { | 56 - (void)setIsLoading:(BOOL)isLoading force:(BOOL)force { |
57 pendingReloadMode_ = NO; | 57 pendingReloadMode_ = NO; |
58 | 58 |
59 // Can always transition to stop mode. Only transition to reload | 59 // Can always transition to stop mode. Only transition to reload |
60 // mode if forced or if the mouse isn't hovering. Otherwise, note | 60 // mode if forced or if the mouse isn't hovering. Otherwise, note |
61 // that reload mode is desired and make no change. | 61 // that reload mode is desired and disable the button. |
62 if (isLoading) { | 62 if (isLoading) { |
63 [self setImage:nsimage_cache::ImageNamed(kStopImageName)]; | 63 [self setImage:nsimage_cache::ImageNamed(kStopImageName)]; |
64 [self setTag:IDC_STOP]; | 64 [self setTag:IDC_STOP]; |
| 65 [self setEnabled:YES]; |
65 } else if (force || ![self isMouseInside]) { | 66 } else if (force || ![self isMouseInside]) { |
66 [self setImage:nsimage_cache::ImageNamed(kReloadImageName)]; | 67 [self setImage:nsimage_cache::ImageNamed(kReloadImageName)]; |
67 [self setTag:IDC_RELOAD]; | 68 [self setTag:IDC_RELOAD]; |
| 69 [self setEnabled:YES]; |
68 } else if ([self tag] == IDC_STOP) { | 70 } else if ([self tag] == IDC_STOP) { |
69 pendingReloadMode_ = YES; | 71 pendingReloadMode_ = YES; |
| 72 [self setEnabled:NO]; |
70 } | 73 } |
71 } | 74 } |
72 | 75 |
73 - (BOOL)sendAction:(SEL)theAction to:(id)theTarget { | 76 - (BOOL)sendAction:(SEL)theAction to:(id)theTarget { |
74 if ([self tag] == IDC_STOP) { | 77 if ([self tag] == IDC_STOP) { |
75 // The stop command won't be valid after the attempt to change | 78 // The stop command won't be valid after the attempt to change |
76 // back to reload. But it "worked", so short-circuit it. | 79 // back to reload. But it "worked", so short-circuit it. |
77 const BOOL ret = | 80 const BOOL ret = |
78 pendingReloadMode_ ? YES : [super sendAction:theAction to:theTarget]; | 81 pendingReloadMode_ ? YES : [super sendAction:theAction to:theTarget]; |
79 | 82 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 115 |
113 @end // ReloadButton | 116 @end // ReloadButton |
114 | 117 |
115 @implementation ReloadButton (Testing) | 118 @implementation ReloadButton (Testing) |
116 | 119 |
117 - (NSTrackingArea*)trackingArea { | 120 - (NSTrackingArea*)trackingArea { |
118 return trackingArea_; | 121 return trackingArea_; |
119 } | 122 } |
120 | 123 |
121 @end | 124 @end |
OLD | NEW |