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 #include "components/mus/example/wm/move_loop.h" | 5 #include "components/mus/example/wm/move_loop.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "components/mus/example/wm/property_util.h" | 8 #include "components/mus/example/wm/property_util.h" |
9 #include "components/mus/public/cpp/window.h" | 9 #include "components/mus/public/cpp/window.h" |
10 #include "components/mus/public/interfaces/input_event_constants.mojom.h" | 10 #include "components/mus/public/interfaces/input_event_constants.mojom.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 event.pointer_data->location->screen_y)); | 24 event.pointer_data->location->screen_y)); |
25 } | 25 } |
26 | 26 |
27 mus::mojom::EventFlags MouseOnlyEventFlags(mus::mojom::EventFlags flags) { | 27 mus::mojom::EventFlags MouseOnlyEventFlags(mus::mojom::EventFlags flags) { |
28 return static_cast<mus::mojom::EventFlags>( | 28 return static_cast<mus::mojom::EventFlags>( |
29 flags & (mus::mojom::EVENT_FLAGS_LEFT_MOUSE_BUTTON | | 29 flags & (mus::mojom::EVENT_FLAGS_LEFT_MOUSE_BUTTON | |
30 mus::mojom::EVENT_FLAGS_MIDDLE_MOUSE_BUTTON | | 30 mus::mojom::EVENT_FLAGS_MIDDLE_MOUSE_BUTTON | |
31 mus::mojom::EVENT_FLAGS_RIGHT_MOUSE_BUTTON)); | 31 mus::mojom::EVENT_FLAGS_RIGHT_MOUSE_BUTTON)); |
32 } | 32 } |
33 | 33 |
| 34 gfx::Rect ClientAreaBounds(const mus::Window* window) { |
| 35 gfx::Rect client_area(window->bounds().size()); |
| 36 client_area.Inset(window->client_area()); |
| 37 return client_area; |
| 38 } |
| 39 |
34 } // namespace | 40 } // namespace |
35 | 41 |
36 MoveLoop::~MoveLoop() { | 42 MoveLoop::~MoveLoop() { |
37 if (target_) | 43 if (target_) |
38 target_->RemoveObserver(this); | 44 target_->RemoveObserver(this); |
39 } | 45 } |
40 | 46 |
41 // static | 47 // static |
42 scoped_ptr<MoveLoop> MoveLoop::Create(mus::Window* target, | 48 scoped_ptr<MoveLoop> MoveLoop::Create(mus::Window* target, |
43 const mus::mojom::Event& event) { | 49 const mus::mojom::Event& event) { |
44 DCHECK_EQ(event.action, mus::mojom::EVENT_TYPE_POINTER_DOWN); | 50 DCHECK_EQ(event.action, mus::mojom::EVENT_TYPE_POINTER_DOWN); |
45 const gfx::Point location(EventLocationToPoint(event)); | 51 const gfx::Point location(EventLocationToPoint(event)); |
46 if (!gfx::Rect(target->bounds().size()).Contains(location) || | 52 if (!gfx::Rect(target->bounds().size()).Contains(location) || |
47 target->client_area().Contains(location)) { | 53 ClientAreaBounds(target).Contains(location)) { |
48 return nullptr; | 54 return nullptr; |
49 } | 55 } |
50 | 56 |
51 // Start a move on left mouse, or any other type of pointer. | 57 // Start a move on left mouse, or any other type of pointer. |
52 if (event.pointer_data->kind == mus::mojom::POINTER_KIND_MOUSE && | 58 if (event.pointer_data->kind == mus::mojom::POINTER_KIND_MOUSE && |
53 MouseOnlyEventFlags(event.flags) != | 59 MouseOnlyEventFlags(event.flags) != |
54 mus::mojom::EVENT_FLAGS_LEFT_MOUSE_BUTTON) { | 60 mus::mojom::EVENT_FLAGS_LEFT_MOUSE_BUTTON) { |
55 return nullptr; | 61 return nullptr; |
56 } | 62 } |
57 | 63 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 const gfx::Point& location, | 122 const gfx::Point& location, |
117 Type* type, | 123 Type* type, |
118 HorizontalLocation* h_loc, | 124 HorizontalLocation* h_loc, |
119 VerticalLocation* v_loc) { | 125 VerticalLocation* v_loc) { |
120 *h_loc = HorizontalLocation::OTHER; | 126 *h_loc = HorizontalLocation::OTHER; |
121 *v_loc = VerticalLocation::OTHER; | 127 *v_loc = VerticalLocation::OTHER; |
122 const int resize_size = static_cast<int>( | 128 const int resize_size = static_cast<int>( |
123 kResizeSize * | 129 kResizeSize * |
124 std::max(1.f, target->viewport_metrics().device_pixel_ratio)); | 130 std::max(1.f, target->viewport_metrics().device_pixel_ratio)); |
125 | 131 |
126 if (location.x() < target->client_area().x()) | 132 const gfx::Rect client_area(ClientAreaBounds(target)); |
| 133 if (location.x() < client_area.x()) |
127 *h_loc = HorizontalLocation::LEFT; | 134 *h_loc = HorizontalLocation::LEFT; |
128 else if (location.x() >= target->client_area().right()) | 135 else if (location.x() >= client_area.right()) |
129 *h_loc = HorizontalLocation::RIGHT; | 136 *h_loc = HorizontalLocation::RIGHT; |
130 else | 137 else |
131 *h_loc = HorizontalLocation::OTHER; | 138 *h_loc = HorizontalLocation::OTHER; |
132 | 139 |
133 if (location.y() < resize_size) | 140 if (location.y() < resize_size) |
134 *v_loc = VerticalLocation::TOP; | 141 *v_loc = VerticalLocation::TOP; |
135 else if (location.y() >= target->client_area().bottom()) | 142 else if (location.y() >= client_area.bottom()) |
136 *v_loc = VerticalLocation::BOTTOM; | 143 *v_loc = VerticalLocation::BOTTOM; |
137 else | 144 else |
138 *v_loc = VerticalLocation::OTHER; | 145 *v_loc = VerticalLocation::OTHER; |
139 | 146 |
140 if (*v_loc == VerticalLocation::OTHER && location.y() >= resize_size && | 147 if (*v_loc == VerticalLocation::OTHER && location.y() >= resize_size && |
141 *h_loc == HorizontalLocation::OTHER) { | 148 *h_loc == HorizontalLocation::OTHER) { |
142 *type = Type::MOVE; | 149 *type = Type::MOVE; |
143 return; | 150 return; |
144 } | 151 } |
145 *type = Type::RESIZE; | 152 *type = Type::RESIZE; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 const gfx::Rect& new_bounds) { | 214 const gfx::Rect& new_bounds) { |
208 DCHECK_EQ(window, target_); | 215 DCHECK_EQ(window, target_); |
209 if (!changing_bounds_) | 216 if (!changing_bounds_) |
210 Cancel(); | 217 Cancel(); |
211 } | 218 } |
212 | 219 |
213 void MoveLoop::OnWindowVisibilityChanged(mus::Window* window) { | 220 void MoveLoop::OnWindowVisibilityChanged(mus::Window* window) { |
214 DCHECK_EQ(window, target_); | 221 DCHECK_EQ(window, target_); |
215 Cancel(); | 222 Cancel(); |
216 } | 223 } |
OLD | NEW |