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

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

Issue 313913004: Block internal PlatformEvents before they are dispatched in touchview. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove obsolete comment and unnecessary includes. Created 6 years, 6 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 572886c1e0f8db6e10a02d9b8ddbc934e1518c08..63656232d54d0a4a175449c038350fcf5b522418 100644
--- a/ash/wm/maximize_mode/maximize_mode_event_blocker.cc
+++ b/ash/wm/maximize_mode/maximize_mode_event_blocker.cc
@@ -4,15 +4,19 @@
#include "ash/wm/maximize_mode/maximize_mode_event_blocker.h"
+#include "ash/display/display_controller.h"
+#include "ash/screen_util.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/client/screen_position_client.h"
+#include "ui/aura/env.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_tree_host.h"
-#include "ui/events/event_targeter.h"
+#include "ui/events/event_utils.h"
#include "ui/events/keycodes/keyboard_codes.h"
-#include "ui/gfx/point.h"
+#include "ui/events/platform/platform_event_source.h"
#if defined(USE_X11)
#include "ash/wm/maximize_mode/internal_input_device_list_x11.h"
@@ -22,144 +26,94 @@ namespace ash {
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.
-class BlockKeyboardAndTouchpadTargeter : public ui::EventTargeter {
- public:
- BlockKeyboardAndTouchpadTargeter(
- aura::Window* root_window,
- MaximizeModeEventBlocker* event_blocker);
- virtual ~BlockKeyboardAndTouchpadTargeter();
-
- // Sets the default targeter to use when the event is not being blocked.
- void SetDefaultTargeter(EventTargeter* default_targeter);
-
- // Overridden from ui::EventTargeter:
- virtual ui::EventTarget* FindTargetForEvent(ui::EventTarget* root,
- 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_;
-
- // A weak pointer to the event blocker which owns the scoped targeter owning
- // this targeter.
- MaximizeModeEventBlocker* event_blocker_;
-
- // 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);
-};
+gfx::Point GetMouseLocationInScreen() {
+ return aura::Env::GetInstance()->last_mouse_location();
+}
-BlockKeyboardAndTouchpadTargeter::BlockKeyboardAndTouchpadTargeter(
- aura::Window* root_window,
- MaximizeModeEventBlocker* event_blocker)
- : root_window_(root_window),
- event_blocker_(event_blocker),
- default_targeter_(NULL),
- last_mouse_location_(root_window->GetHost()->dispatcher()->
- GetLastMouseLocationInRoot()) {
+void SetMouseLocationInScreen(const gfx::Point& screen_location) {
+ gfx::Display display = ash::ScreenUtil::FindDisplayContainingPoint(
+ screen_location);
+ if (!display.is_valid())
+ return;
+ aura::Window* root_window = Shell::GetInstance()->display_controller()->
+ GetRootWindowForDisplayId(display.id());
+ gfx::Point host_location(screen_location);
+ aura::client::ScreenPositionClient* client =
+ aura::client::GetScreenPositionClient(root_window);
+ if (client)
+ client->ConvertPointFromScreen(root_window, &host_location);
+ root_window->GetHost()->MoveCursorTo(host_location);
}
-BlockKeyboardAndTouchpadTargeter::~BlockKeyboardAndTouchpadTargeter() {
+} // namespace
+
+MaximizeModeEventBlocker::MaximizeModeEventBlocker()
+ : last_mouse_location_(GetMouseLocationInScreen())
+#if defined(USE_X11)
+ , internal_devices_(new InternalInputDeviceListX11)
+#endif
+ {
+ ui::PlatformEventSource::GetInstance()->AddPlatformEventFilter(this);
+ // Hide the cursor as mouse events will be blocked.
+ aura::client::CursorClient* cursor_client_ =
+ aura::client::GetCursorClient(Shell::GetTargetRootWindow());
+ if (cursor_client_)
+ cursor_client_->HideCursor();
}
-void BlockKeyboardAndTouchpadTargeter::SetDefaultTargeter(
- ui::EventTargeter* default_targeter) {
- default_targeter_ = default_targeter;
+MaximizeModeEventBlocker::~MaximizeModeEventBlocker() {
+ ui::PlatformEventSource::GetInstance()->RemovePlatformEventFilter(this);
}
-ui::EventTarget* BlockKeyboardAndTouchpadTargeter::FindTargetForEvent(
- ui::EventTarget* root,
- ui::Event* event) {
- bool internal_device = event_blocker_->internal_devices() &&
- event_blocker_->internal_devices()->IsEventFromInternalDevice(event);
- if (event->IsMouseEvent()) {
+bool MaximizeModeEventBlocker::ShouldDispatchEvent(
+ const ui::PlatformEvent& event) {
+ bool internal_device = internal_devices_ &&
+ internal_devices_->IsEventFromInternalDevice(event);
+ ui::EventType type(ui::EventTypeFromNative(event));
+ if (type == ui::ET_MOUSE_MOVED ||
+ type == ui::ET_MOUSE_DRAGGED ||
+ type == ui::ET_MOUSE_ENTERED ||
+ type == ui::ET_MOUSE_EXITED ||
+ type == ui::ET_MOUSE_PRESSED ||
+ type == ui::ET_MOUSE_RELEASED ||
+ type == ui::ET_MOUSE_CAPTURE_CHANGED) {
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;
+ SetMouseLocationInScreen(last_mouse_location_);
+ return false;
} 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_);
+ last_mouse_location_ = GetMouseLocationInScreen();
}
- } else if (internal_device && (event->IsMouseWheelEvent() ||
- event->IsScrollEvent())) {
- return NULL;
- } else if (event->IsKeyEvent() && event->HasNativeEvent()) {
+ } else if (type == ui::ET_KEY_PRESSED || type == ui::ET_KEY_RELEASED) {
// 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);
- if (key_event->key_code() != ui::VKEY_VOLUME_DOWN &&
- key_event->key_code() != ui::VKEY_VOLUME_UP
+ ui::KeyboardCode key_code = ui::KeyboardCodeFromNative(event);
+ if (key_code == ui::VKEY_VOLUME_DOWN ||
+ key_code == ui::VKEY_VOLUME_UP
#if defined(OS_CHROMEOS)
- && key_event->key_code() != ui::VKEY_POWER
+ || key_code == ui::VKEY_POWER
#endif
) {
- return NULL;
+ return true;
}
+ return false;
}
- return default_targeter_->FindTargetForEvent(root, event);
-}
-
-} // namespace
-
-MaximizeModeEventBlocker::MaximizeModeEventBlocker()
-#if defined(USE_X11)
- : internal_devices_(new InternalInputDeviceListX11)
-#endif
- {
- Shell::GetInstance()->AddShellObserver(this);
-
- // Hide the cursor as mouse events will be blocked.
- aura::client::CursorClient* cursor_client_ =
- aura::client::GetCursorClient(Shell::GetTargetRootWindow());
- if (cursor_client_)
- cursor_client_->HideCursor();
-
- // Block keyboard and mouse events on all existing and new root windows for
- // the lifetime of this class.
- aura::Window::Windows root_windows(Shell::GetAllRootWindows());
- for (aura::Window::Windows::iterator iter = root_windows.begin();
- iter != root_windows.end(); ++iter) {
- AddEventTargeterOn(*iter);
+ if (!internal_device)
+ return true;
+
+ if (type == ui::ET_MOUSEWHEEL ||
+ (!(ui::EventFlagsFromNative(event) & ui::EF_FROM_TOUCH) && (
+ type == ui::ET_SCROLL_FLING_START ||
+ type == ui::ET_SCROLL_FLING_CANCEL))) {
+ // Prevent scroll flings from the internal touchpad.
+ return false;
}
-}
-
-MaximizeModeEventBlocker::~MaximizeModeEventBlocker() {
- Shell::GetInstance()->RemoveShellObserver(this);
-}
-
-void MaximizeModeEventBlocker::OnRootWindowAdded(aura::Window* root_window) {
- AddEventTargeterOn(root_window);
-}
-
-void MaximizeModeEventBlocker::AddEventTargeterOn(
- aura::Window* root_window) {
- BlockKeyboardAndTouchpadTargeter* targeter =
- new BlockKeyboardAndTouchpadTargeter(root_window, this);
- aura::ScopedWindowTargeter* scoped_targeter = new aura::ScopedWindowTargeter(
- root_window, scoped_ptr<ui::EventTargeter>(targeter));
- targeter->SetDefaultTargeter(scoped_targeter->old_targeter());
- targeters_.push_back(scoped_targeter);
+ return true;
}
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698