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_controller.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 "views/widget/widget.h" | 11 #include "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 ShelfLayoutController::ShelfLayoutController(views::Widget* launcher_widget, |
25 views::Widget* status) | 25 views::Widget* status_widget) |
26 : animating_(false), | 26 : animating_(false), |
27 visible_(true), | 27 visible_(true), |
28 max_height_(-1), | 28 max_height_(-1), |
29 launcher_(launcher), | 29 launcher_widget_(launcher_widget), |
30 status_(status) { | 30 status_widget_(status_widget) { |
31 gfx::Rect launcher_bounds = launcher->GetWindowScreenBounds(); | 31 gfx::Rect launcher_bounds = launcher_widget->GetWindowScreenBounds(); |
32 gfx::Rect status_bounds = status->GetWindowScreenBounds(); | 32 gfx::Rect status_bounds = status_widget->GetWindowScreenBounds(); |
33 max_height_ = std::max(launcher_bounds.height(), status_bounds.height()); | 33 max_height_ = std::max(launcher_bounds.height(), status_bounds.height()); |
34 GetLayer(launcher)->GetAnimator()->AddObserver(this); | 34 GetLayer(launcher_widget)->GetAnimator()->AddObserver(this); |
35 } | 35 } |
36 | 36 |
37 ShelfLayoutController::~ShelfLayoutController() { | 37 ShelfLayoutController::~ShelfLayoutController() { |
38 GetLayer(launcher_)->GetAnimator()->RemoveObserver(this); | 38 GetLayer(launcher_widget_)->GetAnimator()->RemoveObserver(this); |
39 } | 39 } |
40 | 40 |
41 void ShelfLayoutController::LayoutShelf() { | 41 void ShelfLayoutController::LayoutShelf() { |
42 StopAnimating(); | 42 StopAnimating(); |
43 TargetBounds target_bounds; | 43 TargetBounds target_bounds; |
44 float target_opacity = visible_ ? 1.0f : 0.0f; | 44 float target_opacity = visible_ ? 1.0f : 0.0f; |
45 CalculateTargetBounds(visible_, &target_bounds); | 45 CalculateTargetBounds(visible_, &target_bounds); |
46 GetLayer(launcher_)->SetOpacity(target_opacity); | 46 GetLayer(launcher_widget_)->SetOpacity(target_opacity); |
47 GetLayer(status_)->SetOpacity(target_opacity); | 47 GetLayer(status_widget_)->SetOpacity(target_opacity); |
48 launcher_->SetBounds(target_bounds.launcher_bounds); | 48 launcher_widget_->SetBounds(target_bounds.launcher_bounds); |
49 status_->SetBounds(target_bounds.status_bounds); | 49 status_widget_->SetBounds(target_bounds.status_bounds); |
50 aura::Desktop::GetInstance()->screen()->set_work_area_insets( | 50 aura::Desktop::GetInstance()->screen()->set_work_area_insets( |
51 target_bounds.work_area_insets); | 51 target_bounds.work_area_insets); |
52 } | 52 } |
53 | 53 |
54 void ShelfLayoutController::SetVisible(bool visible) { | 54 void ShelfLayoutController::SetVisible(bool visible) { |
55 bool current_visibility = animating_ ? !visible_ : visible_; | 55 bool current_visibility = animating_ ? !visible_ : visible_; |
56 if (visible == current_visibility) | 56 if (visible == current_visibility) |
57 return; // Nothing changed. | 57 return; // Nothing changed. |
58 | 58 |
59 StopAnimating(); | 59 StopAnimating(); |
60 | 60 |
61 TargetBounds target_bounds; | 61 TargetBounds target_bounds; |
62 float target_opacity = visible ? 1.0f : 0.0f; | 62 float target_opacity = visible ? 1.0f : 0.0f; |
63 CalculateTargetBounds(visible, &target_bounds); | 63 CalculateTargetBounds(visible, &target_bounds); |
64 AnimateWidgetTo(launcher_, target_bounds.launcher_bounds, target_opacity); | 64 AnimateWidgetTo( |
65 AnimateWidgetTo(status_, target_bounds.status_bounds, target_opacity); | 65 launcher_widget_, target_bounds.launcher_bounds, target_opacity); |
| 66 AnimateWidgetTo(status_widget_, target_bounds.status_bounds, target_opacity); |
66 animating_ = true; | 67 animating_ = true; |
67 // |visible_| is updated once the animation completes. | 68 // |visible_| is updated once the animation completes. |
68 } | 69 } |
69 | 70 |
70 void ShelfLayoutController::StopAnimating() { | 71 void ShelfLayoutController::StopAnimating() { |
71 if (animating_) { | 72 if (animating_) { |
72 animating_ = false; | 73 animating_ = false; |
73 visible_ = !visible_; | 74 visible_ = !visible_; |
74 } | 75 } |
75 GetLayer(launcher_)->GetAnimator()->StopAnimating(); | 76 GetLayer(launcher_widget_)->GetAnimator()->StopAnimating(); |
76 } | 77 } |
77 | 78 |
78 void ShelfLayoutController::CalculateTargetBounds(bool visible, | 79 void ShelfLayoutController::CalculateTargetBounds(bool visible, |
79 TargetBounds* target_bounds) { | 80 TargetBounds* target_bounds) { |
80 const gfx::Rect& available_bounds(aura::Desktop::GetInstance()->bounds()); | 81 const gfx::Rect& available_bounds(aura::Desktop::GetInstance()->bounds()); |
81 int y = available_bounds.bottom() - (visible ? max_height_ : 0); | 82 int y = available_bounds.bottom() - (visible ? max_height_ : 0); |
82 gfx::Rect status_bounds(status_->GetWindowScreenBounds()); | 83 gfx::Rect status_bounds(status_widget_->GetWindowScreenBounds()); |
83 target_bounds->status_bounds = gfx::Rect( | 84 target_bounds->status_bounds = gfx::Rect( |
84 available_bounds.right() - status_bounds.width(), | 85 available_bounds.right() - status_bounds.width(), |
85 y + (max_height_ - status_bounds.height()) / 2, | 86 y + (max_height_ - status_bounds.height()) / 2, |
86 status_bounds.width(), status_bounds.height()); | 87 status_bounds.width(), status_bounds.height()); |
87 gfx::Rect launcher_bounds(launcher_->GetWindowScreenBounds()); | 88 gfx::Rect launcher_bounds(launcher_widget_->GetWindowScreenBounds()); |
88 target_bounds->launcher_bounds = gfx::Rect( | 89 target_bounds->launcher_bounds = gfx::Rect( |
89 available_bounds.x(), y + (max_height_ - launcher_bounds.height()) / 2, | 90 available_bounds.x(), y + (max_height_ - launcher_bounds.height()) / 2, |
90 available_bounds.width() - status_bounds.width(), | 91 available_bounds.width() - status_bounds.width(), |
91 launcher_bounds.height()); | 92 launcher_bounds.height()); |
92 if (visible) | 93 if (visible) |
93 target_bounds->work_area_insets = gfx::Insets(0, 0, max_height_, 0); | 94 target_bounds->work_area_insets = gfx::Insets(0, 0, max_height_, 0); |
94 } | 95 } |
95 | 96 |
96 void ShelfLayoutController::AnimateWidgetTo(views::Widget* widget, | 97 void ShelfLayoutController::AnimateWidgetTo(views::Widget* widget, |
97 const gfx::Rect& target_bounds, | 98 const gfx::Rect& target_bounds, |
(...skipping 11 matching lines...) Expand all Loading... |
109 animating_ = false; | 110 animating_ = false; |
110 visible_ = !visible_; | 111 visible_ = !visible_; |
111 TargetBounds target_bounds; | 112 TargetBounds target_bounds; |
112 CalculateTargetBounds(visible_, &target_bounds); | 113 CalculateTargetBounds(visible_, &target_bounds); |
113 aura::Desktop::GetInstance()->screen()->set_work_area_insets( | 114 aura::Desktop::GetInstance()->screen()->set_work_area_insets( |
114 target_bounds.work_area_insets); | 115 target_bounds.work_area_insets); |
115 } | 116 } |
116 | 117 |
117 } // internal | 118 } // internal |
118 } // aura_shell | 119 } // aura_shell |
OLD | NEW |