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

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

Issue 582923002: Do not EASE_IN_OUT after fling, rather EASE_OUT. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
« no previous file with comments | « athena/home/home_card_impl.h ('k') | no next file » | 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/home_card_impl.h" 5 #include "athena/home/home_card_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <limits> 8 #include <limits>
9 9
10 #include "athena/env/public/athena_env.h" 10 #include "athena/env/public/athena_env.h"
11 #include "athena/home/app_list_view_delegate.h" 11 #include "athena/home/app_list_view_delegate.h"
12 #include "athena/home/athena_start_page_view.h" 12 #include "athena/home/athena_start_page_view.h"
13 #include "athena/home/home_card_constants.h" 13 #include "athena/home/home_card_constants.h"
14 #include "athena/home/minimized_home.h" 14 #include "athena/home/minimized_home.h"
15 #include "athena/home/public/app_model_builder.h" 15 #include "athena/home/public/app_model_builder.h"
16 #include "athena/screen/public/screen_manager.h" 16 #include "athena/screen/public/screen_manager.h"
17 #include "athena/util/container_priorities.h" 17 #include "athena/util/container_priorities.h"
18 #include "athena/wm/public/window_manager.h" 18 #include "athena/wm/public/window_manager.h"
19 #include "ui/app_list/search_provider.h" 19 #include "ui/app_list/search_provider.h"
20 #include "ui/app_list/views/app_list_main_view.h" 20 #include "ui/app_list/views/app_list_main_view.h"
21 #include "ui/app_list/views/contents_view.h" 21 #include "ui/app_list/views/contents_view.h"
22 #include "ui/aura/layout_manager.h" 22 #include "ui/aura/layout_manager.h"
23 #include "ui/aura/window.h" 23 #include "ui/aura/window.h"
24 #include "ui/compositor/layer.h" 24 #include "ui/compositor/layer.h"
25 #include "ui/compositor/scoped_layer_animation_settings.h" 25 #include "ui/compositor/scoped_layer_animation_settings.h"
26 #include "ui/gfx/animation/tween.h"
26 #include "ui/views/layout/fill_layout.h" 27 #include "ui/views/layout/fill_layout.h"
27 #include "ui/views/widget/widget.h" 28 #include "ui/views/widget/widget.h"
28 #include "ui/views/widget/widget_delegate.h" 29 #include "ui/views/widget/widget_delegate.h"
29 #include "ui/wm/core/shadow_types.h" 30 #include "ui/wm/core/shadow_types.h"
30 #include "ui/wm/core/visibility_controller.h" 31 #include "ui/wm/core/visibility_controller.h"
31 #include "ui/wm/public/activation_client.h" 32 #include "ui/wm/public/activation_client.h"
32 33
33 namespace athena { 34 namespace athena {
34 namespace { 35 namespace {
35 36
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // Makes sure the homecard is center-aligned horizontally and bottom-aligned 68 // Makes sure the homecard is center-aligned horizontally and bottom-aligned
68 // vertically. 69 // vertically.
69 class HomeCardLayoutManager : public aura::LayoutManager { 70 class HomeCardLayoutManager : public aura::LayoutManager {
70 public: 71 public:
71 HomeCardLayoutManager() 72 HomeCardLayoutManager()
72 : home_card_(NULL), 73 : home_card_(NULL),
73 minimized_layer_(NULL) {} 74 minimized_layer_(NULL) {}
74 75
75 virtual ~HomeCardLayoutManager() {} 76 virtual ~HomeCardLayoutManager() {}
76 77
77 void Layout(bool animate) { 78 void Layout(bool animate, gfx::Tween::Type tween_type) {
78 // |home_card| could be detached from the root window (e.g. when it is being 79 // |home_card| could be detached from the root window (e.g. when it is being
79 // destroyed). 80 // destroyed).
80 if (!home_card_ || !home_card_->IsVisible() || !home_card_->GetRootWindow()) 81 if (!home_card_ || !home_card_->IsVisible() || !home_card_->GetRootWindow())
81 return; 82 return;
82 83
83 scoped_ptr<ui::ScopedLayerAnimationSettings> settings; 84 scoped_ptr<ui::ScopedLayerAnimationSettings> settings;
84 if (animate) { 85 if (animate) {
85 settings.reset(new ui::ScopedLayerAnimationSettings( 86 settings.reset(new ui::ScopedLayerAnimationSettings(
86 home_card_->layer()->GetAnimator())); 87 home_card_->layer()->GetAnimator()));
87 settings->SetTweenType(gfx::Tween::EASE_IN_OUT); 88 settings->SetTweenType(tween_type);
88 } 89 }
89 SetChildBoundsDirect(home_card_, GetBoundsForState( 90 SetChildBoundsDirect(home_card_, GetBoundsForState(
90 home_card_->GetRootWindow()->bounds(), HomeCard::Get()->GetState())); 91 home_card_->GetRootWindow()->bounds(), HomeCard::Get()->GetState()));
91 } 92 }
92 93
93 void SetMinimizedLayer(ui::Layer* minimized_layer) { 94 void SetMinimizedLayer(ui::Layer* minimized_layer) {
94 minimized_layer_ = minimized_layer; 95 minimized_layer_ = minimized_layer;
95 UpdateMinimizedHomeBounds(); 96 UpdateMinimizedHomeBounds();
96 } 97 }
97 98
98 private: 99 private:
99 void UpdateMinimizedHomeBounds() { 100 void UpdateMinimizedHomeBounds() {
100 gfx::Rect minimized_bounds = minimized_layer_->parent()->bounds(); 101 gfx::Rect minimized_bounds = minimized_layer_->parent()->bounds();
101 minimized_bounds.set_y( 102 minimized_bounds.set_y(
102 minimized_bounds.bottom() - kHomeCardMinimizedHeight); 103 minimized_bounds.bottom() - kHomeCardMinimizedHeight);
103 minimized_bounds.set_height(kHomeCardMinimizedHeight); 104 minimized_bounds.set_height(kHomeCardMinimizedHeight);
104 minimized_layer_->SetBounds(minimized_bounds); 105 minimized_layer_->SetBounds(minimized_bounds);
105 } 106 }
106 107
107 // aura::LayoutManager: 108 // aura::LayoutManager:
108 virtual void OnWindowResized() OVERRIDE { 109 virtual void OnWindowResized() OVERRIDE {
109 Layout(false); 110 Layout(false, gfx::Tween::LINEAR);
110 UpdateMinimizedHomeBounds(); 111 UpdateMinimizedHomeBounds();
111 } 112 }
112 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { 113 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
113 if (!home_card_) { 114 if (!home_card_) {
114 home_card_ = child; 115 home_card_ = child;
115 Layout(false); 116 Layout(false, gfx::Tween::LINEAR);
116 } 117 }
117 } 118 }
118 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE { 119 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {
119 if (home_card_ == child) 120 if (home_card_ == child)
120 home_card_ = NULL; 121 home_card_ = NULL;
121 } 122 }
122 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { 123 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {
123 } 124 }
124 virtual void OnChildWindowVisibilityChanged(aura::Window* child, 125 virtual void OnChildWindowVisibilityChanged(aura::Window* child,
125 bool visible) OVERRIDE { 126 bool visible) OVERRIDE {
126 if (home_card_ == child) 127 if (home_card_ == child)
127 Layout(false); 128 Layout(false, gfx::Tween::LINEAR);
128 } 129 }
129 virtual void SetChildBounds(aura::Window* child, 130 virtual void SetChildBounds(aura::Window* child,
130 const gfx::Rect& requested_bounds) OVERRIDE { 131 const gfx::Rect& requested_bounds) OVERRIDE {
131 SetChildBoundsDirect(child, requested_bounds); 132 SetChildBoundsDirect(child, requested_bounds);
132 } 133 }
133 134
134 aura::Window* home_card_; 135 aura::Window* home_card_;
135 ui::Layer* minimized_layer_; 136 ui::Layer* minimized_layer_;
136 137
137 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); 138 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager);
(...skipping 20 matching lines...) Expand all
158 float progress) { 159 float progress) {
159 // TODO(mukai): not clear the focus, but simply close the virtual keyboard. 160 // TODO(mukai): not clear the focus, but simply close the virtual keyboard.
160 GetFocusManager()->ClearFocus(); 161 GetFocusManager()->ClearFocus();
161 if (from_state == HomeCard::VISIBLE_CENTERED) 162 if (from_state == HomeCard::VISIBLE_CENTERED)
162 main_view_->SetLayoutState(1.0f - progress); 163 main_view_->SetLayoutState(1.0f - progress);
163 else if (to_state == HomeCard::VISIBLE_CENTERED) 164 else if (to_state == HomeCard::VISIBLE_CENTERED)
164 main_view_->SetLayoutState(progress); 165 main_view_->SetLayoutState(progress);
165 UpdateShadow(true); 166 UpdateShadow(true);
166 } 167 }
167 168
168 void SetStateWithAnimation(HomeCard::State state) { 169 void SetStateWithAnimation(HomeCard::State state,
170 gfx::Tween::Type tween_type) {
169 UpdateShadow(state != HomeCard::VISIBLE_MINIMIZED); 171 UpdateShadow(state != HomeCard::VISIBLE_MINIMIZED);
170 if (state == HomeCard::VISIBLE_CENTERED) 172 if (state == HomeCard::VISIBLE_CENTERED)
171 main_view_->RequestFocusOnSearchBox(); 173 main_view_->RequestFocusOnSearchBox();
172 else 174 else
173 GetWidget()->GetFocusManager()->ClearFocus(); 175 GetWidget()->GetFocusManager()->ClearFocus();
174 176
175 main_view_->SetLayoutStateWithAnimation( 177 main_view_->SetLayoutStateWithAnimation(
176 (state == HomeCard::VISIBLE_CENTERED) ? 1.0f : 0.0f); 178 (state == HomeCard::VISIBLE_CENTERED) ? 1.0f : 0.0f, tween_type);
177 } 179 }
178 180
179 void ClearGesture() { 181 void ClearGesture() {
180 gesture_manager_.reset(); 182 gesture_manager_.reset();
181 } 183 }
182 184
183 // views::View: 185 // views::View:
184 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { 186 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
185 if (!gesture_manager_ && 187 if (!gesture_manager_ &&
186 event->type() == ui::ET_GESTURE_SCROLL_BEGIN) { 188 event->type() == ui::ET_GESTURE_SCROLL_BEGIN) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 state_ == VISIBLE_MINIMIZED ? 1.0f : 0.0f); 323 state_ == VISIBLE_MINIMIZED ? 1.0f : 0.0f);
322 } 324 }
323 } 325 }
324 if (state_ == HIDDEN) { 326 if (state_ == HIDDEN) {
325 home_card_widget_->Hide(); 327 home_card_widget_->Hide();
326 } else { 328 } else {
327 if (state_ == VISIBLE_MINIMIZED) 329 if (state_ == VISIBLE_MINIMIZED)
328 home_card_widget_->ShowInactive(); 330 home_card_widget_->ShowInactive();
329 else 331 else
330 home_card_widget_->Show(); 332 home_card_widget_->Show();
331 home_card_view_->SetStateWithAnimation(state); 333 home_card_view_->SetStateWithAnimation(state, gfx::Tween::EASE_IN_OUT);
332 layout_manager_->Layout(true); 334 layout_manager_->Layout(true, gfx::Tween::EASE_IN_OUT);
333 } 335 }
334 } 336 }
335 337
336 HomeCard::State HomeCardImpl::GetState() { 338 HomeCard::State HomeCardImpl::GetState() {
337 return state_; 339 return state_;
338 } 340 }
339 341
340 void HomeCardImpl::RegisterSearchProvider( 342 void HomeCardImpl::RegisterSearchProvider(
341 app_list::SearchProvider* search_provider) { 343 app_list::SearchProvider* search_provider) {
342 DCHECK(!search_provider_); 344 DCHECK(!search_provider_);
(...skipping 22 matching lines...) Expand all
365 const ui::Accelerator& accelerator) { 367 const ui::Accelerator& accelerator) {
366 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); 368 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id);
367 369
368 if (state_ == VISIBLE_CENTERED && original_state_ != VISIBLE_BOTTOM) 370 if (state_ == VISIBLE_CENTERED && original_state_ != VISIBLE_BOTTOM)
369 SetState(VISIBLE_MINIMIZED); 371 SetState(VISIBLE_MINIMIZED);
370 else if (state_ == VISIBLE_MINIMIZED) 372 else if (state_ == VISIBLE_MINIMIZED)
371 SetState(VISIBLE_CENTERED); 373 SetState(VISIBLE_CENTERED);
372 return true; 374 return true;
373 } 375 }
374 376
375 void HomeCardImpl::OnGestureEnded(State final_state) { 377 void HomeCardImpl::OnGestureEnded(State final_state, bool is_fling) {
376 home_card_view_->ClearGesture(); 378 home_card_view_->ClearGesture();
377 if (state_ != final_state && 379 if (state_ != final_state &&
378 (state_ == VISIBLE_MINIMIZED || final_state == VISIBLE_MINIMIZED)) { 380 (state_ == VISIBLE_MINIMIZED || final_state == VISIBLE_MINIMIZED)) {
379 SetState(final_state); 381 SetState(final_state);
380 WindowManager::GetInstance()->ToggleOverview(); 382 WindowManager::GetInstance()->ToggleOverview();
381 } else { 383 } else {
382 state_ = final_state; 384 state_ = final_state;
383 home_card_view_->SetStateWithAnimation(state_); 385 // When the animation happens after a fling, EASE_IN_OUT would cause weird
384 layout_manager_->Layout(true); 386 // slow-down right after the finger release because of slow-in. Therefore
387 // EASE_OUT is better.
388 gfx::Tween::Type tween_type =
389 is_fling ? gfx::Tween::EASE_OUT : gfx::Tween::EASE_IN_OUT;
390 home_card_view_->SetStateWithAnimation(state_, tween_type);
391 layout_manager_->Layout(true, tween_type);
385 } 392 }
386 } 393 }
387 394
388 void HomeCardImpl::OnGestureProgressed( 395 void HomeCardImpl::OnGestureProgressed(
389 State from_state, State to_state, float progress) { 396 State from_state, State to_state, float progress) {
390 if (from_state == VISIBLE_MINIMIZED || to_state == VISIBLE_MINIMIZED) { 397 if (from_state == VISIBLE_MINIMIZED || to_state == VISIBLE_MINIMIZED) {
391 minimized_home_->layer()->SetVisible(true); 398 minimized_home_->layer()->SetVisible(true);
392 float opacity = 399 float opacity =
393 (from_state == VISIBLE_MINIMIZED) ? 1.0f - progress : progress; 400 (from_state == VISIBLE_MINIMIZED) ? 1.0f - progress : progress;
394 minimized_home_->layer()->SetOpacity(opacity); 401 minimized_home_->layer()->SetOpacity(opacity);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 instance = NULL; 450 instance = NULL;
444 } 451 }
445 452
446 // static 453 // static
447 HomeCard* HomeCard::Get() { 454 HomeCard* HomeCard::Get() {
448 DCHECK(instance); 455 DCHECK(instance);
449 return instance; 456 return instance;
450 } 457 }
451 458
452 } // namespace athena 459 } // namespace athena
OLDNEW
« no previous file with comments | « athena/home/home_card_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698