| 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 COMPONENTS_MUS_WS_MOVE_LOOP_H_ | 5 #ifndef COMPONENTS_MUS_EXAMPLE_WM_MOVE_LOOP_H_ |
| 6 #define COMPONENTS_MUS_WS_MOVE_LOOP_H_ | 6 #define COMPONENTS_MUS_EXAMPLE_WM_MOVE_LOOP_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "components/mus/ws/server_window_observer.h" | 10 #include "components/mus/public/cpp/window_observer.h" |
| 11 #include "ui/gfx/geometry/point.h" | 11 #include "ui/gfx/geometry/point.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
| 13 #include "ui/mojo/events/input_events.mojom.h" | 13 #include "ui/mojo/events/input_events.mojom.h" |
| 14 | 14 |
| 15 namespace mus { | 15 // MoveLoop is responsible for moving/resizing windows. |
| 16 namespace ws { | 16 class MoveLoop : public mus::WindowObserver { |
| 17 | |
| 18 class ServerWindow; | |
| 19 | |
| 20 // MoveLoop is responsible for moving/resizing windows. EventDispatcher | |
| 21 // attempts to create a MoveLoop on every POINTER_DOWN event. Once a MoveLoop | |
| 22 // is created it is fed events until an event is received that stops the loop. | |
| 23 class MoveLoop : public ServerWindowObserver { | |
| 24 public: | 17 public: |
| 25 enum MoveResult { | 18 enum MoveResult { |
| 26 // The move is still ongoing. | 19 // The move is still ongoing. |
| 27 CONTINUE, | 20 CONTINUE, |
| 28 | 21 |
| 29 // The move is done and the MoveLoop should be destroyed. | 22 // The move is done and the MoveLoop should be destroyed. |
| 30 DONE, | 23 DONE, |
| 31 }; | 24 }; |
| 32 | 25 |
| 33 ~MoveLoop() override; | 26 ~MoveLoop() override; |
| 34 | 27 |
| 35 // If a move/resize loop should occur for the specified parameters creates | 28 // If a move/resize loop should occur for the specified parameters creates |
| 36 // and returns a new MoveLoop. All events should be funneled to the MoveLoop | 29 // and returns a new MoveLoop. All events should be funneled to the MoveLoop |
| 37 // until done (Move()). | 30 // until done (Move()). |
| 38 static scoped_ptr<MoveLoop> Create(ServerWindow* target, | 31 static scoped_ptr<MoveLoop> Create(mus::Window* target, |
| 39 const mojo::Event& event); | 32 const mojo::Event& event); |
| 40 | 33 |
| 41 // Processes an event for a move/resize loop. | 34 // Processes an event for a move/resize loop. |
| 42 MoveResult Move(const mojo::Event& event); | 35 MoveResult Move(const mojo::Event& event); |
| 43 | 36 |
| 44 private: | 37 private: |
| 45 MoveLoop(ServerWindow* target, const mojo::Event& event); | 38 MoveLoop(mus::Window* target, const mojo::Event& event); |
| 46 | 39 |
| 47 // Does the actual move/resize. | 40 // Does the actual move/resize. |
| 48 void MoveImpl(const mojo::Event& event); | 41 void MoveImpl(const mojo::Event& event); |
| 49 | 42 |
| 50 // Cancels the loop. This sets |target_| to null and removes the observer. | 43 // Cancels the loop. This sets |target_| to null and removes the observer. |
| 51 // After this the MoveLoop is still ongoing and won't stop until the | 44 // After this the MoveLoop is still ongoing and won't stop until the |
| 52 // appropriate event is received. | 45 // appropriate event is received. |
| 53 void Cancel(); | 46 void Cancel(); |
| 54 | 47 |
| 55 void Revert(); | 48 void Revert(); |
| 56 | 49 |
| 57 // ServerWindowObserver: | 50 // mus::WindowObserver: |
| 58 void OnWindowHierarchyChanged(ServerWindow* window, | 51 void OnTreeChanged(const TreeChangeParams& params) override; |
| 59 ServerWindow* new_parent, | 52 void OnWindowBoundsChanged(mus::Window* window, |
| 60 ServerWindow* old_parent) override; | 53 const mojo::Rect& old_bounds, |
| 61 void OnWindowBoundsChanged(ServerWindow* window, | 54 const mojo::Rect& new_bounds) override; |
| 62 const gfx::Rect& old_bounds, | 55 void OnWindowVisibilityChanged(mus::Window* window) override; |
| 63 const gfx::Rect& new_bounds) override; | |
| 64 void OnWindowVisibilityChanged(ServerWindow* window) override; | |
| 65 | 56 |
| 66 // The window this MoveLoop is acting on. |target_| is set to null if the | 57 // The window this MoveLoop is acting on. |target_| is set to null if the |
| 67 // window unexpectedly changes while the move is in progress. | 58 // window unexpectedly changes while the move is in progress. |
| 68 ServerWindow* target_; | 59 mus::Window* target_; |
| 69 | 60 |
| 70 // The id of the pointer that triggered the move. | 61 // The id of the pointer that triggered the move. |
| 71 const int32_t pointer_id_; | 62 const int32_t pointer_id_; |
| 72 | 63 |
| 73 // Location of the event (in screen coordinates) that triggered the move. | 64 // Location of the event (in screen coordinates) that triggered the move. |
| 74 const gfx::Point initial_event_screen_location_; | 65 const gfx::Point initial_event_screen_location_; |
| 75 | 66 |
| 76 // Original bounds of the window. | 67 // Original bounds of the window. |
| 77 const gfx::Rect initial_window_bounds_; | 68 const gfx::Rect initial_window_bounds_; |
| 78 | 69 |
| 79 // Set to true when MoveLoop changes the bounds of |target_|. The move is | 70 // Set to true when MoveLoop changes the bounds of |target_|. The move is |
| 80 // canceled if the bounds change unexpectedly during the move. | 71 // canceled if the bounds change unexpectedly during the move. |
| 81 bool changing_bounds_; | 72 bool changing_bounds_; |
| 82 | 73 |
| 83 DISALLOW_COPY_AND_ASSIGN(MoveLoop); | 74 DISALLOW_COPY_AND_ASSIGN(MoveLoop); |
| 84 }; | 75 }; |
| 85 | 76 |
| 86 } // namespace ws | 77 #endif // COMPONENTS_MUS_EXAMPLE_WM_MOVE_LOOP_H_ |
| 87 } // namespace mus | |
| 88 | |
| 89 #endif // COMPONENTS_MUS_WS_MOVE_LOOP_H_ | |
| OLD | NEW |