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 ApplicationDragAndDropHost
;
23 class AppListMainView
;
25 class AppListViewDelegate
;
26 class AppListViewObserver
;
27 class HideViewAnimationObserver
;
28 class PaginationModel
;
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
{
37 // Takes ownership of |delegate|.
38 explicit AppListView(AppListViewDelegate
* delegate
);
39 virtual ~AppListView();
41 // Initializes the widget and use a given |anchor| plus an |anchor_offset| for
43 void InitAsBubbleAttachedToAnchor(gfx::NativeView parent
,
44 int initial_apps_page
,
46 const gfx::Vector2d
& anchor_offset
,
47 views::BubbleBorder::Arrow arrow
,
48 bool border_accepts_events
);
50 // Initializes the widget and use a fixed |anchor_point_in_screen| for
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
);
58 void SetBubbleArrow(views::BubbleBorder::Arrow arrow
);
60 void SetAnchorPoint(const gfx::Point
& anchor_point
);
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
);
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.
77 // Returns true if the app list should be centered and in landscape mode.
78 bool ShouldCenterWindow() const;
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
;
86 // WidgetDelegate overrides:
87 virtual bool ShouldHandleSystemCommands() const OVERRIDE
;
89 // Overridden from AppListViewDelegateObserver:
90 virtual void OnProfilesChanged() OVERRIDE
;
94 void SetProfileByPath(const base::FilePath
& profile_path
);
96 void AddObserver(AppListViewObserver
* observer
);
97 void RemoveObserver(AppListViewObserver
* observer
);
99 // Set a callback to be called the next time any app list paints.
100 void SetNextPaintCallback(const base::Closure
& callback
);
103 HWND
GetHWND() const;
106 AppListMainView
* app_list_main_view() { return app_list_main_view_
; }
108 // Gets the PaginationModel owned by this view's apps grid.
109 PaginationModel
* GetAppsPaginationModel();
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
);
118 // Overridden from views::BubbleDelegateView:
119 virtual void OnBeforeBubbleWidgetInit(
120 views::Widget::InitParams
* params
,
121 views::Widget
* widget
) const OVERRIDE
;
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
;
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
;
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
;
141 // Overridden from SpeechUIModelObserver:
142 virtual void OnSpeechRecognitionStateChanged(
143 SpeechRecognitionState new_state
) OVERRIDE
;
145 scoped_ptr
<AppListViewDelegate
> delegate_
;
147 AppListMainView
* app_list_main_view_
;
148 SpeechView
* speech_view_
;
150 ObserverList
<AppListViewObserver
> observers_
;
151 scoped_ptr
<HideViewAnimationObserver
> animation_observer_
;
153 // For UMA and testing. If non-null, triggered when the app list is painted.
154 base::Closure next_paint_callback_
;
156 DISALLOW_COPY_AND_ASSIGN(AppListView
);
159 } // namespace app_list
161 #endif // UI_APP_LIST_VIEWS_APP_LIST_VIEW_H_