Fix chromecast_browser_test.
[chromium-blink-merge.git] / ash / wm / window_resizer.h
blob6c8de5e3dc8634050c4c186cdd4cbc6c115a60e9
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_
8 #include "ash/ash_export.h"
9 #include "ash/wm/drag_details.h"
10 #include "ash/wm/window_state.h"
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/wm/public/window_move_client.h"
16 namespace aura {
17 class Window;
20 namespace ash {
22 // WindowResizer is used by ToplevelWindowEventFilter to handle dragging, moving
23 // or resizing a window. All coordinates passed to this are in the parent
24 // windows coordinates.
25 class ASH_EXPORT WindowResizer {
26 public:
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();
38 WindowResizer(wm::WindowState* window_state);
39 virtual ~WindowResizer();
41 // Returns a bitmask of the kBoundsChange_ values.
42 static int GetBoundsChangeForWindowComponent(int component);
44 // Returns a bitmask of the kBoundsChange_ values.
45 static int GetPositionChangeDirectionForWindowComponent(int window_component);
47 // Invoked to drag/move/resize the window. |location| is in the coordinates
48 // of the window supplied to the constructor. |event_flags| is the event
49 // flags from the event.
50 virtual void Drag(const gfx::Point& location, int event_flags) = 0;
52 // Invoked to complete the drag.
53 virtual void CompleteDrag() = 0;
55 // Reverts the drag.
56 virtual void RevertDrag() = 0;
58 // Returns the target window the resizer was created for.
59 aura::Window* GetTarget() const {
60 return window_state_ ? window_state_->window() : NULL;
63 // See comment for |DragDetails::initial_location_in_parent|.
64 const gfx::Point& GetInitialLocation() const {
65 return window_state_->drag_details()->initial_location_in_parent;
68 // Drag parameters established when drag starts.
69 const DragDetails& details() const { return *window_state_->drag_details(); }
71 protected:
72 gfx::Rect CalculateBoundsForDrag(const gfx::Point& location);
74 static bool IsBottomEdge(int component);
76 // WindowState of the drag target.
77 wm::WindowState* window_state_;
79 private:
80 // In case of touch resizing, adjusts deltas so that the border is positioned
81 // just under the touch point.
82 void AdjustDeltaForTouchResize(int* delta_x, int* delta_y);
84 // Returns the new origin of the window. The arguments are the difference
85 // between the current location and the initial location.
86 gfx::Point GetOriginForDrag(int delta_x, int delta_y);
88 // Returns the size of the window for the drag.
89 gfx::Size GetSizeForDrag(int* delta_x, int* delta_y);
91 // Returns the width of the window.
92 int GetWidthForDrag(int min_width, int* delta_x);
94 // Returns the height of the drag.
95 int GetHeightForDrag(int min_height, int* delta_y);
98 // Creates a WindowResizer for |window|. This can return a scoped_ptr
99 // initialized with NULL if |window| should not be resized nor dragged.
100 ASH_EXPORT scoped_ptr<WindowResizer> CreateWindowResizer(
101 aura::Window* window,
102 const gfx::Point& point_in_parent,
103 int window_component,
104 aura::client::WindowMoveSource source);
106 } // namespace ash
108 #endif // ASH_WM_WINDOW_RESIZER_H_