OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/aura_shell/shelf_layout_controller.h" | 5 #include "ui/aura_shell/shelf_layout_manager.h" |
6 | 6 |
7 #include "ui/aura/desktop.h" | 7 #include "ui/aura/desktop.h" |
8 #include "ui/aura/screen_aura.h" | 8 #include "ui/aura/screen_aura.h" |
9 #include "ui/gfx/compositor/layer.h" | 9 #include "ui/gfx/compositor/layer.h" |
10 #include "ui/gfx/compositor/layer_animator.h" | 10 #include "ui/gfx/compositor/layer_animator.h" |
11 #include "ui/views/widget/widget.h" | 11 #include "ui/views/widget/widget.h" |
12 | 12 |
13 namespace aura_shell { | 13 namespace aura_shell { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 ui::Layer* GetLayer(views::Widget* widget) { | 18 ui::Layer* GetLayer(views::Widget* widget) { |
19 return widget->GetNativeView()->layer(); | 19 return widget->GetNativeView()->layer(); |
20 } | 20 } |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 ShelfLayoutController::ShelfLayoutController(views::Widget* launcher, | 24 //////////////////////////////////////////////////////////////////////////////// |
25 // ShelfLayoutManager, public: | |
26 | |
27 ShelfLayoutManager::ShelfLayoutManager(views::Widget* launcher, | |
25 views::Widget* status) | 28 views::Widget* status) |
26 : animating_(false), | 29 : animating_(false), |
27 visible_(true), | 30 visible_(true), |
28 max_height_(-1), | 31 max_height_(-1), |
29 launcher_(launcher), | 32 launcher_(launcher), |
30 status_(status) { | 33 status_(status) { |
31 gfx::Rect launcher_bounds = launcher->GetWindowScreenBounds(); | 34 gfx::Rect launcher_bounds = launcher->GetWindowScreenBounds(); |
32 gfx::Rect status_bounds = status->GetWindowScreenBounds(); | 35 gfx::Rect status_bounds = status->GetWindowScreenBounds(); |
33 max_height_ = std::max(launcher_bounds.height(), status_bounds.height()); | 36 max_height_ = std::max(launcher_bounds.height(), status_bounds.height()); |
34 GetLayer(launcher)->GetAnimator()->AddObserver(this); | 37 GetLayer(launcher)->GetAnimator()->AddObserver(this); |
35 } | 38 } |
36 | 39 |
37 ShelfLayoutController::~ShelfLayoutController() { | 40 ShelfLayoutManager::~ShelfLayoutManager() { |
38 GetLayer(launcher_)->GetAnimator()->RemoveObserver(this); | 41 GetLayer(launcher_)->GetAnimator()->RemoveObserver(this); |
39 } | 42 } |
40 | 43 |
41 void ShelfLayoutController::LayoutShelf() { | 44 void ShelfLayoutManager::SetVisible(bool visible) { |
42 StopAnimating(); | |
43 TargetBounds target_bounds; | |
44 float target_opacity = visible_ ? 1.0f : 0.0f; | |
45 CalculateTargetBounds(visible_, &target_bounds); | |
46 GetLayer(launcher_)->SetOpacity(target_opacity); | |
47 GetLayer(status_)->SetOpacity(target_opacity); | |
48 launcher_->SetBounds(target_bounds.launcher_bounds); | |
49 status_->SetBounds(target_bounds.status_bounds); | |
50 aura::Desktop::GetInstance()->screen()->set_work_area_insets( | |
51 target_bounds.work_area_insets); | |
52 } | |
53 | |
54 void ShelfLayoutController::SetVisible(bool visible) { | |
55 bool current_visibility = animating_ ? !visible_ : visible_; | 45 bool current_visibility = animating_ ? !visible_ : visible_; |
56 if (visible == current_visibility) | 46 if (visible == current_visibility) |
57 return; // Nothing changed. | 47 return; // Nothing changed. |
58 | 48 |
59 StopAnimating(); | 49 StopAnimating(); |
60 | 50 |
61 TargetBounds target_bounds; | 51 TargetBounds target_bounds; |
62 float target_opacity = visible ? 1.0f : 0.0f; | 52 float target_opacity = visible ? 1.0f : 0.0f; |
63 CalculateTargetBounds(visible, &target_bounds); | 53 CalculateTargetBounds(visible, &target_bounds); |
64 AnimateWidgetTo(launcher_, target_bounds.launcher_bounds, target_opacity); | 54 AnimateWidgetTo(launcher_, target_bounds.launcher_bounds, target_opacity); |
65 AnimateWidgetTo(status_, target_bounds.status_bounds, target_opacity); | 55 AnimateWidgetTo(status_, target_bounds.status_bounds, target_opacity); |
66 animating_ = true; | 56 animating_ = true; |
67 // |visible_| is updated once the animation completes. | 57 // |visible_| is updated once the animation completes. |
68 } | 58 } |
69 | 59 |
70 void ShelfLayoutController::StopAnimating() { | 60 //////////////////////////////////////////////////////////////////////////////// |
61 // ShelfLayoutManager, aura::LayoutManager implementation: | |
62 | |
63 void ShelfLayoutManager::OnWindowResized() { | |
64 LayoutShelf(); | |
65 } | |
66 | |
67 void ShelfLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | |
68 } | |
69 | |
70 void ShelfLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { | |
71 } | |
72 | |
73 void ShelfLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, | |
74 bool visible) { | |
75 } | |
76 | |
77 void ShelfLayoutManager::SetChildBounds(aura::Window* child, | |
78 const gfx::Rect& requested_bounds) { | |
79 SetChildBoundsDirect(child, requested_bounds); | |
sky
2011/12/02 19:25:53
I think you want if/else, eg:
if (!in_layout_)
Nikita (slow)
2011/12/05 14:41:46
Not really. It works like:
GetWidget()->SetSize(Ge
| |
80 if (!in_layout_) | |
81 LayoutShelf(); | |
82 } | |
83 | |
84 //////////////////////////////////////////////////////////////////////////////// | |
85 // ShelfLayoutManager, private: | |
86 | |
87 void ShelfLayoutManager::LayoutShelf() { | |
88 in_layout_ = true; | |
sky
2011/12/02 19:25:53
use base/auto_reset
Nikita (slow)
2011/12/05 14:41:46
Done.
| |
89 StopAnimating(); | |
90 TargetBounds target_bounds; | |
91 float target_opacity = visible_ ? 1.0f : 0.0f; | |
92 CalculateTargetBounds(visible_, &target_bounds); | |
93 GetLayer(launcher_)->SetOpacity(target_opacity); | |
94 GetLayer(status_)->SetOpacity(target_opacity); | |
95 launcher_->SetBounds(target_bounds.launcher_bounds); | |
96 status_->SetBounds(target_bounds.status_bounds); | |
97 aura::Desktop::GetInstance()->screen()->set_work_area_insets( | |
98 target_bounds.work_area_insets); | |
99 in_layout_ = false; | |
100 } | |
101 | |
102 void ShelfLayoutManager::StopAnimating() { | |
71 if (animating_) { | 103 if (animating_) { |
72 animating_ = false; | 104 animating_ = false; |
73 visible_ = !visible_; | 105 visible_ = !visible_; |
74 } | 106 } |
75 GetLayer(launcher_)->GetAnimator()->StopAnimating(); | 107 GetLayer(launcher_)->GetAnimator()->StopAnimating(); |
76 } | 108 } |
77 | 109 |
78 void ShelfLayoutController::CalculateTargetBounds(bool visible, | 110 void ShelfLayoutManager::CalculateTargetBounds(bool visible, |
79 TargetBounds* target_bounds) { | 111 TargetBounds* target_bounds) { |
80 const gfx::Rect& available_bounds(aura::Desktop::GetInstance()->bounds()); | 112 const gfx::Rect& available_bounds(aura::Desktop::GetInstance()->bounds()); |
81 int y = available_bounds.bottom() - (visible ? max_height_ : 0); | 113 int y = available_bounds.bottom() - (visible ? max_height_ : 0); |
82 gfx::Rect status_bounds(status_->GetWindowScreenBounds()); | 114 gfx::Rect status_bounds(status_->GetWindowScreenBounds()); |
83 target_bounds->status_bounds = gfx::Rect( | 115 target_bounds->status_bounds = gfx::Rect( |
84 available_bounds.right() - status_bounds.width(), | 116 available_bounds.right() - status_bounds.width(), |
85 y + (max_height_ - status_bounds.height()) / 2, | 117 y + (max_height_ - status_bounds.height()) / 2, |
86 status_bounds.width(), status_bounds.height()); | 118 status_bounds.width(), status_bounds.height()); |
87 gfx::Rect launcher_bounds(launcher_->GetWindowScreenBounds()); | 119 gfx::Rect launcher_bounds(launcher_->GetWindowScreenBounds()); |
88 target_bounds->launcher_bounds = gfx::Rect( | 120 target_bounds->launcher_bounds = gfx::Rect( |
89 available_bounds.x(), y + (max_height_ - launcher_bounds.height()) / 2, | 121 available_bounds.x(), y + (max_height_ - launcher_bounds.height()) / 2, |
90 available_bounds.width() - status_bounds.width(), | 122 available_bounds.width() - status_bounds.width(), |
91 launcher_bounds.height()); | 123 launcher_bounds.height()); |
92 if (visible) | 124 if (visible) |
93 target_bounds->work_area_insets = gfx::Insets(0, 0, max_height_, 0); | 125 target_bounds->work_area_insets = gfx::Insets(0, 0, max_height_, 0); |
94 } | 126 } |
95 | 127 |
96 void ShelfLayoutController::AnimateWidgetTo(views::Widget* widget, | 128 void ShelfLayoutManager::AnimateWidgetTo(views::Widget* widget, |
97 const gfx::Rect& target_bounds, | 129 const gfx::Rect& target_bounds, |
98 float target_opacity) { | 130 float target_opacity) { |
99 ui::Layer* layer = GetLayer(widget); | 131 ui::Layer* layer = GetLayer(widget); |
100 ui::LayerAnimator::ScopedSettings animation_setter(layer->GetAnimator()); | 132 ui::LayerAnimator::ScopedSettings animation_setter(layer->GetAnimator()); |
101 widget->SetBounds(target_bounds); | 133 widget->SetBounds(target_bounds); |
102 layer->SetOpacity(target_opacity); | 134 layer->SetOpacity(target_opacity); |
103 } | 135 } |
104 | 136 |
105 void ShelfLayoutController::OnLayerAnimationEnded( | 137 void ShelfLayoutManager::OnLayerAnimationEnded( |
106 const ui::LayerAnimationSequence* sequence) { | 138 const ui::LayerAnimationSequence* sequence) { |
107 if (!animating_) | 139 if (!animating_) |
108 return; | 140 return; |
109 animating_ = false; | 141 animating_ = false; |
110 visible_ = !visible_; | 142 visible_ = !visible_; |
111 TargetBounds target_bounds; | 143 TargetBounds target_bounds; |
112 CalculateTargetBounds(visible_, &target_bounds); | 144 CalculateTargetBounds(visible_, &target_bounds); |
113 aura::Desktop::GetInstance()->screen()->set_work_area_insets( | 145 aura::Desktop::GetInstance()->screen()->set_work_area_insets( |
114 target_bounds.work_area_insets); | 146 target_bounds.work_area_insets); |
115 } | 147 } |
116 | 148 |
117 } // internal | 149 } // internal |
118 } // aura_shell | 150 } // aura_shell |
OLD | NEW |