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 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" | 5 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 tabstrip_model_(browser_->tabstrip_model()) { | 214 tabstrip_model_(browser_->tabstrip_model()) { |
215 Build(); | 215 Build(); |
216 UpdateZoomControls(); | 216 UpdateZoomControls(); |
217 | 217 |
218 tabstrip_model_->AddObserver(this); | 218 tabstrip_model_->AddObserver(this); |
219 | 219 |
220 registrar_.Add(this, NotificationType::ZOOM_LEVEL_CHANGED, | 220 registrar_.Add(this, NotificationType::ZOOM_LEVEL_CHANGED, |
221 Source<Profile>(browser_->profile())); | 221 Source<Profile>(browser_->profile())); |
222 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, | 222 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, |
223 NotificationService::AllSources()); | 223 NotificationService::AllSources()); |
224 registrar_.Add(this, | |
225 NotificationType::BACKGROUND_PAGE_TRACKER_CHANGED, | |
226 NotificationService::AllSources()); | |
227 } | 224 } |
228 | 225 |
229 WrenchMenuModel::~WrenchMenuModel() { | 226 WrenchMenuModel::~WrenchMenuModel() { |
230 if (tabstrip_model_) | 227 if (tabstrip_model_) |
231 tabstrip_model_->RemoveObserver(this); | 228 tabstrip_model_->RemoveObserver(this); |
232 } | 229 } |
233 | 230 |
234 bool WrenchMenuModel::DoesCommandIdDismissMenu(int command_id) const { | 231 bool WrenchMenuModel::DoesCommandIdDismissMenu(int command_id) const { |
235 return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS; | 232 return command_id != IDC_ZOOM_MINUS && command_id != IDC_ZOOM_PLUS; |
236 } | 233 } |
237 | 234 |
238 bool WrenchMenuModel::IsLabelForCommandIdDynamic(int command_id) const { | 235 bool WrenchMenuModel::IsItemForCommandIdDynamic(int command_id) const { |
239 return command_id == IDC_ZOOM_PERCENT_DISPLAY || | 236 return command_id == IDC_ZOOM_PERCENT_DISPLAY || |
240 #if defined(OS_MACOSX) | 237 #if defined(OS_MACOSX) |
241 command_id == IDC_FULLSCREEN || | 238 command_id == IDC_FULLSCREEN || |
242 #endif | 239 #endif |
243 command_id == IDC_SYNC_BOOKMARKS || | 240 command_id == IDC_SYNC_BOOKMARKS || |
244 command_id == IDC_VIEW_BACKGROUND_PAGES; | 241 command_id == IDC_VIEW_BACKGROUND_PAGES; |
245 } | 242 } |
246 | 243 |
| 244 bool WrenchMenuModel::GetIconForCommandId(int command_id, |
| 245 SkBitmap* bitmap) const { |
| 246 switch (command_id) { |
| 247 case IDC_VIEW_BACKGROUND_PAGES: { |
| 248 int num_pages = BackgroundPageTracker::GetInstance()-> |
| 249 GetUnacknowledgedBackgroundPageCount(); |
| 250 if (num_pages > 0) { |
| 251 *bitmap = GetBackgroundPageIcon(); |
| 252 return true; |
| 253 } else { |
| 254 // No icon. |
| 255 return false; |
| 256 } |
| 257 } |
| 258 default: |
| 259 // No icon for other dynamic menu items. |
| 260 return false; |
| 261 } |
| 262 } |
| 263 |
247 string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const { | 264 string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const { |
248 switch (command_id) { | 265 switch (command_id) { |
249 case IDC_SYNC_BOOKMARKS: | 266 case IDC_SYNC_BOOKMARKS: |
250 return GetSyncMenuLabel(); | 267 return GetSyncMenuLabel(); |
251 case IDC_ZOOM_PERCENT_DISPLAY: | 268 case IDC_ZOOM_PERCENT_DISPLAY: |
252 return zoom_label_; | 269 return zoom_label_; |
253 #if defined(OS_MACOSX) | 270 #if defined(OS_MACOSX) |
254 case IDC_FULLSCREEN: { | 271 case IDC_FULLSCREEN: { |
255 int string_id = IDS_ENTER_FULLSCREEN_MAC; // Default to Enter. | 272 int string_id = IDS_ENTER_FULLSCREEN_MAC; // Default to Enter. |
256 // Note: On startup, |window()| may be NULL. | 273 // Note: On startup, |window()| may be NULL. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 // During views shutdown, the tabstrip model/browser is deleted first, while | 360 // During views shutdown, the tabstrip model/browser is deleted first, while |
344 // it is the opposite in gtk land. | 361 // it is the opposite in gtk land. |
345 tabstrip_model_->RemoveObserver(this); | 362 tabstrip_model_->RemoveObserver(this); |
346 tabstrip_model_ = NULL; | 363 tabstrip_model_ = NULL; |
347 } | 364 } |
348 | 365 |
349 void WrenchMenuModel::Observe(NotificationType type, | 366 void WrenchMenuModel::Observe(NotificationType type, |
350 const NotificationSource& source, | 367 const NotificationSource& source, |
351 const NotificationDetails& details) { | 368 const NotificationDetails& details) { |
352 switch (type.value) { | 369 switch (type.value) { |
353 case NotificationType::BACKGROUND_PAGE_TRACKER_CHANGED: { | |
354 int num_pages = BackgroundPageTracker::GetInstance()-> | |
355 GetUnacknowledgedBackgroundPageCount(); | |
356 if (num_pages > 0) { | |
357 SetIcon(GetIndexOfCommandId(IDC_VIEW_BACKGROUND_PAGES), | |
358 GetBackgroundPageIcon()); | |
359 } else { | |
360 // Just set a blank icon (no icon). | |
361 SetIcon(GetIndexOfCommandId(IDC_VIEW_BACKGROUND_PAGES), SkBitmap()); | |
362 } | |
363 break; | |
364 } | |
365 case NotificationType::ZOOM_LEVEL_CHANGED: | 370 case NotificationType::ZOOM_LEVEL_CHANGED: |
366 case NotificationType::NAV_ENTRY_COMMITTED: | 371 case NotificationType::NAV_ENTRY_COMMITTED: |
367 UpdateZoomControls(); | 372 UpdateZoomControls(); |
368 break; | 373 break; |
369 default: | 374 default: |
370 NOTREACHED(); | 375 NOTREACHED(); |
371 } | 376 } |
372 } | 377 } |
373 | 378 |
374 // For testing. | 379 // For testing. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 IDS_VIEW_INCOMPATIBILITIES)); | 480 IDS_VIEW_INCOMPATIBILITIES)); |
476 | 481 |
477 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 482 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
478 SetIcon(GetIndexOfCommandId(IDC_UPGRADE_DIALOG), | 483 SetIcon(GetIndexOfCommandId(IDC_UPGRADE_DIALOG), |
479 *rb.GetBitmapNamed(IDR_UPDATE_MENU)); | 484 *rb.GetBitmapNamed(IDR_UPDATE_MENU)); |
480 #if defined(OS_WIN) | 485 #if defined(OS_WIN) |
481 SetIcon(GetIndexOfCommandId(IDC_VIEW_INCOMPATIBILITIES), | 486 SetIcon(GetIndexOfCommandId(IDC_VIEW_INCOMPATIBILITIES), |
482 *rb.GetBitmapNamed(IDR_CONFLICT_MENU)); | 487 *rb.GetBitmapNamed(IDR_CONFLICT_MENU)); |
483 #endif | 488 #endif |
484 | 489 |
485 // Add an icon to the View Background Pages item if there are unacknowledged | |
486 // pages. | |
487 if (BackgroundPageTracker::GetInstance()-> | |
488 GetUnacknowledgedBackgroundPageCount() > 0) { | |
489 SetIcon(GetIndexOfCommandId(IDC_VIEW_BACKGROUND_PAGES), | |
490 GetBackgroundPageIcon()); | |
491 } | |
492 | |
493 AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE); | 490 AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE); |
494 if (browser_defaults::kShowExitMenuItem) { | 491 if (browser_defaults::kShowExitMenuItem) { |
495 AddSeparator(); | 492 AddSeparator(); |
496 #if defined(OS_CHROMEOS) | 493 #if defined(OS_CHROMEOS) |
497 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) { | 494 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) { |
498 AddItemWithStringId(IDC_EXIT, IDS_EXIT_GUEST_MODE); | 495 AddItemWithStringId(IDC_EXIT, IDS_EXIT_GUEST_MODE); |
499 } else { | 496 } else { |
500 AddItemWithStringId(IDC_EXIT, IDS_SIGN_OUT); | 497 AddItemWithStringId(IDC_EXIT, IDS_SIGN_OUT); |
501 } | 498 } |
502 #else | 499 #else |
(...skipping 27 matching lines...) Expand all Loading... |
530 &enable_increment, &enable_decrement); | 527 &enable_increment, &enable_decrement); |
531 } | 528 } |
532 zoom_label_ = l10n_util::GetStringFUTF16( | 529 zoom_label_ = l10n_util::GetStringFUTF16( |
533 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); | 530 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); |
534 } | 531 } |
535 | 532 |
536 string16 WrenchMenuModel::GetSyncMenuLabel() const { | 533 string16 WrenchMenuModel::GetSyncMenuLabel() const { |
537 return sync_ui_util::GetSyncMenuLabel( | 534 return sync_ui_util::GetSyncMenuLabel( |
538 browser_->profile()->GetOriginalProfile()->GetProfileSyncService()); | 535 browser_->profile()->GetOriginalProfile()->GetProfileSyncService()); |
539 } | 536 } |
OLD | NEW |