| 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 <cfgmgr32.h> |
| 9 #include <lm.h> | 9 #include <lm.h> |
| 10 #include <powrprof.h> | 10 #include <powrprof.h> |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 const wchar_t kWindows8OSKRegPath[] = | 107 const wchar_t kWindows8OSKRegPath[] = |
| 108 L"Software\\Classes\\CLSID\\{054AAE20-4BEA-4347-8A35-64A533254A9D}" | 108 L"Software\\Classes\\CLSID\\{054AAE20-4BEA-4347-8A35-64A533254A9D}" |
| 109 L"\\LocalServer32"; | 109 L"\\LocalServer32"; |
| 110 | 110 |
| 111 // Returns the current platform role. We use the PowerDeterminePlatformRoleEx | 111 // Returns the current platform role. We use the PowerDeterminePlatformRoleEx |
| 112 // API for that. | 112 // API for that. |
| 113 POWER_PLATFORM_ROLE GetPlatformRole() { | 113 POWER_PLATFORM_ROLE GetPlatformRole() { |
| 114 return PowerDeterminePlatformRoleEx(POWER_PLATFORM_ROLE_V2); | 114 return PowerDeterminePlatformRoleEx(POWER_PLATFORM_ROLE_V2); |
| 115 } | 115 } |
| 116 | 116 |
| 117 } // namespace |
| 118 |
| 117 // Uses the Windows 10 WRL API's to query the current system state. The API's | 119 // Uses the Windows 10 WRL API's to query the current system state. The API's |
| 118 // we are using in the function below are supported in Win32 apps as per msdn. | 120 // we are using in the function below are supported in Win32 apps as per msdn. |
| 119 // It looks like the API implementation is buggy at least on Surface 4 causing | 121 // It looks like the API implementation is buggy at least on Surface 4 causing |
| 120 // it to always return UserInteractionMode_Touch which as per documentation | 122 // it to always return UserInteractionMode_Touch which as per documentation |
| 121 // indicates tablet mode. | 123 // indicates tablet mode. |
| 122 bool IsWindows10TabletDevice() { | 124 bool IsWindows10TabletMode(HWND hwnd) { |
| 123 if (GetVersion() < VERSION_WIN10) | 125 if (GetVersion() < VERSION_WIN10) |
| 124 return false; | 126 return false; |
| 125 | 127 |
| 126 using RoGetActivationFactoryFunction = decltype(&RoGetActivationFactory); | 128 using RoGetActivationFactoryFunction = decltype(&RoGetActivationFactory); |
| 127 using WindowsCreateStringFunction = decltype(&WindowsCreateString); | 129 using WindowsCreateStringFunction = decltype(&WindowsCreateString); |
| 128 | 130 |
| 129 static RoGetActivationFactoryFunction get_factory = nullptr; | 131 static RoGetActivationFactoryFunction get_factory = nullptr; |
| 130 static WindowsCreateStringFunction create_string = nullptr; | 132 static WindowsCreateStringFunction create_string = nullptr; |
| 131 | 133 |
| 132 if (!get_factory) { | 134 if (!get_factory) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 view_settings_interop.ReceiveVoid()); | 173 view_settings_interop.ReceiveVoid()); |
| 172 if (FAILED(hr)) | 174 if (FAILED(hr)) |
| 173 return false; | 175 return false; |
| 174 | 176 |
| 175 base::win::ScopedComPtr<ABI::Windows::UI::ViewManagement::IUIViewSettings> | 177 base::win::ScopedComPtr<ABI::Windows::UI::ViewManagement::IUIViewSettings> |
| 176 view_settings; | 178 view_settings; |
| 177 // TODO(ananta) | 179 // TODO(ananta) |
| 178 // Avoid using GetForegroundWindow here and pass in the HWND of the window | 180 // Avoid using GetForegroundWindow here and pass in the HWND of the window |
| 179 // intiating the request to display the keyboard. | 181 // intiating the request to display the keyboard. |
| 180 hr = view_settings_interop->GetForWindow( | 182 hr = view_settings_interop->GetForWindow( |
| 181 ::GetForegroundWindow(), | 183 hwnd, |
| 182 __uuidof(ABI::Windows::UI::ViewManagement::IUIViewSettings), | 184 __uuidof(ABI::Windows::UI::ViewManagement::IUIViewSettings), |
| 183 view_settings.ReceiveVoid()); | 185 view_settings.ReceiveVoid()); |
| 184 if (FAILED(hr)) | 186 if (FAILED(hr)) |
| 185 return false; | 187 return false; |
| 186 | 188 |
| 187 ABI::Windows::UI::ViewManagement::UserInteractionMode mode = | 189 ABI::Windows::UI::ViewManagement::UserInteractionMode mode = |
| 188 ABI::Windows::UI::ViewManagement::UserInteractionMode_Mouse; | 190 ABI::Windows::UI::ViewManagement::UserInteractionMode_Mouse; |
| 189 view_settings->get_UserInteractionMode(&mode); | 191 view_settings->get_UserInteractionMode(&mode); |
| 190 return mode == ABI::Windows::UI::ViewManagement::UserInteractionMode_Touch; | 192 return mode == ABI::Windows::UI::ViewManagement::UserInteractionMode_Touch; |
| 191 } | 193 } |
| 192 | 194 |
| 193 } // namespace | |
| 194 | |
| 195 // Returns true if a physical keyboard is detected on Windows 8 and up. | 195 // Returns true if a physical keyboard is detected on Windows 8 and up. |
| 196 // Uses the Setup APIs to enumerate the attached keyboards and returns true | 196 // Uses the Setup APIs to enumerate the attached keyboards and returns true |
| 197 // if the keyboard count is 1 or more.. While this will work in most cases | 197 // if the keyboard count is 1 or more.. While this will work in most cases |
| 198 // it won't work if there are devices which expose keyboard interfaces which | 198 // it won't work if there are devices which expose keyboard interfaces which |
| 199 // are attached to the machine. | 199 // are attached to the machine. |
| 200 bool IsKeyboardPresentOnSlate(std::string* reason) { | 200 bool IsKeyboardPresentOnSlate(std::string* reason) { |
| 201 bool result = false; | 201 bool result = false; |
| 202 | 202 |
| 203 if (GetVersion() < VERSION_WIN8) { | 203 if (GetVersion() < VERSION_WIN8) { |
| 204 *reason = "Detection not supported"; | 204 *reason = "Detection not supported"; |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 signal(SIGABRT, ForceCrashOnSigAbort); | 468 signal(SIGABRT, ForceCrashOnSigAbort); |
| 469 } | 469 } |
| 470 | 470 |
| 471 bool IsTabletDevice(std::string* reason) { | 471 bool IsTabletDevice(std::string* reason) { |
| 472 if (GetVersion() < VERSION_WIN8) { | 472 if (GetVersion() < VERSION_WIN8) { |
| 473 if (reason) | 473 if (reason) |
| 474 *reason = "Tablet device detection not supported below Windows 8\n"; | 474 *reason = "Tablet device detection not supported below Windows 8\n"; |
| 475 return false; | 475 return false; |
| 476 } | 476 } |
| 477 | 477 |
| 478 if (IsWindows10TabletDevice()) | 478 if (IsWindows10TabletMode(::GetForegroundWindow())) |
| 479 return true; | 479 return true; |
| 480 | 480 |
| 481 if (GetSystemMetrics(SM_MAXIMUMTOUCHES) == 0) { | 481 if (GetSystemMetrics(SM_MAXIMUMTOUCHES) == 0) { |
| 482 if (reason) { | 482 if (reason) { |
| 483 *reason += "Device does not support touch.\n"; | 483 *reason += "Device does not support touch.\n"; |
| 484 } else { | 484 } else { |
| 485 return false; | 485 return false; |
| 486 } | 486 } |
| 487 } | 487 } |
| 488 | 488 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 snapshot->resize(num_modules + 8, NULL); | 689 snapshot->resize(num_modules + 8, NULL); |
| 690 } | 690 } |
| 691 } while (--retries_remaining); | 691 } while (--retries_remaining); |
| 692 | 692 |
| 693 DLOG(ERROR) << "Failed to enumerate modules."; | 693 DLOG(ERROR) << "Failed to enumerate modules."; |
| 694 return false; | 694 return false; |
| 695 } | 695 } |
| 696 | 696 |
| 697 } // namespace win | 697 } // namespace win |
| 698 } // namespace base | 698 } // namespace base |
| OLD | NEW |