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

Unified Diff: media/base/user_input_monitor_win.cc

Issue 2577573002: Removes mouse listeners from UserInputMonitor. (Closed)
Patch Set: Addresses Wez's #48 comment. Created 3 years, 11 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: media/base/user_input_monitor_win.cc
diff --git a/media/base/user_input_monitor_win.cc b/media/base/user_input_monitor_win.cc
index 12446013f74d3a344e6a65237beb14c1095b5ca7..19333590678db4740ce94542345cf97e9e6e2ff4 100644
--- a/media/base/user_input_monitor_win.cc
+++ b/media/base/user_input_monitor_win.cc
@@ -26,7 +26,6 @@ namespace {
// From the HID Usage Tables specification.
const USHORT kGenericDesktopPage = 1;
-const USHORT kMouseUsage = 2;
const USHORT kKeyboardUsage = 6;
// This is the actual implementation of event monitoring. It's separated from
@@ -41,17 +40,15 @@ class UserInputMonitorWinCore
};
explicit UserInputMonitorWinCore(
- scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
- const scoped_refptr<UserInputMonitor::MouseListenerList>&
- mouse_listeners);
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner);
~UserInputMonitorWinCore() override;
// DestructionObserver overrides.
void WillDestroyCurrentMessageLoop() override;
size_t GetKeyPressCount() const;
- void StartMonitor(EventBitMask type);
- void StopMonitor(EventBitMask type);
+ void StartMonitor();
+ void StopMonitor();
private:
// Handles WM_INPUT messages.
@@ -65,12 +62,9 @@ class UserInputMonitorWinCore
// Task runner on which |window_| is created.
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
- scoped_refptr<base::ObserverListThreadSafe<
- UserInputMonitor::MouseEventListener>> mouse_listeners_;
// These members are only accessed on the UI thread.
std::unique_ptr<base::win::MessageWindow> window_;
- uint8_t events_monitored_;
KeyboardEventCounter counter_;
DISALLOW_COPY_AND_ASSIGN(UserInputMonitorWinCore);
@@ -89,8 +83,6 @@ class UserInputMonitorWin : public UserInputMonitor {
// Private UserInputMonitor overrides.
void StartKeyboardMonitoring() override;
void StopKeyboardMonitoring() override;
- void StartMouseMonitoring() override;
- void StopMouseMonitoring() override;
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
UserInputMonitorWinCore* core_;
@@ -99,85 +91,68 @@ class UserInputMonitorWin : public UserInputMonitor {
};
UserInputMonitorWinCore::UserInputMonitorWinCore(
- scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
- const scoped_refptr<UserInputMonitor::MouseListenerList>& mouse_listeners)
- : ui_task_runner_(ui_task_runner),
- mouse_listeners_(mouse_listeners),
- events_monitored_(0) {}
+ scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
+ : ui_task_runner_(ui_task_runner) {}
UserInputMonitorWinCore::~UserInputMonitorWinCore() {
DCHECK(!window_);
- DCHECK(!events_monitored_);
}
void UserInputMonitorWinCore::WillDestroyCurrentMessageLoop() {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
- StopMonitor(MOUSE_EVENT_MASK);
- StopMonitor(KEYBOARD_EVENT_MASK);
+ StopMonitor();
}
size_t UserInputMonitorWinCore::GetKeyPressCount() const {
return counter_.GetKeyPressCount();
}
-void UserInputMonitorWinCore::StartMonitor(EventBitMask type) {
+void UserInputMonitorWinCore::StartMonitor() {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
- if (events_monitored_ & type)
+ if (window_)
return;
- if (type == KEYBOARD_EVENT_MASK)
- counter_.Reset();
-
- if (!window_) {
- window_.reset(new base::win::MessageWindow());
- if (!window_->Create(base::Bind(&UserInputMonitorWinCore::HandleMessage,
- base::Unretained(this)))) {
- PLOG(ERROR) << "Failed to create the raw input window";
- window_.reset();
- return;
- }
+ counter_.Reset();
+
+ std::unique_ptr<base::win::MessageWindow> window =
+ base::MakeUnique<base::win::MessageWindow>();
+ if (!window->Create(base::Bind(&UserInputMonitorWinCore::HandleMessage,
+ base::Unretained(this)))) {
+ PLOG(ERROR) << "Failed to create the raw input window";
+ return;
}
- // Register to receive raw mouse and/or keyboard input.
- std::unique_ptr<RAWINPUTDEVICE> device(
- GetRawInputDevices(type, RIDEV_INPUTSINK));
+ // Register to receive raw keyboard input.
+ std::unique_ptr<RAWINPUTDEVICE> device(GetRawInputDevices(RIDEV_INPUTSINK));
if (!RegisterRawInputDevices(device.get(), 1, sizeof(*device))) {
PLOG(ERROR) << "RegisterRawInputDevices() failed for RIDEV_INPUTSINK";
- window_.reset();
return;
}
+ window_ = std::move(window);
// Start observing message loop destruction if we start monitoring the first
// event.
- if (!events_monitored_)
- base::MessageLoop::current()->AddDestructionObserver(this);
-
- events_monitored_ |= type;
+ base::MessageLoop::current()->AddDestructionObserver(this);
}
-void UserInputMonitorWinCore::StopMonitor(EventBitMask type) {
+void UserInputMonitorWinCore::StopMonitor() {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
- if (!(events_monitored_ & type))
+ if (!window_)
return;
// Stop receiving raw input.
- DCHECK(window_);
- std::unique_ptr<RAWINPUTDEVICE> device(
- GetRawInputDevices(type, RIDEV_REMOVE));
+ std::unique_ptr<RAWINPUTDEVICE> device(GetRawInputDevices(RIDEV_REMOVE));
if (!RegisterRawInputDevices(device.get(), 1, sizeof(*device))) {
PLOG(INFO) << "RegisterRawInputDevices() failed for RIDEV_REMOVE";
}
- events_monitored_ &= ~type;
- if (events_monitored_ == 0) {
- window_.reset();
+ window_ = nullptr;
- // Stop observing message loop destruction if no event is being monitored.
- base::MessageLoop::current()->RemoveDestructionObserver(this);
- }
+ // Stop observing message loop destruction if no event is being monitored.
+ base::MessageLoop::current()->RemoveDestructionObserver(this);
}
LRESULT UserInputMonitorWinCore::OnInput(HRAWINPUT input_handle) {
@@ -205,23 +180,12 @@ LRESULT UserInputMonitorWinCore::OnInput(HRAWINPUT input_handle) {
DCHECK_EQ(size, result);
// Notify the observer about events generated locally.
- if (input->header.dwType == RIM_TYPEMOUSE && input->header.hDevice != NULL) {
- POINT position;
- if (!GetCursorPos(&position)) {
- position.x = 0;
- position.y = 0;
- }
- mouse_listeners_->Notify(
- FROM_HERE, &UserInputMonitor::MouseEventListener::OnMouseMoved,
- SkIPoint::Make(position.x, position.y));
- } else if (input->header.dwType == RIM_TYPEKEYBOARD &&
- input->header.hDevice != NULL) {
- ui::EventType event = (input->data.keyboard.Flags & RI_KEY_BREAK)
- ? ui::ET_KEY_RELEASED
- : ui::ET_KEY_PRESSED;
+ if (input->header.dwType == RIM_TYPEKEYBOARD &&
+ input->header.hDevice != NULL) {
ui::KeyboardCode key_code =
ui::KeyboardCodeForWindowsKeyCode(input->data.keyboard.VKey);
- counter_.OnKeyboardEvent(event, key_code);
+ counter_.OnKeyboardEvent(!(input->data.keyboard.Flags & RI_KEY_BREAK),
Wez 2017/01/11 23:19:19 Looks like this needs migrating back to the ui::Ev
CJ 2017/01/11 23:41:55 Thanks for catching this.
+ key_code);
}
return DefRawInputProc(&input, 1, sizeof(RAWINPUTHEADER));
@@ -243,23 +207,14 @@ bool UserInputMonitorWinCore::HandleMessage(UINT message,
}
}
-RAWINPUTDEVICE* UserInputMonitorWinCore::GetRawInputDevices(EventBitMask event,
- DWORD flags) {
+RAWINPUTDEVICE* UserInputMonitorWinCore::GetRawInputDevices(DWORD flags) {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
std::unique_ptr<RAWINPUTDEVICE> device(new RAWINPUTDEVICE());
- if (event == MOUSE_EVENT_MASK) {
- device->dwFlags = flags;
- device->usUsagePage = kGenericDesktopPage;
- device->usUsage = kMouseUsage;
- device->hwndTarget = window_->hwnd();
- } else {
- DCHECK_EQ(KEYBOARD_EVENT_MASK, event);
- device->dwFlags = flags;
- device->usUsagePage = kGenericDesktopPage;
- device->usUsage = kKeyboardUsage;
- device->hwndTarget = window_->hwnd();
- }
+ device->dwFlags = flags;
+ device->usUsagePage = kGenericDesktopPage;
+ device->usUsage = kKeyboardUsage;
+ device->hwndTarget = window_->hwnd();
return device.release();
}
@@ -270,7 +225,7 @@ RAWINPUTDEVICE* UserInputMonitorWinCore::GetRawInputDevices(EventBitMask event,
UserInputMonitorWin::UserInputMonitorWin(
const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner)
: ui_task_runner_(ui_task_runner),
- core_(new UserInputMonitorWinCore(ui_task_runner, mouse_listeners())) {}
+ core_(new UserInputMonitorWinCore(ui_task_runner)) {}
UserInputMonitorWin::~UserInputMonitorWin() {
if (!ui_task_runner_->DeleteSoon(FROM_HERE, core_))
@@ -284,33 +239,13 @@ size_t UserInputMonitorWin::GetKeyPressCount() const {
void UserInputMonitorWin::StartKeyboardMonitoring() {
ui_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&UserInputMonitorWinCore::StartMonitor,
- core_->AsWeakPtr(),
- UserInputMonitorWinCore::KEYBOARD_EVENT_MASK));
+ base::Bind(&UserInputMonitorWinCore::StartMonitor, core_->AsWeakPtr()));
}
void UserInputMonitorWin::StopKeyboardMonitoring() {
ui_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&UserInputMonitorWinCore::StopMonitor,
- core_->AsWeakPtr(),
- UserInputMonitorWinCore::KEYBOARD_EVENT_MASK));
-}
-
-void UserInputMonitorWin::StartMouseMonitoring() {
- ui_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&UserInputMonitorWinCore::StartMonitor,
- core_->AsWeakPtr(),
- UserInputMonitorWinCore::MOUSE_EVENT_MASK));
-}
-
-void UserInputMonitorWin::StopMouseMonitoring() {
- ui_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&UserInputMonitorWinCore::StopMonitor,
- core_->AsWeakPtr(),
- UserInputMonitorWinCore::MOUSE_EVENT_MASK));
+ base::Bind(&UserInputMonitorWinCore::StopMonitor, core_->AsWeakPtr()));
}
} // namespace
« media/base/user_input_monitor_linux.cc ('K') | « media/base/user_input_monitor_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698