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