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