diff options
author | rbyers@chromium.org <rbyers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-14 20:28:06 +0000 |
---|---|---|
committer | rbyers@chromium.org <rbyers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-14 20:28:06 +0000 |
commit | 347a0c74816b8cea5e595e39dca62dd037b2d686 (patch) | |
tree | c5289c11c8290696acb094bb98714c7a9b8a4a3d /ui/base/layout.cc | |
parent | aa26d4b3674c55cb189dc8081acdd1fbd272f4fe (diff) | |
download | chromium_src-347a0c74816b8cea5e595e39dca62dd037b2d686.zip chromium_src-347a0c74816b8cea5e595e39dca62dd037b2d686.tar.gz chromium_src-347a0c74816b8cea5e595e39dca62dd037b2d686.tar.bz2 |
Make touch-optimized-ui a tri-state flag
By default ('auto') touch-optimized-UI will be enabled if any touch screen is present. The user can also manually disable or enable it ('disabled', 'enabled') for testing purposes.
Note that for now --enable-touch-events is still required to enable the use of touch screens (and hence impact 'auto' here) since it's still experimental.
Also cleans up all the different ways we were trying to read this mode, unifying on ui::GetDisplayLayout().
BUG=124199
TBR=estade@chromium.org (only change in resources is trivial comment change)
TEST=
Review URL: https://chromiumcodereview.appspot.com/10391035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136968 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base/layout.cc')
-rw-r--r-- | ui/base/layout.cc | 69 |
1 files changed, 51 insertions, 18 deletions
diff --git a/ui/base/layout.cc b/ui/base/layout.cc index 8da1fcb..e0e6471 100644 --- a/ui/base/layout.cc +++ b/ui/base/layout.cc @@ -5,41 +5,74 @@ #include "ui/base/layout.h" #include "base/basictypes.h" -#include "build/build_config.h" - -#if defined(USE_ASH) #include "base/command_line.h" +#include "base/logging.h" +#include "build/build_config.h" #include "ui/base/ui_base_switches.h" -#endif + +#if defined(USE_AURA) && defined(USE_X11) +#include "ui/base/touch/touch_factory.h" +#endif // defined(USE_AURA) && defined(USE_X11) #if defined(OS_WIN) #include "base/win/metro.h" #include <Windows.h> #endif // defined(OS_WIN) +namespace { +// Helper function that determines whether we want to optimize the UI for touch. +bool UseTouchOptimizedUI() { + // If --touch-optimized-ui is specified and not set to "auto", then override + // the hardware-determined setting (eg. for testing purposes). + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kTouchOptimizedUI)) { + const std::string switch_value = CommandLine::ForCurrentProcess()-> + GetSwitchValueASCII(switches::kTouchOptimizedUI); + + // Note that simply specifying the switch is the same as enabled. + if (switch_value.empty() || + switch_value == switches::kTouchOptimizedUIEnabled) { + return true; + } else if (switch_value == switches::kTouchOptimizedUIDisabled) { + return false; + } else if (switch_value != switches::kTouchOptimizedUIAuto) { + LOG(ERROR) << "Invalid --touch-optimized-ui option: " << switch_value; + } + } + +#if defined(ENABLE_METRO) + return base::win::GetMetroModule() != NULL; +#elif defined(OS_WIN) + // No touch support on Win outside Metro yet (even with Aura). + return false; +#elif defined(USE_AURA) && defined(USE_X11) + // Determine whether touch-screen hardware is currently available. + // For now we assume this won't change over the life of the process, but + // we'll probably want to support that. crbug.com/124399 + return ui::TouchFactory::GetInstance()->IsTouchDevicePresent(); +#else + return false; +#endif +} +} + namespace ui { // Note that this function should be extended to select // LAYOUT_TOUCH when appropriate on more platforms than just -// Windows. +// Windows and Ash. DisplayLayout GetDisplayLayout() { #if defined(USE_ASH) - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTouchOptimizedUI)) + if (UseTouchOptimizedUI()) return LAYOUT_TOUCH; return LAYOUT_ASH; -#elif !defined(OS_WIN) - return LAYOUT_DESKTOP; -#else // On Windows. - bool use_touch = false; -#if defined(ENABLE_METRO) - use_touch = base::win::GetMetroModule() != NULL; -#endif // defined(ENABLE_METRO) - if (use_touch) { +#elif defined(OS_WIN) + if (UseTouchOptimizedUI()) return LAYOUT_TOUCH; - } else { - return LAYOUT_DESKTOP; - } -#endif // On Windows. + return LAYOUT_DESKTOP; +#else + return LAYOUT_DESKTOP; +#endif } } // namespace ui |