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 3 // found in the LICENSE file. 4 5 #ifndef UI_APP_LIST_VIEWS_APP_LIST_VIEW_H_ 6 #define UI_APP_LIST_VIEWS_APP_LIST_VIEW_H_ 7 8 #include "base/callback.h" 9 #include "base/memory/scoped_ptr.h" 10 #include "base/observer_list.h" 11 #include "ui/app_list/app_list_export.h" 12 #include "ui/app_list/app_list_view_delegate_observer.h" 13 #include "ui/app_list/speech_ui_model_observer.h" 14 #include "ui/views/bubble/bubble_delegate.h" 15 #include "ui/views/widget/widget.h" 16 17 namespace base { 18 class FilePath; 19 } 20 21 namespace app_list { 22 class ApplicationDragAndDropHost; 23 class AppListMainView; 24 class AppListModel; 25 class AppListViewDelegate; 26 class AppListViewObserver; 27 class HideViewAnimationObserver; 28 class PaginationModel; 29 class SpeechView; 30 31 // AppListView is the top-level view and controller of app list UI. It creates 32 // and hosts a AppsGridView and passes AppListModel to it for display. 33 class APP_LIST_EXPORT AppListView : public views::BubbleDelegateView, 34 public AppListViewDelegateObserver, 35 public SpeechUIModelObserver { 36 public: 37 // Takes ownership of |delegate|. 38 explicit AppListView(AppListViewDelegate* delegate); 39 virtual ~AppListView(); 40 41 // Initializes the widget and use a given |anchor| plus an |anchor_offset| for 42 // positioning. 43 void InitAsBubbleAttachedToAnchor(gfx::NativeView parent, 44 int initial_apps_page, 45 views::View* anchor, 46 const gfx::Vector2d& anchor_offset, 47 views::BubbleBorder::Arrow arrow, 48 bool border_accepts_events); 49 50 // Initializes the widget and use a fixed |anchor_point_in_screen| for 51 // positioning. 52 void InitAsBubbleAtFixedLocation(gfx::NativeView parent, 53 int initial_apps_page, 54 const gfx::Point& anchor_point_in_screen, 55 views::BubbleBorder::Arrow arrow, 56 bool border_accepts_events); 57 58 void SetBubbleArrow(views::BubbleBorder::Arrow arrow); 59 60 void SetAnchorPoint(const gfx::Point& anchor_point); 61 62 // If |drag_and_drop_host| is not NULL it will be called upon drag and drop 63 // operations outside the application list. This has to be called after 64 // InitAsBubble was called since the app list object needs to exist so that 65 // it can set the host. 66 void SetDragAndDropHostOfCurrentAppList( 67 ApplicationDragAndDropHost* drag_and_drop_host); 68 69 // Shows the UI when there are no pending icon loads. Otherwise, starts a 70 // timer to show the UI when a maximum allowed wait time has expired. 71 void ShowWhenReady(); 72 73 void Close(); 74 75 void UpdateBounds(); 76 77 // Returns true if the app list should be centered and in landscape mode. 78 bool ShouldCenterWindow() const; 79 80 // Overridden from views::View: 81 virtual gfx::Size GetPreferredSize() const OVERRIDE; 82 virtual void Paint(gfx::Canvas* canvas, 83 const views::CullSet& cull_set) OVERRIDE; 84 virtual void OnThemeChanged() OVERRIDE; 85 86 // WidgetDelegate overrides: 87 virtual bool ShouldHandleSystemCommands() const OVERRIDE; 88 89 // Overridden from AppListViewDelegateObserver: 90 virtual void OnProfilesChanged() OVERRIDE; 91 92 void Prerender(); 93 94 void SetProfileByPath(const base::FilePath& profile_path); 95 96 void AddObserver(AppListViewObserver* observer); 97 void RemoveObserver(AppListViewObserver* observer); 98 99 // Set a callback to be called the next time any app list paints. 100 void SetNextPaintCallback(const base::Closure& callback); 101 102 #if defined(OS_WIN) 103 HWND GetHWND() const; 104 #endif 105 106 AppListMainView* app_list_main_view() { return app_list_main_view_; } 107 108 // Gets the PaginationModel owned by this view's apps grid. 109 PaginationModel* GetAppsPaginationModel(); 110 111 private: 112 void InitAsBubbleInternal(gfx::NativeView parent, 113 int initial_apps_page, 114 views::BubbleBorder::Arrow arrow, 115 bool border_accepts_events, 116 const gfx::Vector2d& anchor_offset); 117 118 // Overridden from views::BubbleDelegateView: 119 virtual void OnBeforeBubbleWidgetInit( 120 views::Widget::InitParams* params, 121 views::Widget* widget) const OVERRIDE; 122 123 // Overridden from views::WidgetDelegateView: 124 virtual views::View* GetInitiallyFocusedView() OVERRIDE; 125 virtual gfx::ImageSkia GetWindowIcon() OVERRIDE; 126 virtual bool WidgetHasHitTestMask() const OVERRIDE; 127 virtual void GetWidgetHitTestMask(gfx::Path* mask) const OVERRIDE; 128 129 // Overridden from views::View: 130 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; 131 virtual void Layout() OVERRIDE; 132 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; 133 134 // Overridden from views::WidgetObserver: 135 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; 136 virtual void OnWidgetVisibilityChanged( 137 views::Widget* widget, bool visible) OVERRIDE; 138 virtual void OnWidgetActivationChanged( 139 views::Widget* widget, bool active) OVERRIDE; 140 141 // Overridden from SpeechUIModelObserver: 142 virtual void OnSpeechRecognitionStateChanged( 143 SpeechRecognitionState new_state) OVERRIDE; 144 145 scoped_ptr<AppListViewDelegate> delegate_; 146 147 AppListMainView* app_list_main_view_; 148 SpeechView* speech_view_; 149 150 ObserverList<AppListViewObserver> observers_; 151 scoped_ptr<HideViewAnimationObserver> animation_observer_; 152 153 // For UMA and testing. If non-null, triggered when the app list is painted. 154 base::Closure next_paint_callback_; 155 156 DISALLOW_COPY_AND_ASSIGN(AppListView); 157 }; 158 159 } // namespace app_list 160 161 #endif // UI_APP_LIST_VIEWS_APP_LIST_VIEW_H_ 162