Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: components/mus/example/wm/move_loop.h

Issue 1416453005: Adds window resizing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/mus/example/wm/BUILD.gn ('k') | components/mus/example/wm/move_loop.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_EXAMPLE_WM_MOVE_LOOP_H_ 5 #ifndef COMPONENTS_MUS_EXAMPLE_WM_MOVE_LOOP_H_
6 #define COMPONENTS_MUS_EXAMPLE_WM_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/public/cpp/window_observer.h" 10 #include "components/mus/public/cpp/window_observer.h"
11 #include "components/mus/public/interfaces/input_events.mojom.h" 11 #include "components/mus/public/interfaces/input_events.mojom.h"
12 #include "ui/gfx/geometry/point.h" 12 #include "ui/gfx/geometry/point.h"
13 #include "ui/gfx/geometry/rect.h" 13 #include "ui/gfx/geometry/rect.h"
14 14
15 // MoveLoop is responsible for moving/resizing windows. 15 // MoveLoop is responsible for moving/resizing windows.
16 class MoveLoop : public mus::WindowObserver { 16 class MoveLoop : public mus::WindowObserver {
17 public: 17 public:
18 enum MoveResult { 18 enum MoveResult {
19 // The move is still ongoing. 19 // The move is still ongoing.
20 CONTINUE, 20 CONTINUE,
21 21
22 // The move is done and the MoveLoop should be destroyed. 22 // The move is done and the MoveLoop should be destroyed.
23 DONE, 23 DONE,
24 }; 24 };
25 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
26 ~MoveLoop() override; 41 ~MoveLoop() override;
27 42
28 // If a move/resize loop should occur for the specified parameters creates 43 // If a move/resize loop should occur for the specified parameters creates
29 // and returns a new MoveLoop. All events should be funneled to the MoveLoop 44 // and returns a new MoveLoop. All events should be funneled to the MoveLoop
30 // until done (Move()). 45 // until done (Move()).
31 static scoped_ptr<MoveLoop> Create(mus::Window* target, 46 static scoped_ptr<MoveLoop> Create(mus::Window* target,
32 const mus::mojom::Event& event); 47 const mus::mojom::Event& event);
33 48
34 // Processes an event for a move/resize loop. 49 // Processes an event for a move/resize loop.
35 MoveResult Move(const mus::mojom::Event& event); 50 MoveResult Move(const mus::mojom::Event& event);
36 51
37 private: 52 private:
38 MoveLoop(mus::Window* target, const mus::mojom::Event& event); 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);
39 69
40 // Does the actual move/resize. 70 // Does the actual move/resize.
41 void MoveImpl(const mus::mojom::Event& event); 71 void MoveImpl(const mus::mojom::Event& event);
42 72
43 // Cancels the loop. This sets |target_| to null and removes the observer. 73 // Cancels the loop. This sets |target_| to null and removes the observer.
44 // After this the MoveLoop is still ongoing and won't stop until the 74 // After this the MoveLoop is still ongoing and won't stop until the
45 // appropriate event is received. 75 // appropriate event is received.
46 void Cancel(); 76 void Cancel();
47 77
48 void Revert(); 78 void Revert();
49 79
80 gfx::Rect DetermineBoundsFromDelta(const gfx::Vector2d& delta);
81
50 // mus::WindowObserver: 82 // mus::WindowObserver:
51 void OnTreeChanged(const TreeChangeParams& params) override; 83 void OnTreeChanged(const TreeChangeParams& params) override;
52 void OnWindowBoundsChanged(mus::Window* window, 84 void OnWindowBoundsChanged(mus::Window* window,
53 const gfx::Rect& old_bounds, 85 const gfx::Rect& old_bounds,
54 const gfx::Rect& new_bounds) override; 86 const gfx::Rect& new_bounds) override;
55 void OnWindowVisibilityChanged(mus::Window* window) override; 87 void OnWindowVisibilityChanged(mus::Window* window) override;
56 88
57 // The window this MoveLoop is acting on. |target_| is set to null if the 89 // The window this MoveLoop is acting on. |target_| is set to null if the
58 // window unexpectedly changes while the move is in progress. 90 // window unexpectedly changes while the move is in progress.
59 mus::Window* target_; 91 mus::Window* target_;
60 92
93 const Type type_;
94 const HorizontalLocation h_loc_;
95 const VerticalLocation v_loc_;
96
61 // The id of the pointer that triggered the move. 97 // The id of the pointer that triggered the move.
62 const int32_t pointer_id_; 98 const int32_t pointer_id_;
63 99
64 // Location of the event (in screen coordinates) that triggered the move. 100 // Location of the event (in screen coordinates) that triggered the move.
65 const gfx::Point initial_event_screen_location_; 101 const gfx::Point initial_event_screen_location_;
66 102
67 // Original bounds of the window. 103 // Original bounds of the window.
68 const gfx::Rect initial_window_bounds_; 104 const gfx::Rect initial_window_bounds_;
69 105
70 // Set to true when MoveLoop changes the bounds of |target_|. The move is 106 // Set to true when MoveLoop changes the bounds of |target_|. The move is
71 // canceled if the bounds change unexpectedly during the move. 107 // canceled if the bounds change unexpectedly during the move.
72 bool changing_bounds_; 108 bool changing_bounds_;
73 109
74 DISALLOW_COPY_AND_ASSIGN(MoveLoop); 110 DISALLOW_COPY_AND_ASSIGN(MoveLoop);
75 }; 111 };
76 112
77 #endif // COMPONENTS_MUS_EXAMPLE_WM_MOVE_LOOP_H_ 113 #endif // COMPONENTS_MUS_EXAMPLE_WM_MOVE_LOOP_H_
OLDNEW
« no previous file with comments | « components/mus/example/wm/BUILD.gn ('k') | components/mus/example/wm/move_loop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698