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 #include "ash/wm/base_layout_manager.h" | 5 #include "ash/wm/base_layout_manager.h" |
6 | 6 |
7 #include "ash/screen_ash.h" | 7 #include "ash/screen_ash.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/wm/property_util.h" | |
10 #include "ash/wm/shelf_layout_manager.h" | 9 #include "ash/wm/shelf_layout_manager.h" |
11 #include "ash/wm/window_animations.h" | 10 #include "ash/wm/window_animations.h" |
| 11 #include "ash/wm/window_properties.h" |
12 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
13 #include "ui/aura/client/aura_constants.h" | 13 #include "ui/aura/client/aura_constants.h" |
14 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
16 #include "ui/aura/window_property.h" | |
17 #include "ui/base/ui_base_types.h" | 16 #include "ui/base/ui_base_types.h" |
18 #include "ui/compositor/layer.h" | 17 #include "ui/compositor/layer.h" |
19 #include "ui/gfx/screen.h" | 18 #include "ui/gfx/screen.h" |
20 | 19 |
21 DECLARE_WINDOW_PROPERTY_TYPE(ui::WindowShowState) | |
22 | |
23 namespace { | 20 namespace { |
24 | 21 |
25 // Given a |window| and tentative |restore_bounds|, returns new bounds that | 22 // Given a |window| and tentative |restore_bounds|, returns new bounds that |
26 // ensure that at least a few pixels of the screen background are visible | 23 // ensure that at least a few pixels of the screen background are visible |
27 // outside the edges of the window. Use this to ensure that restoring a | 24 // outside the edges of the window. Use this to ensure that restoring a |
28 // maximized window creates enough space that the resize handles are easily | 25 // maximized window creates enough space that the resize handles are easily |
29 // clickable. We get into this state when updating Chrome OS R18 to R19, as | 26 // clickable. We get into this state when updating Chrome OS R18 to R19, as |
30 // Chrome OS R18 and earlier used only maximized windows and set their restore | 27 // Chrome OS R18 and earlier used only maximized windows and set their restore |
31 // bounds to the size of the screen. See crbug.com/108073 | 28 // bounds to the size of the screen. See crbug.com/108073 |
32 gfx::Rect BoundsWithScreenEdgeVisible(aura::Window* window, | 29 gfx::Rect BoundsWithScreenEdgeVisible(aura::Window* window, |
33 const gfx::Rect& restore_bounds) { | 30 const gfx::Rect& restore_bounds) { |
34 // If the restore_bounds are more than 1 grid step away from the size the | 31 // If the restore_bounds are more than 1 grid step away from the size the |
35 // window would be when maximized, inset it. | 32 // window would be when maximized, inset it. |
36 int grid_size = ash::Shell::GetInstance()->GetGridSize(); | 33 int grid_size = ash::Shell::GetInstance()->GetGridSize(); |
37 gfx::Rect max_bounds = ash::ScreenAsh::GetMaximizedWindowBounds(window); | 34 gfx::Rect max_bounds = ash::ScreenAsh::GetMaximizedWindowBounds(window); |
38 max_bounds.Inset(grid_size, grid_size); | 35 max_bounds.Inset(grid_size, grid_size); |
39 if (restore_bounds.Contains(max_bounds)) | 36 if (restore_bounds.Contains(max_bounds)) |
40 return max_bounds; | 37 return max_bounds; |
41 return restore_bounds; | 38 return restore_bounds; |
42 } | 39 } |
43 | 40 |
44 // Used to remember the show state before the window was minimized. | |
45 DEFINE_WINDOW_PROPERTY_KEY( | |
46 ui::WindowShowState, kRestoreShowStateKey, ui::SHOW_STATE_DEFAULT); | |
47 | |
48 } // namespace | 41 } // namespace |
49 | 42 |
50 namespace ash { | 43 namespace ash { |
51 namespace internal { | 44 namespace internal { |
52 | 45 |
53 ///////////////////////////////////////////////////////////////////////////// | 46 ///////////////////////////////////////////////////////////////////////////// |
54 // BaseLayoutManager, public: | 47 // BaseLayoutManager, public: |
55 | 48 |
56 BaseLayoutManager::BaseLayoutManager(aura::RootWindow* root_window) | 49 BaseLayoutManager::BaseLayoutManager(aura::RootWindow* root_window) |
57 : root_window_(root_window) { | 50 : root_window_(root_window) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 84 } |
92 | 85 |
93 void BaseLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { | 86 void BaseLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { |
94 } | 87 } |
95 | 88 |
96 void BaseLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, | 89 void BaseLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, |
97 bool visible) { | 90 bool visible) { |
98 if (visible && wm::IsWindowMinimized(child)) { | 91 if (visible && wm::IsWindowMinimized(child)) { |
99 // Attempting to show a minimized window. Unminimize it. | 92 // Attempting to show a minimized window. Unminimize it. |
100 child->SetProperty(aura::client::kShowStateKey, | 93 child->SetProperty(aura::client::kShowStateKey, |
101 child->GetProperty(kRestoreShowStateKey)); | 94 child->GetProperty(internal::kRestoreShowStateKey)); |
102 child->ClearProperty(kRestoreShowStateKey); | 95 child->ClearProperty(internal::kRestoreShowStateKey); |
103 } | 96 } |
104 } | 97 } |
105 | 98 |
106 void BaseLayoutManager::SetChildBounds(aura::Window* child, | 99 void BaseLayoutManager::SetChildBounds(aura::Window* child, |
107 const gfx::Rect& requested_bounds) { | 100 const gfx::Rect& requested_bounds) { |
108 gfx::Rect child_bounds(requested_bounds); | 101 gfx::Rect child_bounds(requested_bounds); |
109 // Avoid a janky resize on startup by ensuring the initial bounds fill the | 102 // Avoid a janky resize on startup by ensuring the initial bounds fill the |
110 // screen. | 103 // screen. |
111 if (wm::IsWindowMaximized(child)) | 104 if (wm::IsWindowMaximized(child)) |
112 child_bounds = ScreenAsh::GetMaximizedWindowBounds(child); | 105 child_bounds = ScreenAsh::GetMaximizedWindowBounds(child); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } | 142 } |
150 } | 143 } |
151 | 144 |
152 ////////////////////////////////////////////////////////////////////////////// | 145 ////////////////////////////////////////////////////////////////////////////// |
153 // BaseLayoutManager, private: | 146 // BaseLayoutManager, private: |
154 | 147 |
155 void BaseLayoutManager::ShowStateChanged(aura::Window* window, | 148 void BaseLayoutManager::ShowStateChanged(aura::Window* window, |
156 ui::WindowShowState last_show_state) { | 149 ui::WindowShowState last_show_state) { |
157 if (wm::IsWindowMinimized(window)) { | 150 if (wm::IsWindowMinimized(window)) { |
158 // Save the previous show state so that we can correctly restore it. | 151 // Save the previous show state so that we can correctly restore it. |
159 window->SetProperty(kRestoreShowStateKey, last_show_state); | 152 window->SetProperty(internal::kRestoreShowStateKey, last_show_state); |
160 SetWindowVisibilityAnimationType( | 153 SetWindowVisibilityAnimationType( |
161 window, WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); | 154 window, WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); |
162 | 155 |
163 // Hide the window. | 156 // Hide the window. |
164 window->Hide(); | 157 window->Hide(); |
165 // Activate another window. | 158 // Activate another window. |
166 if (wm::IsActiveWindow(window)) | 159 if (wm::IsActiveWindow(window)) |
167 wm::DeactivateWindow(window); | 160 wm::DeactivateWindow(window); |
168 } else if ((window->TargetVisibility() || | 161 } else if ((window->TargetVisibility() || |
169 last_show_state == ui::SHOW_STATE_MINIMIZED) && | 162 last_show_state == ui::SHOW_STATE_MINIMIZED) && |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 gfx::Rect monitor_rect = | 216 gfx::Rect monitor_rect = |
224 gfx::Screen::GetMonitorNearestWindow(window).work_area(); | 217 gfx::Screen::GetMonitorNearestWindow(window).work_area(); |
225 // Put as much of the window as possible within the monitor area. | 218 // Put as much of the window as possible within the monitor area. |
226 window->SetBounds(window->bounds().AdjustToFit(monitor_rect)); | 219 window->SetBounds(window->bounds().AdjustToFit(monitor_rect)); |
227 } | 220 } |
228 } | 221 } |
229 } | 222 } |
230 | 223 |
231 } // namespace internal | 224 } // namespace internal |
232 } // namespace ash | 225 } // namespace ash |
OLD | NEW |