Chromium Code Reviews| Index: base/win/win_util.cc |
| diff --git a/base/win/win_util.cc b/base/win/win_util.cc |
| index 93ec543338d1b94818fcc3ae93965af83cc14556..9b29622f03839b449198af2d1d5205f5689f939c 100644 |
| --- a/base/win/win_util.cc |
| +++ b/base/win/win_util.cc |
| @@ -99,6 +99,29 @@ const wchar_t kWindows8OSKRegPath[] = |
| L"Software\\Classes\\CLSID\\{054AAE20-4BEA-4347-8A35-64A533254A9D}" |
| L"\\LocalServer32"; |
| +// Returns the current platform role. We use the PowerDeterminePlatformRoleEx |
| +// API for that. |
| +POWER_PLATFORM_ROLE GetPlatformRole() { |
| + HMODULE power_prof_module = ::GetModuleHandle(L"powrprof.dll"); |
|
jschuh
2016/01/07 01:18:40
Skip the dynamic loads and just do a version check
ananta
2016/01/07 22:41:05
Done.
|
| + if (!power_prof_module) |
| + power_prof_module = ::LoadLibrary(L"powrprof.dll"); |
| + |
| + DCHECK(power_prof_module); |
| + if (!power_prof_module) |
| + return PlatformRoleDesktop; |
| + |
| + typedef POWER_PLATFORM_ROLE (WINAPI* DeterminePlatformRoleEx)( |
| + unsigned long version); |
| + DeterminePlatformRoleEx determine_platform_role_ex = |
| + reinterpret_cast<DeterminePlatformRoleEx>(::GetProcAddress( |
| + power_prof_module, "PowerDeterminePlatformRoleEx")); |
| + |
| + DCHECK(determine_platform_role_ex); |
| + |
| + return determine_platform_role_ex ? |
| + determine_platform_role_ex(POWER_PLATFORM_ROLE_V2) : PlatformRoleDesktop; |
| +} |
| + |
| } // namespace |
| // Returns true if a physical keyboard is detected on Windows 8 and up. |
| @@ -109,10 +132,7 @@ const wchar_t kWindows8OSKRegPath[] = |
| bool IsKeyboardPresentOnSlate(std::string* reason) { |
| bool result = false; |
| - if (GetVersion() < VERSION_WIN7) { |
| - *reason = "Detection not supported"; |
| - return false; |
| - } |
| + DCHECK(GetVersion() >= VERSION_WIN8); |
|
jschuh
2016/01/07 01:18:40
Keep the old code here, because it's called from C
ananta
2016/01/07 22:41:05
Done.
|
| // This function is only supported for Windows 8 and up. |
| if (CommandLine::ForCurrentProcess()->HasSwitch( |
| @@ -133,10 +153,13 @@ bool IsKeyboardPresentOnSlate(std::string* reason) { |
| } |
| } |
| - // If the device is docked, the user is treating the device as a PC. |
| - if (GetSystemMetrics(SM_SYSTEMDOCKED) != 0) { |
| + if (IsTabletDevice(reason)) { |
| + if (reason) |
| + *reason += "Tablet device.\n"; |
| + return true; |
| + } else { |
| if (reason) { |
| - *reason += "SM_SYSTEMDOCKED\n"; |
| + *reason += "Not a tablet device"; |
| result = true; |
| } else { |
| return true; |
| @@ -182,23 +205,6 @@ bool IsKeyboardPresentOnSlate(std::string* reason) { |
| } |
| } |
| - // Check if the device is being used as a laptop or a tablet. This can be |
| - // checked by first checking the role of the device and then the |
| - // corresponding system metric (SM_CONVERTIBLESLATEMODE). If it is being used |
| - // as a tablet then we want the OSK to show up. |
| - POWER_PLATFORM_ROLE role = PowerDeterminePlatformRole(); |
| - |
| - if (((role == PlatformRoleMobile) || (role == PlatformRoleSlate)) && |
| - (GetSystemMetrics(SM_CONVERTIBLESLATEMODE) == 0)) { |
| - if (reason) { |
| - *reason += (role == PlatformRoleMobile) ? "PlatformRoleMobile\n" : |
| - "PlatformRoleSlate\n"; |
| - // Don't change result here if it's already true. |
| - } else { |
| - return false; |
| - } |
| - } |
| - |
| const GUID KEYBOARD_CLASS_GUID = |
| { 0x4D36E96B, 0xE325, 0x11CE, |
| { 0xBF, 0xC1, 0x08, 0x00, 0x2B, 0xE1, 0x03, 0x18 } }; |
| @@ -390,30 +396,56 @@ void SetAbortBehaviorForCrashReporting() { |
| signal(SIGABRT, ForceCrashOnSigAbort); |
| } |
| -bool IsTabletDevice() { |
| - if (GetSystemMetrics(SM_MAXIMUMTOUCHES) == 0) |
| +bool IsTabletDevice(std::string* reason) { |
| + if (GetVersion() < VERSION_WIN8) { |
| + if (reason) |
| + *reason = "Tablet device detection not supported below Windows 8\n"; |
| return false; |
| + } |
| - Version version = GetVersion(); |
| - if (version == VERSION_XP) |
| - return (GetSystemMetrics(SM_TABLETPC) != 0); |
| + if (GetSystemMetrics(SM_MAXIMUMTOUCHES) == 0) { |
| + if (reason) { |
| + *reason += "Device does not support touch.\n"; |
| + } else { |
| + return false; |
| + } |
| + } |
| // If the device is docked, the user is treating the device as a PC. |
| - if (GetSystemMetrics(SM_SYSTEMDOCKED) != 0) |
| - return false; |
| + if (GetSystemMetrics(SM_SYSTEMDOCKED) != 0) { |
| + if (reason) { |
| + *reason += "SM_SYSTEMDOCKED\n"; |
| + } else { |
| + return false; |
| + } |
| + } |
| - // PlatformRoleSlate was only added in Windows 8, but prior to Win8 it is |
| - // still possible to check for a mobile power profile. |
| - POWER_PLATFORM_ROLE role = PowerDeterminePlatformRole(); |
| + // PlatformRoleSlate was added in Windows 8+. |
| + POWER_PLATFORM_ROLE role = GetPlatformRole(); |
| bool mobile_power_profile = (role == PlatformRoleMobile); |
| - bool slate_power_profile = false; |
| - if (version >= VERSION_WIN8) |
| - slate_power_profile = (role == PlatformRoleSlate); |
| + bool slate_power_profile = (role == PlatformRoleSlate); |
| - if (mobile_power_profile || slate_power_profile) |
| - return (GetSystemMetrics(SM_CONVERTIBLESLATEMODE) == 0); |
| + bool is_tablet = false; |
| - return false; |
| + if (mobile_power_profile || slate_power_profile) { |
| + is_tablet = !GetSystemMetrics(SM_CONVERTIBLESLATEMODE); |
| + if (!is_tablet) { |
| + if (reason) { |
| + *reason += "Not in slate mode.\n"; |
| + } else { |
| + return false; |
| + } |
| + } else { |
| + if (reason) { |
| + *reason += (role == PlatformRoleMobile) ? "PlatformRoleMobile\n" : |
| + "PlatformRoleSlate\n"; |
| + } |
| + } |
| + } else { |
| + if (reason) |
| + *reason += "Device role is not mobile or slate.\n"; |
| + } |
| + return is_tablet; |
| } |
| bool DisplayVirtualKeyboard() { |