OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/events/devices/input_device_observer_win.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/callback.h" | |
9 #include "base/memory/singleton.h" | |
10 #include "base/strings/string16.h" | |
11 | |
12 // This macro provides the implementation for the observer notification methods. | |
13 #define NOTIFY_OBSERVERS(method_decl, observer_call) \ | |
14 void InputDeviceObserverWin::method_decl { \ | |
15 for (InputDeviceEventObserver & observer : observers_) \ | |
16 observer.observer_call; \ | |
17 } | |
18 | |
19 namespace ui { | |
20 | |
21 namespace { | |
22 | |
23 // The registry subkey that contains information about the state of the | |
24 // detachable/convertible laptop, it tells if the device has an accessible | |
25 // keyboard. | |
26 // OEMs are expected to follow this guidelines to report docked/undocked state | |
27 // https://msdn.microsoft.com/en-us/library/windows/hardware/dn922653(v=vs.85).a spx. | |
28 const base::char16 kRegistryPriorityControl[] = | |
29 L"System\\CurrentControlSet\\Control\\PriorityControl"; | |
30 | |
31 } // namespace | |
32 | |
33 InputDeviceObserverWin::InputDeviceObserverWin() : weak_factory_(this) { | |
34 registry_key_.reset(new base::win::RegKey( | |
35 HKEY_LOCAL_MACHINE, kRegistryPriorityControl, KEY_NOTIFY | KEY_READ)); | |
36 | |
37 if (registry_key_->Valid()) { | |
38 // Start watching the registry for changes. | |
39 base::win::RegKey::ChangeCallback callback = | |
40 base::Bind(&InputDeviceObserverWin::OnRegistryKeyChanged, | |
41 weak_factory_.GetWeakPtr(), registry_key_.get()); | |
42 registry_key_->StartWatching(callback); | |
43 } | |
44 } | |
45 | |
46 InputDeviceObserverWin* InputDeviceObserverWin::GetInstance() { | |
47 return base::Singleton< | |
48 InputDeviceObserverWin, | |
49 base::LeakySingletonTraits<InputDeviceObserverWin>>::get(); | |
50 } | |
51 | |
52 InputDeviceObserverWin::~InputDeviceObserverWin() {} | |
53 | |
54 void InputDeviceObserverWin::OnRegistryKeyChanged(base::win::RegKey* key) { | |
55 if (!key) | |
56 return; | |
57 | |
58 // |OnRegistryKeyChanged| is removed as an observer when the ChangeCallback is | |
59 // called, so we need to re-register. | |
60 key->StartWatching(base::Bind(&InputDeviceObserverWin::OnRegistryKeyChanged, | |
61 base::Unretained(this), base::Unretained(key))); | |
62 | |
63 NotifyObserversTouchpadDeviceConfigurationChanged(); | |
64 NotifyObserversMouseDeviceConfigurationChanged(); | |
65 NotifyObserversKeyboardDeviceConfigurationChanged(); | |
66 } | |
67 | |
68 void InputDeviceObserverWin::AddObserver(InputDeviceEventObserver* observer) { | |
69 observers_.AddObserver(observer); | |
70 } | |
71 | |
72 void InputDeviceObserverWin::RemoveObserver( | |
73 InputDeviceEventObserver* observer) { | |
74 observers_.RemoveObserver(observer); | |
75 } | |
76 | |
77 NOTIFY_OBSERVERS(NotifyObserversKeyboardDeviceConfigurationChanged(), | |
mustaq
2017/03/21 17:53:08
I guess the the registry key reflects changes in t
| |
78 OnKeyboardDeviceConfigurationChanged()); | |
79 | |
80 NOTIFY_OBSERVERS(NotifyObserversMouseDeviceConfigurationChanged(), | |
81 OnMouseDeviceConfigurationChanged()); | |
82 | |
83 NOTIFY_OBSERVERS(NotifyObserversTouchpadDeviceConfigurationChanged(), | |
84 OnTouchpadDeviceConfigurationChanged()); | |
85 | |
86 } // namespace ui | |
OLD | NEW |