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