| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/wm/app_list_controller.h" | 5 #include "ash/wm/app_list_controller.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/screen_ash.h" | |
| 9 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 10 #include "ash/shell_delegate.h" | 9 #include "ash/shell_delegate.h" |
| 11 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
| 12 #include "ash/wm/shelf_layout_manager.h" | 11 #include "ash/wm/shelf_layout_manager.h" |
| 13 #include "ash/wm/window_util.h" | |
| 14 #include "base/command_line.h" | |
| 15 #include "ui/app_list/app_list_view.h" | 12 #include "ui/app_list/app_list_view.h" |
| 16 #include "ui/app_list/icon_cache.h" | 13 #include "ui/app_list/icon_cache.h" |
| 17 #include "ui/aura/event.h" | 14 #include "ui/aura/event.h" |
| 18 #include "ui/aura/focus_manager.h" | 15 #include "ui/aura/focus_manager.h" |
| 19 #include "ui/aura/root_window.h" | 16 #include "ui/aura/root_window.h" |
| 20 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
| 21 #include "ui/compositor/layer.h" | 18 #include "ui/compositor/layer.h" |
| 22 #include "ui/compositor/scoped_layer_animation_settings.h" | 19 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 23 #include "ui/gfx/screen.h" | |
| 24 #include "ui/gfx/transform_util.h" | 20 #include "ui/gfx/transform_util.h" |
| 25 | 21 |
| 26 namespace ash { | 22 namespace ash { |
| 27 namespace internal { | 23 namespace internal { |
| 28 | 24 |
| 29 namespace { | 25 namespace { |
| 30 | 26 |
| 31 const float kContainerAnimationScaleFactor = 1.05f; | 27 const float kContainerAnimationScaleFactor = 1.05f; |
| 32 | 28 |
| 33 // Duration for both default container and app list animation in milliseconds. | 29 // Duration for show/hide animation in milliseconds. |
| 34 const int kAnimationDurationMs = 130; | 30 const int kAnimationDurationMs = 150; |
| 35 | |
| 36 // Delayed time of 2nd animation in milliseconds. | |
| 37 const int kSecondAnimationStartDelay = kAnimationDurationMs - 20; | |
| 38 | 31 |
| 39 ui::Layer* GetLayer(views::Widget* widget) { | 32 ui::Layer* GetLayer(views::Widget* widget) { |
| 40 return widget->GetNativeView()->layer(); | 33 return widget->GetNativeView()->layer(); |
| 41 } | 34 } |
| 42 | 35 |
| 43 // Bounds returned is used for full screen app list. Use full monitor rect | |
| 44 // so that the app list shade goes behind the launcher. | |
| 45 gfx::Rect GetFullScreenBoundsForWidget(views::Widget* widget) { | |
| 46 gfx::NativeView window = widget->GetNativeView(); | |
| 47 return gfx::Screen::GetMonitorNearestWindow(window).bounds(); | |
| 48 } | |
| 49 | |
| 50 // Return work area rect for full screen app list layout. This function is | |
| 51 // needed to get final work area in one shot instead of waiting for shelf | |
| 52 // animation to finish. | |
| 53 gfx::Rect GetWorkAreaBoundsForWidget(views::Widget* widget) { | |
| 54 gfx::NativeView window = widget->GetNativeView(); | |
| 55 return Shell::GetInstance()->shelf()->IsVisible() ? | |
| 56 ScreenAsh::GetUnmaximizedWorkAreaBounds(window) : | |
| 57 gfx::Screen::GetMonitorNearestWindow(window).work_area(); | |
| 58 } | |
| 59 | |
| 60 // Gets arrow location based on shelf alignment. | 36 // Gets arrow location based on shelf alignment. |
| 61 views::BubbleBorder::ArrowLocation GetBubbleArrowLocation() { | 37 views::BubbleBorder::ArrowLocation GetBubbleArrowLocation() { |
| 62 DCHECK(Shell::HasInstance()); | 38 DCHECK(Shell::HasInstance()); |
| 63 ash::ShelfAlignment shelf_alignment = | 39 ash::ShelfAlignment shelf_alignment = |
| 64 Shell::GetInstance()->shelf()->alignment(); | 40 Shell::GetInstance()->shelf()->alignment(); |
| 65 switch (shelf_alignment) { | 41 switch (shelf_alignment) { |
| 66 case ash::SHELF_ALIGNMENT_BOTTOM: | 42 case ash::SHELF_ALIGNMENT_BOTTOM: |
| 67 return views::BubbleBorder::BOTTOM_RIGHT; | 43 return views::BubbleBorder::BOTTOM_RIGHT; |
| 68 case ash::SHELF_ALIGNMENT_LEFT: | 44 case ash::SHELF_ALIGNMENT_LEFT: |
| 69 return views::BubbleBorder::LEFT_BOTTOM; | 45 return views::BubbleBorder::LEFT_BOTTOM; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 84 app_list::IconCache::CreateInstance(); | 60 app_list::IconCache::CreateInstance(); |
| 85 Shell::GetInstance()->AddShellObserver(this); | 61 Shell::GetInstance()->AddShellObserver(this); |
| 86 } | 62 } |
| 87 | 63 |
| 88 AppListController::~AppListController() { | 64 AppListController::~AppListController() { |
| 89 ResetView(); | 65 ResetView(); |
| 90 app_list::IconCache::DeleteInstance(); | 66 app_list::IconCache::DeleteInstance(); |
| 91 Shell::GetInstance()->RemoveShellObserver(this); | 67 Shell::GetInstance()->RemoveShellObserver(this); |
| 92 } | 68 } |
| 93 | 69 |
| 94 // static | |
| 95 bool AppListController::UseAppListV2() { | |
| 96 return CommandLine::ForCurrentProcess()->HasSwitch( | |
| 97 switches::kEnableAppListV2); | |
| 98 } | |
| 99 | |
| 100 void AppListController::SetVisible(bool visible) { | 70 void AppListController::SetVisible(bool visible) { |
| 101 if (visible == is_visible_) | 71 if (visible == is_visible_) |
| 102 return; | 72 return; |
| 103 | 73 |
| 104 is_visible_ = visible; | 74 is_visible_ = visible; |
| 105 | 75 |
| 106 // App list needs to know the new shelf layout in order to calculate its | 76 // App list needs to know the new shelf layout in order to calculate its |
| 107 // UI layout when AppListView visibility changes. | 77 // UI layout when AppListView visibility changes. |
| 108 Shell::GetInstance()->shelf()->UpdateAutoHideState(); | 78 Shell::GetInstance()->shelf()->UpdateAutoHideState(); |
| 109 | 79 |
| 110 if (view_) { | 80 if (view_) { |
| 111 ScheduleAnimation(); | 81 ScheduleAnimation(); |
| 112 } else if (is_visible_) { | 82 } else if (is_visible_) { |
| 113 // AppListModel and AppListViewDelegate are owned by AppListView. They | 83 // AppListModel and AppListViewDelegate are owned by AppListView. They |
| 114 // will be released with AppListView on close. | 84 // will be released with AppListView on close. |
| 115 app_list::AppListView* view = new app_list::AppListView( | 85 app_list::AppListView* view = new app_list::AppListView( |
| 116 Shell::GetInstance()->delegate()->CreateAppListViewDelegate()); | 86 Shell::GetInstance()->delegate()->CreateAppListViewDelegate()); |
| 117 if (UseAppListV2()) { | 87 view->InitAsBubble( |
| 118 view->InitAsBubble( | 88 Shell::GetInstance()->GetContainer(kShellWindowId_AppListContainer), |
| 119 Shell::GetInstance()->GetContainer(kShellWindowId_AppListContainer), | 89 Shell::GetInstance()->launcher()->GetAppListButtonView(), |
| 120 Shell::GetInstance()->launcher()->GetAppListButtonView(), | 90 GetBubbleArrowLocation()); |
| 121 GetBubbleArrowLocation()); | |
| 122 } else { | |
| 123 views::Widget* launcher_widget = | |
| 124 Shell::GetInstance()->launcher()->widget(); | |
| 125 view->InitAsFullscreenWidget(Shell::GetInstance()->GetContainer( | |
| 126 kShellWindowId_AppListContainer), | |
| 127 GetFullScreenBoundsForWidget(launcher_widget), | |
| 128 GetWorkAreaBoundsForWidget(launcher_widget)); | |
| 129 } | |
| 130 SetView(view); | 91 SetView(view); |
| 131 } | 92 } |
| 132 } | 93 } |
| 133 | 94 |
| 134 bool AppListController::IsVisible() const { | 95 bool AppListController::IsVisible() const { |
| 135 return view_ && view_->GetWidget()->IsVisible(); | 96 return view_ && view_->GetWidget()->IsVisible(); |
| 136 } | 97 } |
| 137 | 98 |
| 138 aura::Window* AppListController::GetWindow() { | 99 aura::Window* AppListController::GetWindow() { |
| 139 return is_visible_ && view_ ? view_->GetWidget()->GetNativeWindow() : NULL; | 100 return is_visible_ && view_ ? view_->GetWidget()->GetNativeWindow() : NULL; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 138 |
| 178 app_list::IconCache::GetInstance()->PurgeAllUnused(); | 139 app_list::IconCache::GetInstance()->PurgeAllUnused(); |
| 179 } | 140 } |
| 180 | 141 |
| 181 void AppListController::ScheduleAnimation() { | 142 void AppListController::ScheduleAnimation() { |
| 182 second_animation_timer_.Stop(); | 143 second_animation_timer_.Stop(); |
| 183 | 144 |
| 184 // Stop observing previous animation. | 145 // Stop observing previous animation. |
| 185 StopObservingImplicitAnimations(); | 146 StopObservingImplicitAnimations(); |
| 186 | 147 |
| 187 ScheduleDimmingAnimation(); | 148 ui::Layer* layer = GetLayer(view_->GetWidget()); |
| 188 | |
| 189 // No browser window fading and app list secondary animation for v2. | |
| 190 if (UseAppListV2()) | |
| 191 return; | |
| 192 | |
| 193 if (is_visible_) { | |
| 194 ScheduleBrowserWindowsAnimation(); | |
| 195 second_animation_timer_.Start( | |
| 196 FROM_HERE, | |
| 197 base::TimeDelta::FromMilliseconds(kSecondAnimationStartDelay), | |
| 198 this, | |
| 199 &AppListController::ScheduleAppListAnimation); | |
| 200 } else { | |
| 201 ScheduleAppListAnimation(); | |
| 202 second_animation_timer_.Start( | |
| 203 FROM_HERE, | |
| 204 base::TimeDelta::FromMilliseconds(kSecondAnimationStartDelay), | |
| 205 this, | |
| 206 &AppListController::ScheduleBrowserWindowsAnimation); | |
| 207 } | |
| 208 } | |
| 209 | |
| 210 void AppListController::ScheduleBrowserWindowsAnimationForContainer( | |
| 211 aura::Window* container) { | |
| 212 DCHECK(container); | |
| 213 ui::Layer* layer = container->layer(); | |
| 214 layer->GetAnimator()->StopAnimating(); | 149 layer->GetAnimator()->StopAnimating(); |
| 215 | 150 |
| 216 ui::ScopedLayerAnimationSettings animation(layer->GetAnimator()); | 151 ui::ScopedLayerAnimationSettings animation(layer->GetAnimator()); |
| 217 animation.SetTransitionDuration( | 152 animation.SetTransitionDuration( |
| 218 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); | 153 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); |
| 219 animation.SetTweenType( | |
| 220 is_visible_ ? ui::Tween::EASE_IN : ui::Tween::EASE_OUT); | |
| 221 | |
| 222 layer->SetOpacity(is_visible_ ? 0.0 : 1.0); | |
| 223 layer->SetTransform(is_visible_ ? | |
| 224 ui::GetScaleTransform( | |
| 225 gfx::Point(layer->bounds().width() / 2, | |
| 226 layer->bounds().height() / 2), | |
| 227 kContainerAnimationScaleFactor) : | |
| 228 ui::Transform()); | |
| 229 } | |
| 230 | |
| 231 void AppListController::ScheduleBrowserWindowsAnimation() { | |
| 232 // Note: containers could be NULL during Shell shutdown. | |
| 233 aura::Window* default_container = Shell::GetInstance()->GetContainer( | |
| 234 kShellWindowId_DefaultContainer); | |
| 235 if (default_container) | |
| 236 ScheduleBrowserWindowsAnimationForContainer(default_container); | |
| 237 aura::Window* always_on_top_container = Shell::GetInstance()-> | |
| 238 GetContainer(kShellWindowId_AlwaysOnTopContainer); | |
| 239 if (always_on_top_container) | |
| 240 ScheduleBrowserWindowsAnimationForContainer(always_on_top_container); | |
| 241 } | |
| 242 | |
| 243 void AppListController::ScheduleDimmingAnimation() { | |
| 244 ui::Layer* layer = GetLayer(view_->GetWidget()); | |
| 245 layer->GetAnimator()->StopAnimating(); | |
| 246 | |
| 247 int duration = UseAppListV2() ? | |
| 248 kAnimationDurationMs : 2 * kAnimationDurationMs; | |
| 249 | |
| 250 ui::ScopedLayerAnimationSettings animation(layer->GetAnimator()); | |
| 251 animation.SetTransitionDuration( | |
| 252 base::TimeDelta::FromMilliseconds(duration)); | |
| 253 animation.AddObserver(this); | 154 animation.AddObserver(this); |
| 254 | 155 |
| 255 layer->SetOpacity(is_visible_ ? 1.0 : 0.0); | 156 layer->SetOpacity(is_visible_ ? 1.0 : 0.0); |
| 256 } | 157 } |
| 257 | 158 |
| 258 void AppListController::ScheduleAppListAnimation() { | |
| 259 if (is_visible_) | |
| 260 view_->AnimateShow(kAnimationDurationMs); | |
| 261 else | |
| 262 view_->AnimateHide(kAnimationDurationMs); | |
| 263 } | |
| 264 | |
| 265 //////////////////////////////////////////////////////////////////////////////// | 159 //////////////////////////////////////////////////////////////////////////////// |
| 266 // AppListController, aura::EventFilter implementation: | 160 // AppListController, aura::EventFilter implementation: |
| 267 | 161 |
| 268 bool AppListController::PreHandleKeyEvent(aura::Window* target, | 162 bool AppListController::PreHandleKeyEvent(aura::Window* target, |
| 269 aura::KeyEvent* event) { | 163 aura::KeyEvent* event) { |
| 270 return false; | 164 return false; |
| 271 } | 165 } |
| 272 | 166 |
| 273 bool AppListController::PreHandleMouseEvent(aura::Window* target, | 167 bool AppListController::PreHandleMouseEvent(aura::Window* target, |
| 274 aura::MouseEvent* event) { | 168 aura::MouseEvent* event) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 305 window->parent() != bubble_container) { | 199 window->parent() != bubble_container) { |
| 306 SetVisible(false); | 200 SetVisible(false); |
| 307 } | 201 } |
| 308 } | 202 } |
| 309 } | 203 } |
| 310 | 204 |
| 311 //////////////////////////////////////////////////////////////////////////////// | 205 //////////////////////////////////////////////////////////////////////////////// |
| 312 // AppListController, aura::RootWindowObserver implementation: | 206 // AppListController, aura::RootWindowObserver implementation: |
| 313 void AppListController::OnRootWindowResized(const aura::RootWindow* root, | 207 void AppListController::OnRootWindowResized(const aura::RootWindow* root, |
| 314 const gfx::Size& old_size) { | 208 const gfx::Size& old_size) { |
| 315 if (view_ && is_visible_) { | 209 if (view_ && is_visible_) |
| 316 views::Widget* launcher_widget = | 210 view_->UpdateBounds(); |
| 317 Shell::GetInstance()->launcher()->widget(); | |
| 318 view_->UpdateBounds(GetFullScreenBoundsForWidget(launcher_widget), | |
| 319 GetWorkAreaBoundsForWidget(launcher_widget)); | |
| 320 } | |
| 321 } | 211 } |
| 322 | 212 |
| 323 //////////////////////////////////////////////////////////////////////////////// | 213 //////////////////////////////////////////////////////////////////////////////// |
| 324 // AppListController, ui::ImplicitAnimationObserver implementation: | 214 // AppListController, ui::ImplicitAnimationObserver implementation: |
| 325 | 215 |
| 326 void AppListController::OnImplicitAnimationsCompleted() { | 216 void AppListController::OnImplicitAnimationsCompleted() { |
| 327 if (is_visible_ ) | 217 if (is_visible_ ) |
| 328 view_->GetWidget()->Activate(); | 218 view_->GetWidget()->Activate(); |
| 329 else | 219 else |
| 330 view_->GetWidget()->Close(); | 220 view_->GetWidget()->Close(); |
| 331 } | 221 } |
| 332 | 222 |
| 333 //////////////////////////////////////////////////////////////////////////////// | 223 //////////////////////////////////////////////////////////////////////////////// |
| 334 // AppListController, views::Widget::Observer implementation: | 224 // AppListController, views::Widget::Observer implementation: |
| 335 | 225 |
| 336 void AppListController::OnWidgetClosing(views::Widget* widget) { | 226 void AppListController::OnWidgetClosing(views::Widget* widget) { |
| 337 DCHECK(view_->GetWidget() == widget); | 227 DCHECK(view_->GetWidget() == widget); |
| 338 if (is_visible_) | 228 if (is_visible_) |
| 339 SetVisible(false); | 229 SetVisible(false); |
| 340 ResetView(); | 230 ResetView(); |
| 341 } | 231 } |
| 342 | 232 |
| 343 //////////////////////////////////////////////////////////////////////////////// | 233 //////////////////////////////////////////////////////////////////////////////// |
| 344 // AppListController, ShellObserver implementation: | 234 // AppListController, ShellObserver implementation: |
| 345 void AppListController::OnShelfAlignmentChanged() { | 235 void AppListController::OnShelfAlignmentChanged() { |
| 346 if (view_ && view_->bubble_style()) | 236 if (view_) |
| 347 view_->SetBubbleArrowLocation(GetBubbleArrowLocation()); | 237 view_->SetBubbleArrowLocation(GetBubbleArrowLocation()); |
| 348 } | 238 } |
| 349 | 239 |
| 350 } // namespace internal | 240 } // namespace internal |
| 351 } // namespace ash | 241 } // namespace ash |
| OLD | NEW |