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
3 // found in the LICENSE file.
5 #ifndef ASH_WM_WORKSPACE_SNAP_SIZER_H_
6 #define ASH_WM_WORKSPACE_SNAP_SIZER_H_
10 #include "ash/ash_export.h"
11 #include "base/basictypes.h"
12 #include "base/time.h"
13 #include "ui/gfx/rect.h"
22 // SnapSizer is responsible for determining the resulting bounds of a window
23 // that is being snapped to the left or right side of the screen.
24 // The bounds used in this class are in the container's coordinates.
25 class ASH_EXPORT SnapSizer
{
33 TOUCH_MAXIMIZE_BUTTON_INPUT
,
37 // Set |input_type| to |TOUCH_MAXIMIZE_BUTTON_INPUT| when called by a touch
38 // operation by the maximize button. This will allow the user to snap resize
39 // the window beginning close to the border.
40 SnapSizer(aura::Window
* window
,
41 const gfx::Point
& start
,
43 InputType input_type
);
46 // Snaps a window left or right.
47 static void SnapWindow(aura::Window
* window
, Edge edge
);
49 // Updates the target bounds based on a mouse move.
50 void Update(const gfx::Point
& location
);
52 // Bounds to position the window at.
53 const gfx::Rect
& target_bounds() const { return target_bounds_
; }
55 // Returns the appropriate snap bounds (e.g. if a window is already snapped,
56 // then it returns the next snap-bounds).
57 gfx::Rect
GetSnapBounds(const gfx::Rect
& bounds
);
59 // Set the snap sizer to the button press default size and prevent resizing.
60 void SelectDefaultSizeAndDisableResize();
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;
67 // 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
69 // 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_|.
71 int CalculateIncrement(int x
, int reference_x
) const;
73 // Changes the bounds. |x| is the current x-coordinate and |delta| the amount
74 // to increase by. |delta| comes from CalculateIncrement() and is applied
76 void ChangeBounds(int x
, int delta
);
78 // Returns the target bounds based on the edge and |size_index_|.
79 gfx::Rect
GetTargetBounds() const;
81 // Returns true if the specified point is along the edge of the screen.
82 bool AlongEdge(int x
) const;
84 // Window being snapped.
85 aura::Window
* window_
;
89 // Current target bounds for the snap.
90 gfx::Rect target_bounds_
;
92 // Time Update() was last invoked.
93 base::TimeTicks time_last_update_
;
95 // Index into |kSizes| that dictates the width of the screen the target
99 // If set, |size_index_| will get ignored and the single button default
100 // setting will be used instead.
101 bool resize_disabled_
;
103 // Number of times Update() has been invoked since last ChangeBounds().
104 int num_moves_since_adjust_
;
106 // X-coordinate the last time ChangeBounds() was invoked.
109 // X-coordinate last supplied to Update().
112 // Initial x-coordinate.
115 // |TOUCH_MAXIMIZE_BUTTON_INPUT| if the snap sizer was created through a
116 // touch & drag operation of the maximizer button. It changes the behavior of
117 // the drag / resize behavior when the dragging starts close to the border.
118 const InputType input_type_
;
120 // A list of usable window widths for size. This gets created when the
121 // sizer gets created.
122 const std::vector
<int> usable_width_
;
124 DISALLOW_COPY_AND_ASSIGN(SnapSizer
);
127 } // namespace internal
130 #endif // ASH_WM_WORKSPACE_SNAP_SIZER_H_