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

Unified Diff: ash/wm/maximize_mode/maximize_mode_event_blocker.cc

Issue 269633005: Only block internal touchpad and allow external mice to continue working in maximize mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move internal device tracking to a separate class with only an X11 implementation. Created 6 years, 7 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: ash/wm/maximize_mode/maximize_mode_event_blocker.cc
diff --git a/ash/wm/maximize_mode/maximize_mode_event_blocker.cc b/ash/wm/maximize_mode/maximize_mode_event_blocker.cc
index f5eb08f26b373bf02b559018a97ace7321c9597d..ec1bcd2df2632abbb34d6e2f30e5dbef14d5a090 100644
--- a/ash/wm/maximize_mode/maximize_mode_event_blocker.cc
+++ b/ash/wm/maximize_mode/maximize_mode_event_blocker.cc
@@ -5,10 +5,18 @@
#include "ash/wm/maximize_mode/maximize_mode_event_blocker.h"
#include "ash/shell.h"
+#include "ash/wm/maximize_mode/internal_input_device_list.h"
#include "base/memory/scoped_ptr.h"
#include "ui/aura/client/cursor_client.h"
+#include "ui/aura/window_event_dispatcher.h"
+#include "ui/aura/window_tree_host.h"
#include "ui/events/event_targeter.h"
#include "ui/events/keycodes/keyboard_codes.h"
+#include "ui/gfx/point.h"
+
+#if defined(USE_X11)
+#include "ash/wm/maximize_mode/internal_input_device_list_x11.h"
+#endif
namespace ash {
@@ -17,11 +25,11 @@ namespace {
// Event targeter to prevent delivery of mouse and touchpad events while
// maximize mode is active. Other events such as touch are passed on to the
// default targeter.
-// TODO(flackr): This should only stop events from the internal keyboard and
-// touchpad.
class BlockKeyboardAndTouchpadTargeter : public ui::EventTargeter {
public:
- BlockKeyboardAndTouchpadTargeter();
+ BlockKeyboardAndTouchpadTargeter(
+ aura::Window* root_window,
+ InternalInputDeviceList* internal_devices);
virtual ~BlockKeyboardAndTouchpadTargeter();
// Sets the default targeter to use when the event is not being blocked.
@@ -32,16 +40,33 @@ class BlockKeyboardAndTouchpadTargeter : public ui::EventTargeter {
ui::Event* event) OVERRIDE;
private:
+ // A weak pointer to the root window on which this targeter will be set. The
+ // root window owns this targeter.
+ aura::Window* root_window_;
+
+ // If set, a class which identifies events coming from internal input devices.
+ InternalInputDeviceList* internal_devices_;
+
// A weak pointer to the targeter this targeter is wrapping. The
// default_targeter is owned by the ScopedWindowTargeter which will be valid
// as long as this targeter is alive.
ui::EventTargeter* default_targeter_;
+ // The last known mouse location to lock the cursor in place to when events
+ // come from the internal touchpad.
+ gfx::Point last_mouse_location_;
+
DISALLOW_COPY_AND_ASSIGN(BlockKeyboardAndTouchpadTargeter);
};
-BlockKeyboardAndTouchpadTargeter::BlockKeyboardAndTouchpadTargeter()
- : default_targeter_(NULL) {
+BlockKeyboardAndTouchpadTargeter::BlockKeyboardAndTouchpadTargeter(
+ aura::Window* root_window,
+ InternalInputDeviceList* internal_devices)
+ : root_window_(root_window),
+ internal_devices_(internal_devices),
+ default_targeter_(NULL),
+ last_mouse_location_(root_window->GetHost()->dispatcher()->
+ GetLastMouseLocationInRoot()) {
}
BlockKeyboardAndTouchpadTargeter::~BlockKeyboardAndTouchpadTargeter() {
@@ -55,10 +80,28 @@ void BlockKeyboardAndTouchpadTargeter::SetDefaultTargeter(
ui::EventTarget* BlockKeyboardAndTouchpadTargeter::FindTargetForEvent(
ui::EventTarget* root,
ui::Event* event) {
+ bool internal_device = internal_devices_ &&
+ internal_devices_->IsEventFromInternalDevice(event);
if (event->HasNativeEvent()) {
- if (event->IsMouseEvent())
- return NULL;
- if (event->IsKeyEvent()) {
+ if (event->IsMouseEvent()) {
+ if (internal_device) {
+ // The cursor movement is handled at a lower level which is not blocked.
+ // Move the mouse cursor back to its last known location resulting from
+ // an external mouse to prevent the internal touchpad from moving it.
+ root_window_->GetHost()->MoveCursorToHostLocation(
+ last_mouse_location_);
+ return NULL;
+ } else {
+ // Track the last location seen from an external mouse event.
+ last_mouse_location_ =
+ static_cast<ui::MouseEvent*>(event)->root_location();
+ root_window_->GetHost()->ConvertPointToHost(&last_mouse_location_);
+ }
+ } else if (event->IsKeyEvent()) {
+ // TODO(flackr): Disable events only from the internal keyboard device
+ // when we begin using XI2 events for keyboard events
+ // (http://crbug.com/368750) and can tell which device the event is
+ // coming from, http://crbug.com/362881.
// TODO(bruthig): Fix this to block rewritten volume keys
// (i.e. F9 and F10) from the device's keyboard. https://crbug.com/368669
ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(event);
@@ -70,6 +113,8 @@ ui::EventTarget* BlockKeyboardAndTouchpadTargeter::FindTargetForEvent(
) {
return NULL;
}
+ } else if (internal_device) {
+ return NULL;
}
}
return default_targeter_->FindTargetForEvent(root, event);
@@ -77,7 +122,11 @@ ui::EventTarget* BlockKeyboardAndTouchpadTargeter::FindTargetForEvent(
} // namespace
-MaximizeModeEventBlocker::MaximizeModeEventBlocker() {
+MaximizeModeEventBlocker::MaximizeModeEventBlocker()
+#if defined(USE_X11)
+ : internal_devices_(new InternalInputDeviceListX11)
+#endif
+ {
Shell::GetInstance()->AddShellObserver(this);
// Hide the cursor as mouse events will be blocked.
@@ -106,7 +155,8 @@ void MaximizeModeEventBlocker::OnRootWindowAdded(aura::Window* root_window) {
void MaximizeModeEventBlocker::AddEventTargeterOn(
aura::Window* root_window) {
BlockKeyboardAndTouchpadTargeter* targeter =
- new BlockKeyboardAndTouchpadTargeter();
+ new BlockKeyboardAndTouchpadTargeter(root_window,
+ internal_devices_.get());
aura::ScopedWindowTargeter* scoped_targeter = new aura::ScopedWindowTargeter(
root_window, scoped_ptr<ui::EventTargeter>(targeter));
targeter->SetDefaultTargeter(scoped_targeter->old_targeter());

Powered by Google App Engine
This is Rietveld 408576698