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 IsKeyboardPresent() { | |
cpu_(ooo_6.6-7.5)
2014/10/16 18:11:33
please rename this to IsKeyboardPresentOnSlate()
ananta
2014/10/16 19:35:58
Done.
| |
64 // This function is only supported for Windows 8 and up. | |
65 if (base::win::GetVersion() < base::win::VERSION_WIN8) { | |
66 DCHECK(false); | |
67 return true; | |
68 } | |
69 | |
70 // This function should be only invoked for machines with touch screens. | |
71 if ((GetSystemMetrics(SM_DIGITIZER) & NID_INTEGRATED_TOUCH) | |
72 != NID_INTEGRATED_TOUCH) { | |
73 DCHECK(false); | |
74 return true; | |
75 } | |
76 | |
77 const GUID KEYBOARD_CLASS_GUID = | |
78 { 0x4D36E96B, 0xE325, 0x11CE, | |
79 { 0xBF, 0xC1, 0x08, 0x00, 0x2B, 0xE1, 0x03, 0x18 } }; | |
80 | |
81 // Query for all the keyboard devices. | |
82 HDEVINFO device_info = | |
83 SetupDiGetClassDevs(&KEYBOARD_CLASS_GUID, NULL, NULL, DIGCF_PRESENT); | |
84 if (device_info == INVALID_HANDLE_VALUE) | |
85 return false; | |
86 | |
87 // Enumerate all keyboards and look for ACPI\PNP and HID\VID devices. If | |
88 // the count is more than 1 we assume that a keyboard is present. This is | |
89 // under the assumption that there will always be one keyboard device. | |
90 bool has_keyboard = false; | |
scottmg
2014/10/16 18:30:46
this is unused
ananta
2014/10/16 19:35:58
Done.
| |
91 int32 keyboard_count = 0; | |
scottmg
2014/10/16 18:30:46
just int
ananta
2014/10/16 19:35:58
Done.
| |
92 for (int i = 0;; ++i) { | |
93 SP_DEVINFO_DATA device_info_data = { 0 }; | |
94 device_info_data.cbSize = sizeof (device_info_data); | |
95 if (!SetupDiEnumDeviceInfo(device_info, i, &device_info_data)) | |
96 break; | |
scottmg
2014/10/16 18:30:46
maybe continue?
ananta
2014/10/16 19:35:58
The loop above continues indefinitely. That would
| |
97 // Get the device ID | |
cpu_(ooo_6.6-7.5)
2014/10/16 18:11:33
period at the end of comments.
ananta
2014/10/16 19:35:58
Done.
| |
98 WCHAR device_id[MAX_DEVICE_ID_LEN]; | |
cpu_(ooo_6.6-7.5)
2014/10/16 18:11:33
WCHAR --> wchar_t
ananta
2014/10/16 19:35:58
Done.
| |
99 CONFIGRET status = CM_Get_Device_ID(device_info_data.DevInst, | |
100 device_id, | |
101 MAX_DEVICE_ID_LEN, | |
102 0); | |
103 if (status == CR_SUCCESS) { | |
104 // To reduce the scope of the hack we only look for PNP and HID | |
105 // keyboards. | |
106 if (!base::strncmp16(L"ACPI\\PNP", device_id, wcslen(L"ACPI\\PNP")) || | |
107 !base::strncmp16(L"HID\\VID", device_id, wcslen(L"HID\\VID"))) { | |
cpu_(ooo_6.6-7.5)
2014/10/16 18:11:33
use StartsWith( and set it to be case insensitive?
ananta
2014/10/16 19:35:58
Done.
| |
108 keyboard_count++; | |
109 } | |
110 } else { | |
111 break; | |
scottmg
2014/10/16 18:30:46
maybe no else to check any others?
ananta
2014/10/16 19:35:58
Good point. Done.
| |
112 } | |
113 } | |
cpu_(ooo_6.6-7.5)
2014/10/16 18:11:33
comment explaining why > 1.
ananta
2014/10/16 19:35:58
Done.
| |
114 return keyboard_count > 1; | |
115 } | |
116 | |
56 } // namespace | 117 } // namespace |
57 | 118 |
58 namespace base { | 119 namespace base { |
59 namespace win { | 120 namespace win { |
60 | 121 |
61 static bool g_crash_on_process_detach = false; | 122 static bool g_crash_on_process_detach = false; |
62 | 123 |
63 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \ | 124 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \ |
64 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont) | 125 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont) |
65 | 126 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 if (mobile_power_profile || slate_power_profile) | 306 if (mobile_power_profile || slate_power_profile) |
246 return (GetSystemMetrics(SM_CONVERTIBLESLATEMODE) == 0); | 307 return (GetSystemMetrics(SM_CONVERTIBLESLATEMODE) == 0); |
247 | 308 |
248 return false; | 309 return false; |
249 } | 310 } |
250 | 311 |
251 bool DisplayVirtualKeyboard() { | 312 bool DisplayVirtualKeyboard() { |
252 if (base::win::GetVersion() < base::win::VERSION_WIN8) | 313 if (base::win::GetVersion() < base::win::VERSION_WIN8) |
253 return false; | 314 return false; |
254 | 315 |
316 if (IsKeyboardPresent()) | |
317 return false; | |
318 | |
255 static base::LazyInstance<string16>::Leaky osk_path = | 319 static base::LazyInstance<string16>::Leaky osk_path = |
256 LAZY_INSTANCE_INITIALIZER; | 320 LAZY_INSTANCE_INITIALIZER; |
257 | 321 |
258 if (osk_path.Get().empty()) { | 322 if (osk_path.Get().empty()) { |
259 // We need to launch TabTip.exe from the location specified under the | 323 // We need to launch TabTip.exe from the location specified under the |
260 // LocalServer32 key for the {{054AAE20-4BEA-4347-8A35-64A533254A9D}} | 324 // LocalServer32 key for the {{054AAE20-4BEA-4347-8A35-64A533254A9D}} |
261 // CLSID. | 325 // CLSID. |
262 // TabTip.exe is typically found at | 326 // TabTip.exe is typically found at |
263 // c:\program files\common files\microsoft shared\ink on English Windows. | 327 // c:\program files\common files\microsoft shared\ink on English Windows. |
264 // We don't want to launch TabTip.exe from | 328 // 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) | 474 #if defined(_MSC_FULL_VER) |
411 #pragma message(__PPOUT__(_MSC_FULL_VER)) | 475 #pragma message(__PPOUT__(_MSC_FULL_VER)) |
412 #endif | 476 #endif |
413 | 477 |
414 #pragma message("Visual Studio 2012 x86 must be updated to at least Update 1") | 478 #pragma message("Visual Studio 2012 x86 must be updated to at least Update 1") |
415 #error Must install Update 1 to Visual Studio 2012. | 479 #error Must install Update 1 to Visual Studio 2012. |
416 #endif | 480 #endif |
417 | 481 |
418 #endif // _MSC_VER | 482 #endif // _MSC_VER |
419 | 483 |
OLD | NEW |