OLD | NEW |
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 "base/win/win_util.h" | 5 #include "base/win/win_util.h" |
6 | 6 |
7 #include <aclapi.h> | 7 #include <aclapi.h> |
| 8 #include <cfgmgr32.h> |
8 #include <lm.h> | 9 #include <lm.h> |
9 #include <powrprof.h> | 10 #include <powrprof.h> |
10 #include <shellapi.h> | 11 #include <shellapi.h> |
11 #include <shlobj.h> | 12 #include <shlobj.h> |
12 #include <shobjidl.h> // Must be before propkey. | 13 #include <shobjidl.h> // Must be before propkey. |
13 #include <initguid.h> | 14 #include <initguid.h> |
14 #include <propkey.h> | 15 #include <propkey.h> |
15 #include <propvarutil.h> | 16 #include <propvarutil.h> |
16 #include <sddl.h> | 17 #include <sddl.h> |
| 18 #include <setupapi.h> |
17 #include <signal.h> | 19 #include <signal.h> |
18 #include <stdlib.h> | 20 #include <stdlib.h> |
19 | 21 |
20 #include "base/lazy_instance.h" | 22 #include "base/lazy_instance.h" |
21 #include "base/logging.h" | 23 #include "base/logging.h" |
22 #include "base/memory/scoped_ptr.h" | 24 #include "base/memory/scoped_ptr.h" |
23 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
24 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
25 #include "base/threading/thread_restrictions.h" | 27 #include "base/threading/thread_restrictions.h" |
26 #include "base/win/metro.h" | 28 #include "base/win/metro.h" |
(...skipping 19 matching lines...) Expand all Loading... |
46 } | 48 } |
47 | 49 |
48 void __cdecl ForceCrashOnSigAbort(int) { | 50 void __cdecl ForceCrashOnSigAbort(int) { |
49 *((int*)0) = 0x1337; | 51 *((int*)0) = 0x1337; |
50 } | 52 } |
51 | 53 |
52 const wchar_t kWindows8OSKRegPath[] = | 54 const wchar_t kWindows8OSKRegPath[] = |
53 L"Software\\Classes\\CLSID\\{054AAE20-4BEA-4347-8A35-64A533254A9D}" | 55 L"Software\\Classes\\CLSID\\{054AAE20-4BEA-4347-8A35-64A533254A9D}" |
54 L"\\LocalServer32"; | 56 L"\\LocalServer32"; |
55 | 57 |
| 58 // Returns true if a physical keyboard is detected on Windows 8 and up. |
| 59 // Uses the Setup APIs to enumerate the attached keyboards and returns true |
| 60 // if the keyboard count is more than 1. While this will work in most cases |
| 61 // it won't work if there are devices which expose keyboard interfaces which |
| 62 // are attached to the machine. |
| 63 bool IsKeyboardPresentOnSlate() { |
| 64 // This function is only supported for Windows 8 and up. |
| 65 DCHECK(base::win::GetVersion() >= base::win::VERSION_WIN8); |
| 66 |
| 67 // This function should be only invoked for machines with touch screens. |
| 68 if ((GetSystemMetrics(SM_DIGITIZER) & NID_INTEGRATED_TOUCH) |
| 69 != NID_INTEGRATED_TOUCH) { |
| 70 return true; |
| 71 } |
| 72 |
| 73 const GUID KEYBOARD_CLASS_GUID = |
| 74 { 0x4D36E96B, 0xE325, 0x11CE, |
| 75 { 0xBF, 0xC1, 0x08, 0x00, 0x2B, 0xE1, 0x03, 0x18 } }; |
| 76 |
| 77 // Query for all the keyboard devices. |
| 78 HDEVINFO device_info = |
| 79 SetupDiGetClassDevs(&KEYBOARD_CLASS_GUID, NULL, NULL, DIGCF_PRESENT); |
| 80 if (device_info == INVALID_HANDLE_VALUE) |
| 81 return false; |
| 82 |
| 83 // Enumerate all keyboards and look for ACPI\PNP and HID\VID devices. If |
| 84 // the count is more than 1 we assume that a keyboard is present. This is |
| 85 // under the assumption that there will always be one keyboard device. |
| 86 int keyboard_count = 0; |
| 87 for (DWORD i = 0;; ++i) { |
| 88 SP_DEVINFO_DATA device_info_data = { 0 }; |
| 89 device_info_data.cbSize = sizeof(device_info_data); |
| 90 if (!SetupDiEnumDeviceInfo(device_info, i, &device_info_data)) |
| 91 break; |
| 92 // Get the device ID. |
| 93 wchar_t device_id[MAX_DEVICE_ID_LEN]; |
| 94 CONFIGRET status = CM_Get_Device_ID(device_info_data.DevInst, |
| 95 device_id, |
| 96 MAX_DEVICE_ID_LEN, |
| 97 0); |
| 98 if (status == CR_SUCCESS) { |
| 99 // To reduce the scope of the hack we only look for PNP and HID |
| 100 // keyboards. |
| 101 if (StartsWith(L"ACPI\\PNP", device_id, false) || |
| 102 StartsWith(L"HID\\VID", device_id, false)) { |
| 103 keyboard_count++; |
| 104 } |
| 105 } |
| 106 } |
| 107 // On a Windows machine, the API's always report 1 keyboard at least |
| 108 // regardless of whether the machine has a keyboard attached or not. |
| 109 // The heuristic we are using is to check the count and return true |
| 110 // if the API's report more than one keyboard. Please note that this |
| 111 // will break for non keyboard devices which expose a keyboard PDO. |
| 112 return keyboard_count > 1; |
| 113 } |
| 114 |
56 } // namespace | 115 } // namespace |
57 | 116 |
58 namespace base { | 117 namespace base { |
59 namespace win { | 118 namespace win { |
60 | 119 |
61 static bool g_crash_on_process_detach = false; | 120 static bool g_crash_on_process_detach = false; |
62 | 121 |
63 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \ | 122 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \ |
64 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont) | 123 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont) |
65 | 124 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 if (mobile_power_profile || slate_power_profile) | 304 if (mobile_power_profile || slate_power_profile) |
246 return (GetSystemMetrics(SM_CONVERTIBLESLATEMODE) == 0); | 305 return (GetSystemMetrics(SM_CONVERTIBLESLATEMODE) == 0); |
247 | 306 |
248 return false; | 307 return false; |
249 } | 308 } |
250 | 309 |
251 bool DisplayVirtualKeyboard() { | 310 bool DisplayVirtualKeyboard() { |
252 if (base::win::GetVersion() < base::win::VERSION_WIN8) | 311 if (base::win::GetVersion() < base::win::VERSION_WIN8) |
253 return false; | 312 return false; |
254 | 313 |
| 314 if (IsKeyboardPresentOnSlate()) |
| 315 return false; |
| 316 |
255 static base::LazyInstance<string16>::Leaky osk_path = | 317 static base::LazyInstance<string16>::Leaky osk_path = |
256 LAZY_INSTANCE_INITIALIZER; | 318 LAZY_INSTANCE_INITIALIZER; |
257 | 319 |
258 if (osk_path.Get().empty()) { | 320 if (osk_path.Get().empty()) { |
259 // We need to launch TabTip.exe from the location specified under the | 321 // We need to launch TabTip.exe from the location specified under the |
260 // LocalServer32 key for the {{054AAE20-4BEA-4347-8A35-64A533254A9D}} | 322 // LocalServer32 key for the {{054AAE20-4BEA-4347-8A35-64A533254A9D}} |
261 // CLSID. | 323 // CLSID. |
262 // TabTip.exe is typically found at | 324 // TabTip.exe is typically found at |
263 // c:\program files\common files\microsoft shared\ink on English Windows. | 325 // c:\program files\common files\microsoft shared\ink on English Windows. |
264 // We don't want to launch TabTip.exe from | 326 // We don't want to launch TabTip.exe from |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 #if defined(_MSC_FULL_VER) | 472 #if defined(_MSC_FULL_VER) |
411 #pragma message(__PPOUT__(_MSC_FULL_VER)) | 473 #pragma message(__PPOUT__(_MSC_FULL_VER)) |
412 #endif | 474 #endif |
413 | 475 |
414 #pragma message("Visual Studio 2012 x86 must be updated to at least Update 1") | 476 #pragma message("Visual Studio 2012 x86 must be updated to at least Update 1") |
415 #error Must install Update 1 to Visual Studio 2012. | 477 #error Must install Update 1 to Visual Studio 2012. |
416 #endif | 478 #endif |
417 | 479 |
418 #endif // _MSC_VER | 480 #endif // _MSC_VER |
419 | 481 |
OLD | NEW |