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_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 Loading... | |
| 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 Loading... | |
| 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. | 303 |
| 295 void CalculateDropTarget(const gfx::Point& drag_point, | 304 // If |point| is a valid folder drop target, returns true and sets |
| 296 bool use_page_button_hovering); | 305 // |drop_target| to the index of the view to do a folder drop for. |
| 306 bool CalculateFolderDropTarget(const gfx::Point& point, Index* drop_target); | |
| 307 | |
| 308 // Calculates the reorder target |point| and sets |drop_target| to the index | |
| 309 // of the view to reorder. | |
| 310 void CalculateReorderDropTarget(const gfx::Point& point, Index* drop_target); | |
| 297 | 311 |
| 298 // Same as CalculateDropTarget, but with folder UI enabled. The drop target | 312 // Same as CalculateDropTarget, but with folder UI enabled. The drop target |
|
tapted
2014/09/15 06:12:53
I think this comment is a stray now
calamity
2014/09/15 06:36:15
Done.
| |
| 299 // can be either a target for re-ordering, or a target folder to move the | 313 // can be either a target for re-ordering, or a target folder to move the |
| 300 // dragged item into if |drag_view_| enters its re-ordering or folder | 314 // dragged item into if |drag_view_| enters its re-ordering or folder |
| 301 // dropping circle. | 315 // dropping circle. |
| 302 void CalculateDropTargetWithFolderEnabled(const gfx::Point& drag_point, | |
| 303 bool use_page_button_hovering); | |
| 304 | 316 |
| 305 // Prepares |drag_and_drop_host_| for dragging. |grid_location| contains | 317 // Prepares |drag_and_drop_host_| for dragging. |grid_location| contains |
| 306 // the drag point in this grid view's coordinates. | 318 // the drag point in this grid view's coordinates. |
| 307 void StartDragAndDropHostDrag(const gfx::Point& grid_location); | 319 void StartDragAndDropHostDrag(const gfx::Point& grid_location); |
| 308 | 320 |
| 309 // Dispatch the drag and drop update event to the dnd host (if needed). | 321 // Dispatch the drag and drop update event to the dnd host (if needed). |
| 310 void DispatchDragEventToDragAndDropHost( | 322 void DispatchDragEventToDragAndDropHost( |
| 311 const gfx::Point& location_in_screen_coordinates); | 323 const gfx::Point& location_in_screen_coordinates); |
| 312 | 324 |
| 313 // Starts the page flip timer if |drag_point| is in left/right side page flip | 325 // Starts the page flip timer if |drag_point| is in left/right side page flip |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 // If |hide| is set the view will get hidden, otherwise it gets shown. | 395 // If |hide| is set the view will get hidden, otherwise it gets shown. |
| 384 void SetViewHidden(views::View* view, bool hide, bool immediate); | 396 void SetViewHidden(views::View* view, bool hide, bool immediate); |
| 385 | 397 |
| 386 // Whether the folder drag-and-drop UI should be enabled. | 398 // Whether the folder drag-and-drop UI should be enabled. |
| 387 bool EnableFolderDragDropUI(); | 399 bool EnableFolderDragDropUI(); |
| 388 | 400 |
| 389 // Whether target specified by |drap_target| can accept more items to be | 401 // Whether target specified by |drap_target| can accept more items to be |
| 390 // dropped into it. | 402 // dropped into it. |
| 391 bool CanDropIntoTarget(const Index& drop_target); | 403 bool CanDropIntoTarget(const Index& drop_target); |
| 392 | 404 |
| 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 | |
| 408 // Returns the size of the entire tile grid. | 405 // Returns the size of the entire tile grid. |
| 409 gfx::Size GetTileGridSize() const; | 406 gfx::Size GetTileGridSize() const; |
| 410 | 407 |
| 411 // Gets the expected bounds of a tile located at |row| and |col| on the | 408 // Returns the slot number which the given |point| falls into or the closest |
| 412 // current page. | 409 // slot if |point| if outside the page's bounds. |
|
tapted
2014/09/15 06:12:53
nit: if outside -> is outside
calamity
2014/09/15 06:36:15
Done.
| |
| 410 Index GetNearestTileIndexForPoint(const gfx::Point& point) const; | |
| 411 | |
| 412 // Gets the bounds of the tile located at |slot| on the current page. | |
| 413 gfx::Rect GetExpectedTileBounds(int slot) const; | |
| 414 | |
| 415 // Gets the bounds of the tile located at |row| and |col| on the current page. | |
| 413 gfx::Rect GetExpectedTileBounds(int row, int col) const; | 416 gfx::Rect GetExpectedTileBounds(int row, int col) const; |
| 414 | 417 |
| 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 | 418 // Gets the item view located at |slot| on the current page. If there is |
| 420 // no item located at |slot|, returns NULL. | 419 // no item located at |slot|, returns NULL. |
| 421 views::View* GetViewAtSlotOnCurrentPage(int slot); | 420 views::View* GetViewAtSlotOnCurrentPage(int slot); |
| 422 | 421 |
| 423 // Sets state of the view with |target_index| to |is_target_folder| for | 422 // Sets state of the view with |target_index| to |is_target_folder| for |
| 424 // dropping |drag_view_|. | 423 // dropping |drag_view_|. |
| 425 void SetAsFolderDroppingTarget(const Index& target_index, | 424 void SetAsFolderDroppingTarget(const Index& target_index, |
| 426 bool is_target_folder); | 425 bool is_target_folder); |
| 427 | 426 |
| 428 // Invoked when |reorder_timer_| fires to show re-order preview UI. | 427 // Invoked when |reorder_timer_| fires to show re-order preview UI. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 #endif | 512 #endif |
| 514 | 513 |
| 515 Pointer drag_pointer_; | 514 Pointer drag_pointer_; |
| 516 | 515 |
| 517 // The most recent reorder drop target. | 516 // The most recent reorder drop target. |
| 518 Index reorder_drop_target_; | 517 Index reorder_drop_target_; |
| 519 | 518 |
| 520 // The most recent folder drop target. | 519 // The most recent folder drop target. |
| 521 Index folder_drop_target_; | 520 Index folder_drop_target_; |
| 522 | 521 |
| 522 // The index where an empty slot has been left as a placeholder for the | |
| 523 // reorder drop target. This updates when the reorder animation triggers. | |
| 524 Index reorder_placeholder_; | |
| 525 | |
| 523 // The current action that ending a drag will perform. | 526 // The current action that ending a drag will perform. |
| 524 DropAttempt drop_attempt_; | 527 DropAttempt drop_attempt_; |
| 525 | 528 |
| 526 // Timer for re-ordering the |drop_target_| and |drag_view_|. | 529 // Timer for re-ordering the |drop_target_| and |drag_view_|. |
| 527 base::OneShotTimer<AppsGridView> reorder_timer_; | 530 base::OneShotTimer<AppsGridView> reorder_timer_; |
| 528 | 531 |
| 529 // Timer for dropping |drag_view_| into the folder containing | 532 // Timer for dropping |drag_view_| into the folder containing |
| 530 // the |drop_target_|. | 533 // the |drop_target_|. |
| 531 base::OneShotTimer<AppsGridView> folder_dropping_timer_; | 534 base::OneShotTimer<AppsGridView> folder_dropping_timer_; |
| 532 | 535 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 564 | 567 |
| 565 // True if the drag_view_ item is a folder item being dragged for reparenting. | 568 // True if the drag_view_ item is a folder item being dragged for reparenting. |
| 566 bool dragging_for_reparent_item_; | 569 bool dragging_for_reparent_item_; |
| 567 | 570 |
| 568 DISALLOW_COPY_AND_ASSIGN(AppsGridView); | 571 DISALLOW_COPY_AND_ASSIGN(AppsGridView); |
| 569 }; | 572 }; |
| 570 | 573 |
| 571 } // namespace app_list | 574 } // namespace app_list |
| 572 | 575 |
| 573 #endif // UI_APP_LIST_VIEWS_APPS_GRID_VIEW_H_ | 576 #endif // UI_APP_LIST_VIEWS_APPS_GRID_VIEW_H_ |
| OLD | NEW |