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