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

Side by Side Diff: athena/home/home_card_impl.cc

Issue 478293004: Refactor the home card structure and introduce animation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 3 months 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 | « athena/home/home_card_gesture_manager.cc ('k') | athena/home/minimized_home.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "athena/home/public/home_card.h" 5 #include "athena/home/public/home_card.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <limits> 8 #include <limits>
9 9
10 #include "athena/common/container_priorities.h" 10 #include "athena/common/container_priorities.h"
11 #include "athena/env/public/athena_env.h" 11 #include "athena/env/public/athena_env.h"
12 #include "athena/home/app_list_view_delegate.h" 12 #include "athena/home/app_list_view_delegate.h"
13 #include "athena/home/athena_start_page_view.h" 13 #include "athena/home/athena_start_page_view.h"
14 #include "athena/home/home_card_constants.h" 14 #include "athena/home/home_card_constants.h"
15 #include "athena/home/home_card_gesture_manager.h" 15 #include "athena/home/home_card_gesture_manager.h"
16 #include "athena/home/minimized_home.h" 16 #include "athena/home/minimized_home.h"
17 #include "athena/home/public/app_model_builder.h" 17 #include "athena/home/public/app_model_builder.h"
18 #include "athena/input/public/accelerator_manager.h" 18 #include "athena/input/public/accelerator_manager.h"
19 #include "athena/screen/public/screen_manager.h" 19 #include "athena/screen/public/screen_manager.h"
20 #include "athena/wm/public/window_manager.h" 20 #include "athena/wm/public/window_manager.h"
21 #include "athena/wm/public/window_manager_observer.h" 21 #include "athena/wm/public/window_manager_observer.h"
22 #include "base/bind.h"
23 #include "base/memory/weak_ptr.h"
24 #include "ui/app_list/search_provider.h" 22 #include "ui/app_list/search_provider.h"
25 #include "ui/app_list/views/app_list_main_view.h" 23 #include "ui/app_list/views/app_list_main_view.h"
26 #include "ui/app_list/views/contents_view.h" 24 #include "ui/app_list/views/contents_view.h"
27 #include "ui/aura/layout_manager.h" 25 #include "ui/aura/layout_manager.h"
28 #include "ui/aura/window.h" 26 #include "ui/aura/window.h"
29 #include "ui/compositor/closure_animation_observer.h" 27 #include "ui/compositor/layer.h"
28 #include "ui/compositor/layer_owner.h"
30 #include "ui/compositor/scoped_layer_animation_settings.h" 29 #include "ui/compositor/scoped_layer_animation_settings.h"
31 #include "ui/views/background.h" 30 #include "ui/views/layout/fill_layout.h"
32 #include "ui/views/layout/box_layout.h"
33 #include "ui/views/widget/widget.h" 31 #include "ui/views/widget/widget.h"
34 #include "ui/views/widget/widget_delegate.h" 32 #include "ui/views/widget/widget_delegate.h"
35 #include "ui/wm/core/shadow_types.h" 33 #include "ui/wm/core/shadow_types.h"
36 #include "ui/wm/core/visibility_controller.h" 34 #include "ui/wm/core/visibility_controller.h"
37 #include "ui/wm/core/window_animations.h"
38 #include "ui/wm/public/activation_change_observer.h" 35 #include "ui/wm/public/activation_change_observer.h"
39 #include "ui/wm/public/activation_client.h" 36 #include "ui/wm/public/activation_client.h"
40 37
41 namespace athena { 38 namespace athena {
42 namespace { 39 namespace {
43 40
44 HomeCard* instance = NULL; 41 HomeCard* instance = NULL;
45 42
46 gfx::Rect GetBoundsForState(const gfx::Rect& screen_bounds, 43 gfx::Rect GetBoundsForState(const gfx::Rect& screen_bounds,
47 HomeCard::State state) { 44 HomeCard::State state) {
48 switch (state) { 45 switch (state) {
49 case HomeCard::HIDDEN: 46 case HomeCard::HIDDEN:
50 break; 47 break;
51 48
52 case HomeCard::VISIBLE_CENTERED: 49 case HomeCard::VISIBLE_CENTERED:
53 return screen_bounds; 50 return screen_bounds;
54 51
52 // Do not change the home_card's size, only changes the top position
53 // instead, because size change causes unnecessary re-layouts.
55 case HomeCard::VISIBLE_BOTTOM: 54 case HomeCard::VISIBLE_BOTTOM:
56 return gfx::Rect(0, 55 return gfx::Rect(0,
57 screen_bounds.bottom() - kHomeCardHeight, 56 screen_bounds.bottom() - kHomeCardHeight,
58 screen_bounds.width(), 57 screen_bounds.width(),
59 kHomeCardHeight); 58 screen_bounds.height());
60 case HomeCard::VISIBLE_MINIMIZED: 59 case HomeCard::VISIBLE_MINIMIZED:
61 return gfx::Rect(0, 60 return gfx::Rect(0,
62 screen_bounds.bottom() - kHomeCardMinimizedHeight, 61 screen_bounds.bottom() - kHomeCardMinimizedHeight,
63 screen_bounds.width(), 62 screen_bounds.width(),
64 kHomeCardMinimizedHeight); 63 screen_bounds.height());
65 } 64 }
66 65
67 NOTREACHED(); 66 NOTREACHED();
68 return gfx::Rect(); 67 return gfx::Rect();
69 } 68 }
70 69
71 // Makes sure the homecard is center-aligned horizontally and bottom-aligned 70 // Makes sure the homecard is center-aligned horizontally and bottom-aligned
72 // vertically. 71 // vertically.
73 class HomeCardLayoutManager : public aura::LayoutManager { 72 class HomeCardLayoutManager : public aura::LayoutManager {
74 public: 73 public:
75 explicit HomeCardLayoutManager() 74 HomeCardLayoutManager()
76 : home_card_(NULL) {} 75 : home_card_(NULL),
76 minimized_layer_(NULL) {}
77 77
78 virtual ~HomeCardLayoutManager() {} 78 virtual ~HomeCardLayoutManager() {}
79 79
80 void Layout() { 80 void Layout(bool animate) {
81 // |home_card| could be detached from the root window (e.g. when it is being 81 // |home_card| could be detached from the root window (e.g. when it is being
82 // destroyed). 82 // destroyed).
83 if (!home_card_ || !home_card_->IsVisible() || !home_card_->GetRootWindow()) 83 if (!home_card_ || !home_card_->IsVisible() || !home_card_->GetRootWindow())
84 return; 84 return;
85 85
86 { 86 scoped_ptr<ui::ScopedLayerAnimationSettings> settings;
87 ui::ScopedLayerAnimationSettings settings( 87 if (animate) {
88 home_card_->layer()->GetAnimator()); 88 settings.reset(new ui::ScopedLayerAnimationSettings(
89 settings.SetTweenType(gfx::Tween::EASE_IN_OUT); 89 home_card_->layer()->GetAnimator()));
90 SetChildBoundsDirect(home_card_, GetBoundsForState( 90 settings->SetTweenType(gfx::Tween::EASE_IN_OUT);
91 home_card_->GetRootWindow()->bounds(), HomeCard::Get()->GetState()));
92 } 91 }
92 SetChildBoundsDirect(home_card_, GetBoundsForState(
93 home_card_->GetRootWindow()->bounds(), HomeCard::Get()->GetState()));
94 }
95
96 void SetMinimizedLayer(ui::Layer* minimized_layer) {
97 minimized_layer_ = minimized_layer;
98 UpdateMinimizedHomeBounds();
93 } 99 }
94 100
95 private: 101 private:
102 void UpdateMinimizedHomeBounds() {
103 gfx::Rect minimized_bounds = minimized_layer_->parent()->bounds();
104 minimized_bounds.set_y(
105 minimized_bounds.bottom() - kHomeCardMinimizedHeight);
106 minimized_bounds.set_height(kHomeCardMinimizedHeight);
107 minimized_layer_->SetBounds(minimized_bounds);
108 }
109
96 // aura::LayoutManager: 110 // aura::LayoutManager:
97 virtual void OnWindowResized() OVERRIDE { Layout(); } 111 virtual void OnWindowResized() OVERRIDE {
112 Layout(false);
113 UpdateMinimizedHomeBounds();
114 }
98 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { 115 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
99 if (!home_card_) { 116 if (!home_card_) {
100 home_card_ = child; 117 home_card_ = child;
101 Layout(); 118 Layout(false);
102 } 119 }
103 } 120 }
104 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE { 121 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {
105 if (home_card_ == child) 122 if (home_card_ == child)
106 home_card_ = NULL; 123 home_card_ = NULL;
107 } 124 }
108 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { 125 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {
109 Layout(); 126 Layout(false);
110 } 127 }
111 virtual void OnChildWindowVisibilityChanged(aura::Window* child, 128 virtual void OnChildWindowVisibilityChanged(aura::Window* child,
112 bool visible) OVERRIDE { 129 bool visible) OVERRIDE {
113 Layout(); 130 Layout(false);
114 } 131 }
115 virtual void SetChildBounds(aura::Window* child, 132 virtual void SetChildBounds(aura::Window* child,
116 const gfx::Rect& requested_bounds) OVERRIDE { 133 const gfx::Rect& requested_bounds) OVERRIDE {
117 SetChildBoundsDirect(child, requested_bounds); 134 SetChildBoundsDirect(child, requested_bounds);
118 } 135 }
119 136
120 aura::Window* home_card_; 137 aura::Window* home_card_;
138 ui::Layer* minimized_layer_;
121 139
122 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); 140 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager);
123 }; 141 };
124 142
125 // The container view of home card contents of each state. 143 // The container view of home card contents of each state.
126 class HomeCardView : public views::WidgetDelegateView { 144 class HomeCardView : public views::WidgetDelegateView {
127 public: 145 public:
128 HomeCardView(app_list::AppListViewDelegate* view_delegate, 146 HomeCardView(app_list::AppListViewDelegate* view_delegate,
129 aura::Window* container, 147 aura::Window* container,
130 HomeCardGestureManager::Delegate* gesture_delegate) 148 HomeCardGestureManager::Delegate* gesture_delegate)
131 : gesture_delegate_(gesture_delegate), 149 : gesture_delegate_(gesture_delegate) {
132 weak_factory_(this) { 150 SetLayoutManager(new views::FillLayout());
133 // Ideally AppListMainView should be used here and have AthenaStartPageView 151 // Ideally AppListMainView should be used here and have AthenaStartPageView
134 // as its child view, so that custom pages and apps grid are available in 152 // as its child view, so that custom pages and apps grid are available in
135 // the home card. 153 // the home card.
136 // TODO(mukai): make it so after the detailed UI has been fixed. 154 // TODO(mukai): make it so after the detailed UI has been fixed.
137 main_view_ = new AthenaStartPageView(view_delegate); 155 main_view_ = new AthenaStartPageView(view_delegate);
138 AddChildView(main_view_); 156 AddChildView(main_view_);
139
140 minimized_view_ = CreateMinimizedHome();
141 minimized_view_->SetPaintToLayer(true);
142 AddChildView(minimized_view_);
143 } 157 }
144 158
145 void SetStateProgress(HomeCard::State from_state, 159 void SetStateProgress(HomeCard::State from_state,
146 HomeCard::State to_state, 160 HomeCard::State to_state,
147 float progress) { 161 float progress) {
148 if (from_state == HomeCard::VISIBLE_BOTTOM && 162 if (from_state == HomeCard::VISIBLE_CENTERED)
149 to_state == HomeCard::VISIBLE_MINIMIZED) { 163 main_view_->SetLayoutState(1.0f - progress);
150 SetStateProgress(to_state, from_state, 1.0 - progress); 164 else if (to_state == HomeCard::VISIBLE_CENTERED)
151 return; 165 main_view_->SetLayoutState(progress);
152 } 166 else
153 167 SetState(to_state);
154 // View from minimized to bottom.
155 if (from_state == HomeCard::VISIBLE_MINIMIZED &&
156 to_state == HomeCard::VISIBLE_BOTTOM) {
157 main_view_->SetVisible(true);
158 minimized_view_->SetVisible(true);
159 minimized_view_->layer()->SetOpacity(1.0f - progress);
160 return;
161 }
162
163 SetState(to_state);
164 } 168 }
165 169
166 void SetState(HomeCard::State state) { 170 void SetState(HomeCard::State state) {
167 main_view_->SetVisible(state == HomeCard::VISIBLE_BOTTOM ||
168 state == HomeCard::VISIBLE_CENTERED);
169 minimized_view_->SetVisible(state == HomeCard::VISIBLE_MINIMIZED);
170 if (minimized_view_->visible())
171 minimized_view_->layer()->SetOpacity(1.0f);
172 if (state == HomeCard::VISIBLE_CENTERED) 171 if (state == HomeCard::VISIBLE_CENTERED)
173 main_view_->RequestFocusOnSearchBox(); 172 main_view_->RequestFocusOnSearchBox();
174 else 173 else
175 GetWidget()->GetFocusManager()->ClearFocus(); 174 GetWidget()->GetFocusManager()->ClearFocus();
176 wm::SetShadowType(GetWidget()->GetNativeView(), 175 wm::SetShadowType(GetWidget()->GetNativeView(),
177 state == HomeCard::VISIBLE_MINIMIZED ? 176 state == HomeCard::VISIBLE_MINIMIZED ?
178 wm::SHADOW_TYPE_NONE : 177 wm::SHADOW_TYPE_NONE :
179 wm::SHADOW_TYPE_RECTANGULAR); 178 wm::SHADOW_TYPE_RECTANGULAR);
179 main_view_->SetLayoutState(
180 (state == HomeCard::VISIBLE_CENTERED) ? 1.0f : 0.0f);
180 } 181 }
181 182
182 void SetStateWithAnimation(HomeCard::State from_state, 183 void SetStateWithAnimation(HomeCard::State state) {
183 HomeCard::State to_state) { 184 if (state == HomeCard::VISIBLE_MINIMIZED)
184 if ((from_state == HomeCard::VISIBLE_MINIMIZED && 185 return;
185 to_state == HomeCard::VISIBLE_BOTTOM) || 186
186 (from_state == HomeCard::VISIBLE_BOTTOM && 187 main_view_->SetLayoutStateWithAnimation(
187 to_state == HomeCard::VISIBLE_MINIMIZED)) { 188 (state == HomeCard::VISIBLE_CENTERED) ? 1.0f : 0.0f);
188 minimized_view_->SetVisible(true);
189 main_view_->SetVisible(true);
190 {
191 ui::ScopedLayerAnimationSettings settings(
192 minimized_view_->layer()->GetAnimator());
193 settings.SetTweenType(gfx::Tween::EASE_IN_OUT);
194 settings.AddObserver(new ui::ClosureAnimationObserver(
195 base::Bind(&HomeCardView::SetState,
196 weak_factory_.GetWeakPtr(),
197 to_state)));
198 minimized_view_->layer()->SetOpacity(
199 (to_state == HomeCard::VISIBLE_MINIMIZED) ? 1.0f : 0.0f);
200 }
201 } else {
202 // TODO(mukai): Take care of other transition.
203 SetState(to_state);
204 }
205 } 189 }
206 190
207 void ClearGesture() { 191 void ClearGesture() {
208 gesture_manager_.reset(); 192 gesture_manager_.reset();
209 } 193 }
210 194
211 // views::View: 195 // views::View:
212 virtual void Layout() OVERRIDE {
213 for (int i = 0; i < child_count(); ++i) {
214 views::View* child = child_at(i);
215 if (child->visible()) {
216 if (child == minimized_view_) {
217 gfx::Rect minimized_bounds = bounds();
218 minimized_bounds.set_y(
219 minimized_bounds.bottom() - kHomeCardMinimizedHeight);
220 minimized_bounds.set_height(kHomeCardMinimizedHeight);
221 child->SetBoundsRect(minimized_bounds);
222 } else {
223 child->SetBoundsRect(bounds());
224 }
225 }
226 }
227 }
228 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { 196 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
229 if (!gesture_manager_ && 197 if (!gesture_manager_ &&
230 event->type() == ui::ET_GESTURE_SCROLL_BEGIN) { 198 event->type() == ui::ET_GESTURE_SCROLL_BEGIN) {
231 gesture_manager_.reset(new HomeCardGestureManager( 199 gesture_manager_.reset(new HomeCardGestureManager(
232 gesture_delegate_, 200 gesture_delegate_,
233 GetWidget()->GetNativeWindow()->GetRootWindow()->bounds())); 201 GetWidget()->GetNativeWindow()->GetRootWindow()->bounds()));
234 } 202 }
235 203
236 if (gesture_manager_) 204 if (gesture_manager_)
237 gesture_manager_->ProcessGestureEvent(event); 205 gesture_manager_->ProcessGestureEvent(event);
238 } 206 }
207 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE {
208 if (HomeCard::Get()->GetState() == HomeCard::VISIBLE_MINIMIZED &&
209 event.IsLeftMouseButton() && event.GetClickCount() == 1) {
210 athena::WindowManager::GetInstance()->ToggleOverview();
211 return true;
212 }
213 return false;
214 }
239 215
240 private: 216 private:
241 // views::WidgetDelegate: 217 // views::WidgetDelegate:
242 virtual views::View* GetContentsView() OVERRIDE { 218 virtual views::View* GetContentsView() OVERRIDE {
243 return this; 219 return this;
244 } 220 }
245 221
246 AthenaStartPageView* main_view_; 222 AthenaStartPageView* main_view_;
247 views::View* minimized_view_;
248 scoped_ptr<HomeCardGestureManager> gesture_manager_; 223 scoped_ptr<HomeCardGestureManager> gesture_manager_;
249 HomeCardGestureManager::Delegate* gesture_delegate_; 224 HomeCardGestureManager::Delegate* gesture_delegate_;
250 base::WeakPtrFactory<HomeCardView> weak_factory_;
251 225
252 DISALLOW_COPY_AND_ASSIGN(HomeCardView); 226 DISALLOW_COPY_AND_ASSIGN(HomeCardView);
253 }; 227 };
254 228
255 class HomeCardImpl : public HomeCard, 229 class HomeCardImpl : public HomeCard,
256 public AcceleratorHandler, 230 public AcceleratorHandler,
257 public HomeCardGestureManager::Delegate, 231 public HomeCardGestureManager::Delegate,
258 public WindowManagerObserver, 232 public WindowManagerObserver,
259 public aura::client::ActivationChangeObserver { 233 public aura::client::ActivationChangeObserver {
260 public: 234 public:
261 explicit HomeCardImpl(AppModelBuilder* model_builder); 235 explicit HomeCardImpl(AppModelBuilder* model_builder);
262 virtual ~HomeCardImpl(); 236 virtual ~HomeCardImpl();
263 237
264 void Init(); 238 void Init();
265 239
266 private: 240 private:
267 enum Command { 241 enum Command {
268 COMMAND_SHOW_HOME_CARD, 242 COMMAND_SHOW_HOME_CARD,
269 }; 243 };
270 void InstallAccelerators(); 244 void InstallAccelerators();
245 void UpdateMinimizedHomeBounds();
271 246
272 // Overridden from HomeCard: 247 // Overridden from HomeCard:
273 virtual void SetState(State state) OVERRIDE; 248 virtual void SetState(State state) OVERRIDE;
274 virtual State GetState() OVERRIDE; 249 virtual State GetState() OVERRIDE;
275 virtual void RegisterSearchProvider( 250 virtual void RegisterSearchProvider(
276 app_list::SearchProvider* search_provider) OVERRIDE; 251 app_list::SearchProvider* search_provider) OVERRIDE;
277 virtual void UpdateVirtualKeyboardBounds( 252 virtual void UpdateVirtualKeyboardBounds(
278 const gfx::Rect& bounds) OVERRIDE; 253 const gfx::Rect& bounds) OVERRIDE;
279 254
280 // AcceleratorHandler: 255 // AcceleratorHandler:
(...skipping 20 matching lines...) Expand all
301 276
302 // original_state_ is the state which the home card should go back to after 277 // original_state_ is the state which the home card should go back to after
303 // the virtual keyboard is hidden. 278 // the virtual keyboard is hidden.
304 HomeCard::State original_state_; 279 HomeCard::State original_state_;
305 280
306 views::Widget* home_card_widget_; 281 views::Widget* home_card_widget_;
307 HomeCardView* home_card_view_; 282 HomeCardView* home_card_view_;
308 scoped_ptr<AppListViewDelegate> view_delegate_; 283 scoped_ptr<AppListViewDelegate> view_delegate_;
309 HomeCardLayoutManager* layout_manager_; 284 HomeCardLayoutManager* layout_manager_;
310 aura::client::ActivationClient* activation_client_; // Not owned 285 aura::client::ActivationClient* activation_client_; // Not owned
286 scoped_ptr<ui::LayerOwner> minimized_home_;
311 287
312 // Right now HomeCard allows only one search provider. 288 // Right now HomeCard allows only one search provider.
313 // TODO(mukai): port app-list's SearchController and Mixer. 289 // TODO(mukai): port app-list's SearchController and Mixer.
314 scoped_ptr<app_list::SearchProvider> search_provider_; 290 scoped_ptr<app_list::SearchProvider> search_provider_;
315 291
316 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); 292 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl);
317 }; 293 };
318 294
319 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder) 295 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder)
320 : model_builder_(model_builder), 296 : model_builder_(model_builder),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 335
360 home_card_view_ = new HomeCardView(view_delegate_.get(), container, this); 336 home_card_view_ = new HomeCardView(view_delegate_.get(), container, this);
361 home_card_widget_ = new views::Widget(); 337 home_card_widget_ = new views::Widget();
362 views::Widget::InitParams widget_params( 338 views::Widget::InitParams widget_params(
363 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 339 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
364 widget_params.parent = container; 340 widget_params.parent = container;
365 widget_params.delegate = home_card_view_; 341 widget_params.delegate = home_card_view_;
366 widget_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 342 widget_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
367 home_card_widget_->Init(widget_params); 343 home_card_widget_->Init(widget_params);
368 344
345 minimized_home_ = CreateMinimizedHome();
346 container->layer()->Add(minimized_home_->layer());
347 container->layer()->StackAtTop(minimized_home_->layer());
348 layout_manager_->SetMinimizedLayer(minimized_home_->layer());
349
369 SetState(VISIBLE_MINIMIZED); 350 SetState(VISIBLE_MINIMIZED);
370 home_card_view_->Layout(); 351 home_card_view_->Layout();
371 352
372 activation_client_ = 353 activation_client_ =
373 aura::client::GetActivationClient(container->GetRootWindow()); 354 aura::client::GetActivationClient(container->GetRootWindow());
374 if (activation_client_) 355 if (activation_client_)
375 activation_client_->AddObserver(this); 356 activation_client_->AddObserver(this);
376 357
377 int work_area_bottom_inset =
378 GetBoundsForState(home_card_widget_->GetNativeWindow()->bounds(),
379 HomeCard::VISIBLE_MINIMIZED).height();
380 AthenaEnv::Get()->SetDisplayWorkAreaInsets( 358 AthenaEnv::Get()->SetDisplayWorkAreaInsets(
381 gfx::Insets(0, 0, work_area_bottom_inset, 0)); 359 gfx::Insets(0, 0, kHomeCardMinimizedHeight, 0));
382 } 360 }
383 361
384 void HomeCardImpl::InstallAccelerators() { 362 void HomeCardImpl::InstallAccelerators() {
385 const AcceleratorData accelerator_data[] = { 363 const AcceleratorData accelerator_data[] = {
386 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, 364 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN,
387 COMMAND_SHOW_HOME_CARD, AF_NONE}, 365 COMMAND_SHOW_HOME_CARD, AF_NONE},
388 }; 366 };
389 AcceleratorManager::Get()->RegisterAccelerators( 367 AcceleratorManager::Get()->RegisterAccelerators(
390 accelerator_data, arraysize(accelerator_data), this); 368 accelerator_data, arraysize(accelerator_data), this);
391 } 369 }
392 370
393 void HomeCardImpl::SetState(HomeCard::State state) { 371 void HomeCardImpl::SetState(HomeCard::State state) {
394 if (state_ == state) 372 if (state_ == state)
395 return; 373 return;
396 374
397 // Update |state_| before changing the visibility of the widgets, so that 375 // Update |state_| before changing the visibility of the widgets, so that
398 // LayoutManager callbacks get the correct state. 376 // LayoutManager callbacks get the correct state.
399 HomeCard::State old_state = state_; 377 HomeCard::State old_state = state_;
400 state_ = state; 378 state_ = state;
401 original_state_ = state; 379 original_state_ = state;
380
381 if (old_state == VISIBLE_MINIMIZED ||
382 state_ == VISIBLE_MINIMIZED) {
383 minimized_home_->layer()->SetVisible(true);
384 {
385 ui::ScopedLayerAnimationSettings settings(
386 minimized_home_->layer()->GetAnimator());
387 minimized_home_->layer()->SetVisible(state_ == VISIBLE_MINIMIZED);
388 minimized_home_->layer()->SetOpacity(
389 state_ == VISIBLE_MINIMIZED ? 1.0f : 0.0f);
390 }
391 }
402 if (state_ == HIDDEN) { 392 if (state_ == HIDDEN) {
403 home_card_widget_->Hide(); 393 home_card_widget_->Hide();
404 } else { 394 } else {
405 if (state_ == VISIBLE_CENTERED) 395 if (state_ == VISIBLE_CENTERED)
406 home_card_widget_->Show(); 396 home_card_widget_->Show();
407 else 397 else
408 home_card_widget_->ShowInactive(); 398 home_card_widget_->ShowInactive();
409 home_card_view_->SetStateWithAnimation(old_state, state); 399 home_card_view_->SetStateWithAnimation(state);
410 layout_manager_->Layout(); 400 layout_manager_->Layout(true);
411 } 401 }
412 } 402 }
413 403
414 HomeCard::State HomeCardImpl::GetState() { 404 HomeCard::State HomeCardImpl::GetState() {
415 return state_; 405 return state_;
416 } 406 }
417 407
418 void HomeCardImpl::RegisterSearchProvider( 408 void HomeCardImpl::RegisterSearchProvider(
419 app_list::SearchProvider* search_provider) { 409 app_list::SearchProvider* search_provider) {
420 DCHECK(!search_provider_); 410 DCHECK(!search_provider_);
(...skipping 25 matching lines...) Expand all
446 return true; 436 return true;
447 } 437 }
448 438
449 void HomeCardImpl::OnGestureEnded(State final_state) { 439 void HomeCardImpl::OnGestureEnded(State final_state) {
450 home_card_view_->ClearGesture(); 440 home_card_view_->ClearGesture();
451 if (state_ != final_state && 441 if (state_ != final_state &&
452 (state_ == VISIBLE_MINIMIZED || final_state == VISIBLE_MINIMIZED)) { 442 (state_ == VISIBLE_MINIMIZED || final_state == VISIBLE_MINIMIZED)) {
453 SetState(final_state); 443 SetState(final_state);
454 WindowManager::GetInstance()->ToggleOverview(); 444 WindowManager::GetInstance()->ToggleOverview();
455 } else { 445 } else {
456 HomeCard::State old_state = state_;
457 state_ = final_state; 446 state_ = final_state;
458 home_card_view_->SetStateWithAnimation(old_state, final_state); 447 home_card_view_->SetStateWithAnimation(state_);
459 layout_manager_->Layout(); 448 layout_manager_->Layout(true);
460 } 449 }
461 } 450 }
462 451
463 void HomeCardImpl::OnGestureProgressed( 452 void HomeCardImpl::OnGestureProgressed(
464 State from_state, State to_state, float progress) { 453 State from_state, State to_state, float progress) {
465 home_card_view_->SetStateProgress(from_state, to_state, progress); 454 if (from_state == VISIBLE_MINIMIZED || to_state == VISIBLE_MINIMIZED) {
466 455 minimized_home_->layer()->SetVisible(true);
456 float opacity =
457 (from_state == VISIBLE_MINIMIZED) ? 1.0f - progress : progress;
458 minimized_home_->layer()->SetOpacity(opacity);
459 }
467 gfx::Rect screen_bounds = 460 gfx::Rect screen_bounds =
468 home_card_widget_->GetNativeWindow()->GetRootWindow()->bounds(); 461 home_card_widget_->GetNativeWindow()->GetRootWindow()->bounds();
469 home_card_widget_->SetBounds(gfx::Tween::RectValueBetween( 462 home_card_widget_->SetBounds(gfx::Tween::RectValueBetween(
470 progress, 463 progress,
471 GetBoundsForState(screen_bounds, from_state), 464 GetBoundsForState(screen_bounds, from_state),
472 GetBoundsForState(screen_bounds, to_state))); 465 GetBoundsForState(screen_bounds, to_state)));
473 466
467 home_card_view_->SetStateProgress(from_state, to_state, progress);
468
474 // TODO(mukai): signals the update to the window manager so that it shows the 469 // TODO(mukai): signals the update to the window manager so that it shows the
475 // intermediate visual state of overview mode. 470 // intermediate visual state of overview mode.
476 } 471 }
477 472
478 void HomeCardImpl::OnOverviewModeEnter() { 473 void HomeCardImpl::OnOverviewModeEnter() {
479 if (state_ == VISIBLE_MINIMIZED) 474 if (state_ == VISIBLE_MINIMIZED)
480 SetState(VISIBLE_BOTTOM); 475 SetState(VISIBLE_BOTTOM);
481 } 476 }
482 477
483 void HomeCardImpl::OnOverviewModeExit() { 478 void HomeCardImpl::OnOverviewModeExit() {
(...skipping 24 matching lines...) Expand all
508 instance = NULL; 503 instance = NULL;
509 } 504 }
510 505
511 // static 506 // static
512 HomeCard* HomeCard::Get() { 507 HomeCard* HomeCard::Get() {
513 DCHECK(instance); 508 DCHECK(instance);
514 return instance; 509 return instance;
515 } 510 }
516 511
517 } // namespace athena 512 } // namespace athena
OLDNEW
« no previous file with comments | « athena/home/home_card_gesture_manager.cc ('k') | athena/home/minimized_home.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698