| 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/common/wm/window_state.h" | 5 #include "ash/common/wm/window_state.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/wm/default_state.h" | 9 #include "ash/common/wm/default_state.h" |
| 10 #include "ash/common/wm/window_positioning_utils.h" | 10 #include "ash/common/wm/window_positioning_utils.h" |
| 11 #include "ash/common/wm/window_state_delegate.h" | 11 #include "ash/common/wm/window_state_delegate.h" |
| 12 #include "ash/common/wm/window_state_observer.h" | 12 #include "ash/common/wm/window_state_observer.h" |
| 13 #include "ash/common/wm/wm_event.h" | 13 #include "ash/common/wm/wm_event.h" |
| 14 #include "ash/common/wm/wm_screen_util.h" | 14 #include "ash/common/wm/wm_screen_util.h" |
| 15 #include "ash/common/wm_window.h" | 15 #include "ash/common/wm_window.h" |
| 16 #include "ash/public/cpp/window_properties.h" |
| 16 #include "base/auto_reset.h" | 17 #include "base/auto_reset.h" |
| 17 | 18 |
| 18 namespace ash { | 19 namespace ash { |
| 19 namespace wm { | 20 namespace wm { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 WMEventType WMEventTypeFromShowState(ui::WindowShowState requested_show_state) { | 24 WMEventType WMEventTypeFromShowState(ui::WindowShowState requested_show_state) { |
| 24 switch (requested_show_state) { | 25 switch (requested_show_state) { |
| 25 case ui::SHOW_STATE_DEFAULT: | 26 case ui::SHOW_STATE_DEFAULT: |
| 26 case ui::SHOW_STATE_NORMAL: | 27 case ui::SHOW_STATE_NORMAL: |
| 27 return WM_EVENT_NORMAL; | 28 return WM_EVENT_NORMAL; |
| 28 case ui::SHOW_STATE_MINIMIZED: | 29 case ui::SHOW_STATE_MINIMIZED: |
| 29 return WM_EVENT_MINIMIZE; | 30 return WM_EVENT_MINIMIZE; |
| 30 case ui::SHOW_STATE_MAXIMIZED: | 31 case ui::SHOW_STATE_MAXIMIZED: |
| 31 return WM_EVENT_MAXIMIZE; | 32 return WM_EVENT_MAXIMIZE; |
| 32 case ui::SHOW_STATE_FULLSCREEN: | 33 case ui::SHOW_STATE_FULLSCREEN: |
| 33 return WM_EVENT_FULLSCREEN; | 34 return WM_EVENT_FULLSCREEN; |
| 34 case ui::SHOW_STATE_INACTIVE: | 35 case ui::SHOW_STATE_INACTIVE: |
| 35 return WM_EVENT_SHOW_INACTIVE; | 36 return WM_EVENT_SHOW_INACTIVE; |
| 36 | 37 |
| 37 case ui::SHOW_STATE_END: | 38 case ui::SHOW_STATE_END: |
| 38 NOTREACHED() << "No WMEvent defined for the show state:" | 39 NOTREACHED() << "No WMEvent defined for the show state:" |
| 39 << requested_show_state; | 40 << requested_show_state; |
| 40 } | 41 } |
| 41 return WM_EVENT_NORMAL; | 42 return WM_EVENT_NORMAL; |
| 42 } | 43 } |
| 43 | 44 |
| 45 WMEventType WMEventTypeFromWindowPinType(WindowPinType type) { |
| 46 switch (type) { |
| 47 case WindowPinType::NONE: |
| 48 return WM_EVENT_NORMAL; |
| 49 case WindowPinType::PINNED: |
| 50 return WM_EVENT_PIN; |
| 51 case WindowPinType::TRUSTED_PINNED: |
| 52 return WM_EVENT_TRUSTED_PIN; |
| 53 } |
| 54 return WM_EVENT_NORMAL; |
| 55 } |
| 56 |
| 44 } // namespace | 57 } // namespace |
| 45 | 58 |
| 46 WindowState::~WindowState() {} | 59 WindowState::~WindowState() {} |
| 47 | 60 |
| 48 bool WindowState::HasDelegate() const { | 61 bool WindowState::HasDelegate() const { |
| 49 return !!delegate_; | 62 return !!delegate_; |
| 50 } | 63 } |
| 51 | 64 |
| 52 void WindowState::SetDelegate(std::unique_ptr<WindowStateDelegate> delegate) { | 65 void WindowState::SetDelegate(std::unique_ptr<WindowStateDelegate> delegate) { |
| 53 DCHECK(!delegate_.get()); | 66 DCHECK(!delegate_.get()); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 ClearRestoreBounds(); | 292 ClearRestoreBounds(); |
| 280 } | 293 } |
| 281 | 294 |
| 282 void WindowState::OnWindowShowStateChanged() { | 295 void WindowState::OnWindowShowStateChanged() { |
| 283 if (!ignore_property_change_) { | 296 if (!ignore_property_change_) { |
| 284 WMEvent event(WMEventTypeFromShowState(GetShowState())); | 297 WMEvent event(WMEventTypeFromShowState(GetShowState())); |
| 285 OnWMEvent(&event); | 298 OnWMEvent(&event); |
| 286 } | 299 } |
| 287 } | 300 } |
| 288 | 301 |
| 302 void WindowState::OnWindowPinTypeChanged() { |
| 303 if (!ignore_property_change_) { |
| 304 WMEvent event(WMEventTypeFromWindowPinType(GetPinType())); |
| 305 OnWMEvent(&event); |
| 306 } |
| 307 } |
| 308 |
| 289 WindowState::WindowState(WmWindow* window) | 309 WindowState::WindowState(WmWindow* window) |
| 290 : window_(window), | 310 : window_(window), |
| 291 window_position_managed_(false), | 311 window_position_managed_(false), |
| 292 bounds_changed_by_user_(false), | 312 bounds_changed_by_user_(false), |
| 293 ignored_by_shelf_(false), | 313 ignored_by_shelf_(false), |
| 294 can_consume_system_keys_(false), | 314 can_consume_system_keys_(false), |
| 295 unminimize_to_restore_bounds_(false), | 315 unminimize_to_restore_bounds_(false), |
| 296 in_immersive_fullscreen_(false), | 316 in_immersive_fullscreen_(false), |
| 297 hide_shelf_when_fullscreen_(true), | 317 hide_shelf_when_fullscreen_(true), |
| 298 autohide_shelf_when_maximized_or_fullscreen_(false), | 318 autohide_shelf_when_maximized_or_fullscreen_(false), |
| 299 minimum_visibility_(false), | 319 minimum_visibility_(false), |
| 300 can_be_dragged_(true), | 320 can_be_dragged_(true), |
| 301 cached_always_on_top_(false), | 321 cached_always_on_top_(false), |
| 302 ignore_property_change_(false), | 322 ignore_property_change_(false), |
| 303 current_state_(new DefaultState(ToWindowStateType(GetShowState()))) {} | 323 current_state_(new DefaultState(ToWindowStateType(GetShowState()))) {} |
| 304 | 324 |
| 305 bool WindowState::GetAlwaysOnTop() const { | 325 bool WindowState::GetAlwaysOnTop() const { |
| 306 return window_->IsAlwaysOnTop(); | 326 return window_->IsAlwaysOnTop(); |
| 307 } | 327 } |
| 308 | 328 |
| 309 ui::WindowShowState WindowState::GetShowState() const { | 329 ui::WindowShowState WindowState::GetShowState() const { |
| 310 return window_->GetShowState(); | 330 return window_->GetShowState(); |
| 311 } | 331 } |
| 312 | 332 |
| 333 WindowPinType WindowState::GetPinType() const { |
| 334 return window_->aura_window()->GetProperty(kWindowPinTypeKey); |
| 335 } |
| 336 |
| 313 void WindowState::SetBoundsInScreen(const gfx::Rect& bounds_in_screen) { | 337 void WindowState::SetBoundsInScreen(const gfx::Rect& bounds_in_screen) { |
| 314 gfx::Rect bounds_in_parent = | 338 gfx::Rect bounds_in_parent = |
| 315 window_->GetParent()->ConvertRectFromScreen(bounds_in_screen); | 339 window_->GetParent()->ConvertRectFromScreen(bounds_in_screen); |
| 316 window_->SetBounds(bounds_in_parent); | 340 window_->SetBounds(bounds_in_parent); |
| 317 } | 341 } |
| 318 | 342 |
| 319 void WindowState::AdjustSnappedBounds(gfx::Rect* bounds) { | 343 void WindowState::AdjustSnappedBounds(gfx::Rect* bounds) { |
| 320 if (is_dragged() || !IsSnapped()) | 344 if (is_dragged() || !IsSnapped()) |
| 321 return; | 345 return; |
| 322 gfx::Rect maximized_bounds = GetMaximizedWindowBoundsInParent(window_); | 346 gfx::Rect maximized_bounds = GetMaximizedWindowBoundsInParent(window_); |
| 323 if (GetStateType() == WINDOW_STATE_TYPE_LEFT_SNAPPED) | 347 if (GetStateType() == WINDOW_STATE_TYPE_LEFT_SNAPPED) |
| 324 bounds->set_x(maximized_bounds.x()); | 348 bounds->set_x(maximized_bounds.x()); |
| 325 else if (GetStateType() == WINDOW_STATE_TYPE_RIGHT_SNAPPED) | 349 else if (GetStateType() == WINDOW_STATE_TYPE_RIGHT_SNAPPED) |
| 326 bounds->set_x(maximized_bounds.right() - bounds->width()); | 350 bounds->set_x(maximized_bounds.right() - bounds->width()); |
| 327 bounds->set_y(maximized_bounds.y()); | 351 bounds->set_y(maximized_bounds.y()); |
| 328 bounds->set_height(maximized_bounds.height()); | 352 bounds->set_height(maximized_bounds.height()); |
| 329 } | 353 } |
| 330 | 354 |
| 331 void WindowState::UpdateWindowShowStateFromStateType() { | 355 void WindowState::UpdateWindowPropertiesFromStateType() { |
| 332 ui::WindowShowState new_window_state = | 356 ui::WindowShowState new_window_state = |
| 333 ToWindowShowState(current_state_->GetType()); | 357 ToWindowShowState(current_state_->GetType()); |
| 334 if (new_window_state != GetShowState()) { | 358 if (new_window_state != GetShowState()) { |
| 335 base::AutoReset<bool> resetter(&ignore_property_change_, true); | 359 base::AutoReset<bool> resetter(&ignore_property_change_, true); |
| 336 window_->SetShowState(new_window_state); | 360 window_->SetShowState(new_window_state); |
| 337 } | 361 } |
| 362 |
| 363 // sync up current window show state with PinType property. |
| 364 WindowPinType pin_type = WindowPinType::NONE; |
| 365 if (GetStateType() == WINDOW_STATE_TYPE_PINNED) |
| 366 pin_type = WindowPinType::PINNED; |
| 367 else if (GetStateType() == WINDOW_STATE_TYPE_TRUSTED_PINNED) |
| 368 pin_type = WindowPinType::TRUSTED_PINNED; |
| 369 if (pin_type != GetPinType()) { |
| 370 base::AutoReset<bool> resetter(&ignore_property_change_, true); |
| 371 window_->aura_window()->SetProperty(kWindowPinTypeKey, pin_type); |
| 372 } |
| 338 } | 373 } |
| 339 | 374 |
| 340 void WindowState::NotifyPreStateTypeChange( | 375 void WindowState::NotifyPreStateTypeChange( |
| 341 WindowStateType old_window_state_type) { | 376 WindowStateType old_window_state_type) { |
| 342 for (auto& observer : observer_list_) | 377 for (auto& observer : observer_list_) |
| 343 observer.OnPreWindowStateTypeChange(this, old_window_state_type); | 378 observer.OnPreWindowStateTypeChange(this, old_window_state_type); |
| 344 } | 379 } |
| 345 | 380 |
| 346 void WindowState::NotifyPostStateTypeChange( | 381 void WindowState::NotifyPostStateTypeChange( |
| 347 WindowStateType old_window_state_type) { | 382 WindowStateType old_window_state_type) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 if (!window_->GetTargetVisibility()) { | 419 if (!window_->GetTargetVisibility()) { |
| 385 SetBoundsConstrained(new_bounds); | 420 SetBoundsConstrained(new_bounds); |
| 386 return; | 421 return; |
| 387 } | 422 } |
| 388 | 423 |
| 389 window_->SetBoundsDirectCrossFade(new_bounds); | 424 window_->SetBoundsDirectCrossFade(new_bounds); |
| 390 } | 425 } |
| 391 | 426 |
| 392 } // namespace wm | 427 } // namespace wm |
| 393 } // namespace ash | 428 } // namespace ash |
| OLD | NEW |