Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: ui/aura_shell/shelf_layout_manager.cc

Issue 8817016: Revert 113185 - [cros, Aura] Refresh status area widget bounds on StatusAreaView layout. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura_shell/shelf_layout_manager.h ('k') | ui/aura_shell/shell.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_manager.h"
6
7 #include "base/auto_reset.h"
8 #include "ui/aura/desktop.h"
9 #include "ui/aura/screen_aura.h"
10 #include "ui/gfx/compositor/layer.h"
11 #include "ui/gfx/compositor/layer_animator.h"
12 #include "ui/views/widget/widget.h"
13
14 namespace aura_shell {
15 namespace internal {
16
17 namespace {
18
19 ui::Layer* GetLayer(views::Widget* widget) {
20 return widget->GetNativeView()->layer();
21 }
22
23 } // namespace
24
25 ////////////////////////////////////////////////////////////////////////////////
26 // ShelfLayoutManager, public:
27
28 ShelfLayoutManager::ShelfLayoutManager(views::Widget* launcher,
29 views::Widget* status)
30 : animating_(false),
31 in_layout_(false),
32 visible_(true),
33 max_height_(-1),
34 launcher_(launcher),
35 status_(status) {
36 gfx::Rect launcher_bounds = launcher->GetWindowScreenBounds();
37 gfx::Rect status_bounds = status->GetWindowScreenBounds();
38 max_height_ = std::max(launcher_bounds.height(), status_bounds.height());
39 GetLayer(launcher)->GetAnimator()->AddObserver(this);
40 }
41
42
43 ShelfLayoutManager::~ShelfLayoutManager() {
44 // Do not try to remove observer from layer as the Launcher is
45 // already deleted.
46 }
47
48 void ShelfLayoutManager::LayoutShelf() {
49 AutoReset<bool> auto_reset_in_layout(&in_layout_, true);
50 StopAnimating();
51 TargetBounds target_bounds;
52 float target_opacity = visible_ ? 1.0f : 0.0f;
53 CalculateTargetBounds(visible_, &target_bounds);
54 GetLayer(launcher_)->SetOpacity(target_opacity);
55 GetLayer(status_)->SetOpacity(target_opacity);
56 launcher_->SetBounds(target_bounds.launcher_bounds);
57 status_->SetBounds(target_bounds.status_bounds);
58 aura::Desktop::GetInstance()->screen()->set_work_area_insets(
59 target_bounds.work_area_insets);
60 }
61
62 void ShelfLayoutManager::SetVisible(bool visible) {
63 bool current_visibility = animating_ ? !visible_ : visible_;
64 if (visible == current_visibility)
65 return; // Nothing changed.
66
67 StopAnimating();
68
69 TargetBounds target_bounds;
70 float target_opacity = visible ? 1.0f : 0.0f;
71 CalculateTargetBounds(visible, &target_bounds);
72 AnimateWidgetTo(launcher_, target_bounds.launcher_bounds, target_opacity);
73 AnimateWidgetTo(status_, target_bounds.status_bounds, target_opacity);
74 animating_ = true;
75 // |visible_| is updated once the animation completes.
76 }
77
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() {
106 if (animating_) {
107 animating_ = false;
108 visible_ = !visible_;
109 }
110 GetLayer(launcher_)->GetAnimator()->StopAnimating();
111 }
112
113 void ShelfLayoutManager::CalculateTargetBounds(bool visible,
114 TargetBounds* target_bounds) {
115 const gfx::Rect& available_bounds(aura::Desktop::GetInstance()->bounds());
116 int y = available_bounds.bottom() - (visible ? max_height_ : 0);
117 gfx::Rect status_bounds(status_->GetWindowScreenBounds());
118 target_bounds->status_bounds = gfx::Rect(
119 available_bounds.right() - status_bounds.width(),
120 y + (max_height_ - status_bounds.height()) / 2,
121 status_bounds.width(), status_bounds.height());
122 gfx::Rect launcher_bounds(launcher_->GetWindowScreenBounds());
123 target_bounds->launcher_bounds = gfx::Rect(
124 available_bounds.x(), y + (max_height_ - launcher_bounds.height()) / 2,
125 available_bounds.width() - status_bounds.width(),
126 launcher_bounds.height());
127 if (visible)
128 target_bounds->work_area_insets = gfx::Insets(0, 0, max_height_, 0);
129 }
130
131 void ShelfLayoutManager::AnimateWidgetTo(views::Widget* widget,
132 const gfx::Rect& target_bounds,
133 float target_opacity) {
134 ui::Layer* layer = GetLayer(widget);
135 ui::LayerAnimator::ScopedSettings animation_setter(layer->GetAnimator());
136 widget->SetBounds(target_bounds);
137 layer->SetOpacity(target_opacity);
138 }
139
140 void ShelfLayoutManager::OnLayerAnimationEnded(
141 const ui::LayerAnimationSequence* sequence) {
142 if (!animating_)
143 return;
144 animating_ = false;
145 visible_ = !visible_;
146 TargetBounds target_bounds;
147 CalculateTargetBounds(visible_, &target_bounds);
148 aura::Desktop::GetInstance()->screen()->set_work_area_insets(
149 target_bounds.work_area_insets);
150 }
151
152 } // internal
153 } // aura_shell
OLDNEW
« no previous file with comments | « ui/aura_shell/shelf_layout_manager.h ('k') | ui/aura_shell/shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698