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 <shobjidl.h> // Must be before propkey. | 8 #include <shobjidl.h> // Must be before propkey. |
9 #include <initguid.h> | 9 #include <initguid.h> |
10 #include <propkey.h> | 10 #include <propkey.h> |
11 #include <propvarutil.h> | 11 #include <propvarutil.h> |
12 #include <sddl.h> | 12 #include <sddl.h> |
13 #include <shlobj.h> | 13 #include <shlobj.h> |
14 | 14 |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/win/registry.h" | 17 #include "base/win/registry.h" |
18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
19 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
20 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
21 #include "base/win/scoped_handle.h" | 21 #include "base/win/scoped_handle.h" |
22 #include "base/win/windows_version.h" | 22 #include "base/win/windows_version.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
| 26 // From MSDN. |
| 27 #define MOUSEEVENTF_FROMTOUCH 0xFF515700 |
| 28 |
26 // TODO(gab): These definitions are temporary and should be removed once the | 29 // TODO(gab): These definitions are temporary and should be removed once the |
27 // win8 SDK defines them. | 30 // win8 SDK defines them. |
28 DEFINE_PROPERTYKEY(PKEY_AppUserModel_DualMode, 0x9F4C2855, 0x9F79, | 31 DEFINE_PROPERTYKEY(PKEY_AppUserModel_DualMode, 0x9F4C2855, 0x9F79, |
29 0x4B39, 0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3, 11); | 32 0x4B39, 0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3, 11); |
30 DEFINE_PROPERTYKEY(PKEY_AppUserModel_DualMode_UK, 0x9F4C2855, 0x9F79, | 33 DEFINE_PROPERTYKEY(PKEY_AppUserModel_DualMode_UK, 0x9F4C2855, 0x9F79, |
31 0x4B39, 0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3, 18); | 34 0x4B39, 0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3, 18); |
32 | 35 |
33 // Sets the value of |property_key| to |property_value| in |property_store|. | 36 // Sets the value of |property_key| to |property_value| in |property_store|. |
34 // Clears the PropVariant contained in |property_value|. | 37 // Clears the PropVariant contained in |property_value|. |
35 bool SetPropVariantValueForPropertyStore( | 38 bool SetPropVariantValueForPropertyStore( |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 106 } |
104 | 107 |
105 bool IsCtrlPressed() { | 108 bool IsCtrlPressed() { |
106 return (::GetKeyState(VK_CONTROL) & 0x8000) == 0x8000; | 109 return (::GetKeyState(VK_CONTROL) & 0x8000) == 0x8000; |
107 } | 110 } |
108 | 111 |
109 bool IsAltPressed() { | 112 bool IsAltPressed() { |
110 return (::GetKeyState(VK_MENU) & 0x8000) == 0x8000; | 113 return (::GetKeyState(VK_MENU) & 0x8000) == 0x8000; |
111 } | 114 } |
112 | 115 |
| 116 // Windows emulates mouse messages for touch events. |
| 117 bool IsMouseEventFromTouch(UINT message) { |
| 118 return (message == WM_MOUSEMOVE || |
| 119 message == WM_LBUTTONDOWN || message == WM_LBUTTONUP || |
| 120 message == WM_RBUTTONDOWN || message == WM_RBUTTONUP) && |
| 121 (GetMessageExtraInfo() & MOUSEEVENTF_FROMTOUCH) == |
| 122 MOUSEEVENTF_FROMTOUCH; |
| 123 } |
| 124 |
113 bool UserAccountControlIsEnabled() { | 125 bool UserAccountControlIsEnabled() { |
114 // This can be slow if Windows ends up going to disk. Should watch this key | 126 // This can be slow if Windows ends up going to disk. Should watch this key |
115 // for changes and only read it once, preferably on the file thread. | 127 // for changes and only read it once, preferably on the file thread. |
116 // http://code.google.com/p/chromium/issues/detail?id=61644 | 128 // http://code.google.com/p/chromium/issues/detail?id=61644 |
117 base::ThreadRestrictions::ScopedAllowIO allow_io; | 129 base::ThreadRestrictions::ScopedAllowIO allow_io; |
118 | 130 |
119 base::win::RegKey key(HKEY_LOCAL_MACHINE, | 131 base::win::RegKey key(HKEY_LOCAL_MACHINE, |
120 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", | 132 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", |
121 KEY_READ); | 133 KEY_READ); |
122 DWORD uac_enabled; | 134 DWORD uac_enabled; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 243 |
232 #ifndef COPY_FILE_COPY_SYMLINK | 244 #ifndef COPY_FILE_COPY_SYMLINK |
233 #error You must install the Windows 2008 or Vista Software Development Kit and \ | 245 #error You must install the Windows 2008 or Vista Software Development Kit and \ |
234 set it as your default include path to build this library. You can grab it by \ | 246 set it as your default include path to build this library. You can grab it by \ |
235 searching for "download windows sdk 2008" in your favorite web search engine. \ | 247 searching for "download windows sdk 2008" in your favorite web search engine. \ |
236 Also make sure you register the SDK with Visual Studio, by selecting \ | 248 Also make sure you register the SDK with Visual Studio, by selecting \ |
237 "Integrate Windows SDK with Visual Studio 2005" from the Windows SDK \ | 249 "Integrate Windows SDK with Visual Studio 2005" from the Windows SDK \ |
238 menu (see Start - All Programs - Microsoft Windows SDK - \ | 250 menu (see Start - All Programs - Microsoft Windows SDK - \ |
239 Visual Studio Registration). | 251 Visual Studio Registration). |
240 #endif | 252 #endif |
OLD | NEW |