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/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
9 #include "ash/screen_util.h" | 9 #include "ash/screen_util.h" |
10 #include "ash/shelf/shelf.h" | 10 #include "ash/shelf/shelf.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // lives in the controller and app list view would access it on destruction. | 166 // lives in the controller and app list view would access it on destruction. |
167 if (view_) { | 167 if (view_) { |
168 view_->GetAppsPaginationModel()->RemoveObserver(this); | 168 view_->GetAppsPaginationModel()->RemoveObserver(this); |
169 if (view_->GetWidget()) | 169 if (view_->GetWidget()) |
170 view_->GetWidget()->CloseNow(); | 170 view_->GetWidget()->CloseNow(); |
171 } | 171 } |
172 | 172 |
173 Shell::GetInstance()->RemoveShellObserver(this); | 173 Shell::GetInstance()->RemoveShellObserver(this); |
174 } | 174 } |
175 | 175 |
176 void AppListController::SetVisible(bool visible, aura::Window* window) { | 176 void AppListController::Show(aura::Window* window) { |
177 if (visible == is_visible_) | 177 if (is_visible_) |
178 return; | 178 return; |
179 | 179 |
180 is_visible_ = visible; | 180 is_visible_ = true; |
181 | 181 |
182 // App list needs to know the new shelf layout in order to calculate its | 182 // App list needs to know the new shelf layout in order to calculate its |
183 // UI layout when AppListView visibility changes. | 183 // UI layout when AppListView visibility changes. |
184 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()-> | 184 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()-> |
185 UpdateAutoHideState(); | 185 UpdateAutoHideState(); |
186 | 186 |
187 if (view_) { | 187 if (view_) { |
188 // Our widget is currently active. When the animation completes we'll hide | |
189 // the widget, changing activation. If a menu is shown before the animation | |
190 // completes then the activation change triggers the menu to close. By | |
191 // deactivating now we ensure there is no activation change when the | |
192 // animation completes and any menus stay open. | |
193 if (!visible) | |
194 view_->GetWidget()->Deactivate(); | |
195 ScheduleAnimation(); | 188 ScheduleAnimation(); |
196 } else if (is_visible_) { | 189 } else { |
197 // AppListModel and AppListViewDelegate are owned by AppListView. They | 190 // AppListModel and AppListViewDelegate are owned by AppListView. They |
198 // will be released with AppListView on close. | 191 // will be released with AppListView on close. |
199 app_list::AppListView* view = new app_list::AppListView( | 192 app_list::AppListView* view = new app_list::AppListView( |
200 Shell::GetInstance()->delegate()->CreateAppListViewDelegate()); | 193 Shell::GetInstance()->delegate()->CreateAppListViewDelegate()); |
201 aura::Window* root_window = window->GetRootWindow(); | 194 aura::Window* root_window = window->GetRootWindow(); |
202 aura::Window* container = GetRootWindowController(root_window)-> | 195 aura::Window* container = GetRootWindowController(root_window)-> |
203 GetContainer(kShellWindowId_AppListContainer); | 196 GetContainer(kShellWindowId_AppListContainer); |
204 views::View* applist_button = | 197 views::View* applist_button = |
205 Shelf::ForWindow(container)->GetAppListButtonView(); | 198 Shelf::ForWindow(container)->GetAppListButtonView(); |
206 is_centered_ = view->ShouldCenterWindow(); | 199 is_centered_ = view->ShouldCenterWindow(); |
(...skipping 30 matching lines...) Expand all Loading... |
237 SetView(view); | 230 SetView(view); |
238 // By setting us as DnD recipient, the app list knows that we can | 231 // By setting us as DnD recipient, the app list knows that we can |
239 // handle items. | 232 // handle items. |
240 SetDragAndDropHostOfCurrentAppList( | 233 SetDragAndDropHostOfCurrentAppList( |
241 Shelf::ForWindow(window)->GetDragAndDropHostForAppList()); | 234 Shelf::ForWindow(window)->GetDragAndDropHostForAppList()); |
242 } | 235 } |
243 // Update applist button status when app list visibility is changed. | 236 // Update applist button status when app list visibility is changed. |
244 Shelf::ForWindow(window)->GetAppListButtonView()->SchedulePaint(); | 237 Shelf::ForWindow(window)->GetAppListButtonView()->SchedulePaint(); |
245 } | 238 } |
246 | 239 |
| 240 void AppListController::Dismiss() { |
| 241 if (!is_visible_) |
| 242 return; |
| 243 |
| 244 // If the app list is currently visible, there should be an existing view. |
| 245 DCHECK(view_); |
| 246 |
| 247 is_visible_ = false; |
| 248 |
| 249 // App list needs to know the new shelf layout in order to calculate its |
| 250 // UI layout when AppListView visibility changes. |
| 251 Shell::GetPrimaryRootWindowController() |
| 252 ->GetShelfLayoutManager() |
| 253 ->UpdateAutoHideState(); |
| 254 |
| 255 // Our widget is currently active. When the animation completes we'll hide |
| 256 // the widget, changing activation. If a menu is shown before the animation |
| 257 // completes then the activation change triggers the menu to close. By |
| 258 // deactivating now we ensure there is no activation change when the |
| 259 // animation completes and any menus stay open. |
| 260 view_->GetWidget()->Deactivate(); |
| 261 ScheduleAnimation(); |
| 262 |
| 263 // Update applist button status when app list visibility is changed. |
| 264 Shelf::ForWindow(view_->GetWidget()->GetNativeView()) |
| 265 ->GetAppListButtonView() |
| 266 ->SchedulePaint(); |
| 267 } |
| 268 |
247 bool AppListController::IsVisible() const { | 269 bool AppListController::IsVisible() const { |
248 return view_ && view_->GetWidget()->IsVisible(); | 270 return view_ && view_->GetWidget()->IsVisible(); |
249 } | 271 } |
250 | 272 |
251 aura::Window* AppListController::GetWindow() { | 273 aura::Window* AppListController::GetWindow() { |
252 return is_visible_ && view_ ? view_->GetWidget()->GetNativeWindow() : NULL; | 274 return is_visible_ && view_ ? view_->GetWidget()->GetNativeWindow() : NULL; |
253 } | 275 } |
254 | 276 |
255 //////////////////////////////////////////////////////////////////////////////// | 277 //////////////////////////////////////////////////////////////////////////////// |
256 // AppListController, private: | 278 // AppListController, private: |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 return; | 369 return; |
348 aura::Window* keyboard_container = root_controller->GetContainer( | 370 aura::Window* keyboard_container = root_controller->GetContainer( |
349 kShellWindowId_VirtualKeyboardContainer); | 371 kShellWindowId_VirtualKeyboardContainer); |
350 if (keyboard_container->Contains(target)) | 372 if (keyboard_container->Contains(target)) |
351 return; | 373 return; |
352 } | 374 } |
353 } | 375 } |
354 | 376 |
355 aura::Window* window = view_->GetWidget()->GetNativeView()->parent(); | 377 aura::Window* window = view_->GetWidget()->GetNativeView()->parent(); |
356 if (!window->Contains(target)) | 378 if (!window->Contains(target)) |
357 SetVisible(false, window); | 379 Dismiss(); |
358 } | 380 } |
359 | 381 |
360 void AppListController::UpdateBounds() { | 382 void AppListController::UpdateBounds() { |
361 if (!view_ || !is_visible_) | 383 if (!view_ || !is_visible_) |
362 return; | 384 return; |
363 | 385 |
364 view_->UpdateBounds(); | 386 view_->UpdateBounds(); |
365 | 387 |
366 if (is_centered_) | 388 if (is_centered_) |
367 view_->SetAnchorPoint(GetCenterOfDisplayForView( | 389 view_->SetAnchorPoint(GetCenterOfDisplayForView( |
(...skipping 17 matching lines...) Expand all Loading... |
385 // AppListController, aura::FocusObserver implementation: | 407 // AppListController, aura::FocusObserver implementation: |
386 | 408 |
387 void AppListController::OnWindowFocused(aura::Window* gained_focus, | 409 void AppListController::OnWindowFocused(aura::Window* gained_focus, |
388 aura::Window* lost_focus) { | 410 aura::Window* lost_focus) { |
389 if (view_ && is_visible_) { | 411 if (view_ && is_visible_) { |
390 aura::Window* applist_window = view_->GetWidget()->GetNativeView(); | 412 aura::Window* applist_window = view_->GetWidget()->GetNativeView(); |
391 aura::Window* applist_container = applist_window->parent(); | 413 aura::Window* applist_container = applist_window->parent(); |
392 | 414 |
393 if (applist_container->Contains(lost_focus) && | 415 if (applist_container->Contains(lost_focus) && |
394 (!gained_focus || !applist_container->Contains(gained_focus))) { | 416 (!gained_focus || !applist_container->Contains(gained_focus))) { |
395 SetVisible(false, applist_window); | 417 Dismiss(); |
396 } | 418 } |
397 } | 419 } |
398 } | 420 } |
399 | 421 |
400 //////////////////////////////////////////////////////////////////////////////// | 422 //////////////////////////////////////////////////////////////////////////////// |
401 // AppListController, aura::WindowObserver implementation: | 423 // AppListController, aura::WindowObserver implementation: |
402 void AppListController::OnWindowBoundsChanged(aura::Window* root, | 424 void AppListController::OnWindowBoundsChanged(aura::Window* root, |
403 const gfx::Rect& old_bounds, | 425 const gfx::Rect& old_bounds, |
404 const gfx::Rect& new_bounds) { | 426 const gfx::Rect& new_bounds) { |
405 UpdateBounds(); | 427 UpdateBounds(); |
406 } | 428 } |
407 | 429 |
408 //////////////////////////////////////////////////////////////////////////////// | 430 //////////////////////////////////////////////////////////////////////////////// |
409 // AppListController, ui::ImplicitAnimationObserver implementation: | 431 // AppListController, ui::ImplicitAnimationObserver implementation: |
410 | 432 |
411 void AppListController::OnImplicitAnimationsCompleted() { | 433 void AppListController::OnImplicitAnimationsCompleted() { |
412 if (is_visible_ ) | 434 if (is_visible_ ) |
413 view_->GetWidget()->Activate(); | 435 view_->GetWidget()->Activate(); |
414 else | 436 else |
415 view_->GetWidget()->Close(); | 437 view_->GetWidget()->Close(); |
416 } | 438 } |
417 | 439 |
418 //////////////////////////////////////////////////////////////////////////////// | 440 //////////////////////////////////////////////////////////////////////////////// |
419 // AppListController, views::WidgetObserver implementation: | 441 // AppListController, views::WidgetObserver implementation: |
420 | 442 |
421 void AppListController::OnWidgetDestroying(views::Widget* widget) { | 443 void AppListController::OnWidgetDestroying(views::Widget* widget) { |
422 DCHECK(view_->GetWidget() == widget); | 444 DCHECK(view_->GetWidget() == widget); |
423 if (is_visible_) | 445 if (is_visible_) |
424 SetVisible(false, widget->GetNativeView()); | 446 Dismiss(); |
425 ResetView(); | 447 ResetView(); |
426 } | 448 } |
427 | 449 |
428 //////////////////////////////////////////////////////////////////////////////// | 450 //////////////////////////////////////////////////////////////////////////////// |
429 // AppListController, keyboard::KeyboardControllerObserver implementation: | 451 // AppListController, keyboard::KeyboardControllerObserver implementation: |
430 | 452 |
431 void AppListController::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { | 453 void AppListController::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { |
432 UpdateBounds(); | 454 UpdateBounds(); |
433 } | 455 } |
434 | 456 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 } else if (should_snap_back_) { | 515 } else if (should_snap_back_) { |
494 should_snap_back_ = false; | 516 should_snap_back_ = false; |
495 ui::ScopedLayerAnimationSettings animation(widget_animator); | 517 ui::ScopedLayerAnimationSettings animation(widget_animator); |
496 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 518 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
497 app_list::kOverscrollPageTransitionDurationMs)); | 519 app_list::kOverscrollPageTransitionDurationMs)); |
498 widget->SetBounds(view_bounds_); | 520 widget->SetBounds(view_bounds_); |
499 } | 521 } |
500 } | 522 } |
501 | 523 |
502 } // namespace ash | 524 } // namespace ash |
OLD | NEW |