| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MASH_WM_MOVE_LOOP_H_ | |
| 6 #define MASH_WM_MOVE_LOOP_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "components/mus/public/cpp/window_observer.h" | |
| 11 #include "components/mus/public/interfaces/input_events.mojom.h" | |
| 12 #include "ui/gfx/geometry/point.h" | |
| 13 #include "ui/gfx/geometry/rect.h" | |
| 14 | |
| 15 // MoveLoop is responsible for moving/resizing windows. | |
| 16 class MoveLoop : public mus::WindowObserver { | |
| 17 public: | |
| 18 enum MoveResult { | |
| 19 // The move is still ongoing. | |
| 20 CONTINUE, | |
| 21 | |
| 22 // The move is done and the MoveLoop should be destroyed. | |
| 23 DONE, | |
| 24 }; | |
| 25 | |
| 26 enum class HorizontalLocation { | |
| 27 LEFT, | |
| 28 RIGHT, | |
| 29 OTHER, | |
| 30 }; | |
| 31 | |
| 32 enum class VerticalLocation { | |
| 33 TOP, | |
| 34 BOTTOM, | |
| 35 OTHER, | |
| 36 }; | |
| 37 | |
| 38 // Number of pixels in which a resize is triggered. | |
| 39 static const int kResizeSize = 8; | |
| 40 | |
| 41 ~MoveLoop() override; | |
| 42 | |
| 43 // If a move/resize loop should occur for the specified parameters creates | |
| 44 // and returns a new MoveLoop. All events should be funneled to the MoveLoop | |
| 45 // until done (Move()). | |
| 46 static scoped_ptr<MoveLoop> Create(mus::Window* target, | |
| 47 const mus::mojom::Event& event); | |
| 48 | |
| 49 // Processes an event for a move/resize loop. | |
| 50 MoveResult Move(const mus::mojom::Event& event); | |
| 51 | |
| 52 private: | |
| 53 enum class Type { | |
| 54 MOVE, | |
| 55 RESIZE, | |
| 56 }; | |
| 57 | |
| 58 MoveLoop(mus::Window* target, | |
| 59 const mus::mojom::Event& event, | |
| 60 Type type, | |
| 61 HorizontalLocation h_loc, | |
| 62 VerticalLocation v_loc); | |
| 63 | |
| 64 static void DetermineType(mus::Window* target, | |
| 65 const gfx::Point& location, | |
| 66 Type* type, | |
| 67 HorizontalLocation* h_loc, | |
| 68 VerticalLocation* v_loc); | |
| 69 | |
| 70 // Does the actual move/resize. | |
| 71 void MoveImpl(const mus::mojom::Event& event); | |
| 72 | |
| 73 // Cancels the loop. This sets |target_| to null and removes the observer. | |
| 74 // After this the MoveLoop is still ongoing and won't stop until the | |
| 75 // appropriate event is received. | |
| 76 void Cancel(); | |
| 77 | |
| 78 void Revert(); | |
| 79 | |
| 80 gfx::Rect DetermineBoundsFromDelta(const gfx::Vector2d& delta); | |
| 81 | |
| 82 // mus::WindowObserver: | |
| 83 void OnTreeChanged(const TreeChangeParams& params) override; | |
| 84 void OnWindowBoundsChanged(mus::Window* window, | |
| 85 const gfx::Rect& old_bounds, | |
| 86 const gfx::Rect& new_bounds) override; | |
| 87 void OnWindowVisibilityChanged(mus::Window* window) override; | |
| 88 | |
| 89 // The window this MoveLoop is acting on. |target_| is set to null if the | |
| 90 // window unexpectedly changes while the move is in progress. | |
| 91 mus::Window* target_; | |
| 92 | |
| 93 const Type type_; | |
| 94 const HorizontalLocation h_loc_; | |
| 95 const VerticalLocation v_loc_; | |
| 96 | |
| 97 // The id of the pointer that triggered the move. | |
| 98 const int32_t pointer_id_; | |
| 99 | |
| 100 // Location of the event (in screen coordinates) that triggered the move. | |
| 101 const gfx::Point initial_event_screen_location_; | |
| 102 | |
| 103 // Original bounds of the window. | |
| 104 const gfx::Rect initial_window_bounds_; | |
| 105 | |
| 106 const gfx::Rect initial_user_set_bounds_; | |
| 107 | |
| 108 // Set to true when MoveLoop changes the bounds of |target_|. The move is | |
| 109 // canceled if the bounds change unexpectedly during the move. | |
| 110 bool changing_bounds_; | |
| 111 | |
| 112 DISALLOW_COPY_AND_ASSIGN(MoveLoop); | |
| 113 }; | |
| 114 | |
| 115 #endif // MASH_WM_MOVE_LOOP_H_ | |
| OLD | NEW |