| 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/window_util.h" | 5 #include "ash/wm/window_util.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/ash_constants.h" | 9 #include "ash/ash_constants.h" |
| 10 #include "ash/root_window_controller.h" | |
| 11 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 12 #include "ash/shell_window_ids.h" | |
| 13 #include "ash/wm/window_properties.h" | 11 #include "ash/wm/window_properties.h" |
| 14 #include "ui/aura/client/activation_client.h" | 12 #include "ui/aura/client/activation_client.h" |
| 15 #include "ui/aura/client/aura_constants.h" | 13 #include "ui/aura/client/aura_constants.h" |
| 16 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
| 17 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 18 #include "ui/aura/window_delegate.h" | |
| 19 #include "ui/compositor/layer.h" | |
| 20 #include "ui/gfx/display.h" | 16 #include "ui/gfx/display.h" |
| 21 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
| 22 #include "ui/gfx/screen.h" | 18 #include "ui/gfx/screen.h" |
| 23 #include "ui/views/corewm/window_util.h" | 19 #include "ui/views/corewm/window_util.h" |
| 24 #include "ui/views/view.h" | 20 #include "ui/views/view.h" |
| 25 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 26 | 22 |
| 27 namespace ash { | 23 namespace ash { |
| 28 namespace wm { | 24 namespace wm { |
| 29 | 25 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 46 } | 42 } |
| 47 | 43 |
| 48 aura::Window* GetActivatableWindow(aura::Window* window) { | 44 aura::Window* GetActivatableWindow(aura::Window* window) { |
| 49 return views::corewm::GetActivatableWindow(window); | 45 return views::corewm::GetActivatableWindow(window); |
| 50 } | 46 } |
| 51 | 47 |
| 52 bool CanActivateWindow(aura::Window* window) { | 48 bool CanActivateWindow(aura::Window* window) { |
| 53 return views::corewm::CanActivateWindow(window); | 49 return views::corewm::CanActivateWindow(window); |
| 54 } | 50 } |
| 55 | 51 |
| 56 bool CanMaximizeWindow(const aura::Window* window) { | 52 bool IsWindowMinimized(aura::Window* window) { |
| 57 return window->GetProperty(aura::client::kCanMaximizeKey); | |
| 58 } | |
| 59 | |
| 60 bool CanMinimizeWindow(const aura::Window* window) { | |
| 61 internal::RootWindowController* controller = | |
| 62 internal::RootWindowController::ForWindow(window); | |
| 63 if (!controller) | |
| 64 return false; | |
| 65 aura::Window* lockscreen = controller->GetContainer( | |
| 66 internal::kShellWindowId_LockScreenContainersContainer); | |
| 67 if (lockscreen->Contains(window)) | |
| 68 return false; | |
| 69 | |
| 70 return true; | |
| 71 } | |
| 72 | |
| 73 bool CanResizeWindow(const aura::Window* window) { | |
| 74 return window->GetProperty(aura::client::kCanResizeKey); | |
| 75 } | |
| 76 | |
| 77 bool CanSnapWindow(aura::Window* window) { | |
| 78 if (!CanResizeWindow(window)) | |
| 79 return false; | |
| 80 if (window->type() == aura::client::WINDOW_TYPE_PANEL) | |
| 81 return false; | |
| 82 // If a window has a maximum size defined, snapping may make it too big. | |
| 83 return window->delegate() ? window->delegate()->GetMaximumSize().IsEmpty() : | |
| 84 true; | |
| 85 } | |
| 86 | |
| 87 bool IsWindowNormal(const aura::Window* window) { | |
| 88 return IsWindowStateNormal(window->GetProperty(aura::client::kShowStateKey)); | |
| 89 } | |
| 90 | |
| 91 bool IsWindowStateNormal(ui::WindowShowState state) { | |
| 92 return state == ui::SHOW_STATE_NORMAL || state == ui::SHOW_STATE_DEFAULT; | |
| 93 } | |
| 94 | |
| 95 bool IsWindowMaximized(const aura::Window* window) { | |
| 96 return window->GetProperty(aura::client::kShowStateKey) == | |
| 97 ui::SHOW_STATE_MAXIMIZED; | |
| 98 } | |
| 99 | |
| 100 bool IsWindowMinimized(const aura::Window* window) { | |
| 101 return window->GetProperty(aura::client::kShowStateKey) == | 53 return window->GetProperty(aura::client::kShowStateKey) == |
| 102 ui::SHOW_STATE_MINIMIZED; | 54 ui::SHOW_STATE_MINIMIZED; |
| 103 } | 55 } |
| 104 | 56 |
| 105 bool IsWindowFullscreen(const aura::Window* window) { | |
| 106 return window->GetProperty(aura::client::kShowStateKey) == | |
| 107 ui::SHOW_STATE_FULLSCREEN; | |
| 108 } | |
| 109 | |
| 110 void MaximizeWindow(aura::Window* window) { | |
| 111 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | |
| 112 } | |
| 113 | |
| 114 void MinimizeWindow(aura::Window* window) { | |
| 115 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | |
| 116 } | |
| 117 | |
| 118 void RestoreWindow(aura::Window* window) { | |
| 119 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | |
| 120 } | |
| 121 | |
| 122 void ToggleMaximizedWindow(aura::Window* window) { | |
| 123 if (ash::wm::IsWindowMaximized(window)) | |
| 124 ash::wm::RestoreWindow(window); | |
| 125 else if (ash::wm::CanMaximizeWindow(window)) | |
| 126 ash::wm::MaximizeWindow(window); | |
| 127 } | |
| 128 | |
| 129 void CenterWindow(aura::Window* window) { | 57 void CenterWindow(aura::Window* window) { |
| 130 const gfx::Display display = | 58 const gfx::Display display = |
| 131 Shell::GetScreen()->GetDisplayNearestWindow(window); | 59 Shell::GetScreen()->GetDisplayNearestWindow(window); |
| 132 gfx::Rect center = display.work_area(); | 60 gfx::Rect center = display.work_area(); |
| 133 center.ClampToCenteredSize(window->bounds().size()); | 61 center.ClampToCenteredSize(window->bounds().size()); |
| 134 window->SetBoundsInScreen(center, display); | 62 window->SetBoundsInScreen(center, display); |
| 135 } | 63 } |
| 136 | 64 |
| 137 void SetAnimateToFullscreen(aura::Window* window, bool animate) { | 65 void SetAnimateToFullscreen(aura::Window* window, bool animate) { |
| 138 window->SetProperty(ash::internal::kAnimateToFullscreenKey, animate); | 66 window->SetProperty(ash::internal::kAnimateToFullscreenKey, animate); |
| 139 } | 67 } |
| 140 | 68 |
| 141 const gfx::Rect* GetPreAutoManageWindowBounds(const aura::Window* window) { | |
| 142 return window->GetProperty(ash::internal::kPreAutoManagedWindowBoundsKey); | |
| 143 } | |
| 144 | |
| 145 void SetPreAutoManageWindowBounds(aura::Window* window, | |
| 146 const gfx::Rect& bounds) { | |
| 147 window->SetProperty(ash::internal::kPreAutoManagedWindowBoundsKey, | |
| 148 new gfx::Rect(bounds)); | |
| 149 } | |
| 150 | |
| 151 void AdjustBoundsToEnsureMinimumWindowVisibility(const gfx::Rect& visible_area, | 69 void AdjustBoundsToEnsureMinimumWindowVisibility(const gfx::Rect& visible_area, |
| 152 gfx::Rect* bounds) { | 70 gfx::Rect* bounds) { |
| 153 AdjustBoundsToEnsureWindowVisibility( | 71 AdjustBoundsToEnsureWindowVisibility( |
| 154 visible_area, kMinimumOnScreenArea, kMinimumOnScreenArea, bounds); | 72 visible_area, kMinimumOnScreenArea, kMinimumOnScreenArea, bounds); |
| 155 } | 73 } |
| 156 | 74 |
| 157 void AdjustBoundsToEnsureWindowVisibility(const gfx::Rect& visible_area, | 75 void AdjustBoundsToEnsureWindowVisibility(const gfx::Rect& visible_area, |
| 158 int min_width, | 76 int min_width, |
| 159 int min_height, | 77 int min_height, |
| 160 gfx::Rect* bounds) { | 78 gfx::Rect* bounds) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 186 return false; | 104 return false; |
| 187 aura::Window* window_container = | 105 aura::Window* window_container = |
| 188 ash::Shell::GetContainer(target_root, window->parent()->id()); | 106 ash::Shell::GetContainer(target_root, window->parent()->id()); |
| 189 // Move the window to the target launcher. | 107 // Move the window to the target launcher. |
| 190 window_container->AddChild(window); | 108 window_container->AddChild(window); |
| 191 return true; | 109 return true; |
| 192 } | 110 } |
| 193 | 111 |
| 194 } // namespace wm | 112 } // namespace wm |
| 195 } // namespace ash | 113 } // namespace ash |
| OLD | NEW |