Skip to content

Commit

Permalink
Rename DisplayConfiguratorAnimation to DisplayAnimator
Browse files Browse the repository at this point in the history
Also cleans up the class to new style guide some.

BUG=576375

Review URL: https://codereview.chromium.org/1590463004

Cr-Commit-Position: refs/heads/master@{#369893}
  • Loading branch information
stevenjb authored and Commit bot committed Jan 16, 2016
1 parent f854247 commit f402ac5
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 109 deletions.
4 changes: 2 additions & 2 deletions ash/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ component("ash") {
"accelerators/magnifier_key_scroller.h",
"accelerators/spoken_feedback_toggler.cc",
"accelerators/spoken_feedback_toggler.h",
"display/display_configurator_animation.cc",
"display/display_configurator_animation.h",
"display/display_animator.cc",
"display/display_animator.h",
"display/resolution_notification_controller.cc",
"display/resolution_notification_controller.h",
"system/tray/media_security/media_capture_observer.h",
Expand Down
8 changes: 4 additions & 4 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@
'desktop_background/user_wallpaper_delegate.h',
'display/cursor_window_controller.cc',
'display/cursor_window_controller.h',
'display/display_animator.cc',
'display/display_animator.h',
'display/display_change_observer_chromeos.cc',
'display/display_change_observer_chromeos.h',
'display/display_color_manager_chromeos.cc',
'display/display_color_manager_chromeos.h',
'display/display_configurator_animation.cc',
'display/display_configurator_animation.h',
'display/window_tree_host_manager.cc',
'display/window_tree_host_manager.h',
'display/display_error_observer_chromeos.cc',
Expand Down Expand Up @@ -1033,8 +1033,8 @@
'accelerators/magnifier_key_scroller.h',
'accelerators/spoken_feedback_toggler.cc',
'accelerators/spoken_feedback_toggler.h',
'display/display_configurator_animation.cc',
'display/display_configurator_animation.h',
'display/display_animator.cc',
'display/display_animator.h',
'display/resolution_notification_controller.cc',
'display/resolution_notification_controller.h',
'system/tray/media_security/media_capture_observer.h',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/display/display_configurator_animation.h"
#include "ash/display/display_animator.h"

#include "ash/shell.h"
#include "ash/shell_window_ids.h"
Expand All @@ -28,9 +28,7 @@ const int kFadingTimeoutDurationInSeconds = 10;
class CallbackRunningObserver {
public:
CallbackRunningObserver(base::Closure callback)
: completed_counter_(0),
animation_aborted_(false),
callback_(callback) {}
: completed_counter_(0), animation_aborted_(false), callback_(callback) {}

void AddNewAnimator(ui::LayerAnimator* animator) {
Observer* observer = new Observer(animator, this);
Expand All @@ -56,10 +54,8 @@ class CallbackRunningObserver {
// The actual observer to listen each animation completion.
class Observer : public ui::LayerAnimationObserver {
public:
Observer(ui::LayerAnimator* animator,
CallbackRunningObserver* observer)
: animator_(animator),
observer_(observer) {}
Observer(ui::LayerAnimator* animator, CallbackRunningObserver* observer)
: animator_(animator), observer_(observer) {}

protected:
// ui::LayerAnimationObserver overrides:
Expand Down Expand Up @@ -95,41 +91,34 @@ class CallbackRunningObserver {

} // namespace

DisplayConfiguratorAnimation::DisplayConfiguratorAnimation()
: weak_ptr_factory_(this) {
}
DisplayAnimator::DisplayAnimator() : weak_ptr_factory_(this) {}

DisplayConfiguratorAnimation::~DisplayConfiguratorAnimation() {
DisplayAnimator::~DisplayAnimator() {
ClearHidingLayers();
}

void DisplayConfiguratorAnimation::StartFadeOutAnimation(
base::Closure callback) {
void DisplayAnimator::StartFadeOutAnimation(base::Closure callback) {
CallbackRunningObserver* observer = new CallbackRunningObserver(callback);
ClearHidingLayers();

// Make the fade-out animation for all root windows. Instead of actually
// hiding the root windows, we put a black layer over a root window for
// safety. These layers remain to hide root windows and will be deleted
// after the animation of OnDisplayModeChanged().
aura::Window::Windows root_windows =
Shell::GetInstance()->GetAllRootWindows();
for (aura::Window::Windows::const_iterator it = root_windows.begin();
it != root_windows.end(); ++it) {
aura::Window* root_window = *it;
for (aura::Window* root_window : Shell::GetInstance()->GetAllRootWindows()) {
ui::Layer* hiding_layer = new ui::Layer(ui::LAYER_SOLID_COLOR);
hiding_layer->SetColor(SK_ColorBLACK);
hiding_layer->SetBounds(root_window->bounds());
ui::Layer* parent =
ash::Shell::GetContainer(root_window,
ash::kShellWindowId_OverlayContainer)->layer();
ui::Layer* parent = ash::Shell::GetContainer(
root_window, ash::kShellWindowId_OverlayContainer)
->layer();
parent->Add(hiding_layer);

hiding_layer->SetOpacity(0.0);

ui::ScopedLayerAnimationSettings settings(hiding_layer->GetAnimator());
settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
kFadingAnimationDurationInMS));
settings.SetTransitionDuration(
base::TimeDelta::FromMilliseconds(kFadingAnimationDurationInMS));
observer->AddNewAnimator(hiding_layer->GetAnimator());
hiding_layer->SetOpacity(1.0f);
hiding_layer->SetVisible(true);
Expand All @@ -142,46 +131,39 @@ void DisplayConfiguratorAnimation::StartFadeOutAnimation(
timer_.reset(new base::OneShotTimer());
timer_->Start(FROM_HERE,
base::TimeDelta::FromSeconds(kFadingTimeoutDurationInSeconds),
this,
&DisplayConfiguratorAnimation::ClearHidingLayers);
this, &DisplayAnimator::ClearHidingLayers);
}

void DisplayConfiguratorAnimation::StartFadeInAnimation() {
void DisplayAnimator::StartFadeInAnimation() {
// We want to make sure clearing all of hiding layers after the animation
// finished. Note that this callback can be canceled, but the cancel only
// happens when the next animation is scheduled. Thus the hiding layers
// should be deleted eventually.
CallbackRunningObserver* observer = new CallbackRunningObserver(
base::Bind(&DisplayConfiguratorAnimation::ClearHidingLayers,
weak_ptr_factory_.GetWeakPtr()));
CallbackRunningObserver* observer = new CallbackRunningObserver(base::Bind(
&DisplayAnimator::ClearHidingLayers, weak_ptr_factory_.GetWeakPtr()));

// Ensure that layers are not animating.
for (std::map<aura::Window*, ui::Layer*>::iterator it =
hiding_layers_.begin(); it != hiding_layers_.end(); ++it) {
ui::LayerAnimator* animator = it->second->GetAnimator();
for (std::map<aura::Window*, ui::Layer*>::value_type& e : hiding_layers_) {
ui::LayerAnimator* animator = e.second->GetAnimator();
if (animator->is_animating())
animator->StopAnimating();
}

// Schedules the fade-in effect for all root windows. Because we put the
// black layers for fade-out, here we actually turn those black layers
// invisible.
aura::Window::Windows root_windows =
Shell::GetInstance()->GetAllRootWindows();
for (aura::Window::Windows::const_iterator it = root_windows.begin();
it != root_windows.end(); ++it) {
aura::Window* root_window = *it;
ui::Layer* hiding_layer = NULL;
for (aura::Window* root_window : Shell::GetInstance()->GetAllRootWindows()) {
ui::Layer* hiding_layer = nullptr;
if (hiding_layers_.find(root_window) == hiding_layers_.end()) {
// In case of the transition from mirroring->non-mirroring, new root
// windows appear and we do not have the black layers for them. Thus
// we need to create the layer and make it visible.
hiding_layer = new ui::Layer(ui::LAYER_SOLID_COLOR);
hiding_layer->SetColor(SK_ColorBLACK);
hiding_layer->SetBounds(root_window->bounds());
ui::Layer* parent =
ash::Shell::GetContainer(
root_window, ash::kShellWindowId_OverlayContainer)->layer();
ui::Layer* parent = ash::Shell::GetContainer(
root_window, ash::kShellWindowId_OverlayContainer)
->layer();
parent->Add(hiding_layer);
hiding_layer->SetOpacity(1.0f);
hiding_layer->SetVisible(true);
Expand All @@ -193,34 +175,34 @@ void DisplayConfiguratorAnimation::StartFadeInAnimation() {
}

ui::ScopedLayerAnimationSettings settings(hiding_layer->GetAnimator());
settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
kFadingAnimationDurationInMS));
settings.SetTransitionDuration(
base::TimeDelta::FromMilliseconds(kFadingAnimationDurationInMS));
observer->AddNewAnimator(hiding_layer->GetAnimator());
hiding_layer->SetOpacity(0.0f);
hiding_layer->SetVisible(false);
}
}

void DisplayConfiguratorAnimation::OnDisplayModeChanged(
void DisplayAnimator::OnDisplayModeChanged(
const ui::DisplayConfigurator::DisplayStateList& displays) {
if (!hiding_layers_.empty())
StartFadeInAnimation();
}

void DisplayConfiguratorAnimation::OnDisplayModeChangeFailed(
void DisplayAnimator::OnDisplayModeChangeFailed(
const ui::DisplayConfigurator::DisplayStateList& displays,
ui::MultipleDisplayState failed_new_state) {
if (!hiding_layers_.empty())
StartFadeInAnimation();
}

void DisplayConfiguratorAnimation::ClearHidingLayers() {
void DisplayAnimator::ClearHidingLayers() {
if (timer_) {
timer_->Stop();
timer_.reset();
}
STLDeleteContainerPairSecondPointers(
hiding_layers_.begin(), hiding_layers_.end());
STLDeleteContainerPairSecondPointers(hiding_layers_.begin(),
hiding_layers_.end());
hiding_layers_.clear();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_DISPLAY_DISPLAY_CONFIGURATOR_ANIMATION_H_
#define ASH_DISPLAY_DISPLAY_CONFIGURATOR_ANIMATION_H_
#ifndef ASH_DISPLAY_DISPLAY_ANIMATOR_H_
#define ASH_DISPLAY_DISPLAY_ANIMATOR_H_

#include <map>

Expand All @@ -25,14 +25,13 @@ class Layer;

namespace ash {

// DisplayConfiguratorAnimation provides the visual effects for
// DisplayAnimator provides the visual effects for
// ui::DisplayConfigurator, such like fade-out/in during changing
// the display mode.
class ASH_EXPORT DisplayConfiguratorAnimation
: public ui::DisplayConfigurator::Observer {
class ASH_EXPORT DisplayAnimator : public ui::DisplayConfigurator::Observer {
public:
DisplayConfiguratorAnimation();
~DisplayConfiguratorAnimation() override;
DisplayAnimator();
~DisplayAnimator() override;

// Starts the fade-out animation for the all root windows. It will
// call |callback| once all of the animations have finished.
Expand All @@ -58,11 +57,11 @@ class ASH_EXPORT DisplayConfiguratorAnimation

std::map<aura::Window*, ui::Layer*> hiding_layers_;
scoped_ptr<base::OneShotTimer> timer_;
base::WeakPtrFactory<DisplayConfiguratorAnimation> weak_ptr_factory_;
base::WeakPtrFactory<DisplayAnimator> weak_ptr_factory_;

DISALLOW_COPY_AND_ASSIGN(DisplayConfiguratorAnimation);
DISALLOW_COPY_AND_ASSIGN(DisplayAnimator);
};

} // namespace ash

#endif // ASH_DISPLAY_DISPLAY_CONFIGURATION_CONTROLLER_H_
#endif // ASH_DISPLAY_DISPLAY_ANIMATOR_H_
7 changes: 3 additions & 4 deletions ash/display/display_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#endif

#if defined(OS_CHROMEOS)
#include "ash/display/display_configurator_animation.h"
#include "ash/display/display_animator.h"
#include "base/sys_info.h"
#endif

Expand Down Expand Up @@ -948,9 +948,8 @@ void DisplayManager::SetMirrorMode(bool mirror) {
multi_display_mode_ =
mirror ? MIRRORING : current_default_multi_display_mode_;
ReconfigureDisplays();
if (Shell::GetInstance()->display_configurator_animation()) {
Shell::GetInstance()->display_configurator_animation()->
StartFadeInAnimation();
if (Shell::GetInstance()->display_animator()) {
Shell::GetInstance()->display_animator()->StartFadeInAnimation();
}
RunPendingTasksForTest();
#endif
Expand Down
12 changes: 4 additions & 8 deletions ash/display/window_tree_host_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include "ui/wm/public/activation_client.h"

#if defined(OS_CHROMEOS)
#include "ash/display/display_configurator_animation.h"
#include "ash/display/display_animator.h"
#include "base/sys_info.h"
#include "base/time/time.h"
#endif // defined(OS_CHROMEOS)
Expand Down Expand Up @@ -438,8 +438,7 @@ void WindowTreeHostManager::ToggleMirrorMode() {
}
#if defined(OS_CHROMEOS)
Shell* shell = Shell::GetInstance();
DisplayConfiguratorAnimation* animation =
shell->display_configurator_animation();
DisplayAnimator* animation = shell->display_animator();
animation->StartFadeOutAnimation(base::Bind(
&WindowTreeHostManager::SetMirrorModeAfterAnimation,
weak_ptr_factory_.GetWeakPtr(), !display_manager->IsInMirrorMode()));
Expand All @@ -455,8 +454,7 @@ void WindowTreeHostManager::SwapPrimaryDisplay() {

if (Shell::GetScreen()->GetNumDisplays() > 1) {
#if defined(OS_CHROMEOS)
DisplayConfiguratorAnimation* animation =
Shell::GetInstance()->display_configurator_animation();
DisplayAnimator* animation = Shell::GetInstance()->display_animator();
if (animation) {
animation->StartFadeOutAnimation(
base::Bind(&WindowTreeHostManager::OnFadeOutForSwapDisplayFinished,
Expand Down Expand Up @@ -924,9 +922,7 @@ AshWindowTreeHost* WindowTreeHostManager::AddWindowTreeHostForDisplay(
void WindowTreeHostManager::OnFadeOutForSwapDisplayFinished() {
#if defined(OS_CHROMEOS)
SetPrimaryDisplay(ScreenUtil::GetSecondaryDisplay());
Shell::GetInstance()
->display_configurator_animation()
->StartFadeInAnimation();
Shell::GetInstance()->display_animator()->StartFadeInAnimation();
#endif
}

Expand Down
11 changes: 5 additions & 6 deletions ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@
#include "ash/accelerators/magnifier_key_scroller.h"
#include "ash/accelerators/spoken_feedback_toggler.h"
#include "ash/ash_constants.h"
#include "ash/display/display_animator.h"
#include "ash/display/display_change_observer_chromeos.h"
#include "ash/display/display_color_manager_chromeos.h"
#include "ash/display/display_configurator_animation.h"
#include "ash/display/display_error_observer_chromeos.h"
#include "ash/display/projecting_observer_chromeos.h"
#include "ash/display/resolution_notification_controller.h"
Expand Down Expand Up @@ -814,9 +814,8 @@ Shell::~Shell() {
display_color_manager_.reset();
if (display_change_observer_)
display_configurator_->RemoveObserver(display_change_observer_.get());
if (display_configurator_animation_)
display_configurator_->RemoveObserver(
display_configurator_animation_.get());
if (display_animator_)
display_configurator_->RemoveObserver(display_animator_.get());
if (display_error_observer_)
display_configurator_->RemoveObserver(display_error_observer_.get());
if (projecting_observer_) {
Expand All @@ -840,8 +839,8 @@ void Shell::Init(const ShellInitParams& init_params) {
bool display_initialized = display_manager_->InitFromCommandLine();
#if defined(OS_CHROMEOS)
display_configurator_->Init(!gpu_support_->IsPanelFittingDisabled());
display_configurator_animation_.reset(new DisplayConfiguratorAnimation());
display_configurator_->AddObserver(display_configurator_animation_.get());
display_animator_.reset(new DisplayAnimator());
display_configurator_->AddObserver(display_animator_.get());

// The DBusThreadManager must outlive this Shell. See the DCHECK in ~Shell.
chromeos::DBusThreadManager* dbus_thread_manager =
Expand Down
8 changes: 3 additions & 5 deletions ash/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ class AutoclickController;
class BluetoothNotificationController;
class CaptureController;
class DesktopBackgroundController;
class DisplayAnimator;
class DisplayChangeObserver;
class DisplayColorManager;
class DisplayConfiguratorAnimation;
class WindowTreeHostManager;
class DisplayErrorObserver;
class DisplayManager;
Expand Down Expand Up @@ -523,9 +523,7 @@ class ASH_EXPORT Shell : public SystemModalContainerEventFilterDelegate,
ui::DisplayConfigurator* display_configurator() {
return display_configurator_.get();
}
DisplayConfiguratorAnimation* display_configurator_animation() {
return display_configurator_animation_.get();
}
DisplayAnimator* display_animator() { return display_animator_.get(); }
DisplayErrorObserver* display_error_observer() {
return display_error_observer_.get();
}
Expand Down Expand Up @@ -726,7 +724,7 @@ class ASH_EXPORT Shell : public SystemModalContainerEventFilterDelegate,
// Controls video output device state.
scoped_ptr<ui::DisplayConfigurator> display_configurator_;
scoped_ptr<DisplayColorManager> display_color_manager_;
scoped_ptr<DisplayConfiguratorAnimation> display_configurator_animation_;
scoped_ptr<DisplayAnimator> display_animator_;
scoped_ptr<DisplayErrorObserver> display_error_observer_;
scoped_ptr<ProjectingObserver> projecting_observer_;

Expand Down
Loading

0 comments on commit f402ac5

Please sign in to comment.