summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorananta <ananta@chromium.org>2016-01-07 17:45:41 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-08 01:46:42 +0000
commit44366f4e8c4970cb49d47c3b38063a5ae01b989a (patch)
treee18499e9cf062ccd0dda8ea30dcf3866ef168245 /base
parentbb01cc280cac8fd2f5c0e9959a5f4b374820eab5 (diff)
downloadchromium_src-44366f4e8c4970cb49d47c3b38063a5ae01b989a.zip
chromium_src-44366f4e8c4970cb49d47c3b38063a5ae01b989a.tar.gz
chromium_src-44366f4e8c4970cb49d47c3b38063a5ae01b989a.tar.bz2
Refactor the IsKeyboardPresentOnSlate function.
Currently this function shares the same logic as the IsTabletDevice function. One of the big differences was the IsTabletDevice function allows calls from Windows XP. Changed that to Windows 8+ and changed the IsKeyboardPresentOnSlate function to call IsTabletDevice. The IsTabletDevice function now takes in a reason argument which is updated with the reason info as to why the device was deemed to be a tablet or not. We now use the PowerDeterminePlatformRoleEx API to determine the platform role. As per msdn this function returns better results on Windows 8+. Next step would be to see if this function reliably works for tablets and slate mode. If yes then we can possibly flip the switch kDisableUsbKeyboardDetect to kEnableUsbKeyboardDetect which would ensure that the OSK pops up by default. BUG=497381 TBR=sky Review URL: https://codereview.chromium.org/1535643006 Cr-Commit-Position: refs/heads/master@{#368241}
Diffstat (limited to 'base')
-rw-r--r--base/win/win_util.cc92
-rw-r--r--base/win/win_util.h11
2 files changed, 63 insertions, 40 deletions
diff --git a/base/win/win_util.cc b/base/win/win_util.cc
index 9e90d10..a37e0f2 100644
--- a/base/win/win_util.cc
+++ b/base/win/win_util.cc
@@ -101,6 +101,12 @@ 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() {
+ return PowerDeterminePlatformRoleEx(POWER_PLATFORM_ROLE_V2);
+}
+
} // namespace
// Returns true if a physical keyboard is detected on Windows 8 and up.
@@ -111,7 +117,7 @@ const wchar_t kWindows8OSKRegPath[] =
bool IsKeyboardPresentOnSlate(std::string* reason) {
bool result = false;
- if (GetVersion() < VERSION_WIN7) {
+ if (GetVersion() < VERSION_WIN8) {
*reason = "Detection not supported";
return false;
}
@@ -135,10 +141,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;
@@ -184,23 +193,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 } };
@@ -392,30 +384,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() {
diff --git a/base/win/win_util.h b/base/win/win_util.h
index 78a0608..6162b51 100644
--- a/base/win/win_util.h
+++ b/base/win/win_util.h
@@ -123,9 +123,14 @@ BASE_EXPORT bool ShouldCrashOnProcessDetach();
BASE_EXPORT void SetAbortBehaviorForCrashReporting();
// A tablet is a device that is touch enabled and also is being used
-// "like a tablet". This is used primarily for metrics in order to gain some
-// insight into how users use Chrome.
-BASE_EXPORT bool IsTabletDevice();
+// "like a tablet". This is used by the following:-
+// 1. Metrics:- To gain insight into how users use Chrome.
+// 2. Physical keyboard presence :- If a device is in tablet mode, it means
+// that there is no physical keyboard attached.
+// This function optionally sets the |reason| parameter to determine as to why
+// or why not a device was deemed to be a tablet.
+// Returns true if the device is in tablet mode.
+BASE_EXPORT bool IsTabletDevice(std::string* reason);
// A slate is a touch device that may have a keyboard attached. This function
// returns true if a keyboard is attached and optionally will set the reason