OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.h" | 5 #include "ash/wm_window.h" |
6 | 6 |
7 #include "ash/ash_constants.h" | 7 #include "ash/ash_constants.h" |
8 #include "ash/public/cpp/config.h" | 8 #include "ash/public/cpp/config.h" |
9 #include "ash/public/cpp/shell_window_ids.h" | 9 #include "ash/public/cpp/shell_window_ids.h" |
10 #include "ash/public/cpp/window_properties.h" | 10 #include "ash/public/cpp/window_properties.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 #include "ui/wm/core/coordinate_conversion.h" | 41 #include "ui/wm/core/coordinate_conversion.h" |
42 #include "ui/wm/core/easy_resize_window_targeter.h" | 42 #include "ui/wm/core/easy_resize_window_targeter.h" |
43 #include "ui/wm/core/ime_util_chromeos.h" | 43 #include "ui/wm/core/ime_util_chromeos.h" |
44 #include "ui/wm/core/transient_window_manager.h" | 44 #include "ui/wm/core/transient_window_manager.h" |
45 #include "ui/wm/core/visibility_controller.h" | 45 #include "ui/wm/core/visibility_controller.h" |
46 #include "ui/wm/core/window_util.h" | 46 #include "ui/wm/core/window_util.h" |
47 | 47 |
48 DECLARE_UI_CLASS_PROPERTY_TYPE(ash::WmWindow*); | 48 DECLARE_UI_CLASS_PROPERTY_TYPE(ash::WmWindow*); |
49 | 49 |
50 namespace ash { | 50 namespace ash { |
51 | 51 namespace { |
52 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(WmWindow, kWmWindowKey, nullptr); | 52 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(WmWindow, kWmWindowKey, nullptr); |
53 | 53 |
54 static_assert(aura::Window::kInitialId == kShellWindowId_Invalid, | 54 static_assert(aura::Window::kInitialId == kShellWindowId_Invalid, |
55 "ids must match"); | 55 "ids must match"); |
56 | 56 |
57 namespace { | |
58 | |
59 // A tentative class to set the bounds on the window. | |
60 // TODO(oshima): Once all logic is cleaned up, move this to the real layout | |
61 // manager with proper friendship. | |
62 class BoundsSetter : public aura::LayoutManager { | |
63 public: | |
64 BoundsSetter() {} | |
65 ~BoundsSetter() override {} | |
66 | |
67 // aura::LayoutManager overrides: | |
68 void OnWindowResized() override {} | |
69 void OnWindowAddedToLayout(aura::Window* child) override {} | |
70 void OnWillRemoveWindowFromLayout(aura::Window* child) override {} | |
71 void OnWindowRemovedFromLayout(aura::Window* child) override {} | |
72 void OnChildWindowVisibilityChanged(aura::Window* child, | |
73 bool visible) override {} | |
74 void SetChildBounds(aura::Window* child, | |
75 const gfx::Rect& requested_bounds) override {} | |
76 | |
77 void SetBounds(aura::Window* window, const gfx::Rect& bounds) { | |
78 SetChildBoundsDirect(window, bounds); | |
79 } | |
80 | |
81 private: | |
82 DISALLOW_COPY_AND_ASSIGN(BoundsSetter); | |
83 }; | |
84 | |
85 } // namespace | 57 } // namespace |
86 | 58 |
87 // static | 59 // static |
88 bool WmWindow::default_use_empty_minimum_size_for_testing_ = false; | 60 bool WmWindow::default_use_empty_minimum_size_for_testing_ = false; |
89 | 61 |
90 WmWindow::~WmWindow() { | 62 WmWindow::~WmWindow() { |
91 if (added_transient_observer_) | 63 if (added_transient_observer_) |
92 ::wm::TransientWindowManager::Get(window_)->RemoveObserver(this); | 64 ::wm::TransientWindowManager::Get(window_)->RemoveObserver(this); |
93 | |
94 window_->RemoveObserver(this); | |
95 } | 65 } |
96 | 66 |
97 // static | 67 // static |
98 const WmWindow* WmWindow::Get(const aura::Window* window) { | 68 const WmWindow* WmWindow::Get(const aura::Window* window) { |
99 if (!window) | 69 if (!window) |
100 return nullptr; | 70 return nullptr; |
101 | 71 |
102 const WmWindow* wm_window = window->GetProperty(kWmWindowKey); | 72 const WmWindow* wm_window = window->GetProperty(kWmWindowKey); |
103 if (wm_window) | 73 if (wm_window) |
104 return wm_window; | 74 return wm_window; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 if (::wm::WindowAnimationsDisabled(window_)) { | 319 if (::wm::WindowAnimationsDisabled(window_)) { |
350 window_->SetBounds(bounds); | 320 window_->SetBounds(bounds); |
351 return; | 321 return; |
352 } | 322 } |
353 | 323 |
354 ui::ScopedLayerAnimationSettings settings(window_->layer()->GetAnimator()); | 324 ui::ScopedLayerAnimationSettings settings(window_->layer()->GetAnimator()); |
355 settings.SetTransitionDuration(delta); | 325 settings.SetTransitionDuration(delta); |
356 window_->SetBounds(bounds); | 326 window_->SetBounds(bounds); |
357 } | 327 } |
358 | 328 |
359 void WmWindow::SetBoundsDirect(const gfx::Rect& bounds) { | |
360 BoundsSetter().SetBounds(window_, bounds); | |
361 wm::SnapWindowToPixelBoundary(window_); | |
362 } | |
363 | |
364 void WmWindow::SetBoundsDirectAnimated(const gfx::Rect& bounds) { | |
365 const int kBoundsChangeSlideDurationMs = 120; | |
366 | |
367 ui::Layer* layer = window_->layer(); | |
368 ui::ScopedLayerAnimationSettings slide_settings(layer->GetAnimator()); | |
369 slide_settings.SetPreemptionStrategy( | |
370 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
371 slide_settings.SetTransitionDuration( | |
372 base::TimeDelta::FromMilliseconds(kBoundsChangeSlideDurationMs)); | |
373 SetBoundsDirect(bounds); | |
374 } | |
375 | |
376 void WmWindow::SetBoundsDirectCrossFade(const gfx::Rect& bounds) { | |
377 const gfx::Rect old_bounds = window_->bounds(); | |
378 | |
379 // Create fresh layers for the window and all its children to paint into. | |
380 // Takes ownership of the old layer and all its children, which will be | |
381 // cleaned up after the animation completes. | |
382 // Specify |set_bounds| to true here to keep the old bounds in the child | |
383 // windows of |window|. | |
384 std::unique_ptr<ui::LayerTreeOwner> old_layer_owner = | |
385 ::wm::RecreateLayers(window_); | |
386 ui::Layer* old_layer = old_layer_owner->root(); | |
387 DCHECK(old_layer); | |
388 ui::Layer* new_layer = window_->layer(); | |
389 | |
390 // Resize the window to the new size, which will force a layout and paint. | |
391 SetBoundsDirect(bounds); | |
392 | |
393 // Ensure the higher-resolution layer is on top. | |
394 bool old_on_top = (old_bounds.width() > bounds.width()); | |
395 if (old_on_top) | |
396 old_layer->parent()->StackBelow(new_layer, old_layer); | |
397 else | |
398 old_layer->parent()->StackAbove(new_layer, old_layer); | |
399 | |
400 CrossFadeAnimation(window_, std::move(old_layer_owner), gfx::Tween::EASE_OUT); | |
401 } | |
402 | |
403 void WmWindow::SetBoundsInScreen(const gfx::Rect& bounds_in_screen, | 329 void WmWindow::SetBoundsInScreen(const gfx::Rect& bounds_in_screen, |
404 const display::Display& dst_display) { | 330 const display::Display& dst_display) { |
405 window_->SetBoundsInScreen(bounds_in_screen, dst_display); | 331 window_->SetBoundsInScreen(bounds_in_screen, dst_display); |
406 } | 332 } |
407 | 333 |
408 gfx::Rect WmWindow::GetBoundsInScreen() const { | 334 gfx::Rect WmWindow::GetBoundsInScreen() const { |
409 return window_->GetBoundsInScreen(); | 335 return window_->GetBoundsInScreen(); |
410 } | 336 } |
411 | 337 |
412 const gfx::Rect& WmWindow::GetBounds() const { | 338 const gfx::Rect& WmWindow::GetBounds() const { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 return window_->GetProperty(aura::client::kShowStateKey); | 370 return window_->GetProperty(aura::client::kShowStateKey); |
445 } | 371 } |
446 | 372 |
447 void WmWindow::SetPreFullscreenShowState(ui::WindowShowState show_state) { | 373 void WmWindow::SetPreFullscreenShowState(ui::WindowShowState show_state) { |
448 // We should never store the ui::SHOW_STATE_MINIMIZED as the show state before | 374 // We should never store the ui::SHOW_STATE_MINIMIZED as the show state before |
449 // fullscreen. | 375 // fullscreen. |
450 DCHECK_NE(show_state, ui::SHOW_STATE_MINIMIZED); | 376 DCHECK_NE(show_state, ui::SHOW_STATE_MINIMIZED); |
451 window_->SetProperty(aura::client::kPreFullscreenShowStateKey, show_state); | 377 window_->SetProperty(aura::client::kPreFullscreenShowStateKey, show_state); |
452 } | 378 } |
453 | 379 |
454 void WmWindow::SetRestoreOverrides(const gfx::Rect& bounds_override, | |
455 ui::WindowShowState window_state_override) { | |
456 if (bounds_override.IsEmpty()) { | |
457 window_->ClearProperty(kRestoreShowStateOverrideKey); | |
458 window_->ClearProperty(kRestoreBoundsOverrideKey); | |
459 return; | |
460 } | |
461 window_->SetProperty(kRestoreShowStateOverrideKey, window_state_override); | |
462 window_->SetProperty(kRestoreBoundsOverrideKey, | |
463 new gfx::Rect(bounds_override)); | |
464 } | |
465 | |
466 void WmWindow::SetLockedToRoot(bool value) { | 380 void WmWindow::SetLockedToRoot(bool value) { |
467 window_->SetProperty(kLockedToRootKey, value); | 381 window_->SetProperty(kLockedToRootKey, value); |
468 } | 382 } |
469 | 383 |
470 bool WmWindow::IsLockedToRoot() const { | 384 bool WmWindow::IsLockedToRoot() const { |
471 return window_->GetProperty(kLockedToRootKey); | 385 return window_->GetProperty(kLockedToRootKey); |
472 } | 386 } |
473 | 387 |
474 void WmWindow::SetCapture() { | 388 void WmWindow::SetCapture() { |
475 window_->SetCapture(); | 389 window_->SetCapture(); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 } | 603 } |
690 | 604 |
691 void WmWindow::RemoveLimitedPreTargetHandler(ui::EventHandler* handler) { | 605 void WmWindow::RemoveLimitedPreTargetHandler(ui::EventHandler* handler) { |
692 window_->RemovePreTargetHandler(handler); | 606 window_->RemovePreTargetHandler(handler); |
693 } | 607 } |
694 | 608 |
695 WmWindow::WmWindow(aura::Window* window) | 609 WmWindow::WmWindow(aura::Window* window) |
696 : window_(window), | 610 : window_(window), |
697 use_empty_minimum_size_for_testing_( | 611 use_empty_minimum_size_for_testing_( |
698 default_use_empty_minimum_size_for_testing_) { | 612 default_use_empty_minimum_size_for_testing_) { |
699 window_->AddObserver(this); | |
700 window_->SetProperty(kWmWindowKey, this); | 613 window_->SetProperty(kWmWindowKey, this); |
701 } | 614 } |
702 | 615 |
703 void WmWindow::OnWindowPropertyChanged(aura::Window* window, | |
704 const void* key, | |
705 intptr_t old) { | |
706 if (key == aura::client::kShowStateKey) { | |
707 ash::wm::GetWindowState(window_)->OnWindowShowStateChanged(); | |
708 return; | |
709 } | |
710 if (key == aura::client::kImmersiveFullscreenKey) { | |
711 bool enable = window_->GetProperty(aura::client::kImmersiveFullscreenKey); | |
712 GetWindowState()->set_in_immersive_fullscreen(enable); | |
713 return; | |
714 } | |
715 if (key == kWindowPinTypeKey) { | |
716 ash::wm::GetWindowState(window_)->OnWindowPinTypeChanged(); | |
717 return; | |
718 } | |
719 } | |
720 | |
721 void WmWindow::OnTransientChildAdded(aura::Window* window, | 616 void WmWindow::OnTransientChildAdded(aura::Window* window, |
722 aura::Window* transient) { | 617 aura::Window* transient) { |
723 for (auto& observer : transient_observers_) | 618 for (auto& observer : transient_observers_) |
724 observer.OnTransientChildAdded(this, Get(transient)); | 619 observer.OnTransientChildAdded(this, Get(transient)); |
725 } | 620 } |
726 | 621 |
727 void WmWindow::OnTransientChildRemoved(aura::Window* window, | 622 void WmWindow::OnTransientChildRemoved(aura::Window* window, |
728 aura::Window* transient) { | 623 aura::Window* transient) { |
729 for (auto& observer : transient_observers_) | 624 for (auto& observer : transient_observers_) |
730 observer.OnTransientChildRemoved(this, Get(transient)); | 625 observer.OnTransientChildRemoved(this, Get(transient)); |
731 } | 626 } |
732 | 627 |
733 } // namespace ash | 628 } // namespace ash |
OLD | NEW |