Chromium Code Reviews| 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" | 10 #include "ash/root_window_controller.h" |
| 11 #include "ash/screen_ash.h" | |
| 11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 12 #include "ash/shell_window_ids.h" | 13 #include "ash/shell_window_ids.h" |
| 13 #include "ash/wm/activation_controller.h" | 14 #include "ash/wm/activation_controller.h" |
| 15 #include "ash/wm/property_util.h" | |
| 14 #include "ash/wm/window_properties.h" | 16 #include "ash/wm/window_properties.h" |
| 15 #include "ui/aura/client/activation_client.h" | 17 #include "ui/aura/client/activation_client.h" |
| 16 #include "ui/aura/client/aura_constants.h" | 18 #include "ui/aura/client/aura_constants.h" |
| 17 #include "ui/aura/root_window.h" | 19 #include "ui/aura/root_window.h" |
| 18 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
| 19 #include "ui/aura/window_delegate.h" | 21 #include "ui/aura/window_delegate.h" |
| 20 #include "ui/compositor/layer.h" | 22 #include "ui/compositor/layer.h" |
| 21 #include "ui/gfx/display.h" | 23 #include "ui/gfx/display.h" |
| 22 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
| 23 #include "ui/gfx/screen.h" | 25 #include "ui/gfx/screen.h" |
| 24 #include "ui/views/corewm/window_util.h" | 26 #include "ui/views/corewm/window_util.h" |
| 25 #include "ui/views/view.h" | 27 #include "ui/views/view.h" |
| 26 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
| 27 | 29 |
| 28 namespace ash { | 30 namespace ash { |
| 29 namespace wm { | 31 namespace wm { |
| 32 namespace { | |
| 33 | |
| 34 // The percent of the screen's width that a snapped window takes up. | |
| 35 const int kSnappedWindowScreenWidthPercent = 50; | |
| 36 | |
| 37 } // namespace | |
| 30 | 38 |
| 31 // TODO(beng): replace many of these functions with the corewm versions. | 39 // TODO(beng): replace many of these functions with the corewm versions. |
| 32 void ActivateWindow(aura::Window* window) { | 40 void ActivateWindow(aura::Window* window) { |
| 33 views::corewm::ActivateWindow(window); | 41 views::corewm::ActivateWindow(window); |
| 34 } | 42 } |
| 35 | 43 |
| 36 void DeactivateWindow(aura::Window* window) { | 44 void DeactivateWindow(aura::Window* window) { |
| 37 views::corewm::DeactivateWindow(window); | 45 views::corewm::DeactivateWindow(window); |
| 38 } | 46 } |
| 39 | 47 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 return true; | 79 return true; |
| 72 } | 80 } |
| 73 | 81 |
| 74 bool CanResizeWindow(const aura::Window* window) { | 82 bool CanResizeWindow(const aura::Window* window) { |
| 75 return window->GetProperty(aura::client::kCanResizeKey); | 83 return window->GetProperty(aura::client::kCanResizeKey); |
| 76 } | 84 } |
| 77 | 85 |
| 78 bool CanSnapWindow(aura::Window* window) { | 86 bool CanSnapWindow(aura::Window* window) { |
| 79 if (!CanResizeWindow(window)) | 87 if (!CanResizeWindow(window)) |
| 80 return false; | 88 return false; |
| 81 // If a window has a maximum size defined, snapping may make it too big. | 89 |
| 82 return window->delegate() ? window->delegate()->GetMaximumSize().IsEmpty() : | 90 if (window->delegate()) { |
| 83 true; | 91 // The size of a snapped window is not affected by the edge it is snapped |
| 92 // to. | |
| 93 gfx::Size snapped_size = | |
| 94 GetSnappedWindowBoundsInParent(window, SNAP_LEFT_EDGE).size(); | |
| 95 | |
| 96 gfx::Size minimum_size = window->delegate()->GetMinimumSize(); | |
| 97 if (minimum_size.width() > snapped_size.width()) | |
|
Mr4D (OOO till 08-26)
2013/08/29 01:03:15
Hmm. Does this mean that if you have a window whic
| |
| 98 return false; | |
| 99 gfx::Size maximum_size = window->delegate()->GetMaximumSize(); | |
| 100 if (!maximum_size.IsEmpty() && | |
| 101 (maximum_size.width() < snapped_size.width() || | |
| 102 maximum_size.height() < snapped_size.height())) { | |
| 103 return false; | |
| 104 } | |
| 105 } | |
| 106 return true; | |
| 84 } | 107 } |
| 85 | 108 |
| 86 bool IsWindowNormal(const aura::Window* window) { | 109 bool IsWindowNormal(const aura::Window* window) { |
| 87 return IsWindowStateNormal(window->GetProperty(aura::client::kShowStateKey)); | 110 return IsWindowStateNormal(window->GetProperty(aura::client::kShowStateKey)); |
| 88 } | 111 } |
| 89 | 112 |
| 90 bool IsWindowStateNormal(ui::WindowShowState state) { | 113 bool IsWindowStateNormal(ui::WindowShowState state) { |
| 91 return state == ui::SHOW_STATE_NORMAL || state == ui::SHOW_STATE_DEFAULT; | 114 return state == ui::SHOW_STATE_NORMAL || state == ui::SHOW_STATE_DEFAULT; |
| 92 } | 115 } |
| 93 | 116 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 112 | 135 |
| 113 void MinimizeWindow(aura::Window* window) { | 136 void MinimizeWindow(aura::Window* window) { |
| 114 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 137 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
| 115 } | 138 } |
| 116 | 139 |
| 117 void RestoreWindow(aura::Window* window) { | 140 void RestoreWindow(aura::Window* window) { |
| 118 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 141 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 119 } | 142 } |
| 120 | 143 |
| 121 void ToggleMaximizedWindow(aura::Window* window) { | 144 void ToggleMaximizedWindow(aura::Window* window) { |
| 122 if (ash::wm::IsWindowMaximized(window)) | 145 if (IsWindowMaximized(window)) |
| 123 ash::wm::RestoreWindow(window); | 146 RestoreWindow(window); |
| 124 else if (ash::wm::CanMaximizeWindow(window)) | 147 else if (CanMaximizeWindow(window)) |
| 125 ash::wm::MaximizeWindow(window); | 148 MaximizeWindow(window); |
| 149 } | |
| 150 | |
| 151 gfx::Rect GetSnappedWindowBoundsInParent(aura::Window* window, SnapEdge edge) { | |
| 152 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window)); | |
| 153 int width = work_area.width() * kSnappedWindowScreenWidthPercent / 100; | |
| 154 int x = (edge == SNAP_LEFT_EDGE) ? work_area.x() : work_area.right() - width; | |
| 155 | |
| 156 return gfx::Rect(x, work_area.y(), width, work_area.height()); | |
| 157 } | |
| 158 | |
| 159 void SnapWindowToEdge(aura::Window* window, SnapEdge edge) { | |
| 160 gfx::Rect bounds(GetSnappedWindowBoundsInParent(window, edge)); | |
| 161 | |
| 162 if (IsWindowFullscreen(window) || IsWindowMaximized(window)) { | |
| 163 // Before we can set the bounds we need to restore the window. | |
| 164 // Restoring the window will set the window to its restored bounds. | |
| 165 // To avoid an unnecessary bounds changes (which may have side effects) | |
| 166 // we set the restore bounds to the bounds we want, restore the window, | |
| 167 // then reset the restore bounds. This way no unnecessary bounds | |
| 168 // changes occurs and the original restore bounds is remembered. | |
| 169 gfx::Rect restore = *GetRestoreBoundsInScreen(window); | |
| 170 SetRestoreBoundsInParent(window, bounds); | |
| 171 RestoreWindow(window); | |
| 172 SetRestoreBoundsInScreen(window, restore); | |
| 173 } else { | |
| 174 window->SetBounds(bounds); | |
| 175 } | |
| 126 } | 176 } |
| 127 | 177 |
| 128 void CenterWindow(aura::Window* window) { | 178 void CenterWindow(aura::Window* window) { |
| 129 const gfx::Display display = | 179 const gfx::Display display = |
| 130 Shell::GetScreen()->GetDisplayNearestWindow(window); | 180 Shell::GetScreen()->GetDisplayNearestWindow(window); |
| 131 gfx::Rect center = display.work_area(); | 181 gfx::Rect center = display.work_area(); |
| 132 center.ClampToCenteredSize(window->bounds().size()); | 182 center.ClampToCenteredSize(window->bounds().size()); |
| 133 window->SetBoundsInScreen(center, display); | 183 window->SetBoundsInScreen(center, display); |
| 134 } | 184 } |
| 135 | 185 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 return false; | 253 return false; |
| 204 aura::Window* window_container = | 254 aura::Window* window_container = |
| 205 ash::Shell::GetContainer(target_root, window->parent()->id()); | 255 ash::Shell::GetContainer(target_root, window->parent()->id()); |
| 206 // Move the window to the target launcher. | 256 // Move the window to the target launcher. |
| 207 window_container->AddChild(window); | 257 window_container->AddChild(window); |
| 208 return true; | 258 return true; |
| 209 } | 259 } |
| 210 | 260 |
| 211 } // namespace wm | 261 } // namespace wm |
| 212 } // namespace ash | 262 } // namespace ash |
| OLD | NEW |