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

Side by Side Diff: ash/wm/workspace/snap_sizer.h

Issue 23471004: Only support left/right maximizing at 50% width when the --ash-enable-alternate-caption-button (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch is now friendlier to pending docking changes Created 7 years, 3 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 ASH_WM_WORKSPACE_SNAP_SIZER_H_ 5 #ifndef ASH_WM_WORKSPACE_SNAP_SIZER_H_
6 #define ASH_WM_WORKSPACE_SNAP_SIZER_H_ 6 #define ASH_WM_WORKSPACE_SNAP_SIZER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/ash_export.h" 10 #include "ash/ash_export.h"
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "ui/gfx/rect.h" 13 #include "ui/gfx/rect.h"
14 14
15 namespace aura { 15 namespace aura {
16 class Window; 16 class Window;
17 } 17 }
18 18
19 namespace ash { 19 namespace ash {
20 namespace internal { 20 namespace internal {
21 21
22 // SnapSizer is responsible for determining the resulting bounds of a window 22 // SnapSizer is responsible for determining whether a window should be side
23 // that is being snapped to the left or right side of the screen. 23 // maximized or docked to the left or right side of the screen.
varkha 2013/08/30 17:13:25 Just "side-maximized" (with this CL). Thanks for b
24 // The bounds used in this class are in the container's coordinates. 24 // The bounds used in this class are in the container's coordinates.
25 // TODO(varkha): Add docking functionality to SnapSizer.
25 class ASH_EXPORT SnapSizer { 26 class ASH_EXPORT SnapSizer {
26 public: 27 public:
27 enum Edge { 28 enum Edge {
28 LEFT_EDGE, 29 LEFT_EDGE,
29 RIGHT_EDGE 30 RIGHT_EDGE
30 }; 31 };
31 32
32 enum InputType { 33 enum StepBehavior {
33 TOUCH_MAXIMIZE_BUTTON_INPUT, 34 STEP_YES,
34 OTHER_INPUT 35 STEP_NO
35 }; 36 };
36 37
37 // Set |input_type| to |TOUCH_MAXIMIZE_BUTTON_INPUT| when called by a touch 38 // If |step_behavior| is STEP_NO, the SnapSizer will always snap to the
38 // operation by the maximize button. This will allow the user to snap resize 39 // default state and will always return the bounds for the default state.
39 // the window beginning close to the border. 40 // The value of |start| matters only if SnapSizer::Update() is called.
40 SnapSizer(aura::Window* window, 41 SnapSizer(aura::Window* window,
41 const gfx::Point& start, 42 const gfx::Point& start,
42 Edge edge, 43 Edge edge,
43 InputType input_type); 44 StepBehavior step_behavior);
44 virtual ~SnapSizer(); 45 virtual ~SnapSizer();
45 46
47 // Returns true if a window can be snapped to |edge| either via side
48 // maximizing the window or docking it.
varkha 2013/08/30 17:13:25 just "side-maximizing" for now with this CL. You c
49 static bool CanSnapWindow(aura::Window* window, Edge edge);
50
46 // Snaps a window left or right. 51 // Snaps a window left or right.
47 static void SnapWindow(aura::Window* window, Edge edge); 52 // If |step_behavior| is STEP_NO or if |window| is not snapped, the window
53 // is snapped with the default state.
54 // If |step_behavior| is STEP_YES and |window| is already snapped, the window
55 // is snapped to the next state.
56 static void SnapWindow(aura::Window* window,
57 Edge edge,
58 StepBehavior step_behavior);
59
60 // Snaps the window to the current state.
61 void Snap();
48 62
49 // Updates the target bounds based on a mouse move. 63 // Updates the target bounds based on a mouse move.
50 void Update(const gfx::Point& location); 64 void Update(const gfx::Point& location);
51 65
52 // Bounds to position the window at. 66 // Bounds to position the window at.
53 const gfx::Rect& target_bounds() const { return target_bounds_; } 67 const gfx::Rect& target_bounds() const { return target_bounds_; }
54 68
55 // Returns the appropriate snap bounds (e.g. if a window is already snapped, 69 private:
56 // then it returns the next snap-bounds). 70 enum State {
57 gfx::Rect GetSnapBounds(const gfx::Rect& bounds); 71 SIDE_MAXIMIZE
72 };
58 73
59 // Set the snap sizer to the button press default size and prevent resizing. 74 // Returns a list of valid states ordered from the state with the largest
60 void SelectDefaultSizeAndDisableResize(); 75 // width to the state with the smallest width.
76 static std::vector<State> BuildValidStatesList(aura::Window* window,
77 StepBehavior step_behavior);
61 78
62 // Returns the target bounds based on the edge and the provided |size_index|.
63 // For unit test purposes this function is not private.
64 gfx::Rect GetTargetBoundsForSize(size_t size_index) const;
65
66 private:
67 // Calculates the amount to increment by. This returns one of -1, 0 or 1 and 79 // Calculates the amount to increment by. This returns one of -1, 0 or 1 and
68 // is intended to by applied to |size_index_|. |x| is the current 80 // is intended to by applied to |state_index_|. |x| is the current
69 // x-coordinate, and |reference_x| is used to determine whether to increase 81 // x-coordinate, and |reference_x| is used to determine whether to increase
70 // or decrease the position. It's one of |last_adjust_x_| or |last_update_x_|. 82 // or decrease the position. It's one of |last_adjust_x_| or |last_update_x_|.
71 int CalculateIncrement(int x, int reference_x) const; 83 int CalculateIncrement(int x, int reference_x) const;
72 84
73 // Changes the bounds. |x| is the current x-coordinate and |delta| the amount 85 // Returns the target bounds based on |edge_| and |state_index_|.
74 // to increase by. |delta| comes from CalculateIncrement() and is applied 86 gfx::Rect GetTargetBounds() const;
75 // to |size_index_|.
76 void ChangeBounds(int x, int delta);
77 87
78 // Returns the target bounds based on the edge and |size_index_|. 88
79 gfx::Rect GetTargetBounds() const; 89 // Increments the current state (aka |state_index_|) by |delta| and updates
90 // |target_bounds_|.
91 void IncrementState(int delta);
80 92
81 // Returns true if the specified point is along the edge of the screen. 93 // Returns true if the specified point is along the edge of the screen.
82 bool AlongEdge(int x) const; 94 bool AlongEdge(int x) const;
83 95
84 // Window being snapped. 96 // Window being snapped.
85 aura::Window* window_; 97 aura::Window* window_;
86 98
87 const Edge edge_; 99 const Edge edge_;
88 100
89 // Current target bounds for the snap. 101 // Current target bounds for the snap.
90 gfx::Rect target_bounds_; 102 gfx::Rect target_bounds_;
91 103
92 // Time Update() was last invoked. 104 // Time Update() was last invoked.
93 base::TimeTicks time_last_update_; 105 base::TimeTicks time_last_update_;
94 106
95 // Index into |kSizes| that dictates the width of the screen the target 107 // Number of times Update() has been invoked since last IncrementState().
96 // bounds should get.
97 int size_index_;
98
99 // If set, |size_index_| will get ignored and the single button default
100 // setting will be used instead.
101 bool resize_disabled_;
102
103 // Number of times Update() has been invoked since last ChangeBounds().
104 int num_moves_since_adjust_; 108 int num_moves_since_adjust_;
105 109
106 // X-coordinate the last time ChangeBounds() was invoked. 110 // X-coordinate the last time IncrementState() was invoked.
107 int last_adjust_x_; 111 int last_adjust_x_;
108 112
109 // X-coordinate last supplied to Update(). 113 // X-coordinate last supplied to Update().
110 int last_update_x_; 114 int last_update_x_;
111 115
112 // Initial x-coordinate. 116 // Initial x-coordinate.
113 const int start_x_; 117 const int start_x_;
114 118
115 // |TOUCH_MAXIMIZE_BUTTON_INPUT| if the snap sizer was created through a 119 // Index into |states_| that dictates the target bounds.
116 // touch & drag operation of the maximizer button. It changes the behavior of 120 int state_index_;
117 // the drag / resize behavior when the dragging starts close to the border.
118 const InputType input_type_;
119 121
120 // A list of usable window widths for size. This gets created when the 122 // The states that |window_| can step through, ordered from the state with
121 // sizer gets created. 123 // the largest width to the state with the smallest width.
122 const std::vector<int> usable_width_; 124 const std::vector<State> states_;
123 125
124 DISALLOW_COPY_AND_ASSIGN(SnapSizer); 126 DISALLOW_COPY_AND_ASSIGN(SnapSizer);
125 }; 127 };
126 128
127 } // namespace internal 129 } // namespace internal
128 } // namespace ash 130 } // namespace ash
129 131
130 #endif // ASH_WM_WORKSPACE_SNAP_SIZER_H_ 132 #endif // ASH_WM_WORKSPACE_SNAP_SIZER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698