Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef UI_APP_LIST_VIEWS_APP_LIST_VIEW_H_ | 5 #ifndef UI_APP_LIST_VIEWS_APP_LIST_VIEW_H_ | 
| 6 #define UI_APP_LIST_VIEWS_APP_LIST_VIEW_H_ | 6 #define UI_APP_LIST_VIEWS_APP_LIST_VIEW_H_ | 
| 7 | 7 | 
| 8 #include <memory> | 8 #include <memory> | 
| 9 | 9 | 
| 10 #include "base/callback.h" | 10 #include "base/callback.h" | 
| 11 #include "base/macros.h" | 11 #include "base/macros.h" | 
| 12 #include "base/scoped_observer.h" | |
| 12 #include "build/build_config.h" | 13 #include "build/build_config.h" | 
| 13 #include "ui/app_list/app_list_export.h" | 14 #include "ui/app_list/app_list_export.h" | 
| 14 #include "ui/app_list/speech_ui_model_observer.h" | 15 #include "ui/app_list/speech_ui_model_observer.h" | 
| 16 #include "ui/display/display_observer.h" | |
| 15 #include "ui/views/bubble/bubble_dialog_delegate.h" | 17 #include "ui/views/bubble/bubble_dialog_delegate.h" | 
| 16 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" | 
| 17 | 19 | 
| 20 namespace display { | |
| 21 class Screen; | |
| 22 } | |
| 23 | |
| 18 namespace app_list { | 24 namespace app_list { | 
| 19 class ApplicationDragAndDropHost; | 25 class ApplicationDragAndDropHost; | 
| 20 class AppListMainView; | 26 class AppListMainView; | 
| 21 class AppListModel; | 27 class AppListModel; | 
| 22 class AppListViewDelegate; | 28 class AppListViewDelegate; | 
| 23 class HideViewAnimationObserver; | 29 class HideViewAnimationObserver; | 
| 24 class PaginationModel; | 30 class PaginationModel; | 
| 25 class SearchBoxView; | 31 class SearchBoxView; | 
| 26 class SpeechView; | 32 class SpeechView; | 
| 27 | 33 | 
| 28 namespace test { | 34 namespace test { | 
| 29 class AppListViewTestApi; | 35 class AppListViewTestApi; | 
| 30 } | 36 } | 
| 31 | 37 | 
| 32 // AppListView is the top-level view and controller of app list UI. It creates | 38 // 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. | 39 // and hosts a AppsGridView and passes AppListModel to it for display. | 
| 34 class APP_LIST_EXPORT AppListView : public views::BubbleDialogDelegateView, | 40 class APP_LIST_EXPORT AppListView : public views::BubbleDialogDelegateView, | 
| 35 public SpeechUIModelObserver { | 41 public SpeechUIModelObserver, | 
| 42 public display::DisplayObserver { | |
| 36 public: | 43 public: | 
| 44 enum AppListState { | |
| 45 // If set, closes |app_list_main_view_| and dismisses the delegate. | |
| 46 CLOSED = 0, | |
| 47 | |
| 48 // The initial state for the app list. If set, the widget will peek over | |
| 49 // the shelf by KPeekingAppListHeight DIPs. | |
| 
 
msw
2017/06/07 17:44:06
Lowercase 'k'
 
newcomer
2017/06/07 19:01:42
Done.
 
 | |
| 50 PEEKING, | |
| 51 | |
| 52 // If set, the widget will be repositioned to take up the whole screen. | |
| 53 FULLSCREEN | |
| 
 
msw
2017/06/07 17:44:06
optional nit: a trailing comma indicates that it's
 
newcomer
2017/06/07 19:01:42
Done.
 
 | |
| 54 }; | |
| 55 | |
| 37 // Does not take ownership of |delegate|. | 56 // Does not take ownership of |delegate|. | 
| 38 explicit AppListView(AppListViewDelegate* delegate); | 57 explicit AppListView(AppListViewDelegate* delegate); | 
| 39 ~AppListView() override; | 58 ~AppListView() override; | 
| 40 | 59 | 
| 41 // Initializes the widget as a bubble or fullscreen view depending on the | 60 // Initializes the widget as a bubble or fullscreen view depending on if the | 
| 42 // presence of a cmd line switch. parent and initial_apps_page are used for | 61 // fullscreen app list feature is set. |parent| and |initial_apps_page| are | 
| 43 // both the bubble and fullscreen initialization. | 62 // used for both the bubble and fullscreen initialization. | 
| 44 void Initialize(gfx::NativeView parent, int initial_apps_page); | 63 void Initialize(gfx::NativeView parent, int initial_apps_page); | 
| 45 | 64 | 
| 46 void SetBubbleArrow(views::BubbleBorder::Arrow arrow); | 65 void SetBubbleArrow(views::BubbleBorder::Arrow arrow); | 
| 47 | 66 | 
| 48 void MaybeSetAnchorPoint(const gfx::Point& anchor_point); | 67 void MaybeSetAnchorPoint(const gfx::Point& anchor_point); | 
| 49 | 68 | 
| 50 // If |drag_and_drop_host| is not NULL it will be called upon drag and drop | 69 // If |drag_and_drop_host| is not NULL it will be called upon drag and drop | 
| 51 // operations outside the application list. This has to be called after | 70 // operations outside the application list. This has to be called after | 
| 52 // Initialize was called since the app list object needs to exist so that | 71 // Initialize was called since the app list object needs to exist so that | 
| 53 // it can set the host. | 72 // it can set the host. | 
| 54 void SetDragAndDropHostOfCurrentAppList( | 73 void SetDragAndDropHostOfCurrentAppList( | 
| 55 ApplicationDragAndDropHost* drag_and_drop_host); | 74 ApplicationDragAndDropHost* drag_and_drop_host); | 
| 56 | 75 | 
| 57 // Shows the UI when there are no pending icon loads. Otherwise, starts a | 76 // Shows the UI when there are no pending icon loads. Otherwise, starts a | 
| 58 // timer to show the UI when a maximum allowed wait time has expired. | 77 // timer to show the UI when a maximum allowed wait time has expired. | 
| 59 void ShowWhenReady(); | 78 void ShowWhenReady(); | 
| 60 | 79 | 
| 61 void CloseAppList(); | |
| 62 | |
| 63 void UpdateBounds(); | 80 void UpdateBounds(); | 
| 64 | 81 | 
| 65 // Enables/disables a semi-transparent overlay over the app list (good for | 82 // Enables/disables a semi-transparent overlay over the app list (good for | 
| 66 // hiding the app list when a modal dialog is being shown). | 83 // hiding the app list when a modal dialog is being shown). | 
| 67 void SetAppListOverlayVisible(bool visible); | 84 void SetAppListOverlayVisible(bool visible); | 
| 68 | 85 | 
| 69 views::Widget* search_box_widget() const { return search_box_widget_; } | 86 views::Widget* search_box_widget() const { return search_box_widget_; } | 
| 70 | 87 | 
| 71 // Overridden from views::View: | 88 // Overridden from views::View: | 
| 72 gfx::Size CalculatePreferredSize() const override; | 89 gfx::Size CalculatePreferredSize() const override; | 
| 73 void OnPaint(gfx::Canvas* canvas) override; | 90 void OnPaint(gfx::Canvas* canvas) override; | 
| 74 const char* GetClassName() const override; | 91 const char* GetClassName() const override; | 
| 75 | 92 | 
| 76 // WidgetDelegate overrides: | 93 // WidgetDelegate overrides: | 
| 77 bool ShouldHandleSystemCommands() const override; | 94 bool ShouldHandleSystemCommands() const override; | 
| 78 bool ShouldDescendIntoChildForEventHandling( | 95 bool ShouldDescendIntoChildForEventHandling( | 
| 79 gfx::NativeView child, | 96 gfx::NativeView child, | 
| 80 const gfx::Point& location) override; | 97 const gfx::Point& location) override; | 
| 81 | 98 | 
| 82 AppListMainView* app_list_main_view() { return app_list_main_view_; } | 99 AppListMainView* app_list_main_view() { return app_list_main_view_; } | 
| 83 | 100 | 
| 84 // Gets the PaginationModel owned by this view's apps grid. | 101 // Gets the PaginationModel owned by this view's apps grid. | 
| 85 PaginationModel* GetAppsPaginationModel(); | 102 PaginationModel* GetAppsPaginationModel(); | 
| 86 | 103 | 
| 87 // Overridden from views::View: | 104 // Overridden from views::View: | 
| 88 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; | 105 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; | 
| 89 void Layout() override; | 106 void Layout() override; | 
| 90 void SchedulePaintInRect(const gfx::Rect& rect) override; | 107 void SchedulePaintInRect(const gfx::Rect& rect) override; | 
| 91 | 108 | 
| 109 // Changes the app list state. | |
| 110 void SetState(AppListState new_state); | |
| 111 | |
| 112 bool IsFullscreen() const { return app_list_state_ == FULLSCREEN; } | |
| 
 
msw
2017/06/07 17:44:06
nit: |is_fullscreen| for inline simple accessors/h
 
newcomer
2017/06/07 19:01:42
Done.
 
 | |
| 113 AppListState app_list_state() const { return app_list_state_; } | |
| 114 | |
| 92 private: | 115 private: | 
| 93 friend class test::AppListViewTestApi; | 116 friend class test::AppListViewTestApi; | 
| 94 | 117 | 
| 95 void InitContents(gfx::NativeView parent, int initial_apps_page); | 118 void InitContents(gfx::NativeView parent, int initial_apps_page); | 
| 96 | 119 | 
| 97 void InitChildWidgets(); | 120 void InitChildWidgets(); | 
| 98 | 121 | 
| 99 // Initializes the widget for fullscreen mode. | 122 // Initializes the widget for fullscreen mode. | 
| 100 void InitializeFullscreen(gfx::NativeView parent, int initial_apps_page); | 123 void InitializeFullscreen(gfx::NativeView parent, int initial_apps_page); | 
| 101 | 124 | 
| 102 // Initializes the widget as a bubble. | 125 // Initializes the widget as a bubble. | 
| 103 void InitializeBubble(gfx::NativeView parent, int initial_apps_page); | 126 void InitializeBubble(gfx::NativeView parent, int initial_apps_page); | 
| 104 | 127 | 
| 128 // Initializes |initial_drag_point_|. | |
| 129 void StartDrag(const gfx::Point& location); | |
| 130 | |
| 131 // Updates the bounds of the widget while maintaining the relative position | |
| 132 // of the top of the widget and the gesture. | |
| 133 void UpdateDrag(const gfx::Point& location); | |
| 134 | |
| 135 // Handles app list state transfers. If the drag was fast enough, ignore the | |
| 136 // release position and snap to the next state. | |
| 137 void EndDrag(const gfx::Point& location); | |
| 138 | |
| 105 // Overridden from views::BubbleDialogDelegateView: | 139 // Overridden from views::BubbleDialogDelegateView: | 
| 106 void OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, | 140 void OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, | 
| 107 views::Widget* widget) const override; | 141 views::Widget* widget) const override; | 
| 108 int GetDialogButtons() const override; | 142 int GetDialogButtons() const override; | 
| 109 | 143 | 
| 110 // Overridden from views::WidgetDelegateView: | 144 // Overridden from views::WidgetDelegateView: | 
| 111 views::View* GetInitiallyFocusedView() override; | 145 views::View* GetInitiallyFocusedView() override; | 
| 112 bool WidgetHasHitTestMask() const override; | 146 bool WidgetHasHitTestMask() const override; | 
| 113 void GetWidgetHitTestMask(gfx::Path* mask) const override; | 147 void GetWidgetHitTestMask(gfx::Path* mask) const override; | 
| 114 | 148 | 
| 149 // Overridden from ui::EventHandler: | |
| 150 void OnMouseEvent(ui::MouseEvent* event) override; | |
| 151 void OnGestureEvent(ui::GestureEvent* event) override; | |
| 152 | |
| 115 // Overridden from views::WidgetObserver: | 153 // Overridden from views::WidgetObserver: | 
| 116 void OnWidgetDestroying(views::Widget* widget) override; | 154 void OnWidgetDestroying(views::Widget* widget) override; | 
| 117 void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override; | 155 void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override; | 
| 118 | 156 | 
| 119 // Overridden from SpeechUIModelObserver: | 157 // Overridden from SpeechUIModelObserver: | 
| 120 void OnSpeechRecognitionStateChanged( | 158 void OnSpeechRecognitionStateChanged( | 
| 121 SpeechRecognitionState new_state) override; | 159 SpeechRecognitionState new_state) override; | 
| 122 | 160 | 
| 161 // Overridden from DisplayObserver: | |
| 162 void OnDisplayMetricsChanged(const display::Display& display, | |
| 163 uint32_t changed_metrics) override; | |
| 164 | |
| 123 AppListViewDelegate* delegate_; // Weak. Owned by AppListService. | 165 AppListViewDelegate* delegate_; // Weak. Owned by AppListService. | 
| 124 | 166 | 
| 125 AppListMainView* app_list_main_view_; | 167 AppListMainView* app_list_main_view_; | 
| 126 SpeechView* speech_view_; | 168 SpeechView* speech_view_; | 
| 169 views::Widget* fullscreen_widget_ = nullptr; // Owned by AppListView. | |
| 127 | 170 | 
| 128 views::View* search_box_focus_host_; // Owned by the views hierarchy. | 171 views::View* search_box_focus_host_; // Owned by the views hierarchy. | 
| 129 views::Widget* search_box_widget_; // Owned by the app list's widget. | 172 views::Widget* search_box_widget_; // Owned by the app list's widget. | 
| 130 SearchBoxView* search_box_view_; // Owned by |search_box_widget_|. | 173 SearchBoxView* search_box_view_; // Owned by |search_box_widget_|. | 
| 174 // Owned by the app list's widget. Null if the fullscreen app list is not | |
| 175 // enabled. | |
| 176 views::View* app_list_background_shield_ = nullptr; | |
| 177 // The gap between the initial gesture event and the top of the window. | |
| 178 gfx::Point initial_drag_point_; | |
| 179 // The velocity of the gesture event. | |
| 180 float last_fling_velocity_ = 0; | |
| 181 // The state of the app list, controlled via SetState(). | |
| 182 AppListState app_list_state_; | |
| 183 | |
| 184 // An observer that notifies AppListView when the display has changed. | |
| 185 ScopedObserver<display::Screen, display::DisplayObserver> display_observer_; | |
| 131 | 186 | 
| 132 // A semi-transparent white overlay that covers the app list while dialogs are | 187 // A semi-transparent white overlay that covers the app list while dialogs are | 
| 133 // open. | 188 // open. | 
| 134 views::View* overlay_view_; | 189 views::View* overlay_view_; | 
| 135 | 190 | 
| 136 std::unique_ptr<HideViewAnimationObserver> animation_observer_; | 191 std::unique_ptr<HideViewAnimationObserver> animation_observer_; | 
| 137 | 192 | 
| 138 // For UMA and testing. If non-null, triggered when the app list is painted. | 193 // For UMA and testing. If non-null, triggered when the app list is painted. | 
| 139 base::Closure next_paint_callback_; | 194 base::Closure next_paint_callback_; | 
| 140 | 195 | 
| 141 DISALLOW_COPY_AND_ASSIGN(AppListView); | 196 DISALLOW_COPY_AND_ASSIGN(AppListView); | 
| 142 }; | 197 }; | 
| 143 | 198 | 
| 144 } // namespace app_list | 199 } // namespace app_list | 
| 145 | 200 | 
| 146 #endif // UI_APP_LIST_VIEWS_APP_LIST_VIEW_H_ | 201 #endif // UI_APP_LIST_VIEWS_APP_LIST_VIEW_H_ | 
| OLD | NEW |