Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: chrome/browser/ui/cocoa/toolbar/reload_button_cocoa.mm

Issue 1770573002: Update extension buttons to Material Design (Mac). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@md_toolbar
Patch Set: Code clean-up. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 forButtonState:image_button_cell::kPressedState]; 115 forButtonState:image_button_cell::kPressedState];
116 [cell setImageID:IDR_STOP_D 116 [cell setImageID:IDR_STOP_D
117 forButtonState:image_button_cell::kDisabledState]; 117 forButtonState:image_button_cell::kDisabledState];
118 [self setToolTip:l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_STOP)]; 118 [self setToolTip:l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_STOP)];
119 } else { 119 } else {
120 NOTREACHED(); 120 NOTREACHED();
121 } 121 }
122 return; 122 return;
123 } 123 }
124 124
125 [self resetIcons]; 125 [self resetButtonStateImages];
126 if (anInt == IDC_RELOAD) { 126 if (anInt == IDC_RELOAD) {
127 [self setToolTip:l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_RELOAD)]; 127 [self setToolTip:l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_RELOAD)];
128 } else if (anInt == IDC_STOP) { 128 } else if (anInt == IDC_STOP) {
129 [self setToolTip:l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_STOP)]; 129 [self setToolTip:l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_STOP)];
130 } else { 130 } else {
131 NOTREACHED(); 131 NOTREACHED();
132 } 132 }
133 } 133 }
134 134
135 - (id)accessibilityAttributeValue:(NSString *)attribute { 135 - (id)accessibilityAttributeValue:(NSString *)attribute {
(...skipping 13 matching lines...) Expand all
149 [self invalidatePendingReloadTimer]; 149 [self invalidatePendingReloadTimer];
150 [self updateTag:IDC_STOP]; 150 [self updateTag:IDC_STOP];
151 } else if (force) { 151 } else if (force) {
152 [self invalidatePendingReloadTimer]; 152 [self invalidatePendingReloadTimer];
153 [self updateTag:IDC_RELOAD]; 153 [self updateTag:IDC_RELOAD];
154 } else if ([self tag] == IDC_STOP && 154 } else if ([self tag] == IDC_STOP &&
155 !pendingReloadTimer_ && 155 !pendingReloadTimer_ &&
156 [[self cell] isMouseInside]) { 156 [[self cell] isMouseInside]) {
157 id cell = [self cell]; 157 id cell = [self cell];
158 if (ui::MaterialDesignController::IsModeMaterial()) { 158 if (ui::MaterialDesignController::IsModeMaterial()) {
159 [self setImagesFromIconId:gfx::VectorIconId::NAVIGATE_STOP]; 159 [self resetButtonStateImages];
160 NSImage* disabledStopImage = 160 NSImage* disabledStopImage =
161 [[self cell] imageForState:image_button_cell::kDisabledState 161 [[self cell] imageForState:image_button_cell::kDisabledState
162 view:self]; 162 view:self];
163 [cell setImage:disabledStopImage 163 [cell setImage:disabledStopImage
164 forButtonState:image_button_cell::kDefaultState]; 164 forButtonState:image_button_cell::kDefaultState];
165 [cell setImage:disabledStopImage 165 [cell setImage:disabledStopImage
166 forButtonState:image_button_cell::kHoverState]; 166 forButtonState:image_button_cell::kHoverState];
167 [cell setImage:disabledStopImage 167 [cell setImage:disabledStopImage
168 forButtonState:image_button_cell::kPressedState]; 168 forButtonState:image_button_cell::kPressedState];
169 } else { 169 } else {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } 229 }
230 } 230 }
231 231
232 return [super sendAction:theAction to:theTarget]; 232 return [super sendAction:theAction to:theTarget];
233 } 233 }
234 234
235 - (ViewID)viewID { 235 - (ViewID)viewID {
236 return VIEW_ID_RELOAD_BUTTON; 236 return VIEW_ID_RELOAD_BUTTON;
237 } 237 }
238 238
239 - (gfx::VectorIconId)vectorIconId {
240 if ([self tag] == IDC_RELOAD) {
241 return gfx::VectorIconId::NAVIGATE_RELOAD;
242 } else if ([self tag] == IDC_STOP) {
243 return gfx::VectorIconId::NAVIGATE_STOP;
244 } else {
245 NOTREACHED();
246 }
247
248 return gfx::VectorIconId::VECTOR_ICON_NONE;
249 }
250
239 - (void)mouseInsideStateDidChange:(BOOL)isInside { 251 - (void)mouseInsideStateDidChange:(BOOL)isInside {
240 [pendingReloadTimer_ fire]; 252 [pendingReloadTimer_ fire];
241 } 253 }
242 254
243 - (void)populateMenu { 255 - (void)populateMenu {
244 [menu_ setAutoenablesItems:NO]; 256 [menu_ setAutoenablesItems:NO];
245 // 0-th item must be blank. (This is because we use a pulldown list, for which 257 // 0-th item must be blank. (This is because we use a pulldown list, for which
246 // Cocoa uses the 0-th item as "title" in the button.) 258 // Cocoa uses the 0-th item as "title" in the button.)
247 [menu_ addItemWithTitle:@"" 259 [menu_ addItemWithTitle:@""
248 action:nil 260 action:nil
(...skipping 30 matching lines...) Expand all
279 - (void)executeMenuItem:(id)sender { 291 - (void)executeMenuItem:(id)sender {
280 if (!commandUpdater_) 292 if (!commandUpdater_)
281 return; 293 return;
282 DCHECK([sender isKindOfClass:[NSMenuItem class]]); 294 DCHECK([sender isKindOfClass:[NSMenuItem class]]);
283 int command = [sender tag]; 295 int command = [sender tag];
284 int event_flags = ui::EventFlagsFromNative([NSApp currentEvent]); 296 int event_flags = ui::EventFlagsFromNative([NSApp currentEvent]);
285 commandUpdater_->ExecuteCommandWithDisposition( 297 commandUpdater_->ExecuteCommandWithDisposition(
286 command, ui::DispositionFromEventFlags(event_flags)); 298 command, ui::DispositionFromEventFlags(event_flags));
287 } 299 }
288 300
289 - (void)resetIcons {
290 if ([self tag] == IDC_RELOAD) {
291 [self setImagesFromIconId:gfx::VectorIconId::NAVIGATE_RELOAD];
292 } else if ([self tag] == IDC_STOP) {
293 [self setImagesFromIconId:gfx::VectorIconId::NAVIGATE_STOP];
294 } else {
295 NOTREACHED();
296 }
297 }
298
299 - (void)viewDidMoveToWindow {
300 // If a dark theme in Material Design, make sure the icon is the correct
301 // color.
302 if ([self window] && ui::MaterialDesignController::IsModeMaterial() &&
303 [[self window] hasDarkTheme]) {
304 [self resetIcons];
305 }
306 }
307
308 @end // ReloadButton 301 @end // ReloadButton
309 302
310 @implementation ReloadButton (Testing) 303 @implementation ReloadButton (Testing)
311 304
312 + (void)setPendingReloadTimeout:(NSTimeInterval)seconds { 305 + (void)setPendingReloadTimeout:(NSTimeInterval)seconds {
313 kPendingReloadTimeout = seconds; 306 kPendingReloadTimeout = seconds;
314 } 307 }
315 308
316 @end 309 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/toolbar/app_toolbar_button.mm ('k') | chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698