Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/display/output_configurator_animation.h" | |
| 6 | |
| 7 #include "ash/shell.h" | |
| 8 #include "ash/shell_window_ids.h" | |
| 9 #include "base/bind.h" | |
| 10 #include "base/stl_util.h" | |
| 11 #include "base/time.h" | |
| 12 #include "ui/aura/root_window.h" | |
| 13 #include "ui/aura/window.h" | |
| 14 #include "ui/compositor/layer.h" | |
| 15 #include "ui/compositor/layer_animation_observer.h" | |
| 16 #include "ui/compositor/layer_animation_sequence.h" | |
| 17 #include "ui/compositor/layer_animator.h" | |
| 18 #include "ui/compositor/scoped_layer_animation_settings.h" | |
| 19 | |
| 20 namespace ash { | |
| 21 namespace internal { | |
| 22 namespace { | |
| 23 | |
| 24 const int kFadingAnimationDurationInMS = 200; | |
| 25 | |
| 26 // CallbackRunningObserver accepts several layer animations and | |
| 27 // runs the specified |callback| when all of the animations have finished. | |
| 28 class CallbackRunningObserver { | |
| 29 public: | |
| 30 CallbackRunningObserver(base::Closure callback) | |
| 31 : completed_counter_(0), | |
| 32 callback_(callback) {} | |
| 33 | |
| 34 void AddNewAnimator(ui::ScopedLayerAnimationSettings *settings) { | |
| 35 Observer* observer = new Observer(this); | |
| 36 settings->AddObserver(observer); | |
| 37 observer_list_.push_back(observer); | |
| 38 } | |
| 39 | |
| 40 private: | |
| 41 void OnSingleTaskCompleted() { | |
| 42 completed_counter_++; | |
| 43 if (completed_counter_ >= observer_list_.size()) { | |
| 44 callback_.Run(); | |
| 45 MessageLoopForUI::current()->DeleteSoon(FROM_HERE, this); | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 // The actual observer to listen each animation completion. | |
| 50 class Observer : public ui::ImplicitAnimationObserver { | |
| 51 public: | |
| 52 Observer(CallbackRunningObserver* observer) | |
| 53 : observer_(observer) {} | |
| 54 | |
| 55 virtual void OnImplicitAnimationsCompleted() OVERRIDE { | |
| 56 observer_->OnSingleTaskCompleted(); | |
| 57 } | |
| 58 | |
| 59 private: | |
| 60 CallbackRunningObserver* observer_; | |
| 61 }; | |
| 62 | |
| 63 size_t completed_counter_; | |
| 64 ScopedVector<Observer> observer_list_; | |
| 65 base::Closure callback_; | |
| 66 }; | |
| 67 | |
| 68 } // namespace | |
| 69 | |
| 70 OutputConfiguratorAnimation::OutputConfiguratorAnimation() { | |
| 71 } | |
| 72 | |
| 73 OutputConfiguratorAnimation::~OutputConfiguratorAnimation() { | |
| 74 ClearHidingLayers(); | |
| 75 } | |
| 76 | |
| 77 void OutputConfiguratorAnimation::WillDisplayModeChange( | |
| 78 base::Closure callback) { | |
| 79 CallbackRunningObserver *observer = new CallbackRunningObserver(callback); | |
| 80 ClearHidingLayers(); | |
|
oshima
2012/07/26 05:27:49
Will this call the callback? My guess is that such
Jun Mukai
2012/07/26 09:44:03
I put a debug code and made sure ClearHidingLayers
oshima
2012/07/26 14:08:17
How they're canceled? ImplicitAnimationObserver ca
Jun Mukai
2012/07/27 02:22:53
Sorry I haven't looked this deeper.
I noticed that
| |
| 81 | |
| 82 // Make the fade-out animation for all root windows. Instead of actually | |
| 83 // hiding the root windows, we put a black layer over a root window for | |
| 84 // safety. | |
| 85 Shell::RootWindowList root_windows = | |
| 86 Shell::GetInstance()->GetAllRootWindows(); | |
| 87 for (Shell::RootWindowList::const_iterator it = root_windows.begin(); | |
| 88 it != root_windows.end(); ++it) { | |
| 89 aura::RootWindow* root_window = *it; | |
| 90 ui::Layer* hiding_layer = new ui::Layer(ui::LAYER_SOLID_COLOR); | |
| 91 hiding_layer->SetColor(SK_ColorBLACK); | |
| 92 hiding_layer->SetBounds(root_window->bounds()); | |
| 93 ui::Layer* parent = ash::Shell::GetContainer( | |
| 94 root_window, | |
| 95 ash::internal::kShellWindowId_OverlayContainer)->layer(); | |
| 96 parent->Add(hiding_layer); | |
| 97 | |
| 98 hiding_layer->SetOpacity(0.0); | |
| 99 hiding_layer->SetTransform(ui::Transform()); | |
|
oshima
2012/07/26 05:27:49
just wondering. why you need this?
Jun Mukai
2012/07/26 09:44:03
oh, I was wrong and it's not necessary anymore. R
| |
| 100 | |
| 101 ui::ScopedLayerAnimationSettings settings(hiding_layer->GetAnimator()); | |
| 102 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | |
| 103 kFadingAnimationDurationInMS)); | |
| 104 observer->AddNewAnimator(&settings); | |
| 105 hiding_layer->SetOpacity(1.0f); | |
| 106 hiding_layer->SetTransform(ui::Transform()); | |
| 107 hiding_layer->SetVisible(true); | |
| 108 hiding_layers_[root_window] = hiding_layer; | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 void OutputConfiguratorAnimation::OnDisplayModeChanged() { | |
| 113 // We want to make sure clearing all of hiding layers after the animation | |
| 114 // finished. | |
| 115 CallbackRunningObserver *observer = new CallbackRunningObserver( | |
| 116 base::Bind(&OutputConfiguratorAnimation::ClearHidingLayers, | |
| 117 base::Unretained(this))); | |
| 118 | |
| 119 // Schedules the fade-in effect for all root windows. Because we put the | |
| 120 // black layers for fade-out, here we actually turn those black layers | |
| 121 // invisible. | |
| 122 Shell::RootWindowList root_windows = | |
| 123 Shell::GetInstance()->GetAllRootWindows(); | |
| 124 for (Shell::RootWindowList::const_iterator it = root_windows.begin(); | |
| 125 it != root_windows.end(); ++it) { | |
| 126 aura::RootWindow* root_window = *it; | |
| 127 ui::Layer* hiding_layer = NULL; | |
| 128 if (hiding_layers_.find(root_window) == hiding_layers_.end()) { | |
| 129 // In case of the transition from mirroring->non-mirroring, new root | |
| 130 // windows appear and we do not have the black layers for them. Thus | |
| 131 // we need to create the layer and make it visible. | |
| 132 hiding_layer = new ui::Layer(ui::LAYER_SOLID_COLOR); | |
| 133 hiding_layer->SetColor(SK_ColorBLACK); | |
| 134 hiding_layer->SetBounds(root_window->bounds()); | |
| 135 ui::Layer* parent = ash::Shell::GetContainer( | |
| 136 root_window, | |
| 137 ash::internal::kShellWindowId_OverlayContainer)->layer(); | |
| 138 parent->Add(hiding_layer); | |
| 139 hiding_layer->SetOpacity(1.0f); | |
| 140 hiding_layer->SetVisible(true); | |
| 141 hiding_layers_[root_window] = hiding_layer; | |
| 142 } else { | |
| 143 hiding_layer = hiding_layers_[root_window]; | |
| 144 } | |
| 145 | |
| 146 ui::ScopedLayerAnimationSettings settings(hiding_layer->GetAnimator()); | |
| 147 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | |
| 148 kFadingAnimationDurationInMS)); | |
| 149 observer->AddNewAnimator(&settings); | |
| 150 hiding_layer->SetOpacity(0.0f); | |
| 151 hiding_layer->SetTransform(ui::Transform()); | |
| 152 hiding_layer->SetVisible(false); | |
| 153 } | |
| 154 } | |
| 155 | |
| 156 void OutputConfiguratorAnimation::ClearHidingLayers() { | |
| 157 STLDeleteContainerPairSecondPointers( | |
| 158 hiding_layers_.begin(), hiding_layers_.end()); | |
|
oshima
2012/07/26 05:27:49
what happen to the layer for detaching display? Wo
Jun Mukai
2012/07/26 09:44:03
I just checked ui/compositor/layer.cc and noticed
oshima
2012/07/26 14:08:17
Ok, so looks like it doesn't delete layer when roo
Jun Mukai
2012/07/27 02:22:53
Sorry, what do you mean? The layers are deleted a
Jun Mukai
2012/07/27 02:36:22
a OneShotTimer is added
| |
| 159 hiding_layers_.clear(); | |
| 160 } | |
| 161 | |
| 162 } // namespace internal | |
| 163 } // namespace ash | |
| OLD | NEW |