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 "mash/wm/frame/move_loop.h" | 5 #include "mash/wm/frame/move_loop.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "components/mus/public/cpp/window.h" | 8 #include "components/mus/public/cpp/window.h" |
9 #include "components/mus/public/interfaces/input_event_constants.mojom.h" | 9 #include "components/mus/public/interfaces/input_event_constants.mojom.h" |
10 #include "mash/wm/property_util.h" | 10 #include "mash/wm/property_util.h" |
11 #include "ui/base/hit_test.h" | 11 #include "ui/base/hit_test.h" |
| 12 #include "ui/events/event.h" |
12 #include "ui/gfx/geometry/point_conversions.h" | 13 #include "ui/gfx/geometry/point_conversions.h" |
13 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
14 | 15 |
15 namespace mash { | 16 namespace mash { |
16 namespace wm { | 17 namespace wm { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 gfx::Point EventScreenLocationToPoint(const mus::mojom::Event& event) { | |
21 return gfx::ToFlooredPoint( | |
22 gfx::PointF(event.pointer_data->location->screen_x, | |
23 event.pointer_data->location->screen_y)); | |
24 } | |
25 | |
26 int MouseOnlyEventFlags(int flags) { | 21 int MouseOnlyEventFlags(int flags) { |
27 return flags & (mus::mojom::kEventFlagLeftMouseButton | | 22 return flags & (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON | |
28 mus::mojom::kEventFlagMiddleMouseButton | | 23 ui::EF_RIGHT_MOUSE_BUTTON); |
29 mus::mojom::kEventFlagRightMouseButton); | |
30 } | 24 } |
31 | 25 |
32 } // namespace | 26 } // namespace |
33 | 27 |
34 MoveLoop::~MoveLoop() { | 28 MoveLoop::~MoveLoop() { |
35 if (target_) | 29 if (target_) |
36 target_->RemoveObserver(this); | 30 target_->RemoveObserver(this); |
37 } | 31 } |
38 | 32 |
39 // static | 33 // static |
40 scoped_ptr<MoveLoop> MoveLoop::Create(mus::Window* target, | 34 scoped_ptr<MoveLoop> MoveLoop::Create(mus::Window* target, |
41 int ht_location, | 35 int ht_location, |
42 const mus::mojom::Event& event) { | 36 const ui::PointerEvent& event) { |
43 DCHECK_EQ(event.action, mus::mojom::EventType::POINTER_DOWN); | 37 DCHECK_EQ(event.type(), ui::ET_POINTER_DOWN); |
44 // Start a move on left mouse, or any other type of pointer. | 38 // Start a move on left mouse, or any other type of pointer. |
45 if (event.pointer_data->kind == mus::mojom::PointerKind::MOUSE && | 39 if (event.IsMousePointerEvent() && |
46 MouseOnlyEventFlags(event.flags) != | 40 MouseOnlyEventFlags(event.flags()) != ui::EF_LEFT_MOUSE_BUTTON) { |
47 mus::mojom::kEventFlagLeftMouseButton) { | |
48 return nullptr; | 41 return nullptr; |
49 } | 42 } |
50 | 43 |
51 Type type; | 44 Type type; |
52 HorizontalLocation h_loc; | 45 HorizontalLocation h_loc; |
53 VerticalLocation v_loc; | 46 VerticalLocation v_loc; |
54 if (!DetermineType(ht_location, &type, &h_loc, &v_loc)) | 47 if (!DetermineType(ht_location, &type, &h_loc, &v_loc)) |
55 return nullptr; | 48 return nullptr; |
56 | 49 |
57 return make_scoped_ptr(new MoveLoop(target, event, type, h_loc, v_loc)); | 50 return make_scoped_ptr(new MoveLoop(target, event, type, h_loc, v_loc)); |
58 } | 51 } |
59 | 52 |
60 MoveLoop::MoveResult MoveLoop::Move(const mus::mojom::Event& event) { | 53 MoveLoop::MoveResult MoveLoop::Move(const ui::PointerEvent& event) { |
61 switch (event.action) { | 54 switch (event.type()) { |
62 case mus::mojom::EventType::POINTER_CANCEL: | 55 case ui::ET_POINTER_CANCELLED: |
63 if (event.pointer_data->pointer_id == pointer_id_) { | 56 if (event.pointer_id() == pointer_id_) { |
64 if (target_) | 57 if (target_) |
65 Revert(); | 58 Revert(); |
66 return MoveResult::DONE; | 59 return MoveResult::DONE; |
67 } | 60 } |
68 return MoveResult::CONTINUE; | 61 return MoveResult::CONTINUE; |
69 | 62 |
70 case mus::mojom::EventType::POINTER_MOVE: | 63 case ui::ET_POINTER_MOVED: |
71 if (target_ && event.pointer_data->pointer_id == pointer_id_) | 64 if (target_ && event.pointer_id() == pointer_id_) |
72 MoveImpl(event); | 65 MoveImpl(event); |
73 return MoveResult::CONTINUE; | 66 return MoveResult::CONTINUE; |
74 | 67 |
75 case mus::mojom::EventType::POINTER_UP: | 68 case ui::ET_POINTER_UP: |
76 if (event.pointer_data->pointer_id == pointer_id_) { | 69 if (event.pointer_id() == pointer_id_) { |
77 // TODO(sky): need to support changed_flags. | 70 // TODO(sky): need to support changed_flags. |
78 if (target_) | 71 if (target_) |
79 MoveImpl(event); | 72 MoveImpl(event); |
80 return MoveResult::DONE; | 73 return MoveResult::DONE; |
81 } | 74 } |
82 return MoveResult::CONTINUE; | 75 return MoveResult::CONTINUE; |
83 | 76 |
84 default: | 77 default: |
85 break; | 78 break; |
86 } | 79 } |
87 | 80 |
88 return MoveResult::CONTINUE; | 81 return MoveResult::CONTINUE; |
89 } | 82 } |
90 | 83 |
91 void MoveLoop::Revert() { | 84 void MoveLoop::Revert() { |
92 if (!target_) | 85 if (!target_) |
93 return; | 86 return; |
94 | 87 |
95 base::AutoReset<bool> resetter(&changing_bounds_, true); | 88 base::AutoReset<bool> resetter(&changing_bounds_, true); |
96 target_->SetBounds(initial_window_bounds_); | 89 target_->SetBounds(initial_window_bounds_); |
97 SetWindowUserSetBounds(target_, initial_user_set_bounds_); | 90 SetWindowUserSetBounds(target_, initial_user_set_bounds_); |
98 } | 91 } |
99 | 92 |
100 MoveLoop::MoveLoop(mus::Window* target, | 93 MoveLoop::MoveLoop(mus::Window* target, |
101 const mus::mojom::Event& event, | 94 const ui::PointerEvent& event, |
102 Type type, | 95 Type type, |
103 HorizontalLocation h_loc, | 96 HorizontalLocation h_loc, |
104 VerticalLocation v_loc) | 97 VerticalLocation v_loc) |
105 : target_(target), | 98 : target_(target), |
106 type_(type), | 99 type_(type), |
107 h_loc_(h_loc), | 100 h_loc_(h_loc), |
108 v_loc_(v_loc), | 101 v_loc_(v_loc), |
109 pointer_id_(event.pointer_data->pointer_id), | 102 pointer_id_(event.pointer_id()), |
110 initial_event_screen_location_(EventScreenLocationToPoint(event)), | 103 initial_event_screen_location_(event.root_location()), |
111 initial_window_bounds_(target->bounds()), | 104 initial_window_bounds_(target->bounds()), |
112 initial_user_set_bounds_(GetWindowUserSetBounds(target)), | 105 initial_user_set_bounds_(GetWindowUserSetBounds(target)), |
113 changing_bounds_(false) { | 106 changing_bounds_(false) { |
114 target->AddObserver(this); | 107 target->AddObserver(this); |
115 } | 108 } |
116 | 109 |
117 // static | 110 // static |
118 bool MoveLoop::DetermineType(int ht_location, | 111 bool MoveLoop::DetermineType(int ht_location, |
119 Type* type, | 112 Type* type, |
120 HorizontalLocation* h_loc, | 113 HorizontalLocation* h_loc, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 case HTLEFT: | 154 case HTLEFT: |
162 *type = Type::RESIZE; | 155 *type = Type::RESIZE; |
163 *h_loc = HorizontalLocation::LEFT; | 156 *h_loc = HorizontalLocation::LEFT; |
164 return true; | 157 return true; |
165 default: | 158 default: |
166 break; | 159 break; |
167 } | 160 } |
168 return false; | 161 return false; |
169 } | 162 } |
170 | 163 |
171 void MoveLoop::MoveImpl(const mus::mojom::Event& event) { | 164 void MoveLoop::MoveImpl(const ui::PointerEvent& event) { |
172 const gfx::Vector2d delta = | 165 const gfx::Vector2d delta = |
173 EventScreenLocationToPoint(event) - initial_event_screen_location_; | 166 event.root_location() - initial_event_screen_location_; |
174 const gfx::Rect new_bounds(DetermineBoundsFromDelta(delta)); | 167 const gfx::Rect new_bounds(DetermineBoundsFromDelta(delta)); |
175 base::AutoReset<bool> resetter(&changing_bounds_, true); | 168 base::AutoReset<bool> resetter(&changing_bounds_, true); |
176 target_->SetBounds(new_bounds); | 169 target_->SetBounds(new_bounds); |
177 SetWindowUserSetBounds(target_, new_bounds); | 170 SetWindowUserSetBounds(target_, new_bounds); |
178 } | 171 } |
179 | 172 |
180 void MoveLoop::Cancel() { | 173 void MoveLoop::Cancel() { |
181 target_->RemoveObserver(this); | 174 target_->RemoveObserver(this); |
182 target_ = nullptr; | 175 target_ = nullptr; |
183 } | 176 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 Cancel(); | 218 Cancel(); |
226 } | 219 } |
227 | 220 |
228 void MoveLoop::OnWindowVisibilityChanged(mus::Window* window) { | 221 void MoveLoop::OnWindowVisibilityChanged(mus::Window* window) { |
229 DCHECK_EQ(window, target_); | 222 DCHECK_EQ(window, target_); |
230 Cancel(); | 223 Cancel(); |
231 } | 224 } |
232 | 225 |
233 } // namespace wm | 226 } // namespace wm |
234 } // namespace mash | 227 } // namespace mash |
OLD | NEW |