| 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/wrench_menu_model.h" | 5 #include "chrome/browser/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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 NotificationService::AllSources()); | 187 NotificationService::AllSources()); |
| 188 } | 188 } |
| 189 | 189 |
| 190 WrenchMenuModel::~WrenchMenuModel() { | 190 WrenchMenuModel::~WrenchMenuModel() { |
| 191 if (tabstrip_model_) | 191 if (tabstrip_model_) |
| 192 tabstrip_model_->RemoveObserver(this); | 192 tabstrip_model_->RemoveObserver(this); |
| 193 } | 193 } |
| 194 | 194 |
| 195 bool WrenchMenuModel::IsLabelForCommandIdDynamic(int command_id) const { | 195 bool WrenchMenuModel::IsLabelForCommandIdDynamic(int command_id) const { |
| 196 return command_id == IDC_ZOOM_PERCENT_DISPLAY || | 196 return command_id == IDC_ZOOM_PERCENT_DISPLAY || |
| 197 command_id == IDC_SYNC_BOOKMARKS || | |
| 198 #if defined(OS_MACOSX) | 197 #if defined(OS_MACOSX) |
| 199 command_id == IDC_FULLSCREEN || | 198 command_id == IDC_FULLSCREEN || |
| 200 #endif | 199 #endif |
| 201 command_id == IDC_ABOUT; | 200 command_id == IDC_SYNC_BOOKMARKS; |
| 202 } | 201 } |
| 203 | 202 |
| 204 string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const { | 203 string16 WrenchMenuModel::GetLabelForCommandId(int command_id) const { |
| 205 switch (command_id) { | 204 switch (command_id) { |
| 206 case IDC_ABOUT: | |
| 207 return GetAboutEntryMenuLabel(); | |
| 208 case IDC_SYNC_BOOKMARKS: | 205 case IDC_SYNC_BOOKMARKS: |
| 209 return GetSyncMenuLabel(); | 206 return GetSyncMenuLabel(); |
| 210 case IDC_ZOOM_PERCENT_DISPLAY: | 207 case IDC_ZOOM_PERCENT_DISPLAY: |
| 211 return zoom_label_; | 208 return zoom_label_; |
| 212 #if defined(OS_MACOSX) | 209 #if defined(OS_MACOSX) |
| 213 case IDC_FULLSCREEN: { | 210 case IDC_FULLSCREEN: { |
| 214 int string_id = IDS_ENTER_FULLSCREEN_MAC; // Default to Enter. | 211 int string_id = IDS_ENTER_FULLSCREEN_MAC; // Default to Enter. |
| 215 // Note: On startup, |window()| may be NULL. | 212 // Note: On startup, |window()| may be NULL. |
| 216 if (browser_->window() && browser_->window()->IsFullscreen()) | 213 if (browser_->window() && browser_->window()->IsFullscreen()) |
| 217 string_id = IDS_EXIT_FULLSCREEN_MAC; | 214 string_id = IDS_EXIT_FULLSCREEN_MAC; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 239 return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); | 236 return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); |
| 240 } | 237 } |
| 241 | 238 |
| 242 return false; | 239 return false; |
| 243 } | 240 } |
| 244 | 241 |
| 245 bool WrenchMenuModel::IsCommandIdEnabled(int command_id) const { | 242 bool WrenchMenuModel::IsCommandIdEnabled(int command_id) const { |
| 246 return browser_->command_updater()->IsCommandEnabled(command_id); | 243 return browser_->command_updater()->IsCommandEnabled(command_id); |
| 247 } | 244 } |
| 248 | 245 |
| 246 bool WrenchMenuModel::IsCommandIdVisible(int command_id) const { |
| 247 if (command_id == IDC_UPGRADE_DIALOG) |
| 248 return Singleton<UpgradeDetector>::get()->notify_upgrade(); |
| 249 return true; |
| 250 } |
| 251 |
| 249 bool WrenchMenuModel::GetAcceleratorForCommandId( | 252 bool WrenchMenuModel::GetAcceleratorForCommandId( |
| 250 int command_id, | 253 int command_id, |
| 251 menus::Accelerator* accelerator) { | 254 menus::Accelerator* accelerator) { |
| 252 return provider_->GetAcceleratorForCommandId(command_id, accelerator); | 255 return provider_->GetAcceleratorForCommandId(command_id, accelerator); |
| 253 } | 256 } |
| 254 | 257 |
| 255 void WrenchMenuModel::TabSelectedAt(TabContents* old_contents, | 258 void WrenchMenuModel::TabSelectedAt(TabContents* old_contents, |
| 256 TabContents* new_contents, | 259 TabContents* new_contents, |
| 257 int index, | 260 int index, |
| 258 bool user_gesture) { | 261 bool user_gesture) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 AddItemWithStringId(IDC_OPTIONS, IDS_OPTIONS); | 362 AddItemWithStringId(IDC_OPTIONS, IDS_OPTIONS); |
| 360 #else | 363 #else |
| 361 AddItemWithStringId(IDC_OPTIONS, IDS_OPTIONS); | 364 AddItemWithStringId(IDC_OPTIONS, IDS_OPTIONS); |
| 362 #endif | 365 #endif |
| 363 | 366 |
| 364 #if defined(OS_CHROMEOS) | 367 #if defined(OS_CHROMEOS) |
| 365 AddCheckItemWithStringId(IDC_TOGGLE_VERTICAL_TABS, | 368 AddCheckItemWithStringId(IDC_TOGGLE_VERTICAL_TABS, |
| 366 IDS_TAB_CXMENU_USE_VERTICAL_TABS); | 369 IDS_TAB_CXMENU_USE_VERTICAL_TABS); |
| 367 #endif | 370 #endif |
| 368 | 371 |
| 369 // TODO(erg): This entire section needs to be reworked and is out of scope of | 372 // On Mac, there is no About item. |
| 370 // the first cleanup patch I'm doing. Part 1 (crbug.com/47320) is moving most | 373 if (browser_defaults::kShowAboutMenuItem) { |
| 371 // of the logic from each platform specific UI code into the model here. Part | 374 AddItem(IDC_ABOUT, l10n_util::GetStringFUTF16( |
| 372 // 2 (crbug.com/46221) is normalizing the about menu item/hidden update menu | 375 IDS_ABOUT, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
| 373 // item behaviour across the three platforms. | 376 } |
| 374 | 377 |
| 375 // On Mac, there is no About item unless it is replaced with the update | 378 AddItem(IDC_UPGRADE_DIALOG, l10n_util::GetStringFUTF16( |
| 376 // available notification. | 379 IDS_UPDATE_NOW, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
| 377 if (browser_defaults::kShowAboutMenuItem || | 380 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 378 Singleton<UpgradeDetector>::get()->notify_upgrade()) { | 381 SetIcon(GetIndexOfCommandId(IDC_UPGRADE_DIALOG), |
| 379 AddItem(IDC_ABOUT, | 382 *rb.GetBitmapNamed(IDR_UPDATE_AVAILABLE)); |
| 380 l10n_util::GetStringFUTF16( | 383 |
| 381 IDS_ABOUT, | |
| 382 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | |
| 383 // ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 384 // SetIcon(GetIndexOfCommandId(IDC_ABOUT), | |
| 385 // *rb.GetBitmapNamed(IDR_UPDATE_AVAILABLE)); | |
| 386 } | |
| 387 AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE); | 384 AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE); |
| 388 if (browser_defaults::kShowExitMenuItem) { | 385 if (browser_defaults::kShowExitMenuItem) { |
| 389 AddSeparator(); | 386 AddSeparator(); |
| 390 #if defined(OS_CHROMEOS) | 387 #if defined(OS_CHROMEOS) |
| 391 AddItemWithStringId(IDC_EXIT, IDS_SIGN_OUT); | 388 AddItemWithStringId(IDC_EXIT, IDS_SIGN_OUT); |
| 392 #else | 389 #else |
| 393 AddItemWithStringId(IDC_EXIT, IDS_EXIT); | 390 AddItemWithStringId(IDC_EXIT, IDS_EXIT); |
| 394 #endif | 391 #endif |
| 395 } | 392 } |
| 396 } | 393 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 std::max(std::min(std::pow(1.2, zoom_level), 3.0), .5)); | 433 std::max(std::min(std::pow(1.2, zoom_level), 3.0), .5)); |
| 437 *enable_decrement = (value != .5); | 434 *enable_decrement = (value != .5); |
| 438 *enable_increment = (value != 3.0); | 435 *enable_increment = (value != 3.0); |
| 439 return value; | 436 return value; |
| 440 } | 437 } |
| 441 | 438 |
| 442 string16 WrenchMenuModel::GetSyncMenuLabel() const { | 439 string16 WrenchMenuModel::GetSyncMenuLabel() const { |
| 443 return sync_ui_util::GetSyncMenuLabel( | 440 return sync_ui_util::GetSyncMenuLabel( |
| 444 browser_->profile()->GetOriginalProfile()->GetProfileSyncService()); | 441 browser_->profile()->GetOriginalProfile()->GetProfileSyncService()); |
| 445 } | 442 } |
| 446 | |
| 447 string16 WrenchMenuModel::GetAboutEntryMenuLabel() const { | |
| 448 if (Singleton<UpgradeDetector>::get()->notify_upgrade()) { | |
| 449 return l10n_util::GetStringFUTF16( | |
| 450 IDS_UPDATE_NOW, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | |
| 451 } | |
| 452 return l10n_util::GetStringFUTF16( | |
| 453 IDS_ABOUT, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | |
| 454 } | |
| OLD | NEW |