| 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/gfx/geometry/point_conversions.h" | 12 #include "ui/gfx/geometry/point_conversions.h" |
| 13 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
| 14 | 14 |
| 15 namespace mash { | 15 namespace mash { |
| 16 namespace wm { | 16 namespace wm { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 gfx::Point EventScreenLocationToPoint(const mus::mojom::Event& event) { | 20 gfx::Point EventScreenLocationToPoint(const mus::mojom::Event& event) { |
| 21 return gfx::ToFlooredPoint( | 21 return gfx::ToFlooredPoint( |
| 22 gfx::PointF(event.pointer_data->location->screen_x, | 22 gfx::PointF(event.pointer_data->location->screen_x, |
| 23 event.pointer_data->location->screen_y)); | 23 event.pointer_data->location->screen_y)); |
| 24 } | 24 } |
| 25 | 25 |
| 26 mus::mojom::EventFlags MouseOnlyEventFlags(mus::mojom::EventFlags flags) { | 26 int MouseOnlyEventFlags(int flags) { |
| 27 return static_cast<mus::mojom::EventFlags>( | 27 return flags & (mus::mojom::kEventFlagLeftMouseButton | |
| 28 flags & (mus::mojom::EVENT_FLAGS_LEFT_MOUSE_BUTTON | | 28 mus::mojom::kEventFlagMiddleMouseButton | |
| 29 mus::mojom::EVENT_FLAGS_MIDDLE_MOUSE_BUTTON | | 29 mus::mojom::kEventFlagRightMouseButton); |
| 30 mus::mojom::EVENT_FLAGS_RIGHT_MOUSE_BUTTON)); | |
| 31 } | 30 } |
| 32 | 31 |
| 33 } // namespace | 32 } // namespace |
| 34 | 33 |
| 35 MoveLoop::~MoveLoop() { | 34 MoveLoop::~MoveLoop() { |
| 36 if (target_) | 35 if (target_) |
| 37 target_->RemoveObserver(this); | 36 target_->RemoveObserver(this); |
| 38 } | 37 } |
| 39 | 38 |
| 40 // static | 39 // static |
| 41 scoped_ptr<MoveLoop> MoveLoop::Create(mus::Window* target, | 40 scoped_ptr<MoveLoop> MoveLoop::Create(mus::Window* target, |
| 42 int ht_location, | 41 int ht_location, |
| 43 const mus::mojom::Event& event) { | 42 const mus::mojom::Event& event) { |
| 44 DCHECK_EQ(event.action, mus::mojom::EVENT_TYPE_POINTER_DOWN); | 43 DCHECK_EQ(event.action, mus::mojom::EventType::POINTER_DOWN); |
| 45 // Start a move on left mouse, or any other type of pointer. | 44 // Start a move on left mouse, or any other type of pointer. |
| 46 if (event.pointer_data->kind == mus::mojom::POINTER_KIND_MOUSE && | 45 if (event.pointer_data->kind == mus::mojom::PointerKind::MOUSE && |
| 47 MouseOnlyEventFlags(event.flags) != | 46 MouseOnlyEventFlags(event.flags) != |
| 48 mus::mojom::EVENT_FLAGS_LEFT_MOUSE_BUTTON) { | 47 mus::mojom::kEventFlagLeftMouseButton) { |
| 49 return nullptr; | 48 return nullptr; |
| 50 } | 49 } |
| 51 | 50 |
| 52 Type type; | 51 Type type; |
| 53 HorizontalLocation h_loc; | 52 HorizontalLocation h_loc; |
| 54 VerticalLocation v_loc; | 53 VerticalLocation v_loc; |
| 55 if (!DetermineType(ht_location, &type, &h_loc, &v_loc)) | 54 if (!DetermineType(ht_location, &type, &h_loc, &v_loc)) |
| 56 return nullptr; | 55 return nullptr; |
| 57 | 56 |
| 58 return make_scoped_ptr(new MoveLoop(target, event, type, h_loc, v_loc)); | 57 return make_scoped_ptr(new MoveLoop(target, event, type, h_loc, v_loc)); |
| 59 } | 58 } |
| 60 | 59 |
| 61 MoveLoop::MoveResult MoveLoop::Move(const mus::mojom::Event& event) { | 60 MoveLoop::MoveResult MoveLoop::Move(const mus::mojom::Event& event) { |
| 62 switch (event.action) { | 61 switch (event.action) { |
| 63 case mus::mojom::EVENT_TYPE_POINTER_CANCEL: | 62 case mus::mojom::EventType::POINTER_CANCEL: |
| 64 if (event.pointer_data->pointer_id == pointer_id_) { | 63 if (event.pointer_data->pointer_id == pointer_id_) { |
| 65 if (target_) | 64 if (target_) |
| 66 Revert(); | 65 Revert(); |
| 67 return MoveResult::DONE; | 66 return MoveResult::DONE; |
| 68 } | 67 } |
| 69 return MoveResult::CONTINUE; | 68 return MoveResult::CONTINUE; |
| 70 | 69 |
| 71 case mus::mojom::EVENT_TYPE_POINTER_MOVE: | 70 case mus::mojom::EventType::POINTER_MOVE: |
| 72 if (target_ && event.pointer_data->pointer_id == pointer_id_) | 71 if (target_ && event.pointer_data->pointer_id == pointer_id_) |
| 73 MoveImpl(event); | 72 MoveImpl(event); |
| 74 return MoveResult::CONTINUE; | 73 return MoveResult::CONTINUE; |
| 75 | 74 |
| 76 case mus::mojom::EVENT_TYPE_POINTER_UP: | 75 case mus::mojom::EventType::POINTER_UP: |
| 77 if (event.pointer_data->pointer_id == pointer_id_) { | 76 if (event.pointer_data->pointer_id == pointer_id_) { |
| 78 // TODO(sky): need to support changed_flags. | 77 // TODO(sky): need to support changed_flags. |
| 79 if (target_) | 78 if (target_) |
| 80 MoveImpl(event); | 79 MoveImpl(event); |
| 81 return MoveResult::DONE; | 80 return MoveResult::DONE; |
| 82 } | 81 } |
| 83 return MoveResult::CONTINUE; | 82 return MoveResult::CONTINUE; |
| 84 | 83 |
| 85 default: | 84 default: |
| 86 break; | 85 break; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 Cancel(); | 225 Cancel(); |
| 227 } | 226 } |
| 228 | 227 |
| 229 void MoveLoop::OnWindowVisibilityChanged(mus::Window* window) { | 228 void MoveLoop::OnWindowVisibilityChanged(mus::Window* window) { |
| 230 DCHECK_EQ(window, target_); | 229 DCHECK_EQ(window, target_); |
| 231 Cancel(); | 230 Cancel(); |
| 232 } | 231 } |
| 233 | 232 |
| 234 } // namespace wm | 233 } // namespace wm |
| 235 } // namespace mash | 234 } // namespace mash |
| OLD | NEW |