mouse_cursor_event_filter.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
1c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// found in the LICENSE file. 4c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 5c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#ifndef ASH_DISPLAY_MOUSE_CURSOR_EVENT_FILTER_H 6c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#define ASH_DISPLAY_MOUSE_CURSOR_EVENT_FILTER_H 7c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 8c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ash/ash_export.h" 9c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/compiler_specific.h" 10c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/gtest_prod_util.h" 11c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 12c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/aura/event_filter.h" 13c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/gfx/rect.h" 14c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 15c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)namespace aura { 16c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class RootWindow; 17c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 18c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 19c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)namespace ash { 20c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class DisplayController; 21c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 22c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)namespace internal { 23c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class SharedDisplayEdgeIndicator; 24c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 25c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// An event filter that controls mouse location in extended desktop 26c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// environment. 27c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class ASH_EXPORT MouseCursorEventFilter : public aura::EventFilter { 28c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) public: 29c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) enum MouseWarpMode { 30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) WARP_ALWAYS, // Always warp the mouse when possible. 31c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) WARP_DRAG, // Used when dragging a window. Top and bottom 32c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // corner of the shared edge is reserved for window 33c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // snapping. 34c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) WARP_NONE, // No mouse warping. Used when resizing the window. 35c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) }; 36c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 37c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) MouseCursorEventFilter(); 38c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual ~MouseCursorEventFilter(); 39c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 40c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void set_mouse_warp_mode(MouseWarpMode mouse_warp_mode) { 41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) mouse_warp_mode_ = mouse_warp_mode; 42c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 44c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Shows/Hide the indicator for window dragging. The |from| 45c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // is the window where the dragging started. 46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void ShowSharedEdgeIndicator(const aura::RootWindow* from); 47c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void HideSharedEdgeIndicator(); 48c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 49c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Overridden from aura::EventFilter: 50c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual bool PreHandleKeyEvent(aura::Window* target, 51c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ui::KeyEvent* event) OVERRIDE; 52c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual bool PreHandleMouseEvent(aura::Window* target, 53c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ui::MouseEvent* event) OVERRIDE; 54c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual ui::EventResult PreHandleTouchEvent( 55c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) aura::Window* target, 56c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ui::TouchEvent* event) OVERRIDE; 57c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual ui::EventResult PreHandleGestureEvent( 58c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) aura::Window* target, 59c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ui::GestureEvent* event) OVERRIDE; 60c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 61c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private: 62c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest, SetMouseWarpModeFlag); 63c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest, WarpMouse); 64c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest, 65c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) WarpMouseDifferentSizeDisplays); 66c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest, 67c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) IndicatorBoundsTestOnRight); 68c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest, 69c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) IndicatorBoundsTestOnLeft); 70c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest, 71c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) IndicatorBoundsTestOnTopBottom); 72c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest, CursorDeviceScaleFactor); 73c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(WorkspaceWindowResizerTest, WarpMousePointer); 74c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(WorkspaceWindowResizerTest, CursorDeviceScaleFactor); 75c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 76c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Warps the mouse cursor to an alternate root window when the 77c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // |point_in_screen|, which is the location of the mouse cursor, 78c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // hits or exceeds the edge of the |target_root| and the mouse cursor 79c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // is considered to be in an alternate display. Returns true if 80c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // the cursor was moved. 81c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool WarpMouseCursorIfNecessary(aura::RootWindow* target_root, 82c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const gfx::Point& point_in_screen); 83c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 84c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void UpdateHorizontalIndicatorWindowBounds(); 85c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void UpdateVerticalIndicatorWindowBounds(); 86c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 87c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) MouseWarpMode mouse_warp_mode_; 88c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 89c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // The bounds for warp hole windows. |dst_indicator_bounds_| is kept 90c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // in the instance for testing. 91c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) gfx::Rect src_indicator_bounds_; 92c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) gfx::Rect dst_indicator_bounds_; 93c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 94c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // The root window in which the dragging started. 95c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const aura::RootWindow* drag_source_root_; 96c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 97c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Shows the area where a window can be dragged in to/out from 98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // another display. 99c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) scoped_ptr<SharedDisplayEdgeIndicator> shared_display_edge_indicator_; 100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 101c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(MouseCursorEventFilter); 102c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 103c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 104c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} // namespace internal 105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} // namespace ash 106c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 107c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif // ASH_DISPLAY_MOUSE_CURSOR_EVENT_FILTER_H 108c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)