OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/cocoa/toolbar/reload_button_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/toolbar/reload_button_cocoa.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 [pendingReloadTimer_ invalidate]; | 82 [pendingReloadTimer_ invalidate]; |
83 pendingReloadTimer_ = nil; | 83 pendingReloadTimer_ = nil; |
84 } | 84 } |
85 | 85 |
86 - (void)updateTag:(NSInteger)anInt { | 86 - (void)updateTag:(NSInteger)anInt { |
87 if ([self tag] == anInt) | 87 if ([self tag] == anInt) |
88 return; | 88 return; |
89 | 89 |
90 // Forcibly remove any stale tooltip which is being displayed. | 90 // Forcibly remove any stale tooltip which is being displayed. |
91 [self removeAllToolTips]; | 91 [self removeAllToolTips]; |
92 id cell = [self cell]; | |
93 [self setTag:anInt]; | 92 [self setTag:anInt]; |
94 | 93 |
95 // The old way of doing things. | |
96 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
97 if (anInt == IDC_RELOAD) { | |
98 [cell setImageID:IDR_RELOAD | |
99 forButtonState:image_button_cell::kDefaultState]; | |
100 [cell setImageID:IDR_RELOAD_H | |
101 forButtonState:image_button_cell::kHoverState]; | |
102 [cell setImageID:IDR_RELOAD_P | |
103 forButtonState:image_button_cell::kPressedState]; | |
104 // The stop button has a disabled image but the reload button doesn't. To | |
105 // unset it we have to explicilty change the image ID to 0. | |
106 [cell setImageID:0 | |
107 forButtonState:image_button_cell::kDisabledState]; | |
108 [self setToolTip:l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_RELOAD)]; | |
109 } else if (anInt == IDC_STOP) { | |
110 [cell setImageID:IDR_STOP | |
111 forButtonState:image_button_cell::kDefaultState]; | |
112 [cell setImageID:IDR_STOP_H | |
113 forButtonState:image_button_cell::kHoverState]; | |
114 [cell setImageID:IDR_STOP_P | |
115 forButtonState:image_button_cell::kPressedState]; | |
116 [cell setImageID:IDR_STOP_D | |
117 forButtonState:image_button_cell::kDisabledState]; | |
118 [self setToolTip:l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_STOP)]; | |
119 } else { | |
120 NOTREACHED(); | |
121 } | |
122 return; | |
123 } | |
124 | |
125 [self resetButtonStateImages]; | 94 [self resetButtonStateImages]; |
126 if (anInt == IDC_RELOAD) { | 95 if (anInt == IDC_RELOAD) { |
127 [self setToolTip:l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_RELOAD)]; | 96 [self setToolTip:l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_RELOAD)]; |
128 } else if (anInt == IDC_STOP) { | 97 } else if (anInt == IDC_STOP) { |
129 [self setToolTip:l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_STOP)]; | 98 [self setToolTip:l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_STOP)]; |
130 } else { | 99 } else { |
131 NOTREACHED(); | 100 NOTREACHED(); |
132 } | 101 } |
133 } | 102 } |
134 | 103 |
(...skipping 12 matching lines...) Expand all Loading... |
147 // that reload mode is desired and disable the button. | 116 // that reload mode is desired and disable the button. |
148 if (isLoading) { | 117 if (isLoading) { |
149 [self invalidatePendingReloadTimer]; | 118 [self invalidatePendingReloadTimer]; |
150 [self updateTag:IDC_STOP]; | 119 [self updateTag:IDC_STOP]; |
151 } else if (force) { | 120 } else if (force) { |
152 [self invalidatePendingReloadTimer]; | 121 [self invalidatePendingReloadTimer]; |
153 [self updateTag:IDC_RELOAD]; | 122 [self updateTag:IDC_RELOAD]; |
154 } else if ([self tag] == IDC_STOP && | 123 } else if ([self tag] == IDC_STOP && |
155 !pendingReloadTimer_ && | 124 !pendingReloadTimer_ && |
156 [[self cell] isMouseInside]) { | 125 [[self cell] isMouseInside]) { |
157 id cell = [self cell]; | 126 [self resetButtonStateImages]; |
158 if (ui::MaterialDesignController::IsModeMaterial()) { | 127 NSImage* disabledStopImage = |
159 [self resetButtonStateImages]; | 128 [[self cell] imageForState:image_button_cell::kDisabledState |
160 NSImage* disabledStopImage = | 129 view:self]; |
161 [[self cell] imageForState:image_button_cell::kDisabledState | 130 [[self cell] setImage:disabledStopImage |
162 view:self]; | |
163 [cell setImage:disabledStopImage | |
164 forButtonState:image_button_cell::kDefaultState]; | |
165 [cell setImage:disabledStopImage | |
166 forButtonState:image_button_cell::kHoverState]; | |
167 [cell setImage:disabledStopImage | |
168 forButtonState:image_button_cell::kPressedState]; | |
169 } else { | |
170 [cell setImageID:IDR_STOP_D | |
171 forButtonState:image_button_cell::kDefaultState]; | 131 forButtonState:image_button_cell::kDefaultState]; |
172 [cell setImageID:IDR_STOP_D | 132 [[self cell] setImage:disabledStopImage |
173 forButtonState:image_button_cell::kDisabledState]; | |
174 [cell setImageID:IDR_STOP_D | |
175 forButtonState:image_button_cell::kHoverState]; | 133 forButtonState:image_button_cell::kHoverState]; |
176 [cell setImageID:IDR_STOP_D | 134 [[self cell] setImage:disabledStopImage |
177 forButtonState:image_button_cell::kPressedState]; | 135 forButtonState:image_button_cell::kPressedState]; |
178 } | |
179 pendingReloadTimer_ = | 136 pendingReloadTimer_ = |
180 [NSTimer timerWithTimeInterval:kPendingReloadTimeout | 137 [NSTimer timerWithTimeInterval:kPendingReloadTimeout |
181 target:self | 138 target:self |
182 selector:@selector(forceReloadState:) | 139 selector:@selector(forceReloadState:) |
183 userInfo:nil | 140 userInfo:nil |
184 repeats:NO]; | 141 repeats:NO]; |
185 // Must add the timer to |NSRunLoopCommonModes| because | 142 // Must add the timer to |NSRunLoopCommonModes| because |
186 // it should run in |NSEventTrackingRunLoopMode| as well as | 143 // it should run in |NSEventTrackingRunLoopMode| as well as |
187 // |NSDefaultRunLoopMode|. | 144 // |NSDefaultRunLoopMode|. |
188 [[NSRunLoop currentRunLoop] addTimer:pendingReloadTimer_ | 145 [[NSRunLoop currentRunLoop] addTimer:pendingReloadTimer_ |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 257 |
301 @end // ReloadButton | 258 @end // ReloadButton |
302 | 259 |
303 @implementation ReloadButton (Testing) | 260 @implementation ReloadButton (Testing) |
304 | 261 |
305 + (void)setPendingReloadTimeout:(NSTimeInterval)seconds { | 262 + (void)setPendingReloadTimeout:(NSTimeInterval)seconds { |
306 kPendingReloadTimeout = seconds; | 263 kPendingReloadTimeout = seconds; |
307 } | 264 } |
308 | 265 |
309 @end | 266 @end |
OLD | NEW |