OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ASH_DISPLAY_EXTENDED_MOUSE_WARP_CONTROLLER_H | 5 #ifndef ASH_DISPLAY_EXTENDED_MOUSE_WARP_CONTROLLER_H |
6 #define ASH_DISPLAY_EXTENDED_MOUSE_WARP_CONTROLLER_H | 6 #define ASH_DISPLAY_EXTENDED_MOUSE_WARP_CONTROLLER_H |
7 | 7 |
8 #include "ash/display/mouse_warp_controller.h" | 8 #include "ash/display/mouse_warp_controller.h" |
9 | 9 |
| 10 #include <vector> |
| 11 |
| 12 #include "ash/display/display_layout.h" |
10 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
11 #include "base/macros.h" | 14 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
13 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
14 | 17 |
15 namespace aura { | 18 namespace aura { |
16 class Window; | 19 class Window; |
17 } | 20 } |
18 | 21 |
19 namespace gfx { | 22 namespace gfx { |
20 class Point; | 23 class Point; |
| 24 class Display; |
21 } | 25 } |
22 | 26 |
23 namespace ash { | 27 namespace ash { |
24 namespace test { | 28 namespace test { |
25 class DisplayManagerTestApi; | 29 class DisplayManagerTestApi; |
26 } | 30 } |
27 class SharedDisplayEdgeIndicator; | 31 class SharedDisplayEdgeIndicator; |
28 | 32 |
29 // A MouseWarpController used in extended display mode. | 33 // A MouseWarpController used in extended display mode. |
30 class ASH_EXPORT ExtendedMouseWarpController : public MouseWarpController { | 34 class ASH_EXPORT ExtendedMouseWarpController : public MouseWarpController { |
31 public: | 35 public: |
32 explicit ExtendedMouseWarpController(aura::Window* drag_source); | 36 explicit ExtendedMouseWarpController(aura::Window* drag_source); |
33 ~ExtendedMouseWarpController() override; | 37 ~ExtendedMouseWarpController() override; |
34 | 38 |
35 // MouseWarpController: | 39 // MouseWarpController: |
36 bool WarpMouseCursor(ui::MouseEvent* event) override; | 40 bool WarpMouseCursor(ui::MouseEvent* event) override; |
37 void SetEnabled(bool enable) override; | 41 void SetEnabled(bool enable) override; |
38 | 42 |
39 private: | 43 private: |
40 friend class test::DisplayManagerTestApi; | 44 friend class test::DisplayManagerTestApi; |
41 FRIEND_TEST_ALL_PREFIXES(ExtendedMouseWarpControllerTest, | 45 FRIEND_TEST_ALL_PREFIXES(ExtendedMouseWarpControllerTest, |
42 IndicatorBoundsTestOnRight); | 46 IndicatorBoundsTestOnRight); |
43 FRIEND_TEST_ALL_PREFIXES(ExtendedMouseWarpControllerTest, | 47 FRIEND_TEST_ALL_PREFIXES(ExtendedMouseWarpControllerTest, |
44 IndicatorBoundsTestOnLeft); | 48 IndicatorBoundsTestOnLeft); |
45 FRIEND_TEST_ALL_PREFIXES(ExtendedMouseWarpControllerTest, | 49 FRIEND_TEST_ALL_PREFIXES(ExtendedMouseWarpControllerTest, |
46 IndicatorBoundsTestOnTopBottom); | 50 IndicatorBoundsTestOnTopBottom); |
| 51 FRIEND_TEST_ALL_PREFIXES(ExtendedMouseWarpControllerTest, |
| 52 IndicatorBoundsTestThreeDisplays); |
| 53 |
| 54 // Defined in header file because tests need access. |
| 55 struct WarpRegion { |
| 56 public: |
| 57 WarpRegion(int64_t a_display_id, |
| 58 int64_t b_display_id, |
| 59 const gfx::Rect& a_indicator_bounds, |
| 60 const gfx::Rect& b_indicator_bounds); |
| 61 ~WarpRegion(); |
| 62 |
| 63 // If the mouse cursor is in |a_edge_bounds_in_native|, then it will be |
| 64 // moved to |b_display_id|. Similarily, if the cursor is in |
| 65 // |b_edge_bounds_in_native|, then it will be moved to |a_display_id|. |
| 66 |
| 67 // The id for the displays. Used for warping the cursor. |
| 68 int64_t a_display_id; |
| 69 int64_t b_display_id; |
| 70 |
| 71 gfx::Rect a_edge_bounds_in_native; |
| 72 gfx::Rect b_edge_bounds_in_native; |
| 73 |
| 74 // The bounds for warp hole windows. These are kept in the instance for |
| 75 // testing. |
| 76 gfx::Rect a_indicator_bounds; |
| 77 gfx::Rect b_indicator_bounds; |
| 78 |
| 79 // Shows the area where a window can be dragged in to/out from another |
| 80 // display. |
| 81 scoped_ptr<SharedDisplayEdgeIndicator> shared_display_edge_indicator; |
| 82 |
| 83 private: |
| 84 DISALLOW_COPY_AND_ASSIGN(WarpRegion); |
| 85 }; |
| 86 |
| 87 std::vector<scoped_ptr<WarpRegion>> warp_regions_; |
| 88 |
| 89 // Registers the WarpRegion; also displays a drag indicator on the screen if |
| 90 // |drag_source| is true. |
| 91 void AddWarpRegion(scoped_ptr<WarpRegion> region, bool drag_source); |
47 | 92 |
48 // Warps the mouse cursor to an alternate root window when the | 93 // Warps the mouse cursor to an alternate root window when the |
49 // mouse location in |event|, hits the edge of the event target's root and | 94 // mouse location in |event|, hits the edge of the event target's root and |
50 // the mouse cursor is considered to be in an alternate display. | 95 // the mouse cursor is considered to be in an alternate display. |
51 // If |update_mouse_location_now| is true, | 96 // If |update_mouse_location_now| is true, |
52 // Returns true if/ the cursor was moved. | 97 // Returns true if/ the cursor was moved. |
53 bool WarpMouseCursorInNativeCoords(const gfx::Point& point_in_native, | 98 bool WarpMouseCursorInNativeCoords(const gfx::Point& point_in_native, |
54 const gfx::Point& point_in_screen, | 99 const gfx::Point& point_in_screen, |
55 bool update_mouse_location_now); | 100 bool update_mouse_location_now); |
56 | 101 |
57 // Update the edge/indicator bounds based on the current | 102 // Update the edge/indicator bounds based on the current |
58 // display configuration. | 103 // display configuration. |
59 void UpdateHorizontalEdgeBounds(); | 104 scoped_ptr<WarpRegion> CreateHorizontalEdgeBounds( |
60 void UpdateVerticalEdgeBounds(); | 105 const gfx::Display& a, |
61 | 106 const gfx::Display& b, |
62 // Returns the source and destination window. When |src_window| is | 107 DisplayLayout::Position position); |
63 // |drag_soruce_root_| when it is set. Otherwise, the |src_window| | 108 scoped_ptr<WarpRegion> CreateVerticalEdgeBounds( |
64 // is always the primary root window, because there is no difference | 109 const gfx::Display& a, |
65 // between moving src to dst and moving dst to src. | 110 const gfx::Display& b, |
66 void GetSrcAndDstRootWindows(aura::Window** src_window, | 111 DisplayLayout::Position position); |
67 aura::Window** dst_window); | |
68 | 112 |
69 void allow_non_native_event_for_test() { allow_non_native_event_ = true; } | 113 void allow_non_native_event_for_test() { allow_non_native_event_ = true; } |
70 | 114 |
71 // The bounds for warp hole windows. |dst_indicator_bounds_| is kept | |
72 // in the instance for testing. | |
73 gfx::Rect src_indicator_bounds_; | |
74 gfx::Rect dst_indicator_bounds_; | |
75 | |
76 gfx::Rect src_edge_bounds_in_native_; | |
77 gfx::Rect dst_edge_bounds_in_native_; | |
78 | |
79 // The root window in which the dragging started. | 115 // The root window in which the dragging started. |
80 aura::Window* drag_source_root_; | 116 aura::Window* drag_source_root_; |
81 | 117 |
82 bool enabled_; | 118 bool enabled_; |
83 | 119 |
84 // Shows the area where a window can be dragged in to/out from | |
85 // another display. | |
86 scoped_ptr<SharedDisplayEdgeIndicator> shared_display_edge_indicator_; | |
87 | |
88 bool allow_non_native_event_; | 120 bool allow_non_native_event_; |
89 | 121 |
90 DISALLOW_COPY_AND_ASSIGN(ExtendedMouseWarpController); | 122 DISALLOW_COPY_AND_ASSIGN(ExtendedMouseWarpController); |
91 }; | 123 }; |
92 | 124 |
93 } // namespace ash | 125 } // namespace ash |
94 | 126 |
95 #endif // ASH_DISPLAY_EXTENDED_MOUSE_WARP_CONTROLLER_H | 127 #endif // ASH_DISPLAY_EXTENDED_MOUSE_WARP_CONTROLLER_H |
OLD | NEW |