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(); | |
196 } else if (is_visible_) { | |
197 // AppListModel and AppListViewDelegate are owned by AppListView. They | 188 // AppListModel and AppListViewDelegate are owned by AppListView. They |
198 // will be released with AppListView on close. | 189 // will be released with AppListView on close. |
199 app_list::AppListView* view = new app_list::AppListView( | 190 app_list::AppListView* view = new app_list::AppListView( |
200 Shell::GetInstance()->delegate()->CreateAppListViewDelegate()); | 191 Shell::GetInstance()->delegate()->CreateAppListViewDelegate()); |
201 aura::Window* root_window = window->GetRootWindow(); | 192 aura::Window* root_window = window->GetRootWindow(); |
202 aura::Window* container = GetRootWindowController(root_window)-> | 193 aura::Window* container = GetRootWindowController(root_window)-> |
203 GetContainer(kShellWindowId_AppListContainer); | 194 GetContainer(kShellWindowId_AppListContainer); |
204 views::View* applist_button = | 195 views::View* applist_button = |
205 Shelf::ForWindow(container)->GetAppListButtonView(); | 196 Shelf::ForWindow(container)->GetAppListButtonView(); |
206 is_centered_ = view->ShouldCenterWindow(); | 197 is_centered_ = view->ShouldCenterWindow(); |
(...skipping 25 matching lines...) Expand all Loading... | |
232 Shelf::ForWindow(container)->GetAppListButtonView()->GetWidget()), | 223 Shelf::ForWindow(container)->GetAppListButtonView()->GetWidget()), |
233 GetBubbleArrow(container), | 224 GetBubbleArrow(container), |
234 true /* border_accepts_events */); | 225 true /* border_accepts_events */); |
235 view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | 226 view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); |
236 } | 227 } |
237 SetView(view); | 228 SetView(view); |
238 // By setting us as DnD recipient, the app list knows that we can | 229 // By setting us as DnD recipient, the app list knows that we can |
239 // handle items. | 230 // handle items. |
240 SetDragAndDropHostOfCurrentAppList( | 231 SetDragAndDropHostOfCurrentAppList( |
241 Shelf::ForWindow(window)->GetDragAndDropHostForAppList()); | 232 Shelf::ForWindow(window)->GetDragAndDropHostForAppList()); |
233 } else { | |
234 ScheduleAnimation(); | |
Matt Giuca
2014/08/19 08:26:29
Is there a reason to invert the if statement? Why
calamity
2014/08/20 00:44:53
Done.
| |
242 } | 235 } |
236 | |
243 // Update applist button status when app list visibility is changed. | 237 // Update applist button status when app list visibility is changed. |
244 Shelf::ForWindow(window)->GetAppListButtonView()->SchedulePaint(); | 238 Shelf::ForWindow(window)->GetAppListButtonView()->SchedulePaint(); |
245 } | 239 } |
246 | 240 |
241 void AppListController::Dismiss() { | |
242 if (!is_visible_) | |
243 return; | |
244 | |
245 is_visible_ = false; | |
246 | |
247 // App list needs to know the new shelf layout in order to calculate its | |
248 // UI layout when AppListView visibility changes. | |
249 Shell::GetPrimaryRootWindowController() | |
250 ->GetShelfLayoutManager() | |
251 ->UpdateAutoHideState(); | |
252 | |
253 if (!view_) | |
Matt Giuca
2014/08/19 08:26:29
This slightly changes the logic in that you won't
calamity
2014/08/20 00:44:53
I don't think this will be a problem. !view_ shoul
Matt Giuca
2014/08/20 06:13:12
Note: We discussed this and decided to replace thi
| |
254 return; | |
255 | |
256 // Our widget is currently active. When the animation completes we'll hide | |
257 // the widget, changing activation. If a menu is shown before the animation | |
258 // completes then the activation change triggers the menu to close. By | |
259 // deactivating now we ensure there is no activation change when the | |
260 // animation completes and any menus stay open. | |
261 view_->GetWidget()->Deactivate(); | |
262 ScheduleAnimation(); | |
263 | |
264 // Update applist button status when app list visibility is changed. | |
265 Shelf::ForWindow(view_->GetWidget()->GetNativeView()) | |
266 ->GetAppListButtonView() | |
267 ->SchedulePaint(); | |
268 } | |
269 | |
247 bool AppListController::IsVisible() const { | 270 bool AppListController::IsVisible() const { |
248 return view_ && view_->GetWidget()->IsVisible(); | 271 return view_ && view_->GetWidget()->IsVisible(); |
249 } | 272 } |
250 | 273 |
251 aura::Window* AppListController::GetWindow() { | 274 aura::Window* AppListController::GetWindow() { |
252 return is_visible_ && view_ ? view_->GetWidget()->GetNativeWindow() : NULL; | 275 return is_visible_ && view_ ? view_->GetWidget()->GetNativeWindow() : NULL; |
253 } | 276 } |
254 | 277 |
255 //////////////////////////////////////////////////////////////////////////////// | 278 //////////////////////////////////////////////////////////////////////////////// |
256 // AppListController, private: | 279 // AppListController, private: |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 return; | 370 return; |
348 aura::Window* keyboard_container = root_controller->GetContainer( | 371 aura::Window* keyboard_container = root_controller->GetContainer( |
349 kShellWindowId_VirtualKeyboardContainer); | 372 kShellWindowId_VirtualKeyboardContainer); |
350 if (keyboard_container->Contains(target)) | 373 if (keyboard_container->Contains(target)) |
351 return; | 374 return; |
352 } | 375 } |
353 } | 376 } |
354 | 377 |
355 aura::Window* window = view_->GetWidget()->GetNativeView()->parent(); | 378 aura::Window* window = view_->GetWidget()->GetNativeView()->parent(); |
356 if (!window->Contains(target)) | 379 if (!window->Contains(target)) |
357 SetVisible(false, window); | 380 Dismiss(); |
358 } | 381 } |
359 | 382 |
360 void AppListController::UpdateBounds() { | 383 void AppListController::UpdateBounds() { |
361 if (!view_ || !is_visible_) | 384 if (!view_ || !is_visible_) |
362 return; | 385 return; |
363 | 386 |
364 view_->UpdateBounds(); | 387 view_->UpdateBounds(); |
365 | 388 |
366 if (is_centered_) | 389 if (is_centered_) |
367 view_->SetAnchorPoint(GetCenterOfDisplayForView( | 390 view_->SetAnchorPoint(GetCenterOfDisplayForView( |
(...skipping 17 matching lines...) Expand all Loading... | |
385 // AppListController, aura::FocusObserver implementation: | 408 // AppListController, aura::FocusObserver implementation: |
386 | 409 |
387 void AppListController::OnWindowFocused(aura::Window* gained_focus, | 410 void AppListController::OnWindowFocused(aura::Window* gained_focus, |
388 aura::Window* lost_focus) { | 411 aura::Window* lost_focus) { |
389 if (view_ && is_visible_) { | 412 if (view_ && is_visible_) { |
390 aura::Window* applist_window = view_->GetWidget()->GetNativeView(); | 413 aura::Window* applist_window = view_->GetWidget()->GetNativeView(); |
391 aura::Window* applist_container = applist_window->parent(); | 414 aura::Window* applist_container = applist_window->parent(); |
392 | 415 |
393 if (applist_container->Contains(lost_focus) && | 416 if (applist_container->Contains(lost_focus) && |
394 (!gained_focus || !applist_container->Contains(gained_focus))) { | 417 (!gained_focus || !applist_container->Contains(gained_focus))) { |
395 SetVisible(false, applist_window); | 418 Dismiss(); |
396 } | 419 } |
397 } | 420 } |
398 } | 421 } |
399 | 422 |
400 //////////////////////////////////////////////////////////////////////////////// | 423 //////////////////////////////////////////////////////////////////////////////// |
401 // AppListController, aura::WindowObserver implementation: | 424 // AppListController, aura::WindowObserver implementation: |
402 void AppListController::OnWindowBoundsChanged(aura::Window* root, | 425 void AppListController::OnWindowBoundsChanged(aura::Window* root, |
403 const gfx::Rect& old_bounds, | 426 const gfx::Rect& old_bounds, |
404 const gfx::Rect& new_bounds) { | 427 const gfx::Rect& new_bounds) { |
405 UpdateBounds(); | 428 UpdateBounds(); |
406 } | 429 } |
407 | 430 |
408 //////////////////////////////////////////////////////////////////////////////// | 431 //////////////////////////////////////////////////////////////////////////////// |
409 // AppListController, ui::ImplicitAnimationObserver implementation: | 432 // AppListController, ui::ImplicitAnimationObserver implementation: |
410 | 433 |
411 void AppListController::OnImplicitAnimationsCompleted() { | 434 void AppListController::OnImplicitAnimationsCompleted() { |
412 if (is_visible_ ) | 435 if (is_visible_ ) |
413 view_->GetWidget()->Activate(); | 436 view_->GetWidget()->Activate(); |
414 else | 437 else |
415 view_->GetWidget()->Close(); | 438 view_->GetWidget()->Close(); |
416 } | 439 } |
417 | 440 |
418 //////////////////////////////////////////////////////////////////////////////// | 441 //////////////////////////////////////////////////////////////////////////////// |
419 // AppListController, views::WidgetObserver implementation: | 442 // AppListController, views::WidgetObserver implementation: |
420 | 443 |
421 void AppListController::OnWidgetDestroying(views::Widget* widget) { | 444 void AppListController::OnWidgetDestroying(views::Widget* widget) { |
422 DCHECK(view_->GetWidget() == widget); | 445 DCHECK(view_->GetWidget() == widget); |
423 if (is_visible_) | 446 if (is_visible_) |
424 SetVisible(false, widget->GetNativeView()); | 447 Dismiss(); |
425 ResetView(); | 448 ResetView(); |
426 } | 449 } |
427 | 450 |
428 //////////////////////////////////////////////////////////////////////////////// | 451 //////////////////////////////////////////////////////////////////////////////// |
429 // AppListController, keyboard::KeyboardControllerObserver implementation: | 452 // AppListController, keyboard::KeyboardControllerObserver implementation: |
430 | 453 |
431 void AppListController::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { | 454 void AppListController::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { |
432 UpdateBounds(); | 455 UpdateBounds(); |
433 } | 456 } |
434 | 457 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
493 } else if (should_snap_back_) { | 516 } else if (should_snap_back_) { |
494 should_snap_back_ = false; | 517 should_snap_back_ = false; |
495 ui::ScopedLayerAnimationSettings animation(widget_animator); | 518 ui::ScopedLayerAnimationSettings animation(widget_animator); |
496 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 519 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
497 app_list::kOverscrollPageTransitionDurationMs)); | 520 app_list::kOverscrollPageTransitionDurationMs)); |
498 widget->SetBounds(view_bounds_); | 521 widget->SetBounds(view_bounds_); |
499 } | 522 } |
500 } | 523 } |
501 | 524 |
502 } // namespace ash | 525 } // namespace ash |
OLD | NEW |