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

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: 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 how a window should be snapped to
23 // that is being snapped to the left or right side of the screen. 23 // the left or right of the screen. The bounds used in this class are in the
24 // The bounds used in this class are in the container's coordinates. 24 // container's coordinates.
25 // The SnapSizer currently only supports side maximizing the window but we want
26 // to use this class for docking as well.
27 // TODO(varkha): Add docking functionality to SnapSizer.
25 class ASH_EXPORT SnapSizer { 28 class ASH_EXPORT SnapSizer {
26 public: 29 public:
27 enum Edge { 30 enum Edge {
28 LEFT_EDGE, 31 LEFT_EDGE,
29 RIGHT_EDGE 32 RIGHT_EDGE
30 }; 33 };
31 34
32 enum InputType { 35 enum StepBehavior {
33 TOUCH_MAXIMIZE_BUTTON_INPUT, 36 STEP_YES,
34 OTHER_INPUT 37 STEP_NO
35 }; 38 };
36 39
37 // Set |input_type| to |TOUCH_MAXIMIZE_BUTTON_INPUT| when called by a touch 40 // 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 41 // default state and will always return the bounds for the default state.
39 // the window beginning close to the border. 42 // The value of |start| matters only if SnapSizer::Update() is called.
40 SnapSizer(aura::Window* window, 43 SnapSizer(aura::Window* window,
41 const gfx::Point& start, 44 const gfx::Point& start,
42 Edge edge, 45 Edge edge,
43 InputType input_type); 46 StepBehavior step_behavior);
44 virtual ~SnapSizer(); 47 virtual ~SnapSizer();
45 48
49 // Returns true if a window can be snapped to |edge|.
50 static bool CanSnapWindow(aura::Window* window);
51
46 // Snaps a window left or right. 52 // Snaps a window left or right.
47 static void SnapWindow(aura::Window* window, Edge edge); 53 // If |step_behavior| is STEP_NO or if |window| is not snapped, the window
54 // is snapped with the default state.
55 // If |step_behavior| is STEP_YES and |window| is already snapped, the window
56 // is snapped to the next state.
57 static void SnapWindow(aura::Window* window,
58 Edge edge,
59 StepBehavior step_behavior);
60
61 // Snaps the window to the current state.
62 void Snap();
48 63
49 // Updates the target bounds based on a mouse move. 64 // Updates the target bounds based on a mouse move.
50 void Update(const gfx::Point& location); 65 void Update(const gfx::Point& location);
51 66
52 // Bounds to position the window at. 67 // Bounds to position the window at.
53 const gfx::Rect& target_bounds() const { return target_bounds_; } 68 const gfx::Rect& target_bounds() const { return target_bounds_; }
54 69
55 // Returns the appropriate snap bounds (e.g. if a window is already snapped, 70 private:
56 // then it returns the next snap-bounds). 71 enum State {
57 gfx::Rect GetSnapBounds(const gfx::Rect& bounds); 72 SIDE_MAXIMIZE
73 };
58 74
59 // Set the snap sizer to the button press default size and prevent resizing. 75 // Returns a list of valid states ordered from the state with the largest
60 void SelectDefaultSizeAndDisableResize(); 76 // width to the state with the smallest width.
77 static std::vector<State> BuildValidStatesList(aura::Window* window,
78 StepBehavior step_behavior);
61 79
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 80 // 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 81 // 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 82 // 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_|. 83 // or decrease the position. It's one of |last_adjust_x_| or |last_update_x_|.
71 int CalculateIncrement(int x, int reference_x) const; 84 int CalculateIncrement(int x, int reference_x) const;
72 85
73 // Changes the bounds. |x| is the current x-coordinate and |delta| the amount 86 // Increments the current state (aka |state_index_|) by |delta| and updates
74 // to increase by. |delta| comes from CalculateIncrement() and is applied 87 // |target_bounds_|.
75 // to |size_index_|. 88 void IncrementState(int delta);
76 void ChangeBounds(int x, int delta);
77 89
78 // Returns the target bounds based on the edge and |size_index_|. 90 // Returns the target bounds based on |edge_| and |state_index_|.
79 gfx::Rect GetTargetBounds() const; 91 gfx::Rect GetTargetBounds() const;
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