Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: ui/app_list/views/apps_grid_view.h

Issue 553753003: Rework app list item drag zones. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fasdaj
Patch Set: fix test Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/app_list/views/app_list_main_view_unittest.cc ('k') | ui/app_list/views/apps_grid_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_APPS_GRID_VIEW_H_ 5 #ifndef UI_APP_LIST_VIEWS_APPS_GRID_VIEW_H_
6 #define UI_APP_LIST_VIEWS_APPS_GRID_VIEW_H_ 6 #define UI_APP_LIST_VIEWS_APPS_GRID_VIEW_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 struct Index { 228 struct Index {
229 Index() : page(-1), slot(-1) {} 229 Index() : page(-1), slot(-1) {}
230 Index(int page, int slot) : page(page), slot(slot) {} 230 Index(int page, int slot) : page(page), slot(slot) {}
231 231
232 bool operator==(const Index& other) const { 232 bool operator==(const Index& other) const {
233 return page == other.page && slot == other.slot; 233 return page == other.page && slot == other.slot;
234 } 234 }
235 bool operator!=(const Index& other) const { 235 bool operator!=(const Index& other) const {
236 return page != other.page || slot != other.slot; 236 return page != other.page || slot != other.slot;
237 } 237 }
238 bool operator<(const Index& other) const {
239 if (page != other.page)
240 return page < other.page;
241
242 return slot < other.slot;
243 }
238 244
239 int page; // Which page an item view is on. 245 int page; // Which page an item view is on.
240 int slot; // Which slot in the page an item view is in. 246 int slot; // Which slot in the page an item view is in.
241 }; 247 };
242 248
243 int tiles_per_page() const { return cols_ * rows_per_page_; } 249 int tiles_per_page() const { return cols_ * rows_per_page_; }
244 250
245 // Updates from model. 251 // Updates from model.
246 void Update(); 252 void Update();
247 253
(...skipping 11 matching lines...) Expand all
259 // struct above with page/slot info of where to display the item. 265 // struct above with page/slot info of where to display the item.
260 Index GetIndexFromModelIndex(int model_index) const; 266 Index GetIndexFromModelIndex(int model_index) const;
261 int GetModelIndexFromIndex(const Index& index) const; 267 int GetModelIndexFromIndex(const Index& index) const;
262 268
263 void SetSelectedItemByIndex(const Index& index); 269 void SetSelectedItemByIndex(const Index& index);
264 bool IsValidIndex(const Index& index) const; 270 bool IsValidIndex(const Index& index) const;
265 271
266 Index GetIndexOfView(const views::View* view) const; 272 Index GetIndexOfView(const views::View* view) const;
267 views::View* GetViewAtIndex(const Index& index) const; 273 views::View* GetViewAtIndex(const Index& index) const;
268 274
275 // Gets the index of the AppListItemView at the end of the view model.
276 Index GetLastViewIndex() const;
277
269 void MoveSelected(int page_delta, int slot_x_delta, int slot_y_delta); 278 void MoveSelected(int page_delta, int slot_x_delta, int slot_y_delta);
270 279
271 void CalculateIdealBounds(); 280 void CalculateIdealBounds();
272 void AnimateToIdealBounds(); 281 void AnimateToIdealBounds();
273 282
274 // Invoked when the given |view|'s current bounds and target bounds are on 283 // Invoked when the given |view|'s current bounds and target bounds are on
275 // different rows. To avoid moving diagonally, |view| would be put into a 284 // different rows. To avoid moving diagonally, |view| would be put into a
276 // slot prior |target| and fade in while moving to |target|. In the meanwhile, 285 // slot prior |target| and fade in while moving to |target|. In the meanwhile,
277 // a layer copy of |view| would start at |current| and fade out while moving 286 // a layer copy of |view| would start at |current| and fade out while moving
278 // to succeeding slot of |current|. |animate_current| controls whether to run 287 // to succeeding slot of |current|. |animate_current| controls whether to run
279 // fading out animation from |current|. |animate_target| controls whether to 288 // fading out animation from |current|. |animate_target| controls whether to
280 // run fading in animation to |target|. 289 // run fading in animation to |target|.
281 void AnimationBetweenRows(views::View* view, 290 void AnimationBetweenRows(views::View* view,
282 bool animate_current, 291 bool animate_current,
283 const gfx::Rect& current, 292 const gfx::Rect& current,
284 bool animate_target, 293 bool animate_target,
285 const gfx::Rect& target); 294 const gfx::Rect& target);
286 295
287 // Extracts drag location info from |event| into |drag_point|. 296 // Extracts drag location info from |event| into |drag_point|.
288 void ExtractDragLocation(const ui::LocatedEvent& event, 297 void ExtractDragLocation(const ui::LocatedEvent& event,
289 gfx::Point* drag_point); 298 gfx::Point* drag_point);
290 299
291 // Calculates reorder and folder drop targets based on |drag_point|. 300 // Updates |reorder_drop_target_|, |folder_drop_target_| and |drop_attempt_|
292 // |drag_point| is in the grid view's coordinates. When 301 // based on |drag_view_|'s position.
293 // |use_page_button_hovering| is true and |drag_point| is hovering on a page 302 void CalculateDropTarget();
294 // button, use the last slot on that page as drop target.
295 void CalculateDropTarget(const gfx::Point& drag_point,
296 bool use_page_button_hovering);
297 303
298 // Same as CalculateDropTarget, but with folder UI enabled. The drop target 304 // If |point| is a valid folder drop target, returns true and sets
299 // can be either a target for re-ordering, or a target folder to move the 305 // |drop_target| to the index of the view to do a folder drop for.
300 // dragged item into if |drag_view_| enters its re-ordering or folder 306 bool CalculateFolderDropTarget(const gfx::Point& point,
301 // dropping circle. 307 Index* drop_target) const;
302 void CalculateDropTargetWithFolderEnabled(const gfx::Point& drag_point, 308
303 bool use_page_button_hovering); 309 // Calculates the reorder target |point| and sets |drop_target| to the index
310 // of the view to reorder.
311 void CalculateReorderDropTarget(const gfx::Point& point,
312 Index* drop_target) const;
304 313
305 // Prepares |drag_and_drop_host_| for dragging. |grid_location| contains 314 // Prepares |drag_and_drop_host_| for dragging. |grid_location| contains
306 // the drag point in this grid view's coordinates. 315 // the drag point in this grid view's coordinates.
307 void StartDragAndDropHostDrag(const gfx::Point& grid_location); 316 void StartDragAndDropHostDrag(const gfx::Point& grid_location);
308 317
309 // Dispatch the drag and drop update event to the dnd host (if needed). 318 // Dispatch the drag and drop update event to the dnd host (if needed).
310 void DispatchDragEventToDragAndDropHost( 319 void DispatchDragEventToDragAndDropHost(
311 const gfx::Point& location_in_screen_coordinates); 320 const gfx::Point& location_in_screen_coordinates);
312 321
313 // Starts the page flip timer if |drag_point| is in left/right side page flip 322 // Starts the page flip timer if |drag_point| is in left/right side page flip
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 // changing the size of it. If |immediate| is set the change will be 390 // changing the size of it. If |immediate| is set the change will be
382 // immediately applied - otherwise it will change gradually. 391 // immediately applied - otherwise it will change gradually.
383 // If |hide| is set the view will get hidden, otherwise it gets shown. 392 // If |hide| is set the view will get hidden, otherwise it gets shown.
384 void SetViewHidden(views::View* view, bool hide, bool immediate); 393 void SetViewHidden(views::View* view, bool hide, bool immediate);
385 394
386 // Whether the folder drag-and-drop UI should be enabled. 395 // Whether the folder drag-and-drop UI should be enabled.
387 bool EnableFolderDragDropUI(); 396 bool EnableFolderDragDropUI();
388 397
389 // Whether target specified by |drap_target| can accept more items to be 398 // Whether target specified by |drap_target| can accept more items to be
390 // dropped into it. 399 // dropped into it.
391 bool CanDropIntoTarget(const Index& drop_target); 400 bool CanDropIntoTarget(const Index& drop_target) const;
392
393 // Calculates the visual index of the nearest tile for which |drag_view_|
394 // enters either its re-ordering or folder dropping circle.
395 void CalculateNearestTileForDragView();
396
397 // Calculates |nearest_tile| in which |vertex| of the |drag_view| is
398 // enclosed.
399 // *|nearest_tile| and *|d_min| will be updated based on the calculation.
400 // *|d_min| is the distance between |nearest_tile| and |drag_view_|.
401 void CalculateNearestTileForVertex(
402 const gfx::Point& vertex, Index* nearest_tile, int* d_min);
403
404 // Returns the bounds of the tile in which |point| is enclosed if there
405 // is a valid item sits on the tile.
406 gfx::Rect GetTileBoundsForPoint(const gfx::Point& point, Index* tile_index);
407 401
408 // Returns the size of the entire tile grid. 402 // Returns the size of the entire tile grid.
409 gfx::Size GetTileGridSize() const; 403 gfx::Size GetTileGridSize() const;
410 404
411 // Gets the expected bounds of a tile located at |row| and |col| on the 405 // Returns the slot number which the given |point| falls into or the closest
412 // current page. 406 // slot if |point| is outside the page's bounds.
407 Index GetNearestTileIndexForPoint(const gfx::Point& point) const;
408
409 // Gets the bounds of the tile located at |slot| on the current page.
410 gfx::Rect GetExpectedTileBounds(int slot) const;
411
412 // Gets the bounds of the tile located at |row| and |col| on the current page.
413 gfx::Rect GetExpectedTileBounds(int row, int col) const; 413 gfx::Rect GetExpectedTileBounds(int row, int col) const;
414 414
415 // Returns true if the slot of |index| is the last possible slot to drop
416 // an item, i.e. first empty slot next to the last item on the last page.
417 bool IsLastPossibleDropTarget(const Index& index) const;
418
419 // Gets the item view located at |slot| on the current page. If there is 415 // Gets the item view located at |slot| on the current page. If there is
420 // no item located at |slot|, returns NULL. 416 // no item located at |slot|, returns NULL.
421 views::View* GetViewAtSlotOnCurrentPage(int slot); 417 views::View* GetViewAtSlotOnCurrentPage(int slot);
422 418
423 // Sets state of the view with |target_index| to |is_target_folder| for 419 // Sets state of the view with |target_index| to |is_target_folder| for
424 // dropping |drag_view_|. 420 // dropping |drag_view_|.
425 void SetAsFolderDroppingTarget(const Index& target_index, 421 void SetAsFolderDroppingTarget(const Index& target_index,
426 bool is_target_folder); 422 bool is_target_folder);
427 423
428 // Invoked when |reorder_timer_| fires to show re-order preview UI. 424 // Invoked when |reorder_timer_| fires to show re-order preview UI.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 #endif 509 #endif
514 510
515 Pointer drag_pointer_; 511 Pointer drag_pointer_;
516 512
517 // The most recent reorder drop target. 513 // The most recent reorder drop target.
518 Index reorder_drop_target_; 514 Index reorder_drop_target_;
519 515
520 // The most recent folder drop target. 516 // The most recent folder drop target.
521 Index folder_drop_target_; 517 Index folder_drop_target_;
522 518
519 // The index where an empty slot has been left as a placeholder for the
520 // reorder drop target. This updates when the reorder animation triggers.
521 Index reorder_placeholder_;
522
523 // The current action that ending a drag will perform. 523 // The current action that ending a drag will perform.
524 DropAttempt drop_attempt_; 524 DropAttempt drop_attempt_;
525 525
526 // Timer for re-ordering the |drop_target_| and |drag_view_|. 526 // Timer for re-ordering the |drop_target_| and |drag_view_|.
527 base::OneShotTimer<AppsGridView> reorder_timer_; 527 base::OneShotTimer<AppsGridView> reorder_timer_;
528 528
529 // Timer for dropping |drag_view_| into the folder containing 529 // Timer for dropping |drag_view_| into the folder containing
530 // the |drop_target_|. 530 // the |drop_target_|.
531 base::OneShotTimer<AppsGridView> folder_dropping_timer_; 531 base::OneShotTimer<AppsGridView> folder_dropping_timer_;
532 532
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 564
565 // True if the drag_view_ item is a folder item being dragged for reparenting. 565 // True if the drag_view_ item is a folder item being dragged for reparenting.
566 bool dragging_for_reparent_item_; 566 bool dragging_for_reparent_item_;
567 567
568 DISALLOW_COPY_AND_ASSIGN(AppsGridView); 568 DISALLOW_COPY_AND_ASSIGN(AppsGridView);
569 }; 569 };
570 570
571 } // namespace app_list 571 } // namespace app_list
572 572
573 #endif // UI_APP_LIST_VIEWS_APPS_GRID_VIEW_H_ 573 #endif // UI_APP_LIST_VIEWS_APPS_GRID_VIEW_H_
OLDNEW
« no previous file with comments | « ui/app_list/views/app_list_main_view_unittest.cc ('k') | ui/app_list/views/apps_grid_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698