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