15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef ASH_WM_APP_LIST_CONTROLLER_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define ASH_WM_APP_LIST_CONTROLLER_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ash/shelf/shelf_icon_observer.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell_observer.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 12eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/timer/timer.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/app_list/pagination_model_observer.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/client/focus_change_observer.h" 157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/aura/window_observer.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_animation_observer.h" 17d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/event_handler.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/rect.h" 19010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "ui/keyboard/keyboard_controller_observer.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget_observer.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace app_list { 23b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)class ApplicationDragAndDropHost; 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AppListView; 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui { 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class LocatedEvent; 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash { 3258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)namespace test { 3358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class AppListControllerTestApi; 3458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 3558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// AppListController is a controller that manages app list UI for shell. 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// It creates AppListView and schedules showing/hiding animation. 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// While the UI is visible, it monitors things such as app list widget's 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// activation state and desktop mouse click to auto dismiss the UI. 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class AppListController : public ui::EventHandler, 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public aura::client::FocusChangeObserver, 427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) public aura::WindowObserver, 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public ui::ImplicitAnimationObserver, 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public views::WidgetObserver, 45010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) public keyboard::KeyboardControllerObserver, 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public ShellObserver, 471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public ShelfIconObserver, 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public app_list::PaginationModelObserver { 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AppListController(); 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~AppListController(); 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Show/hide app list window. The |window| is used to deterime in 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // which display (in which the |window| exists) the app list should 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // be shown. 561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci void Show(aura::Window* window); 571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci void Dismiss(); 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Whether app list window is visible (shown or being shown). 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool IsVisible() const; 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns target visibility. This differs from IsVisible() if an animation 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is ongoing. 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetTargetVisibility() const { return is_visible_; } 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns app list window or NULL if it is not visible. 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::Window* GetWindow(); 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Returns app list view or NULL if it is not visible. 708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) app_list::AppListView* GetView() { return view_; } 718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 72bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch private: 7358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) friend class test::AppListControllerTestApi; 7458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 75b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // If |drag_and_drop_host| is not NULL it will be called upon drag and drop 76b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // operations outside the application list. 77b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) void SetDragAndDropHostOfCurrentAppList( 78b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) app_list::ApplicationDragAndDropHost* drag_and_drop_host); 79b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Sets the app list view and attempts to show it. 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetView(app_list::AppListView* view); 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Forgets the view. 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ResetView(); 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Starts show/hide animation. 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ScheduleAnimation(); 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void ProcessLocatedEvent(ui::LocatedEvent* event); 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Makes app list bubble update its bounds. 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void UpdateBounds(); 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // ui::EventHandler overrides: 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // aura::client::FocusChangeObserver overrides: 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnWindowFocused(aura::Window* gained_focus, 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* lost_focus) OVERRIDE; 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // aura::WindowObserver overrides: 1037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual void OnWindowBoundsChanged(aura::Window* root, 1047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const gfx::Rect& old_bounds, 1057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const gfx::Rect& new_bounds) OVERRIDE; 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ui::ImplicitAnimationObserver overrides: 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnImplicitAnimationsCompleted() OVERRIDE; 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // views::WidgetObserver overrides: 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 113010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // KeyboardControllerObserver overrides: 114010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) virtual void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) OVERRIDE; 115010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ShellObserver overrides: 1171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void OnShelfAlignmentChanged(aura::Window* root_window) OVERRIDE; 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // ShelfIconObserver overrides: 1201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void OnShelfIconPositionsChanged() OVERRIDE; 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // app_list::PaginationModelObserver overrides: 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void TotalPagesChanged() OVERRIDE; 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SelectedPageChanged(int old_selected, int new_selected) OVERRIDE; 1257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual void TransitionStarted() OVERRIDE; 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void TransitionChanged() OVERRIDE; 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Whether we should show or hide app list widget. 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_visible_; 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 131010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Whether the app list should remain centered. 132010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) bool is_centered_; 133010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The AppListView this class manages, owned by its widget. 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) app_list::AppListView* view_; 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 13746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // The current page of the AppsGridView of |view_|. This is stored outside of 13846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // the view's PaginationModel, so that it persists when the view is destroyed. 13946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) int current_apps_page_; 14046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cached bounds of |view_| for snapping back animation after over-scroll. 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect view_bounds_; 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Whether should schedule snap back animation. 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool should_snap_back_; 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(AppListController); 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace ash 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // ASH_WM_APP_LIST_CONTROLLER_H_ 153