OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ASH_WM_WORKSPACE_WINDOW_RESIZER_H_ | 5 #ifndef ASH_WM_WORKSPACE_WINDOW_RESIZER_H_ |
6 #define ASH_WM_WORKSPACE_WINDOW_RESIZER_H_ | 6 #define ASH_WM_WORKSPACE_WINDOW_RESIZER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
| 9 #include <vector> |
| 10 |
9 #include "ash/wm/window_resizer.h" | 11 #include "ash/wm/window_resizer.h" |
10 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
11 | 13 |
12 namespace ash { | 14 namespace ash { |
13 namespace internal { | 15 namespace internal { |
14 | 16 |
15 class RootWindowEventFilter; | 17 class RootWindowEventFilter; |
16 | 18 |
17 // WindowResizer implementation for workspaces. This enforces that windows are | 19 // WindowResizer implementation for workspaces. This enforces that windows are |
18 // not allowed to vertically move or resize outside of the work area. As windows | 20 // not allowed to vertically move or resize outside of the work area. As windows |
19 // are moved outside the work area they are shrunk. We remember the height of | 21 // are moved outside the work area they are shrunk. We remember the height of |
20 // the window before it was moved so that if the window is again moved up we | 22 // the window before it was moved so that if the window is again moved up we |
21 // attempt to restore the old height. | 23 // attempt to restore the old height. |
22 class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer { | 24 class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer { |
23 public: | 25 public: |
| 26 // When dragging an attached window this is the min size we'll make sure is |
| 27 // visibile. In the vertical direction we take the max of this and that from |
| 28 // the delegate. |
| 29 static const int kMinOnscreenSize; |
| 30 |
24 virtual ~WorkspaceWindowResizer(); | 31 virtual ~WorkspaceWindowResizer(); |
25 | 32 |
26 // Creates a new WorkspaceWindowResizer. The caller takes ownership of the | |
27 // returned object. Returns NULL if not resizable. | |
28 static WorkspaceWindowResizer* Create( | 33 static WorkspaceWindowResizer* Create( |
29 aura::Window* window, | 34 aura::Window* window, |
30 const gfx::Point& location, | 35 const gfx::Point& location, |
31 int window_component, | 36 int window_component, |
32 int grid_size); | 37 int grid_size, |
| 38 const std::vector<aura::Window*>& attached_windows); |
33 | 39 |
34 // Returns true if the drag will result in changing the window in anyway. | 40 // Returns true if the drag will result in changing the window in anyway. |
35 bool is_resizable() const { return details_.is_resizable; } | 41 bool is_resizable() const { return details_.is_resizable; } |
36 | 42 |
37 const gfx::Point& initial_location_in_parent() const { | 43 const gfx::Point& initial_location_in_parent() const { |
38 return details_.initial_location_in_parent; | 44 return details_.initial_location_in_parent; |
39 } | 45 } |
40 | 46 |
41 // Overridden from WindowResizer: | 47 // Overridden from WindowResizer: |
42 virtual void Drag(const gfx::Point& location) OVERRIDE; | 48 virtual void Drag(const gfx::Point& location) OVERRIDE; |
43 virtual void CompleteDrag() OVERRIDE; | 49 virtual void CompleteDrag() OVERRIDE; |
44 virtual void RevertDrag() OVERRIDE; | 50 virtual void RevertDrag() OVERRIDE; |
45 | 51 |
46 private: | 52 private: |
| 53 WorkspaceWindowResizer(const Details& details, |
| 54 const std::vector<aura::Window*>& attached_windows); |
| 55 |
| 56 private: |
47 explicit WorkspaceWindowResizer(const Details& details); | 57 explicit WorkspaceWindowResizer(const Details& details); |
48 | 58 |
| 59 // Lays out the attached windows. |bounds| is the bounds of the main window. |
| 60 void LayoutAttachedWindowsHorizontally(const gfx::Rect& bounds); |
| 61 void LayoutAttachedWindowsVertically(const gfx::Rect& bounds); |
| 62 |
49 // Adjusts the bounds to enforce that windows are vertically contained in the | 63 // Adjusts the bounds to enforce that windows are vertically contained in the |
50 // work area. | 64 // work area. |
51 void AdjustBoundsForMainWindow(gfx::Rect* bounds) const; | 65 void AdjustBoundsForMainWindow(gfx::Rect* bounds) const; |
52 void AdjustBoundsForWindow(const gfx::Rect& work_area, | 66 void AdjustBoundsForWindow(const gfx::Rect& work_area, |
53 aura::Window* window, | 67 aura::Window* window, |
54 gfx::Rect* bounds) const; | 68 gfx::Rect* bounds) const; |
55 | 69 |
56 // Clears the cached height of the window being dragged. | 70 // Clears the cached width/height of the window being dragged. |
57 void ClearCachedHeights(); | 71 void ClearCachedHeights(); |
| 72 void ClearCachedWidths(); |
58 | 73 |
59 // Returns true if the window touches the bottom of the work area. | 74 // Returns true if the window touches the bottom/right edge of the work area. |
60 bool TouchesBottomOfScreen() const; | 75 bool TouchesBottomOfScreen() const; |
| 76 bool TouchesRightSideOfScreen() const; |
| 77 |
| 78 // Returns a coordinate along the primary axis. Used to share code for |
| 79 // left/right multi window resize and top/bottom resize. |
| 80 int PrimaryAxisSize(const gfx::Size& size) const; |
| 81 int PrimaryAxisCoordinate(int x, int y) const; |
61 | 82 |
62 aura::Window* window() const { return details_.window; } | 83 aura::Window* window() const { return details_.window; } |
63 | 84 |
64 const Details details_; | 85 const Details details_; |
65 | 86 |
66 // True if the window size (height) should be constrained. | 87 // True if the window size (height) should be constrained. |
67 const bool constrain_size_; | 88 const bool constrain_size_; |
68 | 89 |
| 90 const std::vector<aura::Window*> attached_windows_; |
| 91 |
69 // Set to true once Drag() is invoked and the bounds of the window change. | 92 // Set to true once Drag() is invoked and the bounds of the window change. |
70 bool did_move_or_resize_; | 93 bool did_move_or_resize_; |
71 | 94 |
72 internal::RootWindowEventFilter* root_filter_; | 95 internal::RootWindowEventFilter* root_filter_; |
73 | 96 |
| 97 // The initial size of each of the windows in |attached_windows_| along the |
| 98 // primary axis. |
| 99 std::vector<int> initial_size_; |
| 100 |
| 101 // The min size of each of the windows in |attached_windows_| along the |
| 102 // primary axis. |
| 103 std::vector<int> min_size_; |
| 104 |
| 105 // The amount each of the windows in |attached_windows_| can be compressed. |
| 106 // This is a fraction of the amount a window can be compressed over the total |
| 107 // space the windows can be compressed. |
| 108 std::vector<float> compress_fraction_; |
| 109 |
| 110 // Sum of sizes in |min_size_|. |
| 111 int total_min_; |
| 112 |
| 113 // Sum of the sizes in |initial_size_|. |
| 114 int total_initial_size_; |
| 115 |
74 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizer); | 116 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizer); |
75 }; | 117 }; |
76 | 118 |
77 } // namespace internal | 119 } // namespace internal |
78 } // namespace ash | 120 } // namespace ash |
79 | 121 |
80 #endif // ASH_WM_WORKSPACE_WINDOW_RESIZER_H_ | 122 #endif // ASH_WM_WORKSPACE_WINDOW_RESIZER_H_ |
OLD | NEW |