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

Side by Side Diff: chrome/browser/ui/toolbar/wrench_menu_model.cc

Issue 10827146: crbug.com/127841 - Request Tablet Site on CB with touch screen. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 8 years, 4 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 #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 "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 24 matching lines...) Expand all
35 #include "chrome/browser/ui/metro_pin_tab_helper.h" 35 #include "chrome/browser/ui/metro_pin_tab_helper.h"
36 #include "chrome/browser/ui/tab_contents/tab_contents.h" 36 #include "chrome/browser/ui/tab_contents/tab_contents.h"
37 #include "chrome/browser/ui/tabs/tab_strip_model.h" 37 #include "chrome/browser/ui/tabs/tab_strip_model.h"
38 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" 38 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h"
39 #include "chrome/browser/upgrade_detector.h" 39 #include "chrome/browser/upgrade_detector.h"
40 #include "chrome/common/chrome_paths.h" 40 #include "chrome/common/chrome_paths.h"
41 #include "chrome/common/chrome_switches.h" 41 #include "chrome/common/chrome_switches.h"
42 #include "chrome/common/pref_names.h" 42 #include "chrome/common/pref_names.h"
43 #include "chrome/common/profiling.h" 43 #include "chrome/common/profiling.h"
44 #include "content/public/browser/host_zoom_map.h" 44 #include "content/public/browser/host_zoom_map.h"
45 #include "content/public/browser/navigation_entry.h"
45 #include "content/public/browser/notification_service.h" 46 #include "content/public/browser/notification_service.h"
46 #include "content/public/browser/notification_source.h" 47 #include "content/public/browser/notification_source.h"
47 #include "content/public/browser/notification_types.h" 48 #include "content/public/browser/notification_types.h"
48 #include "content/public/browser/user_metrics.h" 49 #include "content/public/browser/user_metrics.h"
49 #include "content/public/browser/web_contents.h" 50 #include "content/public/browser/web_contents.h"
50 #include "grit/chromium_strings.h" 51 #include "grit/chromium_strings.h"
51 #include "grit/generated_resources.h" 52 #include "grit/generated_resources.h"
52 #include "grit/theme_resources.h" 53 #include "grit/theme_resources.h"
53 #include "ui/base/l10n/l10n_util.h" 54 #include "ui/base/l10n/l10n_util.h"
54 #include "ui/base/layout.h" 55 #include "ui/base/layout.h"
55 #include "ui/base/models/button_menu_item_model.h" 56 #include "ui/base/models/button_menu_item_model.h"
56 #include "ui/base/resource/resource_bundle.h" 57 #include "ui/base/resource/resource_bundle.h"
58 #include "ui/base/touch/touch_factory.h"
57 #include "ui/gfx/image/image.h" 59 #include "ui/gfx/image/image.h"
58 #include "ui/gfx/image/image_skia.h" 60 #include "ui/gfx/image/image_skia.h"
59 61
60 #if defined(TOOLKIT_GTK) 62 #if defined(TOOLKIT_GTK)
61 #include <gtk/gtk.h> 63 #include <gtk/gtk.h>
62 #include "chrome/browser/ui/gtk/gtk_util.h" 64 #include "chrome/browser/ui/gtk/gtk_util.h"
63 #endif 65 #endif
64 66
65 #if defined(OS_WIN) 67 #if defined(OS_WIN)
66 #include "base/win/metro.h" 68 #include "base/win/metro.h"
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 content::RecordAction(UserMetricsAction("ShowHelpTabViaWrenchMenu")); 356 content::RecordAction(UserMetricsAction("ShowHelpTabViaWrenchMenu"));
355 357
356 chrome::ExecuteCommand(browser_, command_id); 358 chrome::ExecuteCommand(browser_, command_id);
357 } 359 }
358 360
359 bool WrenchMenuModel::IsCommandIdChecked(int command_id) const { 361 bool WrenchMenuModel::IsCommandIdChecked(int command_id) const {
360 if (command_id == IDC_SHOW_BOOKMARK_BAR) { 362 if (command_id == IDC_SHOW_BOOKMARK_BAR) {
361 return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); 363 return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
362 } else if (command_id == IDC_PROFILING_ENABLED) { 364 } else if (command_id == IDC_PROFILING_ENABLED) {
363 return Profiling::BeingProfiled(); 365 return Profiling::BeingProfiled();
366 } else if (command_id == IDC_TOGGLE_REQUEST_TABLET_SITE) {
367 content::NavigationEntry* entry = GetActiveNavigationEntry();
sky 2012/08/06 21:41:06 Can this functionality (and 382) be moved to brows
sschmitz 2012/08/07 02:19:49 I moved "382", IsCommandEnabled, to browser_comman
368 if (!entry)
369 return false; // The control is disabled in this case.
370 return entry->GetIsOverridingUserAgent();
364 } 371 }
365 372
366 return false; 373 return false;
367 } 374 }
368 375
369 bool WrenchMenuModel::IsCommandIdEnabled(int command_id) const { 376 bool WrenchMenuModel::IsCommandIdEnabled(int command_id) const {
370 GlobalError* error = GlobalErrorServiceFactory::GetForProfile( 377 GlobalError* error = GlobalErrorServiceFactory::GetForProfile(
371 browser_->profile())->GetGlobalErrorByMenuItemCommandID(command_id); 378 browser_->profile())->GetGlobalErrorByMenuItemCommandID(command_id);
372 if (error) 379 if (error)
373 return true; 380 return true;
374 381
382 if (command_id == IDC_TOGGLE_REQUEST_TABLET_SITE) {
383 // Disable the control when there is no active navigation entry.
384 // Otherwise follow "normal" rules.
385 if (!GetActiveNavigationEntry())
386 return false;
387 }
388
375 return chrome::IsCommandEnabled(browser_, command_id); 389 return chrome::IsCommandEnabled(browser_, command_id);
376 } 390 }
377 391
378 bool WrenchMenuModel::IsCommandIdVisible(int command_id) const { 392 bool WrenchMenuModel::IsCommandIdVisible(int command_id) const {
379 #if defined(OS_WIN) 393 #if defined(OS_WIN)
380 if (command_id == IDC_VIEW_INCOMPATIBILITIES) { 394 if (command_id == IDC_VIEW_INCOMPATIBILITIES) {
381 EnumerateModulesModel* loaded_modules = 395 EnumerateModulesModel* loaded_modules =
382 EnumerateModulesModel::GetInstance(); 396 EnumerateModulesModel::GetInstance();
383 if (loaded_modules->confirmed_bad_modules_detected() <= 0) 397 if (loaded_modules->confirmed_bad_modules_detected() <= 0)
384 return false; 398 return false;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 browser_->profile()->GetOriginalProfile()->IsSyncAccessible()) { 512 browser_->profile()->GetOriginalProfile()->IsSyncAccessible()) {
499 const string16 short_product_name = 513 const string16 short_product_name =
500 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME); 514 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME);
501 AddItem(IDC_SHOW_SYNC_SETUP, l10n_util::GetStringFUTF16( 515 AddItem(IDC_SHOW_SYNC_SETUP, l10n_util::GetStringFUTF16(
502 IDS_SYNC_MENU_PRE_SYNCED_LABEL, short_product_name)); 516 IDS_SYNC_MENU_PRE_SYNCED_LABEL, short_product_name));
503 AddSeparator(); 517 AddSeparator();
504 } 518 }
505 519
506 AddItemWithStringId(IDC_OPTIONS, IDS_SETTINGS); 520 AddItemWithStringId(IDC_OPTIONS, IDS_SETTINGS);
507 521
522 #if defined(OS_CHROMEOS)
523 // Note: on Chromebooks with default to "Desktop Site" even for
524 // Chromebooks with a touch screen.
525 // The following toggle lets the user switch to
526 // "Tablet Site". This functionality is under two flags:
527 // - to turn in on only for touch devices (intended use)
528 // - to turn it on regardless of touch device (for testing)
529 bool enable_flag = CommandLine::ForCurrentProcess()->HasSwitch(
530 switches::kEnableRequestTabletSite);
531 bool force_flag = CommandLine::ForCurrentProcess()->HasSwitch(
532 switches::kEnableRequestTabletSiteEvenIfNonTouchDevice);
533 if (force_flag ||
534 (enable_flag && ui::TouchFactory::GetInstance()->IsTouchDevicePresent()))
535 AddCheckItemWithStringId(IDC_TOGGLE_REQUEST_TABLET_SITE,
536 IDS_TOGGLE_REQUEST_TABLET_SITE);
537 #endif
538
508 if (!is_touch_menu) { 539 if (!is_touch_menu) {
509 AddItem(IDC_ABOUT, l10n_util::GetStringUTF16(IDS_ABOUT)); 540 AddItem(IDC_ABOUT, l10n_util::GetStringUTF16(IDS_ABOUT));
510 string16 num_background_pages = base::FormatNumber( 541 string16 num_background_pages = base::FormatNumber(
511 TaskManager::GetBackgroundPageCount()); 542 TaskManager::GetBackgroundPageCount());
512 AddItem(IDC_VIEW_BACKGROUND_PAGES, l10n_util::GetStringFUTF16( 543 AddItem(IDC_VIEW_BACKGROUND_PAGES, l10n_util::GetStringFUTF16(
513 IDS_VIEW_BACKGROUND_PAGES, num_background_pages)); 544 IDS_VIEW_BACKGROUND_PAGES, num_background_pages));
514 } 545 }
515 546
516 if (browser_defaults::kShowUpgradeMenuItem) 547 if (browser_defaults::kShowUpgradeMenuItem)
517 AddItem(IDC_UPGRADE_DIALOG, l10n_util::GetStringUTF16(IDS_UPDATE_NOW)); 548 AddItem(IDC_UPGRADE_DIALOG, l10n_util::GetStringUTF16(IDS_UPDATE_NOW));
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 bool enable_decrement = false; 664 bool enable_decrement = false;
634 int zoom_percent = 100; 665 int zoom_percent = 100;
635 if (chrome::GetActiveWebContents(browser_)) { 666 if (chrome::GetActiveWebContents(browser_)) {
636 zoom_percent = chrome::GetActiveWebContents(browser_)->GetZoomPercent( 667 zoom_percent = chrome::GetActiveWebContents(browser_)->GetZoomPercent(
637 &enable_increment, &enable_decrement); 668 &enable_increment, &enable_decrement);
638 } 669 }
639 zoom_label_ = l10n_util::GetStringFUTF16( 670 zoom_label_ = l10n_util::GetStringFUTF16(
640 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); 671 IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent));
641 } 672 }
642 673
674 content::NavigationEntry* WrenchMenuModel::GetActiveNavigationEntry() const {
675 if (!browser_)
676 return NULL;
677 content::WebContents* current_tab = chrome::GetActiveWebContents(browser_);
678 if (!current_tab)
679 return NULL;
680 return current_tab->GetController().GetActiveEntry();
681 }
682
643 string16 WrenchMenuModel::GetSyncMenuLabel() const { 683 string16 WrenchMenuModel::GetSyncMenuLabel() const {
644 Profile* profile = browser_->profile()->GetOriginalProfile(); 684 Profile* profile = browser_->profile()->GetOriginalProfile();
645 return sync_ui_util::GetSyncMenuLabel( 685 return sync_ui_util::GetSyncMenuLabel(
646 ProfileSyncServiceFactory::GetForProfile(profile), 686 ProfileSyncServiceFactory::GetForProfile(profile),
647 *SigninManagerFactory::GetForProfile(profile)); 687 *SigninManagerFactory::GetForProfile(profile));
648 } 688 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698