| 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/shell.h" | |
| 10 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
| 11 #include "ash/wm/aura/wm_window_aura.h" | |
| 12 #include "ash/wm/common/root_window_finder.h" | 10 #include "ash/wm/common/root_window_finder.h" |
| 11 #include "ash/wm/common/wm_root_window_controller.h" |
| 12 #include "ash/wm/common/wm_window.h" |
| 13 #include "grit/ash_resources.h" | 13 #include "grit/ash_resources.h" |
| 14 #include "ui/aura/window.h" | |
| 15 #include "ui/compositor/layer.h" | 14 #include "ui/compositor/layer.h" |
| 16 #include "ui/compositor/scoped_layer_animation_settings.h" | 15 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 17 #include "ui/views/background.h" | 16 #include "ui/views/background.h" |
| 18 #include "ui/views/painter.h" | 17 #include "ui/views/painter.h" |
| 19 #include "ui/views/view.h" | 18 #include "ui/views/view.h" |
| 20 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 21 | 20 |
| 22 namespace ash { | 21 namespace ash { |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 54 } | 53 } |
| 55 | 54 |
| 56 // Starts an animation of |widget| to |new_bounds_in_screen|. No-op if |widget| | 55 // Starts an animation of |widget| to |new_bounds_in_screen|. No-op if |widget| |
| 57 // is NULL. | 56 // is NULL. |
| 58 void AnimateToBounds(views::Widget* widget, | 57 void AnimateToBounds(views::Widget* widget, |
| 59 const gfx::Rect& new_bounds_in_screen) { | 58 const gfx::Rect& new_bounds_in_screen) { |
| 60 if (!widget) | 59 if (!widget) |
| 61 return; | 60 return; |
| 62 | 61 |
| 63 ui::ScopedLayerAnimationSettings scoped_setter( | 62 ui::ScopedLayerAnimationSettings scoped_setter( |
| 64 widget->GetNativeWindow()->layer()->GetAnimator()); | 63 wm::WmWindow::Get(widget)->GetLayer()->GetAnimator()); |
| 65 scoped_setter.SetTweenType(gfx::Tween::EASE_IN); | 64 scoped_setter.SetTweenType(gfx::Tween::EASE_IN); |
| 66 scoped_setter.SetPreemptionStrategy( | 65 scoped_setter.SetPreemptionStrategy( |
| 67 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 66 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 68 scoped_setter.SetTransitionDuration( | 67 scoped_setter.SetTransitionDuration( |
| 69 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); | 68 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); |
| 70 widget->SetBounds(new_bounds_in_screen); | 69 widget->SetBounds(new_bounds_in_screen); |
| 71 } | 70 } |
| 72 | 71 |
| 73 } // namespace | 72 } // namespace |
| 74 | 73 |
| 75 // PhantomWindowController ---------------------------------------------------- | 74 // PhantomWindowController ---------------------------------------------------- |
| 76 | 75 |
| 77 PhantomWindowController::PhantomWindowController(aura::Window* window) | 76 PhantomWindowController::PhantomWindowController(wm::WmWindow* window) |
| 78 : window_(window) { | 77 : window_(window) {} |
| 79 } | |
| 80 | 78 |
| 81 PhantomWindowController::~PhantomWindowController() { | 79 PhantomWindowController::~PhantomWindowController() { |
| 82 } | 80 } |
| 83 | 81 |
| 84 void PhantomWindowController::Show(const gfx::Rect& bounds_in_screen) { | 82 void PhantomWindowController::Show(const gfx::Rect& bounds_in_screen) { |
| 85 gfx::Rect adjusted_bounds_in_screen = GetAdjustedBounds(bounds_in_screen); | 83 gfx::Rect adjusted_bounds_in_screen = GetAdjustedBounds(bounds_in_screen); |
| 86 if (adjusted_bounds_in_screen == target_bounds_in_screen_) | 84 if (adjusted_bounds_in_screen == target_bounds_in_screen_) |
| 87 return; | 85 return; |
| 88 target_bounds_in_screen_ = adjusted_bounds_in_screen; | 86 target_bounds_in_screen_ = adjusted_bounds_in_screen; |
| 89 | 87 |
| 90 gfx::Rect start_bounds_in_screen = target_bounds_in_screen_; | 88 gfx::Rect start_bounds_in_screen = target_bounds_in_screen_; |
| 91 int start_width = std::max( | 89 int start_width = std::max( |
| 92 kMinSizeWithShadow, | 90 kMinSizeWithShadow, |
| 93 static_cast<int>(start_bounds_in_screen.width() * kStartBoundsRatio)); | 91 static_cast<int>(start_bounds_in_screen.width() * kStartBoundsRatio)); |
| 94 int start_height = std::max( | 92 int start_height = std::max( |
| 95 kMinSizeWithShadow, | 93 kMinSizeWithShadow, |
| 96 static_cast<int>(start_bounds_in_screen.height() * kStartBoundsRatio)); | 94 static_cast<int>(start_bounds_in_screen.height() * kStartBoundsRatio)); |
| 97 start_bounds_in_screen.Inset( | 95 start_bounds_in_screen.Inset( |
| 98 floor((start_bounds_in_screen.width() - start_width) / 2.0f), | 96 floor((start_bounds_in_screen.width() - start_width) / 2.0f), |
| 99 floor((start_bounds_in_screen.height() - start_height) / 2.0f)); | 97 floor((start_bounds_in_screen.height() - start_height) / 2.0f)); |
| 100 phantom_widget_ = CreatePhantomWidget( | 98 phantom_widget_ = |
| 101 wm::WmWindowAura::GetAuraWindow( | 99 CreatePhantomWidget(wm::GetRootWindowMatching(target_bounds_in_screen_), |
| 102 wm::GetRootWindowMatching(target_bounds_in_screen_)), | 100 start_bounds_in_screen); |
| 103 start_bounds_in_screen); | |
| 104 | 101 |
| 105 AnimateToBounds(phantom_widget_.get(), target_bounds_in_screen_); | 102 AnimateToBounds(phantom_widget_.get(), target_bounds_in_screen_); |
| 106 } | 103 } |
| 107 | 104 |
| 108 std::unique_ptr<views::Widget> PhantomWindowController::CreatePhantomWidget( | 105 std::unique_ptr<views::Widget> PhantomWindowController::CreatePhantomWidget( |
| 109 aura::Window* root_window, | 106 wm::WmWindow* root_window, |
| 110 const gfx::Rect& bounds_in_screen) { | 107 const gfx::Rect& bounds_in_screen) { |
| 111 std::unique_ptr<views::Widget> phantom_widget(new views::Widget); | 108 std::unique_ptr<views::Widget> phantom_widget(new views::Widget); |
| 112 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 109 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 113 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 110 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 114 // PhantomWindowController is used by FrameMaximizeButton to highlight the | 111 // PhantomWindowController is used by FrameMaximizeButton to highlight the |
| 115 // launcher button. Put the phantom in the same window as the launcher so that | 112 // launcher button. Put the phantom in the same window as the launcher so that |
| 116 // the phantom is visible. | 113 // the phantom is visible. |
| 117 params.parent = Shell::GetContainer(root_window, | |
| 118 kShellWindowId_ShelfContainer); | |
| 119 params.keep_on_top = true; | 114 params.keep_on_top = true; |
| 120 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 115 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 116 root_window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( |
| 117 phantom_widget.get(), kShellWindowId_ShelfContainer, ¶ms); |
| 121 phantom_widget->set_focus_on_creation(false); | 118 phantom_widget->set_focus_on_creation(false); |
| 122 phantom_widget->Init(params); | 119 phantom_widget->Init(params); |
| 123 phantom_widget->SetVisibilityChangedAnimationsEnabled(false); | 120 phantom_widget->SetVisibilityChangedAnimationsEnabled(false); |
| 124 phantom_widget->GetNativeWindow()->SetName("PhantomWindow"); | 121 wm::WmWindow* phantom_widget_window = wm::WmWindow::Get(phantom_widget.get()); |
| 125 phantom_widget->GetNativeWindow()->set_id(kShellWindowId_PhantomWindow); | 122 phantom_widget_window->SetName("PhantomWindow"); |
| 123 phantom_widget_window->SetShellWindowId(kShellWindowId_PhantomWindow); |
| 126 phantom_widget->SetBounds(bounds_in_screen); | 124 phantom_widget->SetBounds(bounds_in_screen); |
| 127 phantom_widget->StackAbove(window_); | 125 // TODO(sky): I suspect this is never true, verify that. |
| 126 if (phantom_widget_window->GetParent() == window_->GetParent()) { |
| 127 phantom_widget_window->GetParent()->StackChildAbove(phantom_widget_window, |
| 128 window_); |
| 129 } |
| 128 | 130 |
| 129 const int kImages[] = IMAGE_GRID(IDR_AURA_PHANTOM_WINDOW); | 131 const int kImages[] = IMAGE_GRID(IDR_AURA_PHANTOM_WINDOW); |
| 130 views::Painter* background_painter = | 132 views::Painter* background_painter = |
| 131 views::Painter::CreateImageGridPainter(kImages); | 133 views::Painter::CreateImageGridPainter(kImages); |
| 132 views::View* content_view = new views::View; | 134 views::View* content_view = new views::View; |
| 133 content_view->set_background( | 135 content_view->set_background( |
| 134 views::Background::CreateBackgroundPainter(true, background_painter)); | 136 views::Background::CreateBackgroundPainter(true, background_painter)); |
| 135 phantom_widget->SetContentsView(content_view); | 137 phantom_widget->SetContentsView(content_view); |
| 136 | 138 |
| 137 // Show the widget after all the setups. | 139 // Show the widget after all the setups. |
| 138 phantom_widget->Show(); | 140 phantom_widget->Show(); |
| 139 | 141 |
| 140 // Fade the window in. | 142 // Fade the window in. |
| 141 ui::Layer* widget_layer = phantom_widget->GetNativeWindow()->layer(); | 143 ui::Layer* widget_layer = phantom_widget_window->GetLayer(); |
| 142 widget_layer->SetOpacity(0); | 144 widget_layer->SetOpacity(0); |
| 143 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator()); | 145 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator()); |
| 144 scoped_setter.SetTransitionDuration( | 146 scoped_setter.SetTransitionDuration( |
| 145 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); | 147 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); |
| 146 widget_layer->SetOpacity(1); | 148 widget_layer->SetOpacity(1); |
| 147 | 149 |
| 148 return phantom_widget; | 150 return phantom_widget; |
| 149 } | 151 } |
| 150 | 152 |
| 151 } // namespace ash | 153 } // namespace ash |
| OLD | NEW |