Upstream version 7.36.149.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/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   // Takes ownership of |delegate|.
39   explicit AppListView(AppListViewDelegate* delegate);
40   virtual ~AppListView();
41
42   // Initializes the widget and use a given |anchor| plus an |anchor_offset| for
43   // positioning.
44   void InitAsBubbleAttachedToAnchor(gfx::NativeView parent,
45                                     PaginationModel* pagination_model,
46                                     views::View* anchor,
47                                     const gfx::Vector2d& anchor_offset,
48                                     views::BubbleBorder::Arrow arrow,
49                                     bool border_accepts_events);
50
51   // Initializes the widget and use a fixed |anchor_point_in_screen| for
52   // positioning.
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);
58
59   void SetBubbleArrow(views::BubbleBorder::Arrow arrow);
60
61   void SetAnchorPoint(const gfx::Point& anchor_point);
62
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);
69
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.
72   void ShowWhenReady();
73
74   void Close();
75
76   void UpdateBounds();
77
78   // Returns true if the app list should be centered and in landscape mode.
79   bool ShouldCenterWindow() const;
80
81   // Overridden from views::View:
82   virtual gfx::Size GetPreferredSize() OVERRIDE;
83   virtual void Paint(gfx::Canvas* canvas) OVERRIDE;
84   virtual void OnThemeChanged() OVERRIDE;
85
86   // WidgetDelegate overrides:
87   virtual bool ShouldHandleSystemCommands() const OVERRIDE;
88
89   // Overridden from AppListViewDelegateObserver:
90   virtual void OnProfilesChanged() OVERRIDE;
91
92   void Prerender();
93
94   void SetProfileByPath(const base::FilePath& profile_path);
95
96   void AddObserver(AppListViewObserver* observer);
97   void RemoveObserver(AppListViewObserver* observer);
98
99   // Set a callback to be called the next time any app list paints.
100   static void SetNextPaintCallback(void (*callback)());
101
102 #if defined(OS_WIN)
103   HWND GetHWND() const;
104 #endif
105
106   AppListMainView* app_list_main_view() { return app_list_main_view_; }
107
108  private:
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);
114
115   // Overridden from views::BubbleDelegateView:
116   virtual void OnBeforeBubbleWidgetInit(
117       views::Widget::InitParams* params,
118       views::Widget* widget) const OVERRIDE;
119
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;
125
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;
130
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;
137
138   // Overridden from SpeechUIModelObserver:
139   virtual void OnSpeechRecognitionStateChanged(
140       SpeechRecognitionState new_state) OVERRIDE;
141
142   SigninDelegate* GetSigninDelegate();
143
144   scoped_ptr<AppListViewDelegate> delegate_;
145
146   AppListMainView* app_list_main_view_;
147   SigninView* signin_view_;
148   SpeechView* speech_view_;
149
150   ObserverList<AppListViewObserver> observers_;
151   scoped_ptr<HideViewAnimationObserver> animation_observer_;
152
153   DISALLOW_COPY_AND_ASSIGN(AppListView);
154 };
155
156 }  // namespace app_list
157
158 #endif  // UI_APP_LIST_VIEWS_APP_LIST_VIEW_H_