mouse_cursor_event_filter.h revision 1e9bf3e0803691d0a228da41fc608347b6db4340
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;
22
23namespace internal {
24class SharedDisplayEdgeIndicator;
25
26// An event filter that controls mouse location in extended desktop
27// environment.
28class ASH_EXPORT MouseCursorEventFilter : public ui::EventHandler {
29 public:
30  enum MouseWarpMode {
31    WARP_ALWAYS,   // Always warp the mouse when possible.
32    WARP_DRAG,     // Used when dragging a window. Top and bottom
33                   // corner of the shared edge is reserved for window
34                   // snapping.
35    WARP_NONE,     // No mouse warping. Used when resizing the window.
36  };
37
38  MouseCursorEventFilter();
39  virtual ~MouseCursorEventFilter();
40
41  void set_mouse_warp_mode(MouseWarpMode mouse_warp_mode) {
42    mouse_warp_mode_ = mouse_warp_mode;
43  }
44
45  // Shows/Hide the indicator for window dragging. The |from|
46  // is the window where the dragging started.
47  void ShowSharedEdgeIndicator(const aura::Window* from);
48  void HideSharedEdgeIndicator();
49
50  // Overridden from ui::EventHandler:
51  virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
52
53 private:
54  friend class DragWindowResizerTest;
55  friend class MouseCursorEventFilterTest;
56  FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest, DoNotWarpTwice);
57  FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest, SetMouseWarpModeFlag);
58  FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest,
59                           IndicatorBoundsTestOnRight);
60  FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest,
61                           IndicatorBoundsTestOnLeft);
62  FRIEND_TEST_ALL_PREFIXES(MouseCursorEventFilterTest,
63                           IndicatorBoundsTestOnTopBottom);
64  FRIEND_TEST_ALL_PREFIXES(DragWindowResizerTest, WarpMousePointer);
65
66  void reset_was_mouse_warped_for_test() { was_mouse_warped_ = false; }
67
68  // Warps the mouse cursor to an alternate root window when the
69  // |point_in_screen|, which is the location of the mouse cursor,
70  // hits or exceeds the edge of the |target_root| and the mouse cursor
71  // is considered to be in an alternate display. Returns true if
72  // the cursor was moved.
73  bool WarpMouseCursorIfNecessary(aura::Window* target_root,
74                                  const gfx::Point& point_in_screen);
75
76  void UpdateHorizontalIndicatorWindowBounds();
77  void UpdateVerticalIndicatorWindowBounds();
78
79  MouseWarpMode mouse_warp_mode_;
80
81  // This flag is used to suppress the accidental mouse warp back to the
82  // original display.
83  bool was_mouse_warped_;
84
85  // The bounds for warp hole windows. |dst_indicator_bounds_| is kept
86  // in the instance for testing.
87  gfx::Rect src_indicator_bounds_;
88  gfx::Rect dst_indicator_bounds_;
89
90  // The root window in which the dragging started.
91  const aura::Window* drag_source_root_;
92
93  float scale_when_drag_started_;
94
95  // Shows the area where a window can be dragged in to/out from
96  // another display.
97  scoped_ptr<SharedDisplayEdgeIndicator> shared_display_edge_indicator_;
98
99  DISALLOW_COPY_AND_ASSIGN(MouseCursorEventFilter);
100};
101
102}  // namespace internal
103}  // namespace ash
104
105#endif  // ASH_DISPLAY_MOUSE_CURSOR_EVENT_FILTER_H
106