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.
5 #include "ash/desktop_background/desktop_background_widget_controller.h"
7 #include "ash/ash_export.h"
8 #include "ui/aura/root_window.h"
9 #include "ui/aura/window_property.h"
10 #include "ui/views/widget/widget.h"
12 // Exported for tests.
13 DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(
14 ASH_EXPORT
, ash::internal::DesktopBackgroundWidgetController
*);
15 DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(
16 ASH_EXPORT
, ash::internal::AnimatingDesktopController
*);
21 DEFINE_OWNED_WINDOW_PROPERTY_KEY(DesktopBackgroundWidgetController
,
22 kDesktopController
, NULL
);
23 DEFINE_OWNED_WINDOW_PROPERTY_KEY(AnimatingDesktopController
,
24 kAnimatingDesktopController
, NULL
);
26 DesktopBackgroundWidgetController::DesktopBackgroundWidgetController(
27 views::Widget
* widget
) : widget_(widget
) {
29 widget_
->AddObserver(this);
32 DesktopBackgroundWidgetController::DesktopBackgroundWidgetController(
33 ui::Layer
* layer
) : widget_(NULL
) {
37 DesktopBackgroundWidgetController::~DesktopBackgroundWidgetController() {
39 widget_
->RemoveObserver(this);
42 } else if (layer_
.get())
46 void DesktopBackgroundWidgetController::OnWidgetDestroying(
47 views::Widget
* widget
) {
48 widget_
->RemoveObserver(this);
52 void DesktopBackgroundWidgetController::SetBounds(gfx::Rect bounds
) {
54 widget_
->SetBounds(bounds
);
55 else if (layer_
.get())
56 layer_
->SetBounds(bounds
);
59 bool DesktopBackgroundWidgetController::Reparent(aura::RootWindow
* root_window
,
63 views::Widget::ReparentNativeView(widget_
->GetNativeView(),
64 root_window
->GetChildById(dest_container
));
68 ui::Layer
* layer
= layer_
.get();
69 root_window
->GetChildById(src_container
)->layer()->Remove(layer
);
70 root_window
->GetChildById(dest_container
)->layer()->Add(layer
);
73 // Nothing to reparent.
77 AnimatingDesktopController::AnimatingDesktopController(
78 DesktopBackgroundWidgetController
* component
) {
79 controller_
.reset(component
);
82 AnimatingDesktopController::~AnimatingDesktopController() {
85 void AnimatingDesktopController::StopAnimating() {
87 ui::Layer
* layer
= controller_
->layer() ? controller_
->layer() :
88 controller_
->widget()->GetNativeView()->layer();
89 layer
->GetAnimator()->StopAnimating();
93 DesktopBackgroundWidgetController
* AnimatingDesktopController::GetController(
94 bool pass_ownership
) {
96 return controller_
.release();
97 return controller_
.get();
100 } // namespace internal