Chromium Code Reviews| Index: ash/wm/workspace/snap_sizer.h |
| diff --git a/ash/wm/workspace/snap_sizer.h b/ash/wm/workspace/snap_sizer.h |
| index bd5f719ae482d1d78be1c20d70fd0895e3eb0703..fd576be4ac5b09908d97d452d80db0f8f6817e42 100644 |
| --- a/ash/wm/workspace/snap_sizer.h |
| +++ b/ash/wm/workspace/snap_sizer.h |
| @@ -19,9 +19,12 @@ class Window; |
| namespace ash { |
| namespace internal { |
| -// SnapSizer is responsible for determining the resulting bounds of a window |
| -// that is being snapped to the left or right side of the screen. |
| -// The bounds used in this class are in the container's coordinates. |
| +// SnapSizer is responsible for determining how a window should be snapped to |
| +// the left or right of the screen. The bounds used in this class are in the |
| +// container's coordinates. |
| +// The SnapSizer currently only supports side maximizing the window but we want |
| +// to use this class for docking as well. |
| +// TODO(varkha): Add docking functionality to SnapSizer. |
| class ASH_EXPORT SnapSizer { |
| public: |
| enum Edge { |
| @@ -29,22 +32,34 @@ class ASH_EXPORT SnapSizer { |
| RIGHT_EDGE |
| }; |
| - enum InputType { |
| - TOUCH_MAXIMIZE_BUTTON_INPUT, |
| - OTHER_INPUT |
| + enum StepBehavior { |
|
Mr4D (OOO till 08-26)
2013/09/06 21:57:54
Could you please rename these to something better
|
| + STEP_YES, |
| + STEP_NO |
| }; |
| - // Set |input_type| to |TOUCH_MAXIMIZE_BUTTON_INPUT| when called by a touch |
| - // operation by the maximize button. This will allow the user to snap resize |
| - // the window beginning close to the border. |
| + // If |step_behavior| is STEP_NO, the SnapSizer will always snap to the |
| + // default state and will always return the bounds for the default state. |
| + // The value of |start| matters only if SnapSizer::Update() is called. |
| SnapSizer(aura::Window* window, |
| const gfx::Point& start, |
| Edge edge, |
| - InputType input_type); |
| + StepBehavior step_behavior); |
| virtual ~SnapSizer(); |
| + // Returns true if a window can be snapped to |edge|. |
| + static bool CanSnapWindow(aura::Window* window); |
| + |
| // Snaps a window left or right. |
| - static void SnapWindow(aura::Window* window, Edge edge); |
| + // If |step_behavior| is STEP_NO or if |window| is not snapped, the window |
| + // is snapped with the default state. |
| + // If |step_behavior| is STEP_YES and |window| is already snapped, the window |
| + // is snapped to the next state. |
| + static void SnapWindow(aura::Window* window, |
| + Edge edge, |
| + StepBehavior step_behavior); |
| + |
| + // Snaps the window to the current state. |
| + void Snap(); |
| // Updates the target bounds based on a mouse move. |
| void Update(const gfx::Point& location); |
| @@ -52,30 +67,27 @@ class ASH_EXPORT SnapSizer { |
| // Bounds to position the window at. |
| const gfx::Rect& target_bounds() const { return target_bounds_; } |
| - // Returns the appropriate snap bounds (e.g. if a window is already snapped, |
| - // then it returns the next snap-bounds). |
| - gfx::Rect GetSnapBounds(const gfx::Rect& bounds); |
| - |
| - // Set the snap sizer to the button press default size and prevent resizing. |
| - void SelectDefaultSizeAndDisableResize(); |
| + private: |
| + enum State { |
| + SIDE_MAXIMIZE |
| + }; |
| - // Returns the target bounds based on the edge and the provided |size_index|. |
| - // For unit test purposes this function is not private. |
| - gfx::Rect GetTargetBoundsForSize(size_t size_index) const; |
| + // Returns a list of valid states ordered from the state with the largest |
| + // width to the state with the smallest width. |
| + static std::vector<State> BuildValidStatesList(aura::Window* window, |
| + StepBehavior step_behavior); |
| - private: |
| // Calculates the amount to increment by. This returns one of -1, 0 or 1 and |
| - // is intended to by applied to |size_index_|. |x| is the current |
| + // is intended to by applied to |state_index_|. |x| is the current |
| // x-coordinate, and |reference_x| is used to determine whether to increase |
| // or decrease the position. It's one of |last_adjust_x_| or |last_update_x_|. |
| int CalculateIncrement(int x, int reference_x) const; |
| - // Changes the bounds. |x| is the current x-coordinate and |delta| the amount |
| - // to increase by. |delta| comes from CalculateIncrement() and is applied |
| - // to |size_index_|. |
| - void ChangeBounds(int x, int delta); |
| + // Increments the current state (aka |state_index_|) by |delta| and updates |
| + // |target_bounds_|. |
| + void IncrementState(int delta); |
| - // Returns the target bounds based on the edge and |size_index_|. |
| + // Returns the target bounds based on |edge_| and |state_index_|. |
| gfx::Rect GetTargetBounds() const; |
| // Returns true if the specified point is along the edge of the screen. |
| @@ -92,18 +104,10 @@ class ASH_EXPORT SnapSizer { |
| // Time Update() was last invoked. |
| base::TimeTicks time_last_update_; |
| - // Index into |kSizes| that dictates the width of the screen the target |
| - // bounds should get. |
| - int size_index_; |
| - |
| - // If set, |size_index_| will get ignored and the single button default |
| - // setting will be used instead. |
| - bool resize_disabled_; |
| - |
| - // Number of times Update() has been invoked since last ChangeBounds(). |
| + // Number of times Update() has been invoked since last IncrementState(). |
| int num_moves_since_adjust_; |
| - // X-coordinate the last time ChangeBounds() was invoked. |
| + // X-coordinate the last time IncrementState() was invoked. |
| int last_adjust_x_; |
| // X-coordinate last supplied to Update(). |
| @@ -112,14 +116,12 @@ class ASH_EXPORT SnapSizer { |
| // Initial x-coordinate. |
| const int start_x_; |
| - // |TOUCH_MAXIMIZE_BUTTON_INPUT| if the snap sizer was created through a |
| - // touch & drag operation of the maximizer button. It changes the behavior of |
| - // the drag / resize behavior when the dragging starts close to the border. |
| - const InputType input_type_; |
| + // Index into |states_| that dictates the target bounds. |
| + int state_index_; |
| - // A list of usable window widths for size. This gets created when the |
| - // sizer gets created. |
| - const std::vector<int> usable_width_; |
| + // The states that |window_| can step through, ordered from the state with |
| + // the largest width to the state with the smallest width. |
| + const std::vector<State> states_; |
| DISALLOW_COPY_AND_ASSIGN(SnapSizer); |
| }; |