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 | 10 |
10 namespace { | 11 namespace { |
11 | 12 |
12 NSString* const kReloadImageName = @"reload_Template.pdf"; | 13 NSString* const kReloadImageName = @"reload_Template.pdf"; |
13 NSString* const kStopImageName = @"stop_Template.pdf"; | 14 NSString* const kStopImageName = @"stop_Template.pdf"; |
14 | 15 |
15 } // namespace | 16 } // namespace |
16 | 17 |
17 @implementation ReloadButton | 18 @implementation ReloadButton |
18 | 19 |
(...skipping 24 matching lines...) Expand all Loading... |
43 userInfo:nil]); | 44 userInfo:nil]); |
44 [self addTrackingArea:trackingArea_]; | 45 [self addTrackingArea:trackingArea_]; |
45 } | 46 } |
46 | 47 |
47 - (void)awakeFromNib { | 48 - (void)awakeFromNib { |
48 [self updateTrackingAreas]; | 49 [self updateTrackingAreas]; |
49 | 50 |
50 // 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 |
51 // want to stop+reload or reload+stop. | 52 // want to stop+reload or reload+stop. |
52 [self setIgnoresMultiClick:YES]; | 53 [self setIgnoresMultiClick:YES]; |
| 54 [self setCommand:IDC_RELOAD]; |
53 } | 55 } |
54 | 56 |
55 - (void)setIsLoading:(BOOL)isLoading force:(BOOL)force { | 57 - (void)setIsLoading:(BOOL)isLoading force:(BOOL)force { |
56 pendingReloadMode_ = NO; | 58 pendingReloadMode_ = NO; |
57 | 59 |
58 // Can always transition to stop mode. Only transition to reload | 60 // Can always transition to stop mode. Only transition to reload |
59 // mode if forced or if the mouse isn't hovering. Otherwise, note | 61 // mode if forced or if the mouse isn't hovering. Otherwise, note |
60 // that reload mode is desired and make no change. | 62 // that reload mode is desired and make no change. |
61 if (isLoading) { | 63 if (isLoading) { |
62 [self setImage:nsimage_cache::ImageNamed(kStopImageName)]; | 64 [self setImage:nsimage_cache::ImageNamed(kStopImageName)]; |
63 [self setTag:IDC_STOP]; | 65 [self setCommand:IDC_STOP]; |
64 } else if (force || ![self isMouseInside]) { | 66 } else if (force || ![self isMouseInside]) { |
65 [self setImage:nsimage_cache::ImageNamed(kReloadImageName)]; | 67 [self setImage:nsimage_cache::ImageNamed(kReloadImageName)]; |
66 [self setTag:IDC_RELOAD]; | 68 [self setCommand:IDC_RELOAD]; |
67 } else if ([self tag] == IDC_STOP) { | 69 } else if ([self command] == IDC_STOP) { |
68 pendingReloadMode_ = YES; | 70 pendingReloadMode_ = YES; |
69 } | 71 } |
70 } | 72 } |
71 | 73 |
72 - (BOOL)sendAction:(SEL)theAction to:(id)theTarget { | 74 - (BOOL)sendAction:(SEL)theAction to:(id)theTarget { |
73 if ([self tag] == IDC_STOP) { | 75 if ([self command] == IDC_STOP) { |
74 // The stop command won't be valid after the attempt to change | 76 // The stop command won't be valid after the attempt to change |
75 // back to reload. But it "worked", so short-circuit it. | 77 // back to reload. But it "worked", so short-circuit it. |
76 const BOOL ret = | 78 const BOOL ret = |
77 pendingReloadMode_ ? YES : [super sendAction:theAction to:theTarget]; | 79 pendingReloadMode_ ? YES : [super sendAction:theAction to:theTarget]; |
78 | 80 |
79 // When the stop is processed, immediately change to reload mode, | 81 // When the stop is processed, immediately change to reload mode, |
80 // even though the IPC still has to bounce off the renderer and | 82 // even though the IPC still has to bounce off the renderer and |
81 // back before the regular |-setIsLoaded:force:| will be called. | 83 // back before the regular |-setIsLoaded:force:| will be called. |
82 // [This is how views and gtk do it.] | 84 // [This is how views and gtk do it.] |
83 if (ret) | 85 if (ret) |
(...skipping 14 matching lines...) Expand all Loading... |
98 | 100 |
99 // Reload mode was requested during the hover. | 101 // Reload mode was requested during the hover. |
100 if (pendingReloadMode_) | 102 if (pendingReloadMode_) |
101 [self setIsLoading:NO force:YES]; | 103 [self setIsLoading:NO force:YES]; |
102 } | 104 } |
103 | 105 |
104 - (BOOL)isMouseInside { | 106 - (BOOL)isMouseInside { |
105 return trackingArea_ && isMouseInside_; | 107 return trackingArea_ && isMouseInside_; |
106 } | 108 } |
107 | 109 |
| 110 // Tag is used solely for ViewID. Override to prevent changing of it. |
| 111 - (NSInteger)tag { |
| 112 return view_id_util::ViewIDToTag(VIEW_ID_RELOAD_BUTTON); |
| 113 } |
| 114 |
108 @end // ReloadButton | 115 @end // ReloadButton |
109 | 116 |
110 @implementation ReloadButton (Testing) | 117 @implementation ReloadButton (Testing) |
111 | 118 |
112 - (NSTrackingArea*)trackingArea { | 119 - (NSTrackingArea*)trackingArea { |
113 return trackingArea_; | 120 return trackingArea_; |
114 } | 121 } |
115 | 122 |
116 @end | 123 @end |
OLD | NEW |