| 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 "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
| 9 #include "ash/wm/coordinate_conversion.h" | 9 #include "ash/wm/coordinate_conversion.h" |
| 10 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| 11 #include "ui/aura/client/screen_position_client.h" | |
| 12 #include "ui/aura/root_window.h" | |
| 13 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_delegate.h" | |
| 15 #include "ui/aura/window_observer.h" | |
| 16 #include "ui/base/animation/slide_animation.h" | 12 #include "ui/base/animation/slide_animation.h" |
| 17 #include "ui/base/animation/tween.h" | |
| 18 #include "ui/compositor/layer.h" | 13 #include "ui/compositor/layer.h" |
| 19 #include "ui/compositor/scoped_layer_animation_settings.h" | 14 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 20 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
| 21 #include "ui/gfx/screen.h" | |
| 22 #include "ui/gfx/skia_util.h" | 16 #include "ui/gfx/skia_util.h" |
| 23 #include "ui/views/corewm/shadow_types.h" | |
| 24 #include "ui/views/painter.h" | 17 #include "ui/views/painter.h" |
| 25 #include "ui/views/view.h" | 18 #include "ui/views/view.h" |
| 26 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 27 | 20 |
| 28 namespace ash { | 21 namespace ash { |
| 29 namespace internal { | 22 namespace internal { |
| 30 | 23 |
| 31 namespace { | 24 namespace { |
| 32 | 25 |
| 33 // Amount to inset from the bounds for EdgePainter. | 26 // Amount to inset from the bounds for EdgePainter. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 70 |
| 78 private: | 71 private: |
| 79 DISALLOW_COPY_AND_ASSIGN(EdgePainter); | 72 DISALLOW_COPY_AND_ASSIGN(EdgePainter); |
| 80 }; | 73 }; |
| 81 | 74 |
| 82 } // namespace | 75 } // namespace |
| 83 | 76 |
| 84 PhantomWindowController::PhantomWindowController(aura::Window* window) | 77 PhantomWindowController::PhantomWindowController(aura::Window* window) |
| 85 : window_(window), | 78 : window_(window), |
| 86 phantom_below_window_(NULL), | 79 phantom_below_window_(NULL), |
| 87 phantom_widget_(NULL), | 80 phantom_widget_(NULL) { |
| 88 style_(STYLE_SHADOW) { | |
| 89 } | 81 } |
| 90 | 82 |
| 91 PhantomWindowController::~PhantomWindowController() { | 83 PhantomWindowController::~PhantomWindowController() { |
| 92 Hide(); | 84 Hide(); |
| 93 } | 85 } |
| 94 | 86 |
| 95 void PhantomWindowController::SetDestinationDisplay( | 87 void PhantomWindowController::Show(const gfx::Rect& bounds) { |
| 96 const gfx::Display& dst_display) { | |
| 97 dst_display_ = dst_display; | |
| 98 } | |
| 99 | |
| 100 void PhantomWindowController::Show(const gfx::Rect& bounds, ui::Layer* layer) { | |
| 101 if (bounds == bounds_) | 88 if (bounds == bounds_) |
| 102 return; | 89 return; |
| 103 bounds_ = bounds; | 90 bounds_ = bounds; |
| 104 if (!phantom_widget_) { | 91 if (!phantom_widget_) { |
| 105 // Show the phantom at the bounds of the window. We'll animate to the target | 92 // Show the phantom at the bounds of the window. We'll animate to the target |
| 106 // bounds. | 93 // bounds. |
| 107 start_bounds_ = window_->GetBoundsInScreen(); | 94 start_bounds_ = window_->GetBoundsInScreen(); |
| 108 CreatePhantomWidget(start_bounds_, layer); | 95 CreatePhantomWidget(start_bounds_); |
| 109 } else { | 96 } else { |
| 110 start_bounds_ = phantom_widget_->GetWindowBoundsInScreen(); | 97 start_bounds_ = phantom_widget_->GetWindowBoundsInScreen(); |
| 111 } | 98 } |
| 112 animation_.reset(new ui::SlideAnimation(this)); | 99 animation_.reset(new ui::SlideAnimation(this)); |
| 113 animation_->SetTweenType(ui::Tween::EASE_IN); | 100 animation_->SetTweenType(ui::Tween::EASE_IN); |
| 114 animation_->SetSlideDuration(kAnimationDuration); | 101 animation_->SetSlideDuration(kAnimationDuration); |
| 115 animation_->Show(); | 102 animation_->Show(); |
| 116 } | 103 } |
| 117 | 104 |
| 118 void PhantomWindowController::SetBounds(const gfx::Rect& bounds) { | |
| 119 DCHECK(IsShowing()); | |
| 120 animation_.reset(); | |
| 121 bounds_ = bounds; | |
| 122 SetBoundsInternal(bounds); | |
| 123 } | |
| 124 | |
| 125 void PhantomWindowController::Hide() { | 105 void PhantomWindowController::Hide() { |
| 126 if (phantom_widget_) | 106 if (phantom_widget_) |
| 127 phantom_widget_->Close(); | 107 phantom_widget_->Close(); |
| 128 phantom_widget_ = NULL; | 108 phantom_widget_ = NULL; |
| 129 } | 109 } |
| 130 | 110 |
| 131 bool PhantomWindowController::IsShowing() const { | 111 bool PhantomWindowController::IsShowing() const { |
| 132 return phantom_widget_ != NULL; | 112 return phantom_widget_ != NULL; |
| 133 } | 113 } |
| 134 | 114 |
| 135 void PhantomWindowController::set_style(Style style) { | |
| 136 // Cannot change |style_| after the widget is initialized. | |
| 137 DCHECK(!phantom_widget_); | |
| 138 style_ = style; | |
| 139 } | |
| 140 | |
| 141 void PhantomWindowController::SetOpacity(float opacity) { | |
| 142 DCHECK(phantom_widget_); | |
| 143 ui::Layer* layer = phantom_widget_->GetNativeWindow()->layer(); | |
| 144 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator()); | |
| 145 layer->SetOpacity(opacity); | |
| 146 } | |
| 147 | |
| 148 float PhantomWindowController::GetOpacity() const { | |
| 149 DCHECK(phantom_widget_); | |
| 150 return phantom_widget_->GetNativeWindow()->layer()->opacity(); | |
| 151 } | |
| 152 | |
| 153 void PhantomWindowController::AnimationProgressed( | 115 void PhantomWindowController::AnimationProgressed( |
| 154 const ui::Animation* animation) { | 116 const ui::Animation* animation) { |
| 155 SetBoundsInternal(animation->CurrentValueBetween(start_bounds_, bounds_)); | 117 phantom_widget_->SetBounds( |
| 118 animation->CurrentValueBetween(start_bounds_, bounds_)); |
| 156 } | 119 } |
| 157 | 120 |
| 158 void PhantomWindowController::CreatePhantomWidget(const gfx::Rect& bounds, | 121 void PhantomWindowController::CreatePhantomWidget(const gfx::Rect& bounds) { |
| 159 ui::Layer* layer) { | |
| 160 DCHECK(!phantom_widget_); | 122 DCHECK(!phantom_widget_); |
| 161 phantom_widget_ = new views::Widget; | 123 phantom_widget_ = new views::Widget; |
| 162 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 124 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 163 params.transparent = true; | 125 params.transparent = true; |
| 164 // PhantomWindowController is used by FrameMaximizeButton to highlight the | 126 // PhantomWindowController is used by FrameMaximizeButton to highlight the |
| 165 // launcher button. Put the phantom in the same window as the launcher so that | 127 // launcher button. Put the phantom in the same window as the launcher so that |
| 166 // the phantom is visible. | 128 // the phantom is visible. |
| 167 params.parent = Shell::GetContainer(wm::GetRootWindowMatching(bounds), | 129 params.parent = Shell::GetContainer(wm::GetRootWindowMatching(bounds), |
| 168 kShellWindowId_LauncherContainer); | 130 kShellWindowId_LauncherContainer); |
| 169 params.can_activate = false; | 131 params.can_activate = false; |
| 170 params.keep_on_top = true; | 132 params.keep_on_top = true; |
| 171 phantom_widget_->set_focus_on_creation(false); | 133 phantom_widget_->set_focus_on_creation(false); |
| 172 phantom_widget_->Init(params); | 134 phantom_widget_->Init(params); |
| 173 phantom_widget_->SetVisibilityChangedAnimationsEnabled(false); | 135 phantom_widget_->SetVisibilityChangedAnimationsEnabled(false); |
| 174 phantom_widget_->GetNativeWindow()->SetName("PhantomWindow"); | 136 phantom_widget_->GetNativeWindow()->SetName("PhantomWindow"); |
| 175 phantom_widget_->GetNativeWindow()->set_id(kShellWindowId_PhantomWindow); | 137 phantom_widget_->GetNativeWindow()->set_id(kShellWindowId_PhantomWindow); |
| 176 if (style_ == STYLE_SHADOW) { | 138 views::View* content_view = new views::View; |
| 177 views::View* content_view = new views::View; | 139 content_view->set_background( |
| 178 content_view->set_background( | 140 views::Background::CreateBackgroundPainter(true, new EdgePainter)); |
| 179 views::Background::CreateBackgroundPainter(true, new EdgePainter)); | 141 phantom_widget_->SetContentsView(content_view); |
| 180 phantom_widget_->SetContentsView(content_view); | 142 phantom_widget_->SetBounds(bounds); |
| 181 } else if (style_ == STYLE_DRAGGING) { | |
| 182 // Show shadow for the dragging window. | |
| 183 SetShadowType(phantom_widget_->GetNativeWindow(), | |
| 184 views::corewm::SHADOW_TYPE_RECTANGULAR); | |
| 185 } | |
| 186 SetBoundsInternal(bounds); | |
| 187 if (phantom_below_window_) | 143 if (phantom_below_window_) |
| 188 phantom_widget_->StackBelow(phantom_below_window_); | 144 phantom_widget_->StackBelow(phantom_below_window_); |
| 189 else | 145 else |
| 190 phantom_widget_->StackAbove(window_); | 146 phantom_widget_->StackAbove(window_); |
| 191 | 147 |
| 192 if (layer) { | |
| 193 aura::Window* window = phantom_widget_->GetNativeWindow(); | |
| 194 layer->SetVisible(true); | |
| 195 window->layer()->Add(layer); | |
| 196 window->layer()->StackAtTop(layer); | |
| 197 } | |
| 198 | |
| 199 // Show the widget after all the setups. | 148 // Show the widget after all the setups. |
| 200 phantom_widget_->Show(); | 149 phantom_widget_->Show(); |
| 201 | 150 |
| 202 // Fade the window in. | 151 // Fade the window in. |
| 203 ui::Layer* widget_layer = phantom_widget_->GetNativeWindow()->layer(); | 152 ui::Layer* widget_layer = phantom_widget_->GetNativeWindow()->layer(); |
| 204 widget_layer->SetOpacity(0); | 153 widget_layer->SetOpacity(0); |
| 205 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator()); | 154 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator()); |
| 206 widget_layer->SetOpacity(1); | 155 widget_layer->SetOpacity(1); |
| 207 } | 156 } |
| 208 | 157 |
| 209 void PhantomWindowController::SetBoundsInternal(const gfx::Rect& bounds) { | |
| 210 aura::Window* window = phantom_widget_->GetNativeWindow(); | |
| 211 aura::client::ScreenPositionClient* screen_position_client = | |
| 212 aura::client::GetScreenPositionClient(window->GetRootWindow()); | |
| 213 if (screen_position_client && | |
| 214 dst_display_.id() != gfx::Display::kInvalidDisplayID) { | |
| 215 screen_position_client->SetBounds(window, bounds, dst_display_); | |
| 216 } else { | |
| 217 phantom_widget_->SetBounds(bounds); | |
| 218 } | |
| 219 } | |
| 220 | |
| 221 } // namespace internal | 158 } // namespace internal |
| 222 } // namespace ash | 159 } // namespace ash |
| OLD | NEW |