| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/aura_shell/shelf_layout_controller.h" | |
| 6 | |
| 7 #include "ui/aura/desktop.h" | |
| 8 #include "ui/aura/screen_aura.h" | |
| 9 #include "ui/gfx/compositor/layer.h" | |
| 10 #include "ui/gfx/compositor/layer_animator.h" | |
| 11 #include "ui/views/widget/widget.h" | |
| 12 | |
| 13 namespace aura_shell { | |
| 14 namespace internal { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 ui::Layer* GetLayer(views::Widget* widget) { | |
| 19 return widget->GetNativeView()->layer(); | |
| 20 } | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 ShelfLayoutController::ShelfLayoutController(views::Widget* launcher, | |
| 25 views::Widget* status) | |
| 26 : animating_(false), | |
| 27 visible_(true), | |
| 28 max_height_(-1), | |
| 29 launcher_(launcher), | |
| 30 status_(status) { | |
| 31 gfx::Rect launcher_bounds = launcher->GetWindowScreenBounds(); | |
| 32 gfx::Rect status_bounds = status->GetWindowScreenBounds(); | |
| 33 max_height_ = std::max(launcher_bounds.height(), status_bounds.height()); | |
| 34 GetLayer(launcher)->GetAnimator()->AddObserver(this); | |
| 35 } | |
| 36 | |
| 37 ShelfLayoutController::~ShelfLayoutController() { | |
| 38 // Do not try to remove observer from layer as the Launcher is | |
| 39 // already deleted. | |
| 40 } | |
| 41 | |
| 42 void ShelfLayoutController::LayoutShelf() { | |
| 43 StopAnimating(); | |
| 44 TargetBounds target_bounds; | |
| 45 float target_opacity = visible_ ? 1.0f : 0.0f; | |
| 46 CalculateTargetBounds(visible_, &target_bounds); | |
| 47 GetLayer(launcher_)->SetOpacity(target_opacity); | |
| 48 GetLayer(status_)->SetOpacity(target_opacity); | |
| 49 launcher_->SetBounds(target_bounds.launcher_bounds); | |
| 50 status_->SetBounds(target_bounds.status_bounds); | |
| 51 aura::Desktop::GetInstance()->screen()->set_work_area_insets( | |
| 52 target_bounds.work_area_insets); | |
| 53 } | |
| 54 | |
| 55 void ShelfLayoutController::SetVisible(bool visible) { | |
| 56 bool current_visibility = animating_ ? !visible_ : visible_; | |
| 57 if (visible == current_visibility) | |
| 58 return; // Nothing changed. | |
| 59 | |
| 60 StopAnimating(); | |
| 61 | |
| 62 TargetBounds target_bounds; | |
| 63 float target_opacity = visible ? 1.0f : 0.0f; | |
| 64 CalculateTargetBounds(visible, &target_bounds); | |
| 65 AnimateWidgetTo(launcher_, target_bounds.launcher_bounds, target_opacity); | |
| 66 AnimateWidgetTo(status_, target_bounds.status_bounds, target_opacity); | |
| 67 animating_ = true; | |
| 68 // |visible_| is updated once the animation completes. | |
| 69 } | |
| 70 | |
| 71 void ShelfLayoutController::StopAnimating() { | |
| 72 if (animating_) { | |
| 73 animating_ = false; | |
| 74 visible_ = !visible_; | |
| 75 } | |
| 76 GetLayer(launcher_)->GetAnimator()->StopAnimating(); | |
| 77 } | |
| 78 | |
| 79 void ShelfLayoutController::CalculateTargetBounds(bool visible, | |
| 80 TargetBounds* target_bounds) { | |
| 81 const gfx::Rect& available_bounds(aura::Desktop::GetInstance()->bounds()); | |
| 82 int y = available_bounds.bottom() - (visible ? max_height_ : 0); | |
| 83 gfx::Rect status_bounds(status_->GetWindowScreenBounds()); | |
| 84 target_bounds->status_bounds = gfx::Rect( | |
| 85 available_bounds.right() - status_bounds.width(), | |
| 86 y + (max_height_ - status_bounds.height()) / 2, | |
| 87 status_bounds.width(), status_bounds.height()); | |
| 88 gfx::Rect launcher_bounds(launcher_->GetWindowScreenBounds()); | |
| 89 target_bounds->launcher_bounds = gfx::Rect( | |
| 90 available_bounds.x(), y + (max_height_ - launcher_bounds.height()) / 2, | |
| 91 available_bounds.width() - status_bounds.width(), | |
| 92 launcher_bounds.height()); | |
| 93 if (visible) | |
| 94 target_bounds->work_area_insets = gfx::Insets(0, 0, max_height_, 0); | |
| 95 } | |
| 96 | |
| 97 void ShelfLayoutController::AnimateWidgetTo(views::Widget* widget, | |
| 98 const gfx::Rect& target_bounds, | |
| 99 float target_opacity) { | |
| 100 ui::Layer* layer = GetLayer(widget); | |
| 101 ui::LayerAnimator::ScopedSettings animation_setter(layer->GetAnimator()); | |
| 102 widget->SetBounds(target_bounds); | |
| 103 layer->SetOpacity(target_opacity); | |
| 104 } | |
| 105 | |
| 106 void ShelfLayoutController::OnLayerAnimationEnded( | |
| 107 const ui::LayerAnimationSequence* sequence) { | |
| 108 if (!animating_) | |
| 109 return; | |
| 110 animating_ = false; | |
| 111 visible_ = !visible_; | |
| 112 TargetBounds target_bounds; | |
| 113 CalculateTargetBounds(visible_, &target_bounds); | |
| 114 aura::Desktop::GetInstance()->screen()->set_work_area_insets( | |
| 115 target_bounds.work_area_insets); | |
| 116 } | |
| 117 | |
| 118 } // internal | |
| 119 } // aura_shell | |
| OLD | NEW |