Chromium Code Reviews| 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 "third_party/skia/include/core/SkCanvas.h" | 9 #include "third_party/skia/include/core/SkCanvas.h" |
| 10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 SkIntToScalar(kRoundRectSize), paint); | 65 SkIntToScalar(kRoundRectSize), paint); |
| 66 } | 66 } |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 DISALLOW_COPY_AND_ASSIGN(EdgePainter); | 69 DISALLOW_COPY_AND_ASSIGN(EdgePainter); |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 } // namespace | 72 } // namespace |
| 73 | 73 |
| 74 PhantomWindowController::PhantomWindowController(aura::Window* window) | 74 PhantomWindowController::PhantomWindowController(aura::Window* window) |
| 75 : window_(window) { | 75 : window_(window), |
| 76 phantom_below_window_(NULL), | |
| 77 phantom_widget_(NULL) { | |
| 76 } | 78 } |
| 77 | 79 |
| 78 PhantomWindowController::~PhantomWindowController() { | 80 PhantomWindowController::~PhantomWindowController() { |
| 79 Hide(); | 81 Hide(); |
| 80 } | 82 } |
| 81 | 83 |
| 82 void PhantomWindowController::Show(const gfx::Rect& bounds) { | 84 void PhantomWindowController::Show(const gfx::Rect& bounds) { |
| 83 if (bounds == bounds_) | 85 if (bounds == bounds_) |
| 84 return; | 86 return; |
| 85 bounds_ = bounds; | 87 bounds_ = bounds; |
| 86 if (!phantom_widget_.get()) { | 88 if (!phantom_widget_) { |
| 87 // Show the phantom at the bounds of the window. We'll animate to the target | 89 // Show the phantom at the bounds of the window. We'll animate to the target |
| 88 // bounds. | 90 // bounds. |
| 89 start_bounds_ = window_->GetBoundsInScreen(); | 91 start_bounds_ = window_->GetBoundsInScreen(); |
| 90 CreatePhantomWidget(start_bounds_); | 92 CreatePhantomWidget(start_bounds_); |
| 91 } else { | 93 } else { |
| 92 start_bounds_ = phantom_widget_->GetWindowBoundsInScreen(); | 94 start_bounds_ = phantom_widget_->GetWindowBoundsInScreen(); |
| 93 } | 95 } |
| 94 animation_.reset(new ui::SlideAnimation(this)); | 96 animation_.reset(new ui::SlideAnimation(this)); |
| 95 animation_->Show(); | 97 animation_->Show(); |
| 96 } | 98 } |
| 97 | 99 |
| 98 void PhantomWindowController::SetBounds(const gfx::Rect& bounds) { | 100 void PhantomWindowController::SetBounds(const gfx::Rect& bounds) { |
| 99 DCHECK(IsShowing()); | 101 DCHECK(IsShowing()); |
| 100 animation_.reset(); | 102 animation_.reset(); |
| 101 bounds_ = bounds; | 103 bounds_ = bounds; |
| 102 phantom_widget_->SetBounds(bounds_); | 104 phantom_widget_->SetBounds(bounds_); |
| 103 } | 105 } |
| 104 | 106 |
| 105 void PhantomWindowController::Hide() { | 107 void PhantomWindowController::Hide() { |
| 106 phantom_widget_.reset(); | 108 phantom_widget_->Close(); |
| 109 phantom_widget_ = NULL; | |
| 107 } | 110 } |
| 108 | 111 |
| 109 bool PhantomWindowController::IsShowing() const { | 112 bool PhantomWindowController::IsShowing() const { |
| 110 return phantom_widget_.get() != NULL; | 113 return phantom_widget_ != NULL; |
| 111 } | 114 } |
| 112 | 115 |
| 113 void PhantomWindowController::AnimationProgressed( | 116 void PhantomWindowController::AnimationProgressed( |
| 114 const ui::Animation* animation) { | 117 const ui::Animation* animation) { |
| 115 phantom_widget_->SetBounds( | 118 phantom_widget_->SetBounds( |
| 116 animation->CurrentValueBetween(start_bounds_, bounds_)); | 119 animation->CurrentValueBetween(start_bounds_, bounds_)); |
| 117 } | 120 } |
| 118 | 121 |
| 119 void PhantomWindowController::CreatePhantomWidget(const gfx::Rect& bounds) { | 122 void PhantomWindowController::CreatePhantomWidget(const gfx::Rect& bounds) { |
| 120 DCHECK(!phantom_widget_.get()); | 123 DCHECK(!phantom_widget_); |
| 121 phantom_widget_.reset(new views::Widget); | 124 phantom_widget_ = new views::Widget; |
| 122 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 125 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 123 params.transparent = true; | 126 params.transparent = true; |
| 124 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 127 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET; |
|
sky
2012/08/03 23:10:17
You can remove this line NATIVE_WIDGET_OWNS_WIDGET
Mr4D (OOO till 08-26)
2012/08/04 00:42:23
Done.
| |
| 125 // PhantomWindowController is used by FrameMaximizeButton to highlight the | 128 // PhantomWindowController is used by FrameMaximizeButton to highlight the |
| 126 // launcher button. Put the phantom in the same window as the launcher so that | 129 // launcher button. Put the phantom in the same window as the launcher so that |
| 127 // the phantom is visible. | 130 // the phantom is visible. |
| 128 params.parent = Shell::GetContainer( | 131 params.parent = Shell::GetContainer( |
| 129 Shell::GetInstance()->GetRootWindowMatching(bounds), | 132 Shell::GetInstance()->GetRootWindowMatching(bounds), |
| 130 kShellWindowId_LauncherContainer); | 133 kShellWindowId_LauncherContainer); |
| 131 params.can_activate = false; | 134 params.can_activate = false; |
| 132 params.keep_on_top = true; | 135 params.keep_on_top = true; |
| 133 phantom_widget_->set_focus_on_creation(false); | 136 phantom_widget_->set_focus_on_creation(false); |
| 134 phantom_widget_->Init(params); | 137 phantom_widget_->Init(params); |
| 135 phantom_widget_->SetVisibilityChangedAnimationsEnabled(false); | 138 phantom_widget_->SetVisibilityChangedAnimationsEnabled(false); |
| 136 phantom_widget_->GetNativeWindow()->SetName("PhantomWindow"); | 139 phantom_widget_->GetNativeWindow()->SetName("PhantomWindow"); |
| 137 views::View* content_view = new views::View; | 140 views::View* content_view = new views::View; |
| 138 content_view->set_background( | 141 content_view->set_background( |
| 139 views::Background::CreateBackgroundPainter(true, new EdgePainter)); | 142 views::Background::CreateBackgroundPainter(true, new EdgePainter)); |
| 140 phantom_widget_->SetContentsView(content_view); | 143 phantom_widget_->SetContentsView(content_view); |
| 141 phantom_widget_->SetBounds(bounds); | 144 phantom_widget_->SetBounds(bounds); |
| 142 phantom_widget_->StackAbove(window_); | 145 if (phantom_below_window_) |
| 146 phantom_widget_->StackBelow(phantom_below_window_); | |
| 147 else | |
| 148 phantom_widget_->StackAbove(window_); | |
| 143 phantom_widget_->Show(); | 149 phantom_widget_->Show(); |
| 144 // Fade the window in. | 150 // Fade the window in. |
| 145 ui::Layer* layer = phantom_widget_->GetNativeWindow()->layer(); | 151 ui::Layer* layer = phantom_widget_->GetNativeWindow()->layer(); |
| 146 layer->SetOpacity(0); | 152 layer->SetOpacity(0); |
| 147 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator()); | 153 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator()); |
| 148 layer->SetOpacity(1); | 154 layer->SetOpacity(1); |
| 149 } | 155 } |
| 150 | 156 |
| 151 } // namespace internal | 157 } // namespace internal |
| 152 } // namespace ash | 158 } // namespace ash |
| OLD | NEW |