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.
5 #ifndef UI_APP_LIST_VIEWS_APP_LIST_VIEW_H_
6 #define UI_APP_LIST_VIEWS_APP_LIST_VIEW_H_
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"
22 class AppListViewTestApi;
30 class ApplicationDragAndDropHost;
31 class AppListMainView;
33 class AppListViewDelegate;
34 class AppListViewObserver;
35 class HideViewAnimationObserver;
36 class PaginationModel;
40 // AppListView is the top-level view and controller of app list UI. It creates
41 // and hosts a AppsGridView and passes AppListModel to it for display.
42 class APP_LIST_EXPORT AppListView : public views::BubbleDelegateView,
43 public AppListViewDelegateObserver,
44 public SpeechUIModelObserver {
46 // Does not take ownership of |delegate|.
47 explicit AppListView(AppListViewDelegate* delegate);
48 ~AppListView() override;
50 // Initializes the widget and use a given |anchor| plus an |anchor_offset| for
52 void InitAsBubbleAttachedToAnchor(gfx::NativeView parent,
53 int initial_apps_page,
55 const gfx::Vector2d& anchor_offset,
56 views::BubbleBorder::Arrow arrow,
57 bool border_accepts_events);
59 // Initializes the widget and use a fixed |anchor_point_in_screen| for
61 void InitAsBubbleAtFixedLocation(gfx::NativeView parent,
62 int initial_apps_page,
63 const gfx::Point& anchor_point_in_screen,
64 views::BubbleBorder::Arrow arrow,
65 bool border_accepts_events);
67 void SetBubbleArrow(views::BubbleBorder::Arrow arrow);
69 void SetAnchorPoint(const gfx::Point& anchor_point);
71 // If |drag_and_drop_host| is not NULL it will be called upon drag and drop
72 // operations outside the application list. This has to be called after
73 // InitAsBubble was called since the app list object needs to exist so that
74 // it can set the host.
75 void SetDragAndDropHostOfCurrentAppList(
76 ApplicationDragAndDropHost* drag_and_drop_host);
78 // Shows the UI when there are no pending icon loads. Otherwise, starts a
79 // timer to show the UI when a maximum allowed wait time has expired.
86 // Enables/disables a semi-transparent overlay over the app list (good for
87 // hiding the app list when a modal dialog is being shown).
88 void SetAppListOverlayVisible(bool visible);
90 // Returns true if the app list should be centered and in landscape mode.
91 bool ShouldCenterWindow() const;
93 // Overridden from views::View:
94 gfx::Size GetPreferredSize() const override;
95 void Paint(gfx::Canvas* canvas, const views::CullSet& cull_set) override;
96 void OnThemeChanged() override;
98 // WidgetDelegate overrides:
99 bool ShouldHandleSystemCommands() const override;
101 // Overridden from AppListViewDelegateObserver:
102 void OnProfilesChanged() override;
103 void OnShutdown() override;
107 void SetProfileByPath(const base::FilePath& profile_path);
109 void AddObserver(AppListViewObserver* observer);
110 void RemoveObserver(AppListViewObserver* observer);
112 // Set a callback to be called the next time any app list paints.
113 void SetNextPaintCallback(const base::Closure& callback);
116 HWND GetHWND() const;
119 AppListMainView* app_list_main_view() { return app_list_main_view_; }
121 // Gets the PaginationModel owned by this view's apps grid.
122 PaginationModel* GetAppsPaginationModel();
125 friend class ::test::AppListViewTestApi;
127 void InitAsBubbleInternal(gfx::NativeView parent,
128 int initial_apps_page,
129 views::BubbleBorder::Arrow arrow,
130 bool border_accepts_events,
131 const gfx::Vector2d& anchor_offset);
133 // Overridden from views::BubbleDelegateView:
134 void OnBeforeBubbleWidgetInit(views::Widget::InitParams* params,
135 views::Widget* widget) const override;
137 // Overridden from views::WidgetDelegateView:
138 views::View* GetInitiallyFocusedView() override;
139 gfx::ImageSkia GetWindowIcon() override;
140 bool WidgetHasHitTestMask() const override;
141 void GetWidgetHitTestMask(gfx::Path* mask) const override;
143 // Overridden from views::View:
144 bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
145 void Layout() override;
146 void SchedulePaintInRect(const gfx::Rect& rect) override;
148 // Overridden from views::WidgetObserver:
149 void OnWidgetDestroying(views::Widget* widget) override;
150 void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override;
151 void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
153 // Overridden from SpeechUIModelObserver:
154 void OnSpeechRecognitionStateChanged(
155 SpeechRecognitionState new_state) override;
157 AppListViewDelegate* delegate_; // Weak. Owned by AppListService.
159 AppListMainView* app_list_main_view_;
160 SearchBoxView* search_box_view_;
161 SpeechView* speech_view_;
163 // The red "experimental" banner for the experimental app list.
164 views::ImageView* experimental_banner_view_;
166 // A semi-transparent white overlay that covers the app list while dialogs are
168 views::View* overlay_view_;
170 ObserverList<AppListViewObserver> observers_;
171 scoped_ptr<HideViewAnimationObserver> animation_observer_;
173 // For UMA and testing. If non-null, triggered when the app list is painted.
174 base::Closure next_paint_callback_;
176 DISALLOW_COPY_AND_ASSIGN(AppListView);
179 } // namespace app_list
181 #endif // UI_APP_LIST_VIEWS_APP_LIST_VIEW_H_