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