Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: ash/common/wallpaper/wallpaper_widget_controller.cc

Issue 2729363002: chromeos: Move files in //ash/common to //ash, part 3 (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/common/wallpaper/wallpaper_widget_controller.h ('k') | ash/common/wm_activation_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/common/wallpaper/wallpaper_widget_controller.h"
6
7 #include "ash/ash_export.h"
8 #include "ash/common/wallpaper/wallpaper_delegate.h"
9 #include "ash/common/wm_shell.h"
10 #include "ash/common/wm_window.h"
11 #include "ash/root_window_controller.h"
12 #include "ui/compositor/layer_animation_observer.h"
13 #include "ui/compositor/scoped_layer_animation_settings.h"
14 #include "ui/views/widget/widget.h"
15
16 namespace ash {
17 namespace {
18
19 class ShowWallpaperAnimationObserver : public ui::ImplicitAnimationObserver,
20 public views::WidgetObserver {
21 public:
22 ShowWallpaperAnimationObserver(RootWindowController* root_window_controller,
23 views::Widget* wallpaper_widget,
24 bool is_initial_animation)
25 : root_window_controller_(root_window_controller),
26 wallpaper_widget_(wallpaper_widget),
27 is_initial_animation_(is_initial_animation) {
28 DCHECK(wallpaper_widget_);
29 wallpaper_widget_->AddObserver(this);
30 }
31
32 ~ShowWallpaperAnimationObserver() override {
33 StopObservingImplicitAnimations();
34 if (wallpaper_widget_)
35 wallpaper_widget_->RemoveObserver(this);
36 }
37
38 private:
39 // Overridden from ui::ImplicitAnimationObserver:
40 void OnImplicitAnimationsScheduled() override {
41 if (is_initial_animation_)
42 root_window_controller_->OnInitialWallpaperAnimationStarted();
43 }
44
45 void OnImplicitAnimationsCompleted() override {
46 root_window_controller_->OnWallpaperAnimationFinished(wallpaper_widget_);
47 delete this;
48 }
49
50 // Overridden from views::WidgetObserver.
51 void OnWidgetDestroying(views::Widget* widget) override { delete this; }
52
53 RootWindowController* root_window_controller_;
54 views::Widget* wallpaper_widget_;
55
56 // Is this object observing the initial brightness/grayscale animation?
57 const bool is_initial_animation_;
58
59 DISALLOW_COPY_AND_ASSIGN(ShowWallpaperAnimationObserver);
60 };
61
62 } // namespace
63
64 WallpaperWidgetController::WallpaperWidgetController(views::Widget* widget)
65 : widget_(widget),
66 widget_parent_(WmWindow::Get(widget->GetNativeWindow())->GetParent()) {
67 DCHECK(widget_);
68 widget_->AddObserver(this);
69 widget_parent_->aura_window()->AddObserver(this);
70 }
71
72 WallpaperWidgetController::~WallpaperWidgetController() {
73 if (widget_) {
74 views::Widget* widget = widget_;
75 RemoveObservers();
76 widget->CloseNow();
77 }
78 }
79
80 void WallpaperWidgetController::OnWidgetDestroying(views::Widget* widget) {
81 RemoveObservers();
82 }
83
84 void WallpaperWidgetController::SetBounds(const gfx::Rect& bounds) {
85 if (widget_)
86 widget_->SetBounds(bounds);
87 }
88
89 bool WallpaperWidgetController::Reparent(WmWindow* root_window, int container) {
90 if (widget_) {
91 widget_parent_->aura_window()->RemoveObserver(this);
92 WmWindow* window = WmWindow::Get(widget_->GetNativeWindow());
93 root_window->GetChildByShellWindowId(container)->AddChild(window);
94 widget_parent_ = WmWindow::Get(widget_->GetNativeWindow())->GetParent();
95 widget_parent_->aura_window()->AddObserver(this);
96 return true;
97 }
98 // Nothing to reparent.
99 return false;
100 }
101
102 void WallpaperWidgetController::RemoveObservers() {
103 widget_parent_->aura_window()->RemoveObserver(this);
104 widget_->RemoveObserver(this);
105 widget_ = nullptr;
106 }
107
108 void WallpaperWidgetController::OnWindowBoundsChanged(
109 aura::Window* window,
110 const gfx::Rect& old_bounds,
111 const gfx::Rect& new_bounds) {
112 SetBounds(new_bounds);
113 }
114
115 void WallpaperWidgetController::StartAnimating(
116 RootWindowController* root_window_controller) {
117 if (widget_) {
118 ui::ScopedLayerAnimationSettings settings(
119 widget_->GetLayer()->GetAnimator());
120 settings.AddObserver(new ShowWallpaperAnimationObserver(
121 root_window_controller, widget_,
122 WmShell::Get()->wallpaper_delegate()->ShouldShowInitialAnimation()));
123 // When |widget_| shows, AnimateShowWindowCommon() is called to do the
124 // animation. Sets transition duration to 0 to avoid animating to the
125 // show animation's initial values.
126 settings.SetTransitionDuration(base::TimeDelta());
127 widget_->Show();
128 }
129 }
130
131 AnimatingWallpaperWidgetController::AnimatingWallpaperWidgetController(
132 WallpaperWidgetController* controller)
133 : controller_(controller) {}
134
135 AnimatingWallpaperWidgetController::~AnimatingWallpaperWidgetController() {}
136
137 void AnimatingWallpaperWidgetController::StopAnimating() {
138 if (controller_)
139 controller_->widget()->GetLayer()->GetAnimator()->StopAnimating();
140 }
141
142 WallpaperWidgetController* AnimatingWallpaperWidgetController::GetController(
143 bool pass_ownership) {
144 if (pass_ownership)
145 return controller_.release();
146 return controller_.get();
147 }
148
149 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wallpaper/wallpaper_widget_controller.h ('k') | ash/common/wm_activation_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698