• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef ASH_WM_WINDOW_RESIZER_H_
6 #define ASH_WM_WINDOW_RESIZER_H_
7 
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/rect.h"
14 #include "ui/wm/public/window_move_client.h"
15 
16 namespace aura {
17 class Window;
18 }
19 
20 namespace ash {
21 
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;
31 
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;
36 
37   WindowResizer();
38   WindowResizer(wm::WindowState* window_state);
39   virtual ~WindowResizer();
40 
41   // Returns a bitmask of the kBoundsChange_ values.
42   static int GetBoundsChangeForWindowComponent(int component);
43 
44   // Returns a bitmask of the kBoundsChange_ values.
45   static int GetPositionChangeDirectionForWindowComponent(int window_component);
46 
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;
51 
52   // Invoked to complete the drag.
53   virtual void CompleteDrag() = 0;
54 
55   // Reverts the drag.
56   virtual void RevertDrag() = 0;
57 
58   // Returns the target window the resizer was created for.
GetTarget()59   aura::Window* GetTarget() const {
60     return window_state_ ? window_state_->window() : NULL;
61   }
62 
63   // See comment for |DragDetails::initial_location_in_parent|.
GetInitialLocation()64   const gfx::Point& GetInitialLocation() const {
65     return window_state_->drag_details()->initial_location_in_parent;
66   }
67 
68   // Drag parameters established when drag starts.
details()69   const DragDetails& details() const { return *window_state_->drag_details(); }
70 
71  protected:
72   gfx::Rect CalculateBoundsForDrag(const gfx::Point& location);
73 
74   static bool IsBottomEdge(int component);
75 
76   // WindowState of the drag target.
77   wm::WindowState* window_state_;
78 
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);
83 
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);
87 
88   // Returns the size of the window for the drag.
89   gfx::Size GetSizeForDrag(int* delta_x, int* delta_y);
90 
91   // Returns the width of the window.
92   int GetWidthForDrag(int min_width, int* delta_x);
93 
94   // Returns the height of the drag.
95   int GetHeightForDrag(int min_height, int* delta_y);
96 };
97 
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);
105 
106 }  // namespace ash
107 
108 #endif  // ASH_WM_WINDOW_RESIZER_H_
109