| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_state.h" | 5 #include "ash/wm/window_state.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/ash_switches.h" | 9 #include "ash/wm/common/wm_screen_util.h" |
| 10 #include "ash/root_window_controller.h" | |
| 11 #include "ash/screen_util.h" | |
| 12 #include "ash/shell_window_ids.h" | |
| 13 #include "ash/wm/default_state.h" | 10 #include "ash/wm/default_state.h" |
| 14 #include "ash/wm/window_animations.h" | |
| 15 #include "ash/wm/window_properties.h" | |
| 16 #include "ash/wm/window_state_delegate.h" | 11 #include "ash/wm/window_state_delegate.h" |
| 17 #include "ash/wm/window_state_observer.h" | 12 #include "ash/wm/window_state_observer.h" |
| 18 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
| 19 #include "ash/wm/wm_event.h" | 14 #include "ash/wm/wm_event.h" |
| 20 #include "base/auto_reset.h" | 15 #include "base/auto_reset.h" |
| 21 #include "base/command_line.h" | |
| 22 #include "ui/aura/client/aura_constants.h" | 16 #include "ui/aura/client/aura_constants.h" |
| 23 #include "ui/aura/layout_manager.h" | |
| 24 #include "ui/aura/window.h" | |
| 25 #include "ui/aura/window_delegate.h" | |
| 26 #include "ui/compositor/layer_tree_owner.h" | |
| 27 #include "ui/compositor/scoped_layer_animation_settings.h" | |
| 28 #include "ui/gfx/display.h" | 17 #include "ui/gfx/display.h" |
| 29 #include "ui/gfx/screen.h" | 18 #include "ui/gfx/screen.h" |
| 30 #include "ui/wm/core/window_util.h" | |
| 31 | 19 |
| 32 namespace ash { | 20 namespace ash { |
| 33 namespace wm { | 21 namespace wm { |
| 34 | 22 |
| 35 namespace { | 23 namespace { |
| 36 | 24 |
| 37 // A tentative class to set the bounds on the window. | |
| 38 // TODO(oshima): Once all logic is cleaned up, move this to the real layout | |
| 39 // manager with proper friendship. | |
| 40 class BoundsSetter : public aura::LayoutManager { | |
| 41 public: | |
| 42 BoundsSetter() {} | |
| 43 ~BoundsSetter() override {} | |
| 44 | |
| 45 // aura::LayoutManager overrides: | |
| 46 void OnWindowResized() override {} | |
| 47 void OnWindowAddedToLayout(aura::Window* child) override {} | |
| 48 void OnWillRemoveWindowFromLayout(aura::Window* child) override {} | |
| 49 void OnWindowRemovedFromLayout(aura::Window* child) override {} | |
| 50 void OnChildWindowVisibilityChanged(aura::Window* child, | |
| 51 bool visible) override {} | |
| 52 void SetChildBounds(aura::Window* child, | |
| 53 const gfx::Rect& requested_bounds) override {} | |
| 54 | |
| 55 void SetBounds(aura::Window* window, const gfx::Rect& bounds) { | |
| 56 SetChildBoundsDirect(window, bounds); | |
| 57 } | |
| 58 | |
| 59 private: | |
| 60 DISALLOW_COPY_AND_ASSIGN(BoundsSetter); | |
| 61 }; | |
| 62 | |
| 63 WMEventType WMEventTypeFromShowState(ui::WindowShowState requested_show_state) { | 25 WMEventType WMEventTypeFromShowState(ui::WindowShowState requested_show_state) { |
| 64 switch (requested_show_state) { | 26 switch (requested_show_state) { |
| 65 case ui::SHOW_STATE_DEFAULT: | 27 case ui::SHOW_STATE_DEFAULT: |
| 66 case ui::SHOW_STATE_NORMAL: | 28 case ui::SHOW_STATE_NORMAL: |
| 67 return WM_EVENT_NORMAL; | 29 return WM_EVENT_NORMAL; |
| 68 case ui::SHOW_STATE_MINIMIZED: | 30 case ui::SHOW_STATE_MINIMIZED: |
| 69 return WM_EVENT_MINIMIZE; | 31 return WM_EVENT_MINIMIZE; |
| 70 case ui::SHOW_STATE_MAXIMIZED: | 32 case ui::SHOW_STATE_MAXIMIZED: |
| 71 return WM_EVENT_MAXIMIZE; | 33 return WM_EVENT_MAXIMIZE; |
| 72 case ui::SHOW_STATE_FULLSCREEN: | 34 case ui::SHOW_STATE_FULLSCREEN: |
| 73 return WM_EVENT_FULLSCREEN; | 35 return WM_EVENT_FULLSCREEN; |
| 74 case ui::SHOW_STATE_INACTIVE: | 36 case ui::SHOW_STATE_INACTIVE: |
| 75 return WM_EVENT_SHOW_INACTIVE; | 37 return WM_EVENT_SHOW_INACTIVE; |
| 76 case ui::SHOW_STATE_DOCKED: | 38 case ui::SHOW_STATE_DOCKED: |
| 77 return WM_EVENT_DOCK; | 39 return WM_EVENT_DOCK; |
| 78 case ui::SHOW_STATE_END: | 40 case ui::SHOW_STATE_END: |
| 79 NOTREACHED() << "No WMEvent defined for the show state:" | 41 NOTREACHED() << "No WMEvent defined for the show state:" |
| 80 << requested_show_state; | 42 << requested_show_state; |
| 81 } | 43 } |
| 82 return WM_EVENT_NORMAL; | 44 return WM_EVENT_NORMAL; |
| 83 } | 45 } |
| 84 | 46 |
| 85 } // namespace | 47 } // namespace |
| 86 | 48 |
| 87 WindowState::~WindowState() { | 49 WindowState::~WindowState() { |
| 88 // WindowState is registered as an owned property of |window_|, and window | |
| 89 // unregisters all of its observers in its d'tor before destroying its | |
| 90 // properties. As a result, window_->RemoveObserver() doesn't need to (and | |
| 91 // shouldn't) be called here. | |
| 92 } | 50 } |
| 93 | 51 |
| 94 bool WindowState::HasDelegate() const { | 52 bool WindowState::HasDelegate() const { |
| 95 return !!delegate_; | 53 return !!delegate_; |
| 96 } | 54 } |
| 97 | 55 |
| 98 void WindowState::SetDelegate(std::unique_ptr<WindowStateDelegate> delegate) { | 56 void WindowState::SetDelegate(std::unique_ptr<WindowStateDelegate> delegate) { |
| 99 DCHECK(!delegate_.get()); | 57 DCHECK(!delegate_.get()); |
| 100 delegate_ = std::move(delegate); | 58 delegate_ = std::move(delegate); |
| 101 } | 59 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 130 bool WindowState::IsNormalStateType() const { | 88 bool WindowState::IsNormalStateType() const { |
| 131 return GetStateType() == WINDOW_STATE_TYPE_NORMAL || | 89 return GetStateType() == WINDOW_STATE_TYPE_NORMAL || |
| 132 GetStateType() == WINDOW_STATE_TYPE_DEFAULT; | 90 GetStateType() == WINDOW_STATE_TYPE_DEFAULT; |
| 133 } | 91 } |
| 134 | 92 |
| 135 bool WindowState::IsNormalOrSnapped() const { | 93 bool WindowState::IsNormalOrSnapped() const { |
| 136 return IsNormalStateType() || IsSnapped(); | 94 return IsNormalStateType() || IsSnapped(); |
| 137 } | 95 } |
| 138 | 96 |
| 139 bool WindowState::IsActive() const { | 97 bool WindowState::IsActive() const { |
| 140 return IsActiveWindow(window_); | 98 return window_->IsActive(); |
| 141 } | 99 } |
| 142 | 100 |
| 143 bool WindowState::IsDocked() const { | 101 bool WindowState::IsDocked() const { |
| 144 return GetStateType() == WINDOW_STATE_TYPE_DOCKED || | 102 return GetStateType() == WINDOW_STATE_TYPE_DOCKED || |
| 145 GetStateType() == WINDOW_STATE_TYPE_DOCKED_MINIMIZED; | 103 GetStateType() == WINDOW_STATE_TYPE_DOCKED_MINIMIZED; |
| 146 } | 104 } |
| 147 | 105 |
| 148 bool WindowState::IsUserPositionable() const { | 106 bool WindowState::IsUserPositionable() const { |
| 149 return (window()->type() == ui::wm::WINDOW_TYPE_NORMAL || | 107 return (window_->GetType() == ui::wm::WINDOW_TYPE_NORMAL || |
| 150 window()->type() == ui::wm::WINDOW_TYPE_PANEL); | 108 window_->GetType() == ui::wm::WINDOW_TYPE_PANEL); |
| 151 } | 109 } |
| 152 | 110 |
| 153 bool WindowState::CanMaximize() const { | 111 bool WindowState::CanMaximize() const { |
| 154 // Window must have the kCanMaximizeKey and have no maximum width or height. | 112 // Window must have the kCanMaximizeKey and have no maximum width or height. |
| 155 if (!window()->GetProperty(aura::client::kCanMaximizeKey)) | 113 if (!window_->CanMaximize()) |
| 156 return false; | 114 return false; |
| 157 | 115 |
| 158 if (!window()->delegate()) | 116 if (!window_->HasNonClientArea()) |
| 159 return true; | 117 return true; |
| 160 | 118 |
| 161 gfx::Size max_size = window_->delegate()->GetMaximumSize(); | 119 gfx::Size max_size = window_->GetMaximumSize(); |
| 162 return !max_size.width() && !max_size.height(); | 120 return !max_size.width() && !max_size.height(); |
| 163 } | 121 } |
| 164 | 122 |
| 165 bool WindowState::CanMinimize() const { | 123 bool WindowState::CanMinimize() const { |
| 166 return window()->GetProperty(aura::client::kCanMinimizeKey); | 124 return window_->CanMinimize(); |
| 167 } | 125 } |
| 168 | 126 |
| 169 bool WindowState::CanResize() const { | 127 bool WindowState::CanResize() const { |
| 170 return window_->GetProperty(aura::client::kCanResizeKey); | 128 return window_->CanResize(); |
| 171 } | 129 } |
| 172 | 130 |
| 173 bool WindowState::CanActivate() const { | 131 bool WindowState::CanActivate() const { |
| 174 return ::wm::CanActivateWindow(window_); | 132 return window_->CanActivate(); |
| 175 } | 133 } |
| 176 | 134 |
| 177 bool WindowState::CanSnap() const { | 135 bool WindowState::CanSnap() const { |
| 178 if (!CanResize() || window_->type() == ui::wm::WINDOW_TYPE_PANEL || | 136 if (!CanResize() || window_->GetType() == ui::wm::WINDOW_TYPE_PANEL || |
| 179 ::wm::GetTransientParent(window_)) | 137 window_->GetTransientParent()) { |
| 180 return false; | 138 return false; |
| 139 } |
| 181 // If a window cannot be maximized, assume it cannot snap either. | 140 // If a window cannot be maximized, assume it cannot snap either. |
| 182 // TODO(oshima): We should probably snap if the maximum size is greater than | 141 // TODO(oshima): We should probably snap if the maximum size is greater than |
| 183 // the snapped size. | 142 // the snapped size. |
| 184 return CanMaximize(); | 143 return CanMaximize(); |
| 185 } | 144 } |
| 186 | 145 |
| 187 bool WindowState::HasRestoreBounds() const { | 146 bool WindowState::HasRestoreBounds() const { |
| 188 return window_->GetProperty(aura::client::kRestoreBoundsKey) != NULL; | 147 return window_->HasRestoreBounds(); |
| 189 } | 148 } |
| 190 | 149 |
| 191 void WindowState::Maximize() { | 150 void WindowState::Maximize() { |
| 192 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 151 window_->Maximize(); |
| 193 } | 152 } |
| 194 | 153 |
| 195 void WindowState::Minimize() { | 154 void WindowState::Minimize() { |
| 196 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | 155 window_->Minimize(); |
| 197 } | 156 } |
| 198 | 157 |
| 199 void WindowState::Unminimize() { | 158 void WindowState::Unminimize() { |
| 200 window_->SetProperty( | 159 window_->Unminimize(); |
| 201 aura::client::kShowStateKey, | |
| 202 window_->GetProperty(aura::client::kRestoreShowStateKey)); | |
| 203 window_->ClearProperty(aura::client::kRestoreShowStateKey); | |
| 204 } | 160 } |
| 205 | 161 |
| 206 void WindowState::Activate() { | 162 void WindowState::Activate() { |
| 207 ActivateWindow(window_); | 163 window_->Activate(); |
| 208 } | 164 } |
| 209 | 165 |
| 210 void WindowState::Deactivate() { | 166 void WindowState::Deactivate() { |
| 211 DeactivateWindow(window_); | 167 window_->Deactivate(); |
| 212 } | 168 } |
| 213 | 169 |
| 214 void WindowState::Restore() { | 170 void WindowState::Restore() { |
| 215 if (!IsNormalStateType()) { | 171 if (!IsNormalStateType()) { |
| 216 const WMEvent event(WM_EVENT_NORMAL); | 172 const WMEvent event(WM_EVENT_NORMAL); |
| 217 OnWMEvent(&event); | 173 OnWMEvent(&event); |
| 218 } | 174 } |
| 219 } | 175 } |
| 220 | 176 |
| 221 void WindowState::DisableAlwaysOnTop(aura::Window* window_on_top) { | 177 void WindowState::DisableAlwaysOnTop(WmWindow* window_on_top) { |
| 222 DCHECK(window_on_top); | 178 DCHECK(window_on_top); |
| 223 if (GetAlwaysOnTop()) { | 179 if (GetAlwaysOnTop()) { |
| 224 // |window_| is hidden first to avoid canceling fullscreen mode when it is | 180 // |window_| is hidden first to avoid canceling fullscreen mode when it is |
| 225 // no longer always on top and gets added to default container. This avoids | 181 // no longer always on top and gets added to default container. This avoids |
| 226 // sending redundant OnFullscreenStateChanged to the layout manager. The | 182 // sending redundant OnFullscreenStateChanged to the layout manager. The |
| 227 // |window_| visibility is restored after it no longer obscures the | 183 // |window_| visibility is restored after it no longer obscures the |
| 228 // |window_on_top|. | 184 // |window_on_top|. |
| 229 bool visible = window_->IsVisible(); | 185 bool visible = window_->IsVisible(); |
| 230 if (visible) | 186 if (visible) |
| 231 window_->Hide(); | 187 window_->Hide(); |
| 232 window_->SetProperty(aura::client::kAlwaysOnTopKey, false); | 188 window_->SetAlwaysOnTop(false); |
| 233 // Technically it is possible that a |window_| could make itself | 189 // Technically it is possible that a |window_| could make itself |
| 234 // always_on_top really quickly. This is probably not a realistic case but | 190 // always_on_top really quickly. This is probably not a realistic case but |
| 235 // check if the two windows are in the same container just in case. | 191 // check if the two windows are in the same container just in case. |
| 236 if (window_on_top->parent() == window_->parent()) | 192 if (window_on_top->GetParent() == window_->GetParent()) |
| 237 window_->parent()->StackChildAbove(window_on_top, window_); | 193 window_->GetParent()->StackChildAbove(window_on_top, window_); |
| 238 if (visible) | 194 if (visible) |
| 239 window_->Show(); | 195 window_->Show(); |
| 240 cached_always_on_top_ = true; | 196 cached_always_on_top_ = true; |
| 241 } | 197 } |
| 242 } | 198 } |
| 243 | 199 |
| 244 void WindowState::RestoreAlwaysOnTop() { | 200 void WindowState::RestoreAlwaysOnTop() { |
| 245 if (delegate() && delegate()->RestoreAlwaysOnTop(this)) | 201 if (delegate() && delegate()->RestoreAlwaysOnTop(this)) |
| 246 return; | 202 return; |
| 247 if (cached_always_on_top_) { | 203 if (cached_always_on_top_) { |
| 248 cached_always_on_top_ = false; | 204 cached_always_on_top_ = false; |
| 249 window_->SetProperty(aura::client::kAlwaysOnTopKey, true); | 205 window_->SetAlwaysOnTop(true); |
| 250 } | 206 } |
| 251 } | 207 } |
| 252 | 208 |
| 253 void WindowState::OnWMEvent(const WMEvent* event) { | 209 void WindowState::OnWMEvent(const WMEvent* event) { |
| 254 current_state_->OnWMEvent(this, event); | 210 current_state_->OnWMEvent(this, event); |
| 255 } | 211 } |
| 256 | 212 |
| 257 void WindowState::SaveCurrentBoundsForRestore() { | 213 void WindowState::SaveCurrentBoundsForRestore() { |
| 258 gfx::Rect bounds_in_screen = | 214 gfx::Rect bounds_in_screen = |
| 259 ScreenUtil::ConvertRectToScreen(window_->parent(), | 215 window_->GetParent()->ConvertRectToScreen(window_->GetBounds()); |
| 260 window_->bounds()); | |
| 261 SetRestoreBoundsInScreen(bounds_in_screen); | 216 SetRestoreBoundsInScreen(bounds_in_screen); |
| 262 } | 217 } |
| 263 | 218 |
| 264 gfx::Rect WindowState::GetRestoreBoundsInScreen() const { | 219 gfx::Rect WindowState::GetRestoreBoundsInScreen() const { |
| 265 return *window_->GetProperty(aura::client::kRestoreBoundsKey); | 220 return window_->GetRestoreBoundsInScreen(); |
| 266 } | 221 } |
| 267 | 222 |
| 268 gfx::Rect WindowState::GetRestoreBoundsInParent() const { | 223 gfx::Rect WindowState::GetRestoreBoundsInParent() const { |
| 269 return ScreenUtil::ConvertRectFromScreen(window_->parent(), | 224 return window_->GetParent()->ConvertRectFromScreen( |
| 270 GetRestoreBoundsInScreen()); | 225 GetRestoreBoundsInScreen()); |
| 271 } | 226 } |
| 272 | 227 |
| 273 void WindowState::SetRestoreBoundsInScreen(const gfx::Rect& bounds) { | 228 void WindowState::SetRestoreBoundsInScreen(const gfx::Rect& bounds) { |
| 274 window_->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds)); | 229 window_->SetRestoreBoundsInScreen(bounds); |
| 275 } | 230 } |
| 276 | 231 |
| 277 void WindowState::SetRestoreBoundsInParent(const gfx::Rect& bounds) { | 232 void WindowState::SetRestoreBoundsInParent(const gfx::Rect& bounds) { |
| 278 SetRestoreBoundsInScreen( | 233 SetRestoreBoundsInScreen(window_->GetParent()->ConvertRectToScreen(bounds)); |
| 279 ScreenUtil::ConvertRectToScreen(window_->parent(), bounds)); | |
| 280 } | 234 } |
| 281 | 235 |
| 282 void WindowState::ClearRestoreBounds() { | 236 void WindowState::ClearRestoreBounds() { |
| 283 window_->ClearProperty(aura::client::kRestoreBoundsKey); | 237 window_->ClearRestoreBounds(); |
| 284 } | 238 } |
| 285 | 239 |
| 286 std::unique_ptr<WindowState::State> WindowState::SetStateObject( | 240 std::unique_ptr<WindowState::State> WindowState::SetStateObject( |
| 287 std::unique_ptr<WindowState::State> new_state) { | 241 std::unique_ptr<WindowState::State> new_state) { |
| 288 current_state_->DetachState(this); | 242 current_state_->DetachState(this); |
| 289 std::unique_ptr<WindowState::State> old_object = std::move(current_state_); | 243 std::unique_ptr<WindowState::State> old_object = std::move(current_state_); |
| 290 current_state_ = std::move(new_state); | 244 current_state_ = std::move(new_state); |
| 291 current_state_->AttachState(this, old_object.get()); | 245 current_state_->AttachState(this, old_object.get()); |
| 292 return old_object; | 246 return old_object; |
| 293 } | 247 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 304 void WindowState::RemoveObserver(WindowStateObserver* observer) { | 258 void WindowState::RemoveObserver(WindowStateObserver* observer) { |
| 305 observer_list_.RemoveObserver(observer); | 259 observer_list_.RemoveObserver(observer); |
| 306 } | 260 } |
| 307 | 261 |
| 308 void WindowState::set_bounds_changed_by_user(bool bounds_changed_by_user) { | 262 void WindowState::set_bounds_changed_by_user(bool bounds_changed_by_user) { |
| 309 bounds_changed_by_user_ = bounds_changed_by_user; | 263 bounds_changed_by_user_ = bounds_changed_by_user; |
| 310 if (bounds_changed_by_user) | 264 if (bounds_changed_by_user) |
| 311 pre_auto_manage_window_bounds_.reset(); | 265 pre_auto_manage_window_bounds_.reset(); |
| 312 } | 266 } |
| 313 | 267 |
| 314 void WindowState::CreateDragDetails(aura::Window* window, | 268 void WindowState::CreateDragDetails(const gfx::Point& point_in_parent, |
| 315 const gfx::Point& point_in_parent, | |
| 316 int window_component, | 269 int window_component, |
| 317 aura::client::WindowMoveSource source) { | 270 aura::client::WindowMoveSource source) { |
| 318 drag_details_.reset( | 271 drag_details_.reset( |
| 319 new DragDetails(window, point_in_parent, window_component, source)); | 272 new DragDetails(window_, point_in_parent, window_component, source)); |
| 320 } | 273 } |
| 321 | 274 |
| 322 void WindowState::DeleteDragDetails() { | 275 void WindowState::DeleteDragDetails() { |
| 323 drag_details_.reset(); | 276 drag_details_.reset(); |
| 324 } | 277 } |
| 325 | 278 |
| 326 void WindowState::SetAndClearRestoreBounds() { | 279 void WindowState::SetAndClearRestoreBounds() { |
| 327 DCHECK(HasRestoreBounds()); | 280 DCHECK(HasRestoreBounds()); |
| 328 SetBoundsInScreen(GetRestoreBoundsInScreen()); | 281 SetBoundsInScreen(GetRestoreBoundsInScreen()); |
| 329 ClearRestoreBounds(); | 282 ClearRestoreBounds(); |
| 330 } | 283 } |
| 331 | 284 |
| 332 void WindowState::OnWindowPropertyChanged(aura::Window* window, | 285 void WindowState::OnWindowShowStateChanged() { |
| 333 const void* key, | 286 if (!ignore_property_change_) { |
| 334 intptr_t old) { | |
| 335 DCHECK_EQ(window, window_); | |
| 336 if (key == aura::client::kShowStateKey && !ignore_property_change_) { | |
| 337 WMEvent event(WMEventTypeFromShowState(GetShowState())); | 287 WMEvent event(WMEventTypeFromShowState(GetShowState())); |
| 338 OnWMEvent(&event); | 288 OnWMEvent(&event); |
| 339 } | 289 } |
| 340 } | 290 } |
| 341 | 291 |
| 342 WindowState::WindowState(aura::Window* window) | 292 WindowState::WindowState(WmWindow* window) |
| 343 : window_(window), | 293 : window_(window), |
| 344 window_position_managed_(false), | 294 window_position_managed_(false), |
| 345 bounds_changed_by_user_(false), | 295 bounds_changed_by_user_(false), |
| 346 panel_attached_(true), | 296 panel_attached_(true), |
| 347 ignored_by_shelf_(false), | 297 ignored_by_shelf_(false), |
| 348 can_consume_system_keys_(false), | 298 can_consume_system_keys_(false), |
| 349 top_row_keys_are_function_keys_(false), | 299 top_row_keys_are_function_keys_(false), |
| 350 unminimize_to_restore_bounds_(false), | 300 unminimize_to_restore_bounds_(false), |
| 351 in_immersive_fullscreen_(false), | 301 in_immersive_fullscreen_(false), |
| 352 hide_shelf_when_fullscreen_(true), | 302 hide_shelf_when_fullscreen_(true), |
| 353 minimum_visibility_(false), | 303 minimum_visibility_(false), |
| 354 can_be_dragged_(true), | 304 can_be_dragged_(true), |
| 355 cached_always_on_top_(false), | 305 cached_always_on_top_(false), |
| 356 ignore_property_change_(false), | 306 ignore_property_change_(false), |
| 357 current_state_(new DefaultState(ToWindowStateType(GetShowState()))) { | 307 current_state_(new DefaultState(ToWindowStateType(GetShowState()))) {} |
| 358 window_->AddObserver(this); | |
| 359 } | |
| 360 | 308 |
| 361 bool WindowState::GetAlwaysOnTop() const { | 309 bool WindowState::GetAlwaysOnTop() const { |
| 362 return window_->GetProperty(aura::client::kAlwaysOnTopKey); | 310 return window_->IsAlwaysOnTop(); |
| 363 } | 311 } |
| 364 | 312 |
| 365 ui::WindowShowState WindowState::GetShowState() const { | 313 ui::WindowShowState WindowState::GetShowState() const { |
| 366 return window_->GetProperty(aura::client::kShowStateKey); | 314 return window_->GetShowState(); |
| 367 } | 315 } |
| 368 | 316 |
| 369 void WindowState::SetBoundsInScreen( | 317 void WindowState::SetBoundsInScreen( |
| 370 const gfx::Rect& bounds_in_screen) { | 318 const gfx::Rect& bounds_in_screen) { |
| 371 gfx::Rect bounds_in_parent = | 319 gfx::Rect bounds_in_parent = |
| 372 ScreenUtil::ConvertRectFromScreen(window_->parent(), | 320 window_->GetParent()->ConvertRectFromScreen(bounds_in_screen); |
| 373 bounds_in_screen); | |
| 374 window_->SetBounds(bounds_in_parent); | 321 window_->SetBounds(bounds_in_parent); |
| 375 } | 322 } |
| 376 | 323 |
| 377 void WindowState::AdjustSnappedBounds(gfx::Rect* bounds) { | 324 void WindowState::AdjustSnappedBounds(gfx::Rect* bounds) { |
| 378 if (is_dragged() || !IsSnapped()) | 325 if (is_dragged() || !IsSnapped()) |
| 379 return; | 326 return; |
| 380 gfx::Rect maximized_bounds = ScreenUtil::GetMaximizedWindowBoundsInParent( | 327 gfx::Rect maximized_bounds = GetMaximizedWindowBoundsInParent(window_); |
| 381 window_); | |
| 382 if (GetStateType() == WINDOW_STATE_TYPE_LEFT_SNAPPED) | 328 if (GetStateType() == WINDOW_STATE_TYPE_LEFT_SNAPPED) |
| 383 bounds->set_x(maximized_bounds.x()); | 329 bounds->set_x(maximized_bounds.x()); |
| 384 else if (GetStateType() == WINDOW_STATE_TYPE_RIGHT_SNAPPED) | 330 else if (GetStateType() == WINDOW_STATE_TYPE_RIGHT_SNAPPED) |
| 385 bounds->set_x(maximized_bounds.right() - bounds->width()); | 331 bounds->set_x(maximized_bounds.right() - bounds->width()); |
| 386 bounds->set_y(maximized_bounds.y()); | 332 bounds->set_y(maximized_bounds.y()); |
| 387 bounds->set_height(maximized_bounds.height()); | 333 bounds->set_height(maximized_bounds.height()); |
| 388 } | 334 } |
| 389 | 335 |
| 390 void WindowState::UpdateWindowShowStateFromStateType() { | 336 void WindowState::UpdateWindowShowStateFromStateType() { |
| 391 ui::WindowShowState new_window_state = | 337 ui::WindowShowState new_window_state = |
| 392 ToWindowShowState(current_state_->GetType()); | 338 ToWindowShowState(current_state_->GetType()); |
| 393 if (new_window_state != GetShowState()) { | 339 if (new_window_state != GetShowState()) { |
| 394 base::AutoReset<bool> resetter(&ignore_property_change_, true); | 340 base::AutoReset<bool> resetter(&ignore_property_change_, true); |
| 395 window_->SetProperty(aura::client::kShowStateKey, new_window_state); | 341 window_->SetShowState(new_window_state); |
| 396 } | 342 } |
| 397 } | 343 } |
| 398 | 344 |
| 399 void WindowState::NotifyPreStateTypeChange( | 345 void WindowState::NotifyPreStateTypeChange( |
| 400 WindowStateType old_window_state_type) { | 346 WindowStateType old_window_state_type) { |
| 401 FOR_EACH_OBSERVER(WindowStateObserver, observer_list_, | 347 FOR_EACH_OBSERVER(WindowStateObserver, observer_list_, |
| 402 OnPreWindowStateTypeChange(this, old_window_state_type)); | 348 OnPreWindowStateTypeChange(this, old_window_state_type)); |
| 403 } | 349 } |
| 404 | 350 |
| 405 void WindowState::NotifyPostStateTypeChange( | 351 void WindowState::NotifyPostStateTypeChange( |
| 406 WindowStateType old_window_state_type) { | 352 WindowStateType old_window_state_type) { |
| 407 FOR_EACH_OBSERVER(WindowStateObserver, observer_list_, | 353 FOR_EACH_OBSERVER(WindowStateObserver, observer_list_, |
| 408 OnPostWindowStateTypeChange(this, old_window_state_type)); | 354 OnPostWindowStateTypeChange(this, old_window_state_type)); |
| 409 } | 355 } |
| 410 | 356 |
| 411 void WindowState::SetBoundsDirect(const gfx::Rect& bounds) { | 357 void WindowState::SetBoundsDirect(const gfx::Rect& bounds) { |
| 412 gfx::Rect actual_new_bounds(bounds); | 358 gfx::Rect actual_new_bounds(bounds); |
| 413 // Ensure we don't go smaller than our minimum bounds in "normal" window | 359 // Ensure we don't go smaller than our minimum bounds in "normal" window |
| 414 // modes | 360 // modes |
| 415 if (window_->delegate() && !IsMaximized() && !IsFullscreen()) { | 361 if (window_->HasNonClientArea() && !IsMaximized() && !IsFullscreen()) { |
| 416 // Get the minimum usable size of the minimum size and the screen size. | 362 // Get the minimum usable size of the minimum size and the screen size. |
| 417 gfx::Size min_size = window_->delegate()->GetMinimumSize(); | 363 gfx::Size min_size = window_->GetMinimumSize(); |
| 418 min_size.SetToMin(gfx::Screen::GetScreen() | 364 min_size.SetToMin(window_->GetDisplayNearestWindow().work_area().size()); |
| 419 ->GetDisplayNearestWindow(window_) | |
| 420 .work_area() | |
| 421 .size()); | |
| 422 | 365 |
| 423 actual_new_bounds.set_width( | 366 actual_new_bounds.set_width( |
| 424 std::max(min_size.width(), actual_new_bounds.width())); | 367 std::max(min_size.width(), actual_new_bounds.width())); |
| 425 actual_new_bounds.set_height( | 368 actual_new_bounds.set_height( |
| 426 std::max(min_size.height(), actual_new_bounds.height())); | 369 std::max(min_size.height(), actual_new_bounds.height())); |
| 427 } | 370 } |
| 428 BoundsSetter().SetBounds(window_, actual_new_bounds); | 371 window_->SetBoundsDirect(actual_new_bounds); |
| 429 SnapWindowToPixelBoundary(window_); | |
| 430 } | 372 } |
| 431 | 373 |
| 432 void WindowState::SetBoundsConstrained(const gfx::Rect& bounds) { | 374 void WindowState::SetBoundsConstrained(const gfx::Rect& bounds) { |
| 433 gfx::Rect work_area_in_parent = | 375 gfx::Rect work_area_in_parent = GetDisplayWorkAreaBoundsInParent(window_); |
| 434 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_); | |
| 435 gfx::Rect child_bounds(bounds); | 376 gfx::Rect child_bounds(bounds); |
| 436 AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds); | 377 AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds); |
| 437 SetBoundsDirect(child_bounds); | 378 SetBoundsDirect(child_bounds); |
| 438 } | 379 } |
| 439 | 380 |
| 440 void WindowState::SetBoundsDirectAnimated(const gfx::Rect& bounds) { | 381 void WindowState::SetBoundsDirectAnimated(const gfx::Rect& bounds) { |
| 441 const int kBoundsChangeSlideDurationMs = 120; | 382 window_->SetBoundsDirectAnimated(bounds); |
| 442 | |
| 443 ui::Layer* layer = window_->layer(); | |
| 444 ui::ScopedLayerAnimationSettings slide_settings(layer->GetAnimator()); | |
| 445 slide_settings.SetPreemptionStrategy( | |
| 446 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
| 447 slide_settings.SetTransitionDuration( | |
| 448 base::TimeDelta::FromMilliseconds(kBoundsChangeSlideDurationMs)); | |
| 449 SetBoundsDirect(bounds); | |
| 450 } | 383 } |
| 451 | 384 |
| 452 void WindowState::SetBoundsDirectCrossFade(const gfx::Rect& new_bounds) { | 385 void WindowState::SetBoundsDirectCrossFade(const gfx::Rect& new_bounds) { |
| 453 // Some test results in invoking CrossFadeToBounds when window is not visible. | 386 // Some test results in invoking CrossFadeToBounds when window is not visible. |
| 454 // No animation is necessary in that case, thus just change the bounds and | 387 // No animation is necessary in that case, thus just change the bounds and |
| 455 // quit. | 388 // quit. |
| 456 if (!window_->TargetVisibility()) { | 389 if (!window_->GetTargetVisibility()) { |
| 457 SetBoundsConstrained(new_bounds); | 390 SetBoundsConstrained(new_bounds); |
| 458 return; | 391 return; |
| 459 } | 392 } |
| 460 | 393 |
| 461 const gfx::Rect old_bounds = window_->bounds(); | 394 window_->SetBoundsDirectCrossFade(new_bounds); |
| 462 | |
| 463 // Create fresh layers for the window and all its children to paint into. | |
| 464 // Takes ownership of the old layer and all its children, which will be | |
| 465 // cleaned up after the animation completes. | |
| 466 // Specify |set_bounds| to true here to keep the old bounds in the child | |
| 467 // windows of |window|. | |
| 468 std::unique_ptr<ui::LayerTreeOwner> old_layer_owner = | |
| 469 ::wm::RecreateLayers(window_); | |
| 470 ui::Layer* old_layer = old_layer_owner->root(); | |
| 471 DCHECK(old_layer); | |
| 472 ui::Layer* new_layer = window_->layer(); | |
| 473 | |
| 474 // Resize the window to the new size, which will force a layout and paint. | |
| 475 SetBoundsDirect(new_bounds); | |
| 476 | |
| 477 // Ensure the higher-resolution layer is on top. | |
| 478 bool old_on_top = (old_bounds.width() > new_bounds.width()); | |
| 479 if (old_on_top) | |
| 480 old_layer->parent()->StackBelow(new_layer, old_layer); | |
| 481 else | |
| 482 old_layer->parent()->StackAbove(new_layer, old_layer); | |
| 483 | |
| 484 CrossFadeAnimation(window_, std::move(old_layer_owner), gfx::Tween::EASE_OUT); | |
| 485 } | |
| 486 | |
| 487 WindowState* GetActiveWindowState() { | |
| 488 aura::Window* active = GetActiveWindow(); | |
| 489 return active ? GetWindowState(active) : NULL; | |
| 490 } | |
| 491 | |
| 492 WindowState* GetWindowState(aura::Window* window) { | |
| 493 if (!window) | |
| 494 return NULL; | |
| 495 WindowState* settings = window->GetProperty(kWindowStateKey); | |
| 496 if(!settings) { | |
| 497 settings = new WindowState(window); | |
| 498 window->SetProperty(kWindowStateKey, settings); | |
| 499 } | |
| 500 return settings; | |
| 501 } | |
| 502 | |
| 503 const WindowState* GetWindowState(const aura::Window* window) { | |
| 504 return GetWindowState(const_cast<aura::Window*>(window)); | |
| 505 } | 395 } |
| 506 | 396 |
| 507 } // namespace wm | 397 } // namespace wm |
| 508 } // namespace ash | 398 } // namespace ash |
| OLD | NEW |