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/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"
21 class ApplicationDragAndDropHost;
22 class AppListMainView;
24 class AppListViewDelegate;
25 class AppListViewObserver;
26 class HideViewAnimationObserver;
27 class PaginationModel;
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 {
38 // Takes ownership of |delegate|.
39 explicit AppListView(AppListViewDelegate* delegate);
40 virtual ~AppListView();
42 // Initializes the widget and use a given |anchor| plus an |anchor_offset| for
44 void InitAsBubbleAttachedToAnchor(gfx::NativeView parent,
45 PaginationModel* pagination_model,
47 const gfx::Vector2d& anchor_offset,
48 views::BubbleBorder::Arrow arrow,
49 bool border_accepts_events);
51 // Initializes the widget and use a fixed |anchor_point_in_screen| for
53 void InitAsBubbleAtFixedLocation(gfx::NativeView parent,
54 PaginationModel* pagination_model,
55 const gfx::Point& anchor_point_in_screen,
56 views::BubbleBorder::Arrow arrow,
57 bool border_accepts_events);
59 void SetBubbleArrow(views::BubbleBorder::Arrow arrow);
61 void SetAnchorPoint(const gfx::Point& anchor_point);
63 // If |drag_and_drop_host| is not NULL it will be called upon drag and drop
64 // operations outside the application list. This has to be called after
65 // InitAsBubble was called since the app list object needs to exist so that
66 // it can set the host.
67 void SetDragAndDropHostOfCurrentAppList(
68 ApplicationDragAndDropHost* drag_and_drop_host);
70 // Shows the UI when there are no pending icon loads. Otherwise, starts a
71 // timer to show the UI when a maximum allowed wait time has expired.
78 // Returns true if the app list should be centered and in landscape mode.
79 bool ShouldCenterWindow() const;
81 // Overridden from views::View:
82 virtual gfx::Size GetPreferredSize() OVERRIDE;
83 virtual void Paint(gfx::Canvas* canvas) 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 static void SetNextPaintCallback(void (*callback)());
103 HWND GetHWND() const;
106 AppListMainView* app_list_main_view() { return app_list_main_view_; }
109 void InitAsBubbleInternal(gfx::NativeView parent,
110 PaginationModel* pagination_model,
111 views::BubbleBorder::Arrow arrow,
112 bool border_accepts_events,
113 const gfx::Vector2d& anchor_offset);
115 // Overridden from views::BubbleDelegateView:
116 virtual void OnBeforeBubbleWidgetInit(
117 views::Widget::InitParams* params,
118 views::Widget* widget) const OVERRIDE;
120 // Overridden from views::WidgetDelegateView:
121 virtual views::View* GetInitiallyFocusedView() OVERRIDE;
122 virtual gfx::ImageSkia GetWindowIcon() OVERRIDE;
123 virtual bool WidgetHasHitTestMask() const OVERRIDE;
124 virtual void GetWidgetHitTestMask(gfx::Path* mask) const OVERRIDE;
126 // Overridden from views::View:
127 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
128 virtual void Layout() OVERRIDE;
129 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
131 // Overridden from views::WidgetObserver:
132 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
133 virtual void OnWidgetVisibilityChanged(
134 views::Widget* widget, bool visible) OVERRIDE;
135 virtual void OnWidgetActivationChanged(
136 views::Widget* widget, bool active) OVERRIDE;
138 // Overridden from SpeechUIModelObserver:
139 virtual void OnSpeechRecognitionStateChanged(
140 SpeechRecognitionState new_state) OVERRIDE;
142 SigninDelegate* GetSigninDelegate();
144 scoped_ptr<AppListViewDelegate> delegate_;
146 AppListMainView* app_list_main_view_;
147 SigninView* signin_view_;
148 SpeechView* speech_view_;
150 ObserverList<AppListViewObserver> observers_;
151 scoped_ptr<HideViewAnimationObserver> animation_observer_;
153 DISALLOW_COPY_AND_ASSIGN(AppListView);
156 } // namespace app_list
158 #endif // UI_APP_LIST_VIEWS_APP_LIST_VIEW_H_