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_WINDOW_RESIZER_H_
6 #define ASH_WM_WINDOW_RESIZER_H_
9 #include "ash/ash_export.h"
10 #include "base/basictypes.h"
11 #include "ui/gfx/rect.h"
20 class RootWindowEventFilter
;
23 // WindowResizer is used by ToplevelWindowEventFilter to handle dragging,
24 // moving or resizing a window.
25 class ASH_EXPORT WindowResizer
{
27 // Constants to identify the type of resize.
28 static const int kBoundsChange_None
;
29 static const int kBoundsChange_Repositions
;
30 static const int kBoundsChange_Resizes
;
32 // Used to indicate which direction the resize occurs in.
33 static const int kBoundsChangeDirection_None
;
34 static const int kBoundsChangeDirection_Horizontal
;
35 static const int kBoundsChangeDirection_Vertical
;
37 WindowResizer(aura::Window
* window
,
38 const gfx::Point
& location
,
43 // Returns a bitmask of the kBoundsChange_ values.
44 static int GetBoundsChangeForWindowComponent(int component
);
46 // Returns a location >= |location| that is aligned to fall on increments of
48 static int AlignToGrid(int location
, int grid_size
);
50 // Invoked to drag/move/resize the window. |location| is in the coordinates
51 // of the window supplied to the constructor.
52 void Drag(const gfx::Point
& location
);
54 // Invoked to complete the drag.
57 // Returns true if the drag will result in changing the window in anyway.
58 bool is_resizable() const { return is_resizable_
; }
60 // See description above members for details.
61 const gfx::Rect
& initial_bounds() const { return initial_bounds_
; }
62 const gfx::Point
& initial_location_in_parent() const {
63 return initial_location_in_parent_
;
65 int window_component() const { return window_component_
; }
66 aura::Window
* window() const { return window_
; }
69 // Returns the bounds to give to the window once the mouse has moved to
71 gfx::Rect
GetBoundsForDrag(const gfx::Point
& location
);
73 // Returns the new origin of the window. The arguments are the difference
74 // between the current location and the initial location.
75 gfx::Point
GetOriginForDrag(int delta_x
, int delta_y
) const;
77 // Returns the size of the window for the drag.
78 gfx::Size
GetSizeForDrag(int* delta_x
, int* delta_y
) const;
80 // Returns the width of the window.
81 int GetWidthForDrag(int min_width
, int* delta_x
) const;
83 // Returns the height of the drag.
84 int GetHeightForDrag(int min_height
, int* delta_y
) const;
86 // The window we're resizing.
87 aura::Window
* window_
;
89 // Initial bounds of the window.
90 const gfx::Rect initial_bounds_
;
92 // Location passed to the constructor, in |window->parent()|'s coordinates.
93 const gfx::Point initial_location_in_parent_
;
95 // The component the user pressed on.
96 const int window_component_
;
98 // Bitmask of the |kBoundsChange_| constants.
99 const int bounds_change_
;
101 // Bitmask of the |kBoundsChangeDirection_| constants.
102 const int position_change_direction_
;
104 // Bitmask of the |kBoundsChangeDirection_| constants.
105 const int size_change_direction_
;
107 // Will the drag actually modify the window?
108 const bool is_resizable_
;
111 const int grid_size_
;
113 // Set to true once Drag() is invoked and the bounds of the window change.
114 bool did_move_or_resize_
;
116 internal::RootWindowEventFilter
* root_filter_
;
118 DISALLOW_COPY_AND_ASSIGN(WindowResizer
);
123 #endif // ASH_WM_WINDOW_RESIZER_H_