| 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 COMPONENTS_MUS_WS_MOVE_LOOP_H_ | |
| 6 #define COMPONENTS_MUS_WS_MOVE_LOOP_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "components/mus/ws/server_window_observer.h" | |
| 11 #include "ui/gfx/geometry/point.h" | |
| 12 #include "ui/gfx/geometry/rect.h" | |
| 13 #include "ui/mojo/events/input_events.mojom.h" | |
| 14 | |
| 15 namespace mus { | |
| 16 namespace ws { | |
| 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: | |
| 25 enum MoveResult { | |
| 26 // The move is still ongoing. | |
| 27 CONTINUE, | |
| 28 | |
| 29 // The move is done and the MoveLoop should be destroyed. | |
| 30 DONE, | |
| 31 }; | |
| 32 | |
| 33 ~MoveLoop() override; | |
| 34 | |
| 35 // 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 | |
| 37 // until done (Move()). | |
| 38 static scoped_ptr<MoveLoop> Create(ServerWindow* target, | |
| 39 const mojo::Event& event); | |
| 40 | |
| 41 // Processes an event for a move/resize loop. | |
| 42 MoveResult Move(const mojo::Event& event); | |
| 43 | |
| 44 private: | |
| 45 MoveLoop(ServerWindow* target, const mojo::Event& event); | |
| 46 | |
| 47 // Does the actual move/resize. | |
| 48 void MoveImpl(const mojo::Event& event); | |
| 49 | |
| 50 // 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 | |
| 52 // appropriate event is received. | |
| 53 void Cancel(); | |
| 54 | |
| 55 void Revert(); | |
| 56 | |
| 57 // ServerWindowObserver: | |
| 58 void OnWindowHierarchyChanged(ServerWindow* window, | |
| 59 ServerWindow* new_parent, | |
| 60 ServerWindow* old_parent) override; | |
| 61 void OnWindowBoundsChanged(ServerWindow* window, | |
| 62 const gfx::Rect& old_bounds, | |
| 63 const gfx::Rect& new_bounds) override; | |
| 64 void OnWindowVisibilityChanged(ServerWindow* window) override; | |
| 65 | |
| 66 // The window this MoveLoop is acting on. |target_| is set to null if the | |
| 67 // window unexpectedly changes while the move is in progress. | |
| 68 ServerWindow* target_; | |
| 69 | |
| 70 // The id of the pointer that triggered the move. | |
| 71 const int32_t pointer_id_; | |
| 72 | |
| 73 // Location of the event (in screen coordinates) that triggered the move. | |
| 74 const gfx::Point initial_event_screen_location_; | |
| 75 | |
| 76 // Original bounds of the window. | |
| 77 const gfx::Rect initial_window_bounds_; | |
| 78 | |
| 79 // Set to true when MoveLoop changes the bounds of |target_|. The move is | |
| 80 // canceled if the bounds change unexpectedly during the move. | |
| 81 bool changing_bounds_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(MoveLoop); | |
| 84 }; | |
| 85 | |
| 86 } // namespace ws | |
| 87 } // namespace mus | |
| 88 | |
| 89 #endif // COMPONENTS_MUS_WS_MOVE_LOOP_H_ | |
| OLD | NEW |