Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / ui / app_list / views / apps_grid_view.h
index 13e1a51..fefa9f2 100644 (file)
@@ -6,13 +6,16 @@
 #define UI_APP_LIST_VIEWS_APPS_GRID_VIEW_H_
 
 #include <set>
+#include <string>
 
 #include "base/basictypes.h"
 #include "base/compiler_specific.h"
+#include "base/memory/ref_counted.h"
 #include "base/timer/timer.h"
 #include "ui/app_list/app_list_export.h"
 #include "ui/app_list/app_list_model.h"
 #include "ui/app_list/app_list_model_observer.h"
+#include "ui/app_list/pagination_model.h"
 #include "ui/app_list/pagination_model_observer.h"
 #include "ui/base/models/list_model_observer.h"
 #include "ui/compositor/layer_animation_observer.h"
 #include "ui/base/dragdrop/drag_source_win.h"
 #endif
 
-namespace content {
-class WebContents;
-}
-
 namespace views {
 class ButtonListener;
 class DragImageView;
-class WebView;
 }
 
 namespace app_list {
@@ -50,8 +48,9 @@ class AppsGridViewTestApi;
 class ApplicationDragAndDropHost;
 class AppListItemView;
 class AppsGridViewDelegate;
+class AppsGridViewFolderDelegate;
 class PageSwitcher;
-class PaginationModel;
+class PaginationController;
 
 // AppsGridView displays a grid for AppListItemList sub model.
 class APP_LIST_EXPORT AppsGridView : public views::View,
@@ -68,18 +67,19 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
   };
 
   // Constructs the app icon grid view. |delegate| is the delegate of this
-  // view, which usually is the hosting AppListView. |pagination_model| is
-  // the paging info shared within the launcher UI.
-  AppsGridView(AppsGridViewDelegate* delegate,
-               PaginationModel* pagination_model);
+  // view, which usually is the hosting AppListView.
+  explicit AppsGridView(AppsGridViewDelegate* delegate);
   virtual ~AppsGridView();
 
   // Sets fixed layout parameters. After setting this, CalculateLayout below
   // is no longer called to dynamically choosing those layout params.
-  void SetLayout(int icon_size, int cols, int rows_per_page);
+  void SetLayout(int cols, int rows_per_page);
 
-  int cols() { return cols_; }
-  int rows_per_page() { return rows_per_page_; }
+  int cols() const { return cols_; }
+  int rows_per_page() const { return rows_per_page_; }
+
+  // This resets the grid view to a fresh state for showing the app list.
+  void ResetForShowApps();
 
   // Sets |model| to use. Note this does not take ownership of |model|.
   void SetModel(AppListModel* model);
@@ -110,27 +110,31 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
   void UpdateDrag(Pointer pointer, const gfx::Point& point);
   void EndDrag(bool cancel);
   bool IsDraggedView(const views::View* view) const;
-
-  void StartSettingUpSynchronousDrag();
-  bool RunSynchronousDrag();
-  void CleanUpSynchronousDrag();
-  void OnGotShortcutPath(const base::FilePath& path);
+  void ClearDragState();
+  void SetDragViewVisible(bool visible);
 
   // Set the drag and drop host for application links.
   void SetDragAndDropHostOfCurrentAppList(
       ApplicationDragAndDropHost* drag_and_drop_host);
 
-  // Prerenders the icons on and around |page_index|.
-  void Prerender(int page_index);
+  // Prerenders the icons on and around the currently selected page.
+  void Prerender();
+
+  // Return true if the |bounds_animator_| is animating |view|.
+  bool IsAnimatingView(views::View* view);
 
   bool has_dragged_view() const { return drag_view_ != NULL; }
   bool dragging() const { return drag_pointer_ != NONE; }
 
+  // Gets the PaginationModel used for the grid view.
+  PaginationModel* pagination_model() { return &pagination_model_; }
+
   // Overridden from views::View:
-  virtual gfx::Size GetPreferredSize() OVERRIDE;
+  virtual gfx::Size GetPreferredSize() const OVERRIDE;
   virtual void Layout() OVERRIDE;
   virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
   virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE;
+  virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE;
   virtual void ViewHierarchyChanged(
       const ViewHierarchyChangedDetails& details) OVERRIDE;
   virtual bool GetDropFormats(
@@ -139,6 +143,10 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
   virtual bool CanDrop(const OSExchangeData& data) OVERRIDE;
   virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE;
 
+  // Overridden from ui::EventHandler:
+  virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
+  virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
+
   // Stops the timer that triggers a page flip during a drag.
   void StopPageFlipTimer();
 
@@ -163,18 +171,20 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
   // Updates drag in the root level grid view when receiving the drag event
   // dispatched from the hidden grid view for reparenting a folder item.
   void UpdateDragFromReparentItem(Pointer pointer,
-      const ui::LocatedEvent& event);
+                                  const gfx::Point& drag_point);
 
   // Dispatches the drag event from hidden grid view to the top level grid view.
   void DispatchDragEventForReparent(Pointer pointer,
-      const ui::LocatedEvent& event);
+                                    const gfx::Point& drag_point);
 
   // Handles EndDrag event dispatched from the hidden folder grid view in the
   // root level grid view to end reparenting a folder item.
   // |events_forwarded_to_drag_drop_host|: True if the dragged item is dropped
   // to the drag_drop_host, eg. dropped on shelf.
+  // |cancel_drag|: True if the drag is ending because it has been canceled.
   void EndDragFromReparentItemInRootLevel(
-      bool events_forwarded_to_drag_drop_host);
+      bool events_forwarded_to_drag_drop_host,
+      bool cancel_drag);
 
   // Handles EndDrag event in the hidden folder grid view to end reparenting
   // a folder item.
@@ -195,12 +205,16 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
     return forward_events_to_drag_and_drop_host_;
   }
 
-  void set_is_root_level(bool value) { is_root_level_ = value; }
+  void set_folder_delegate(AppsGridViewFolderDelegate* folder_delegate) {
+    folder_delegate_ = folder_delegate;
+  }
 
-  AppListItemView* activated_item_view() const {
-    return activated_item_view_;
+  AppListItemView* activated_folder_item_view() const {
+    return activated_folder_item_view_;
   }
 
+  const AppListModel* model() const { return model_; }
+
  private:
   friend class test::AppsGridViewTestApi;
 
@@ -221,6 +235,12 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
     bool operator!=(const Index& other) const {
       return page != other.page || slot != other.slot;
     }
+    bool operator<(const Index& other) const {
+      if (page != other.page)
+        return page < other.page;
+
+      return slot < other.slot;
+    }
 
     int page;  // Which page an item view is on.
     int slot;  // Which slot in the page an item view is in.
@@ -252,6 +272,9 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
   Index GetIndexOfView(const views::View* view) const;
   views::View* GetViewAtIndex(const Index& index) const;
 
+  // Gets the index of the AppListItemView at the end of the view model.
+  Index GetLastViewIndex() const;
+
   void MoveSelected(int page_delta, int slot_x_delta, int slot_y_delta);
 
   void CalculateIdealBounds();
@@ -274,19 +297,19 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
   void ExtractDragLocation(const ui::LocatedEvent& event,
                            gfx::Point* drag_point);
 
-  // Calculates |drop_target_| based on |drag_point|. |drag_point| is in the
-  // grid view's coordinates. When |use_page_button_hovering| is true and
-  // |drag_point| is hovering on a page button, use the last slot on that page
-  // as drop target.
-  void CalculateDropTarget(const gfx::Point& drag_point,
-                           bool use_page_button_hovering);
+  // Updates |reorder_drop_target_|, |folder_drop_target_| and |drop_attempt_|
+  // based on |drag_view_|'s position.
+  void CalculateDropTarget();
+
+  // If |point| is a valid folder drop target, returns true and sets
+  // |drop_target| to the index of the view to do a folder drop for.
+  bool CalculateFolderDropTarget(const gfx::Point& point,
+                                 Index* drop_target) const;
 
-  // Same as CalculateDropTarget, but with folder UI enabled. The |drop_target_|
-  // can be either a target for re-ordering, or a target folder to move the
-  // dragged item into if |drag_view_| enters its re-ordering or folder
-  // dropping circle.
-  void CalculateDropTargetWithFolderEnabled(const gfx::Point& drag_point,
-                                            bool use_page_button_hovering);
+  // Calculates the reorder target |point| and sets |drop_target| to the index
+  // of the view to reorder.
+  void CalculateReorderDropTarget(const gfx::Point& point,
+                                  Index* drop_target) const;
 
   // Prepares |drag_and_drop_host_| for dragging. |grid_location| contains
   // the drag point in this grid view's coordinates.
@@ -374,29 +397,20 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
 
   // Whether target specified by |drap_target| can accept more items to be
   // dropped into it.
-  bool CanDropIntoTarget(const Index& drop_target);
+  bool CanDropIntoTarget(const Index& drop_target) const;
 
-  // Returns the visual index of the nearest tile in which |drag_view_| enters
-  // either its re-ordering or folder dropping circle.
-  Index GetNearestTileForDragView();
+  // Returns the size of the entire tile grid.
+  gfx::Size GetTileGridSize() const;
 
-  // Calculates |nearest_tile| in which |vertex| of the |drag_view| is
-  // enclosed.
-  // *|nearest_tile| and *|d_min| will be updated based on the calculation.
-  // *|d_min| is the distance between |nearest_tile| and |drag_view_|.
-  void CalculateNearestTileForVertex(
-      const gfx::Point& vertex, Index* nearest_tile, int* d_min);
+  // Returns the slot number which the given |point| falls into or the closest
+  // slot if |point| is outside the page's bounds.
+  Index GetNearestTileIndexForPoint(const gfx::Point& point) const;
 
-  // Returns the bounds of the tile in which |point| is enclosed if there
-  // is a valid item sits on the tile.
-  gfx::Rect GetTileBoundsForPoint(const gfx::Point& point, Index* tile_index);
+  // Gets the bounds of the tile located at |slot| on the current page.
+  gfx::Rect GetExpectedTileBounds(int slot) const;
 
-  // Gets the bounds of the tile located at |row| and |col| on current page.
-  gfx::Rect GetTileBounds(int row, int col) const;
-
-  // Returns true if the slot of |index| is the first empty slot next to the
-  // last item on the last page.
-  bool IsFirstEmptySlot(const Index& index) const;
+  // Gets the bounds of the tile located at |row| and |col| on the current page.
+  gfx::Rect GetExpectedTileBounds(int row, int col) const;
 
   // Gets the item view located at |slot| on the current page. If there is
   // no item located at |slot|, returns NULL.
@@ -419,7 +433,7 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
 
   // Updates drag state for dragging inside a folder's grid view.
   void UpdateDragStateInsideFolder(Pointer pointer,
-      const ui::LocatedEvent& event);
+                                   const gfx::Point& drag_point);
 
   // Returns true if drag event is happening in the root level AppsGridView
   // for reparenting a folder item.
@@ -427,7 +441,7 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
 
   // Returns true if drag event is happening in the hidden AppsGridView of the
   // folder during reparenting a folder item.
-  bool IsDraggingForReprentInHiddenGridView() const;
+  bool IsDraggingForReparentInHiddenGridView() const;
 
   // Returns the target icon bounds for |drag_item_view| to fly back
   // to its parent |folder_item_view| in animation.
@@ -437,13 +451,26 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
   // Returns true if the grid view is under an OEM folder.
   bool IsUnderOEMFolder();
 
+  void StartSettingUpSynchronousDrag();
+  bool RunSynchronousDrag();
+  void CleanUpSynchronousDrag();
+#if defined(OS_WIN)
+  void OnGotShortcutPath(scoped_refptr<SynchronousDrag> drag,
+                         const base::FilePath& path);
+#endif
+
   AppListModel* model_;  // Owned by AppListView.
   AppListItemList* item_list_;  // Not owned.
   AppsGridViewDelegate* delegate_;
-  PaginationModel* pagination_model_;  // Owned by AppListController.
+
+  // This can be NULL. Only grid views inside folders have a folder delegate.
+  AppsGridViewFolderDelegate* folder_delegate_;
+
+  PaginationModel pagination_model_;
+  // Must appear after |pagination_model_|.
+  scoped_ptr<PaginationController> pagination_controller_;
   PageSwitcher* page_switcher_view_;  // Owned by views hierarchy.
 
-  gfx::Size icon_size_;
   int cols_;
   int rows_per_page_;
 
@@ -476,10 +503,24 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
   // Created when a drag is started (ie: drag exceeds the drag threshold), but
   // not Run() until supplied with a shortcut path.
   scoped_refptr<SynchronousDrag> synchronous_drag_;
+
+  // Whether to use SynchronousDrag to support dropping to task bar etc.
+  bool use_synchronous_drag_;
 #endif
 
   Pointer drag_pointer_;
-  Index drop_target_;
+
+  // The most recent reorder drop target.
+  Index reorder_drop_target_;
+
+  // The most recent folder drop target.
+  Index folder_drop_target_;
+
+  // The index where an empty slot has been left as a placeholder for the
+  // reorder drop target. This updates when the reorder animation triggers.
+  Index reorder_placeholder_;
+
+  // The current action that ending a drag will perform.
   DropAttempt drop_attempt_;
 
   // Timer for re-ordering the |drop_target_| and |drag_view_|.
@@ -514,11 +555,8 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
 
   views::BoundsAnimator bounds_animator_;
 
-  // If true, AppsGridView is rending items at the root level of the app list.
-  bool is_root_level_;
-
-  // The most recent activated item view.
-  AppListItemView* activated_item_view_;
+  // The most recent activated folder item view.
+  AppListItemView* activated_folder_item_view_;
 
   // Tracks if drag_view_ is dragged out of the folder container bubble
   // when dragging a item inside a folder.