Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Unified Diff: ui/events/devices/input_device_observer_win.cc

Issue 2690323002: Make Interaction Media Features MQ dynamic on Windows. (Closed)
Patch Set: Rebased Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/events/devices/input_device_observer_win.cc
diff --git a/ui/events/devices/input_device_observer_win.cc b/ui/events/devices/input_device_observer_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ac993059455f4ed456d7f4a5cb25f9afb8e7474e
--- /dev/null
+++ b/ui/events/devices/input_device_observer_win.cc
@@ -0,0 +1,86 @@
+// Copyright (c) 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/events/devices/input_device_observer_win.h"
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/memory/singleton.h"
+#include "base/strings/string16.h"
+
+// This macro provides the implementation for the observer notification methods.
+#define NOTIFY_OBSERVERS(method_decl, observer_call) \
+ void InputDeviceObserverWin::method_decl { \
+ for (InputDeviceEventObserver & observer : observers_) \
+ observer.observer_call; \
+ }
+
+namespace ui {
+
+namespace {
+
+// The registry subkey that contains information about the state of the
+// detachable/convertible laptop, it tells if the device has an accessible
+// keyboard.
+// OEMs are expected to follow this guidelines to report docked/undocked state
+// https://msdn.microsoft.com/en-us/library/windows/hardware/dn922653(v=vs.85).aspx.
+const base::char16 kRegistryPriorityControl[] =
+ L"System\\CurrentControlSet\\Control\\PriorityControl";
+
+} // namespace
+
+InputDeviceObserverWin::InputDeviceObserverWin() : weak_factory_(this) {
+ registry_key_.reset(new base::win::RegKey(
+ HKEY_LOCAL_MACHINE, kRegistryPriorityControl, KEY_NOTIFY | KEY_READ));
+
+ if (registry_key_->Valid()) {
+ // Start watching the registry for changes.
+ base::win::RegKey::ChangeCallback callback =
+ base::Bind(&InputDeviceObserverWin::OnRegistryKeyChanged,
+ weak_factory_.GetWeakPtr(), registry_key_.get());
+ registry_key_->StartWatching(callback);
+ }
+}
+
+InputDeviceObserverWin* InputDeviceObserverWin::GetInstance() {
+ return base::Singleton<
+ InputDeviceObserverWin,
+ base::LeakySingletonTraits<InputDeviceObserverWin>>::get();
+}
+
+InputDeviceObserverWin::~InputDeviceObserverWin() {}
+
+void InputDeviceObserverWin::OnRegistryKeyChanged(base::win::RegKey* key) {
+ if (!key)
+ return;
+
+ // |OnRegistryKeyChanged| is removed as an observer when the ChangeCallback is
+ // called, so we need to re-register.
+ key->StartWatching(base::Bind(&InputDeviceObserverWin::OnRegistryKeyChanged,
+ base::Unretained(this), base::Unretained(key)));
+
+ NotifyObserversTouchpadDeviceConfigurationChanged();
+ NotifyObserversMouseDeviceConfigurationChanged();
+ NotifyObserversKeyboardDeviceConfigurationChanged();
+}
+
+void InputDeviceObserverWin::AddObserver(InputDeviceEventObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void InputDeviceObserverWin::RemoveObserver(
+ InputDeviceEventObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+NOTIFY_OBSERVERS(NotifyObserversKeyboardDeviceConfigurationChanged(),
mustaq 2017/03/21 17:53:08 I guess the the registry key reflects changes in t
+ OnKeyboardDeviceConfigurationChanged());
+
+NOTIFY_OBSERVERS(NotifyObserversMouseDeviceConfigurationChanged(),
+ OnMouseDeviceConfigurationChanged());
+
+NOTIFY_OBSERVERS(NotifyObserversTouchpadDeviceConfigurationChanged(),
+ OnTouchpadDeviceConfigurationChanged());
+
+} // namespace ui
« ui/events/devices/device_data_manager.cc ('K') | « ui/events/devices/input_device_observer_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698