| 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/workspace/phantom_window_controller.h" | 5 #include "ash/wm/workspace/phantom_window_controller.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "ash/public/cpp/shell_window_ids.h" | 9 #include "ash/public/cpp/shell_window_ids.h" |
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| 11 #include "ash/wm/root_window_finder.h" | 11 #include "ash/wm/root_window_finder.h" |
| 12 #include "ash/wm_window.h" | 12 #include "ui/aura/window.h" |
| 13 #include "ui/compositor/layer.h" | 13 #include "ui/compositor/layer.h" |
| 14 #include "ui/compositor/scoped_layer_animation_settings.h" | 14 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 15 #include "ui/views/background.h" | 15 #include "ui/views/background.h" |
| 16 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
| 17 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
| 18 #include "ui/wm/core/shadow_controller.h" | 18 #include "ui/wm/core/shadow_controller.h" |
| 19 | 19 |
| 20 namespace ash { | 20 namespace ash { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 // The shadow ninebox requires a minimum size to work well. See | 35 // The shadow ninebox requires a minimum size to work well. See |
| 36 // ui/wm/core/shadow.cc | 36 // ui/wm/core/shadow.cc |
| 37 constexpr int kMinWidthWithShadow = 2 * static_cast<int>(kShadowElevation); | 37 constexpr int kMinWidthWithShadow = 2 * static_cast<int>(kShadowElevation); |
| 38 constexpr int kMinHeightWithShadow = 4 * static_cast<int>(kShadowElevation); | 38 constexpr int kMinHeightWithShadow = 4 * static_cast<int>(kShadowElevation); |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 // PhantomWindowController ---------------------------------------------------- | 42 // PhantomWindowController ---------------------------------------------------- |
| 43 | 43 |
| 44 PhantomWindowController::PhantomWindowController(WmWindow* window) | 44 PhantomWindowController::PhantomWindowController(aura::Window* window) |
| 45 : window_(window) {} | 45 : window_(window) {} |
| 46 | 46 |
| 47 PhantomWindowController::~PhantomWindowController() {} | 47 PhantomWindowController::~PhantomWindowController() {} |
| 48 | 48 |
| 49 void PhantomWindowController::Show(const gfx::Rect& bounds_in_screen) { | 49 void PhantomWindowController::Show(const gfx::Rect& bounds_in_screen) { |
| 50 if (bounds_in_screen == target_bounds_in_screen_) | 50 if (bounds_in_screen == target_bounds_in_screen_) |
| 51 return; | 51 return; |
| 52 target_bounds_in_screen_ = bounds_in_screen; | 52 target_bounds_in_screen_ = bounds_in_screen; |
| 53 | 53 |
| 54 gfx::Rect start_bounds_in_screen = target_bounds_in_screen_; | 54 gfx::Rect start_bounds_in_screen = target_bounds_in_screen_; |
| 55 int start_width = std::max( | 55 int start_width = std::max( |
| 56 kMinWidthWithShadow, | 56 kMinWidthWithShadow, |
| 57 static_cast<int>(start_bounds_in_screen.width() * kStartBoundsRatio)); | 57 static_cast<int>(start_bounds_in_screen.width() * kStartBoundsRatio)); |
| 58 int start_height = std::max( | 58 int start_height = std::max( |
| 59 kMinHeightWithShadow, | 59 kMinHeightWithShadow, |
| 60 static_cast<int>(start_bounds_in_screen.height() * kStartBoundsRatio)); | 60 static_cast<int>(start_bounds_in_screen.height() * kStartBoundsRatio)); |
| 61 start_bounds_in_screen.Inset( | 61 start_bounds_in_screen.Inset( |
| 62 floor((start_bounds_in_screen.width() - start_width) / 2.0f), | 62 floor((start_bounds_in_screen.width() - start_width) / 2.0f), |
| 63 floor((start_bounds_in_screen.height() - start_height) / 2.0f)); | 63 floor((start_bounds_in_screen.height() - start_height) / 2.0f)); |
| 64 phantom_widget_ = | 64 phantom_widget_ = |
| 65 CreatePhantomWidget(wm::GetRootWindowMatching(target_bounds_in_screen_), | 65 CreatePhantomWidget(wm::GetRootWindowMatching(target_bounds_in_screen_), |
| 66 start_bounds_in_screen); | 66 start_bounds_in_screen); |
| 67 } | 67 } |
| 68 | 68 |
| 69 std::unique_ptr<views::Widget> PhantomWindowController::CreatePhantomWidget( | 69 std::unique_ptr<views::Widget> PhantomWindowController::CreatePhantomWidget( |
| 70 WmWindow* root_window, | 70 aura::Window* root_window, |
| 71 const gfx::Rect& bounds_in_screen) { | 71 const gfx::Rect& bounds_in_screen) { |
| 72 std::unique_ptr<views::Widget> phantom_widget(new views::Widget); | 72 std::unique_ptr<views::Widget> phantom_widget(new views::Widget); |
| 73 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 73 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 74 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 74 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 75 // PhantomWindowController is used by FrameMaximizeButton to highlight the | 75 // PhantomWindowController is used by FrameMaximizeButton to highlight the |
| 76 // launcher button. Put the phantom in the same window as the launcher so that | 76 // launcher button. Put the phantom in the same window as the launcher so that |
| 77 // the phantom is visible. | 77 // the phantom is visible. |
| 78 params.keep_on_top = true; | 78 params.keep_on_top = true; |
| 79 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 79 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 80 params.name = "PhantomWindow"; | 80 params.name = "PhantomWindow"; |
| 81 params.layer_type = ui::LAYER_SOLID_COLOR; | 81 params.layer_type = ui::LAYER_SOLID_COLOR; |
| 82 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_DROP; | 82 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_DROP; |
| 83 params.shadow_elevation = ::wm::ShadowElevation::LARGE; | 83 params.shadow_elevation = ::wm::ShadowElevation::LARGE; |
| 84 root_window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( | 84 RootWindowController::ForWindow(root_window) |
| 85 phantom_widget.get(), kShellWindowId_ShelfContainer, ¶ms); | 85 ->ConfigureWidgetInitParamsForContainer( |
| 86 phantom_widget.get(), kShellWindowId_ShelfContainer, ¶ms); |
| 86 phantom_widget->set_focus_on_creation(false); | 87 phantom_widget->set_focus_on_creation(false); |
| 87 phantom_widget->Init(params); | 88 phantom_widget->Init(params); |
| 88 phantom_widget->SetVisibilityChangedAnimationsEnabled(false); | 89 phantom_widget->SetVisibilityChangedAnimationsEnabled(false); |
| 89 WmWindow* phantom_widget_window = | 90 aura::Window* phantom_widget_window = phantom_widget->GetNativeWindow(); |
| 90 WmWindow::Get(phantom_widget->GetNativeWindow()); | 91 phantom_widget_window->set_id(kShellWindowId_PhantomWindow); |
| 91 phantom_widget_window->aura_window()->set_id(kShellWindowId_PhantomWindow); | |
| 92 phantom_widget->SetBounds(bounds_in_screen); | 92 phantom_widget->SetBounds(bounds_in_screen); |
| 93 // TODO(sky): I suspect this is never true, verify that. | 93 // TODO(sky): I suspect this is never true, verify that. |
| 94 if (phantom_widget_window->GetParent() == window_->GetParent()) { | 94 if (phantom_widget_window->parent() == window_->parent()) { |
| 95 phantom_widget_window->GetParent()->StackChildAbove(phantom_widget_window, | 95 phantom_widget_window->parent()->StackChildAbove(phantom_widget_window, |
| 96 window_); | 96 window_); |
| 97 } | 97 } |
| 98 ui::Layer* widget_layer = phantom_widget_window->GetLayer(); | 98 ui::Layer* widget_layer = phantom_widget_window->layer(); |
| 99 widget_layer->SetColor(SkColorSetA(SK_ColorWHITE, 0.4 * 255)); | 99 widget_layer->SetColor(SkColorSetA(SK_ColorWHITE, 0.4 * 255)); |
| 100 | 100 |
| 101 phantom_widget->Show(); | 101 phantom_widget->Show(); |
| 102 | 102 |
| 103 // Fade the window in. | 103 // Fade the window in. |
| 104 widget_layer->SetOpacity(0); | 104 widget_layer->SetOpacity(0); |
| 105 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator()); | 105 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator()); |
| 106 scoped_setter.SetTransitionDuration( | 106 scoped_setter.SetTransitionDuration( |
| 107 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); | 107 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); |
| 108 scoped_setter.SetTweenType(gfx::Tween::EASE_IN); | 108 scoped_setter.SetTweenType(gfx::Tween::EASE_IN); |
| 109 scoped_setter.SetPreemptionStrategy( | 109 scoped_setter.SetPreemptionStrategy( |
| 110 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 110 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 111 widget_layer->SetOpacity(1); | 111 widget_layer->SetOpacity(1); |
| 112 phantom_widget->SetBounds(target_bounds_in_screen_); | 112 phantom_widget->SetBounds(target_bounds_in_screen_); |
| 113 | 113 |
| 114 return phantom_widget; | 114 return phantom_widget; |
| 115 } | 115 } |
| 116 | 116 |
| 117 } // namespace ash | 117 } // namespace ash |
| OLD | NEW |