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

Side by Side Diff: ash/wm/app_list_controller.cc

Issue 485453003: Split AppListController::SetVisible into Show and Dismiss. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add DCHECK Created 6 years, 4 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 | « ash/wm/app_list_controller.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 (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
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 26 matching lines...) Expand all
233 GetBubbleArrow(container), 226 GetBubbleArrow(container),
234 true /* border_accepts_events */); 227 true /* border_accepts_events */);
235 view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); 228 view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
236 } 229 }
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 }
236
Matt Giuca 2014/08/20 06:13:12 nit: extra blank line.
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 // Our widget is currently active. When the animation completes we'll hide
254 // the widget, changing activation. If a menu is shown before the animation
255 // completes then the activation change triggers the menu to close. By
256 // deactivating now we ensure there is no activation change when the
257 // animation completes and any menus stay open.
258 DCHECK(view_);
Matt Giuca 2014/08/20 06:13:12 nit: I think this DCHECK should be immediately aft
259 view_->GetWidget()->Deactivate();
260 ScheduleAnimation();
261
262 // Update applist button status when app list visibility is changed.
263 Shelf::ForWindow(view_->GetWidget()->GetNativeView())
264 ->GetAppListButtonView()
265 ->SchedulePaint();
266 }
267
247 bool AppListController::IsVisible() const { 268 bool AppListController::IsVisible() const {
248 return view_ && view_->GetWidget()->IsVisible(); 269 return view_ && view_->GetWidget()->IsVisible();
249 } 270 }
250 271
251 aura::Window* AppListController::GetWindow() { 272 aura::Window* AppListController::GetWindow() {
252 return is_visible_ && view_ ? view_->GetWidget()->GetNativeWindow() : NULL; 273 return is_visible_ && view_ ? view_->GetWidget()->GetNativeWindow() : NULL;
253 } 274 }
254 275
255 //////////////////////////////////////////////////////////////////////////////// 276 ////////////////////////////////////////////////////////////////////////////////
256 // AppListController, private: 277 // AppListController, private:
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 return; 368 return;
348 aura::Window* keyboard_container = root_controller->GetContainer( 369 aura::Window* keyboard_container = root_controller->GetContainer(
349 kShellWindowId_VirtualKeyboardContainer); 370 kShellWindowId_VirtualKeyboardContainer);
350 if (keyboard_container->Contains(target)) 371 if (keyboard_container->Contains(target))
351 return; 372 return;
352 } 373 }
353 } 374 }
354 375
355 aura::Window* window = view_->GetWidget()->GetNativeView()->parent(); 376 aura::Window* window = view_->GetWidget()->GetNativeView()->parent();
356 if (!window->Contains(target)) 377 if (!window->Contains(target))
357 SetVisible(false, window); 378 Dismiss();
358 } 379 }
359 380
360 void AppListController::UpdateBounds() { 381 void AppListController::UpdateBounds() {
361 if (!view_ || !is_visible_) 382 if (!view_ || !is_visible_)
362 return; 383 return;
363 384
364 view_->UpdateBounds(); 385 view_->UpdateBounds();
365 386
366 if (is_centered_) 387 if (is_centered_)
367 view_->SetAnchorPoint(GetCenterOfDisplayForView( 388 view_->SetAnchorPoint(GetCenterOfDisplayForView(
(...skipping 17 matching lines...) Expand all
385 // AppListController, aura::FocusObserver implementation: 406 // AppListController, aura::FocusObserver implementation:
386 407
387 void AppListController::OnWindowFocused(aura::Window* gained_focus, 408 void AppListController::OnWindowFocused(aura::Window* gained_focus,
388 aura::Window* lost_focus) { 409 aura::Window* lost_focus) {
389 if (view_ && is_visible_) { 410 if (view_ && is_visible_) {
390 aura::Window* applist_window = view_->GetWidget()->GetNativeView(); 411 aura::Window* applist_window = view_->GetWidget()->GetNativeView();
391 aura::Window* applist_container = applist_window->parent(); 412 aura::Window* applist_container = applist_window->parent();
392 413
393 if (applist_container->Contains(lost_focus) && 414 if (applist_container->Contains(lost_focus) &&
394 (!gained_focus || !applist_container->Contains(gained_focus))) { 415 (!gained_focus || !applist_container->Contains(gained_focus))) {
395 SetVisible(false, applist_window); 416 Dismiss();
396 } 417 }
397 } 418 }
398 } 419 }
399 420
400 //////////////////////////////////////////////////////////////////////////////// 421 ////////////////////////////////////////////////////////////////////////////////
401 // AppListController, aura::WindowObserver implementation: 422 // AppListController, aura::WindowObserver implementation:
402 void AppListController::OnWindowBoundsChanged(aura::Window* root, 423 void AppListController::OnWindowBoundsChanged(aura::Window* root,
403 const gfx::Rect& old_bounds, 424 const gfx::Rect& old_bounds,
404 const gfx::Rect& new_bounds) { 425 const gfx::Rect& new_bounds) {
405 UpdateBounds(); 426 UpdateBounds();
406 } 427 }
407 428
408 //////////////////////////////////////////////////////////////////////////////// 429 ////////////////////////////////////////////////////////////////////////////////
409 // AppListController, ui::ImplicitAnimationObserver implementation: 430 // AppListController, ui::ImplicitAnimationObserver implementation:
410 431
411 void AppListController::OnImplicitAnimationsCompleted() { 432 void AppListController::OnImplicitAnimationsCompleted() {
412 if (is_visible_ ) 433 if (is_visible_ )
413 view_->GetWidget()->Activate(); 434 view_->GetWidget()->Activate();
414 else 435 else
415 view_->GetWidget()->Close(); 436 view_->GetWidget()->Close();
416 } 437 }
417 438
418 //////////////////////////////////////////////////////////////////////////////// 439 ////////////////////////////////////////////////////////////////////////////////
419 // AppListController, views::WidgetObserver implementation: 440 // AppListController, views::WidgetObserver implementation:
420 441
421 void AppListController::OnWidgetDestroying(views::Widget* widget) { 442 void AppListController::OnWidgetDestroying(views::Widget* widget) {
422 DCHECK(view_->GetWidget() == widget); 443 DCHECK(view_->GetWidget() == widget);
423 if (is_visible_) 444 if (is_visible_)
424 SetVisible(false, widget->GetNativeView()); 445 Dismiss();
425 ResetView(); 446 ResetView();
426 } 447 }
427 448
428 //////////////////////////////////////////////////////////////////////////////// 449 ////////////////////////////////////////////////////////////////////////////////
429 // AppListController, keyboard::KeyboardControllerObserver implementation: 450 // AppListController, keyboard::KeyboardControllerObserver implementation:
430 451
431 void AppListController::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { 452 void AppListController::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) {
432 UpdateBounds(); 453 UpdateBounds();
433 } 454 }
434 455
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 } else if (should_snap_back_) { 514 } else if (should_snap_back_) {
494 should_snap_back_ = false; 515 should_snap_back_ = false;
495 ui::ScopedLayerAnimationSettings animation(widget_animator); 516 ui::ScopedLayerAnimationSettings animation(widget_animator);
496 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( 517 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
497 app_list::kOverscrollPageTransitionDurationMs)); 518 app_list::kOverscrollPageTransitionDurationMs));
498 widget->SetBounds(view_bounds_); 519 widget->SetBounds(view_bounds_);
499 } 520 }
500 } 521 }
501 522
502 } // namespace ash 523 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/app_list_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698