Commit a2ddd2de authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Refactor target slot calculation code in PagedViewStructure.

Put repeated code in its own method, and optimize the method.

Change-Id: I418ea40480626bfe56a547d64fe74b7019dd53c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1585973Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654598}
parent 59aee65d
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "ash/app_list/model/app_list_item.h" #include "ash/app_list/model/app_list_item.h"
#include "ash/app_list/views/app_list_item_view.h" #include "ash/app_list/views/app_list_item_view.h"
#include "ash/app_list/views/apps_grid_view.h" #include "ash/app_list/views/apps_grid_view.h"
#include "base/stl_util.h"
#include "ui/views/view_model.h" #include "ui/views/view_model.h"
namespace app_list { namespace app_list {
...@@ -185,14 +186,7 @@ GridIndex PagedViewStructure::GetLastTargetIndex() const { ...@@ -185,14 +186,7 @@ GridIndex PagedViewStructure::GetLastTargetIndex() const {
return GridIndex(0, 0); return GridIndex(0, 0);
int last_page_index = total_pages() - 1; int last_page_index = total_pages() - 1;
int target_slot = 0; int target_slot = CalculateTargetSlot(pages_.back());
auto& last_page = pages_.back();
for (size_t i = 0; i < last_page.size(); ++i) {
// Skip the item view being dragged if it exists in the last page.
if (last_page[i] != apps_grid_view_->drag_view_)
++target_slot;
}
if (target_slot == apps_grid_view_->TilesPerPage(last_page_index)) { if (target_slot == apps_grid_view_->TilesPerPage(last_page_index)) {
// The last page is full, so the last target visual index is the first slot // The last page is full, so the last target visual index is the first slot
// in the next new page. // in the next new page.
...@@ -210,15 +204,7 @@ GridIndex PagedViewStructure::GetLastTargetIndexOfPage(int page_index) const { ...@@ -210,15 +204,7 @@ GridIndex PagedViewStructure::GetLastTargetIndexOfPage(int page_index) const {
if (page_index == page_size) if (page_index == page_size)
return GridIndex(page_index, 0); return GridIndex(page_index, 0);
int target_slot = 0; int target_slot = CalculateTargetSlot(pages_[page_index]);
auto& page = pages_[page_index];
for (size_t i = 0; i < page.size(); ++i) {
// Skip the item view being dragged if it exists in the specified
// page_index.
if (page[i] != apps_grid_view_->drag_view())
++target_slot;
}
if (target_slot == apps_grid_view_->TilesPerPage(page_index)) { if (target_slot == apps_grid_view_->TilesPerPage(page_index)) {
// The specified page is full, so the last target visual index is the last // The specified page is full, so the last target visual index is the last
// slot in the page_index. // slot in the page_index.
...@@ -320,6 +306,13 @@ bool PagedViewStructure::IsFullPage(int page_index) const { ...@@ -320,6 +306,13 @@ bool PagedViewStructure::IsFullPage(int page_index) const {
apps_grid_view_->TilesPerPage(page_index); apps_grid_view_->TilesPerPage(page_index);
} }
int PagedViewStructure::CalculateTargetSlot(const Page& page) const {
size_t target_slot = page.size();
if (base::ContainsValue(page, apps_grid_view_->drag_view()))
--target_slot;
return static_cast<int>(target_slot);
}
bool PagedViewStructure::ClearOverflow() { bool PagedViewStructure::ClearOverflow() {
bool changed = false; bool changed = false;
std::vector<AppListItemView*> overflow_views; std::vector<AppListItemView*> overflow_views;
......
...@@ -96,6 +96,10 @@ class APP_LIST_EXPORT PagedViewStructure { ...@@ -96,6 +96,10 @@ class APP_LIST_EXPORT PagedViewStructure {
const Pages& pages() const { return pages_; } const Pages& pages() const { return pages_; }
private: private:
// Skips the item view being dragged if it exists in the specified
// |page|.
int CalculateTargetSlot(const Page& page) const;
// Clear overflowing item views by moving them to the next page. Returns true // Clear overflowing item views by moving them to the next page. Returns true
// if view structure is changed. // if view structure is changed.
bool ClearOverflow(); bool ClearOverflow();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment