From 196bd06c218ed7e832c3666954fd0c8d72f8419b Mon Sep 17 00:00:00 2001 From: calamity Date: Fri, 12 Sep 2014 02:27:18 -0700 Subject: [PATCH] Clean up of tile sizing code for the Apps Grid View. This CL cleans up some tile size code and centralizes the calculation of the apps grid's size. It also incidentally fixes a bug where the padding between pages was smaller than it should have been. BUG=411775 Review URL: https://codereview.chromium.org/553763002 Cr-Commit-Position: refs/heads/master@{#294559} --- ui/app_list/views/apps_grid_view.cc | 52 ++++++++++++++----------------------- ui/app_list/views/apps_grid_view.h | 8 ++++-- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/ui/app_list/views/apps_grid_view.cc b/ui/app_list/views/apps_grid_view.cc index ec8f29a0a2ca..d89a19940e9d 100644 --- a/ui/app_list/views/apps_grid_view.cc +++ b/ui/app_list/views/apps_grid_view.cc @@ -878,15 +878,12 @@ bool AppsGridView::IsAnimatingView(views::View* view) { gfx::Size AppsGridView::GetPreferredSize() const { const gfx::Insets insets(GetInsets()); - const gfx::Size tile_size = gfx::Size(kPreferredTileWidth, - kPreferredTileHeight); int page_switcher_height = kBottomPadding; if (page_switcher_view_) page_switcher_height = page_switcher_view_->GetPreferredSize().height(); - return gfx::Size( - tile_size.width() * cols_ + insets.width(), - tile_size.height() * rows_per_page_ + - page_switcher_height + insets.height()); + gfx::Size size = GetTileGridSize(); + size.Enlarge(insets.width(), insets.height() + page_switcher_height); + return size; } bool AppsGridView::GetDropFormats( @@ -1162,20 +1159,12 @@ void AppsGridView::MoveSelected(int page_delta, } void AppsGridView::CalculateIdealBounds() { - gfx::Rect rect(GetContentsBounds()); - if (rect.IsEmpty()) - return; - - gfx::Size tile_size(kPreferredTileWidth, kPreferredTileHeight); - - gfx::Rect grid_rect(gfx::Size(tile_size.width() * cols_, - tile_size.height() * rows_per_page_)); - grid_rect.Intersect(rect); + gfx::Size grid_size = GetTileGridSize(); // Page size including padding pixels. A tile.x + page_width means the same // tile slot in the next page; similarly for tile.y + page_height. - const int page_width = grid_rect.width() + kPagePadding; - const int page_height = grid_rect.height() + kPagePadding; + const int page_width = grid_size.width() + kPagePadding; + const int page_height = grid_size.height() + kPagePadding; // If there is a transition, calculates offset for current and target page. const int current_page = pagination_model_.selected_page(); @@ -1241,10 +1230,8 @@ void AppsGridView::CalculateIdealBounds() { const int row = view_index.slot / cols_; const int col = view_index.slot % cols_; - gfx::Rect tile_slot( - gfx::Point(grid_rect.x() + col * tile_size.width() + x_offset, - grid_rect.y() + row * tile_size.height() + y_offset), - tile_size); + gfx::Rect tile_slot = GetExpectedTileBounds(row, col); + tile_slot.Offset(x_offset, y_offset); if (i < view_model_.view_size()) { view_model_.set_ideal_bounds(i, tile_slot); } else { @@ -2188,7 +2175,7 @@ gfx::Rect AppsGridView::GetTileBoundsForPoint(const gfx::Point& point, int y = point.y(); int col = (x - bounds.x()) / kPreferredTileWidth; int row = (y - bounds.y()) / kPreferredTileHeight; - gfx::Rect tile_rect = GetTileBounds(row, col); + gfx::Rect tile_rect = GetExpectedTileBounds(row, col); // Check if |point| is outside a valid item's tile. Index index(pagination_model_.selected_page(), row * cols_ + col); @@ -2196,17 +2183,18 @@ gfx::Rect AppsGridView::GetTileBoundsForPoint(const gfx::Point& point, return tile_rect; } -gfx::Rect AppsGridView::GetTileBounds(int row, int col) const { +gfx::Size AppsGridView::GetTileGridSize() const { + gfx::Rect bounds = GetExpectedTileBounds(0, 0); + bounds.Union(GetExpectedTileBounds(rows_per_page_ - 1, cols_ - 1)); + return bounds.size(); +} + +gfx::Rect AppsGridView::GetExpectedTileBounds(int row, int col) const { gfx::Rect bounds(GetContentsBounds()); gfx::Size tile_size(kPreferredTileWidth, kPreferredTileHeight); - gfx::Rect grid_rect(gfx::Size(tile_size.width() * cols_, - tile_size.height() * rows_per_page_)); - grid_rect.Intersect(bounds); - gfx::Rect tile_rect( - gfx::Point(grid_rect.x() + col * tile_size.width(), - grid_rect.y() + row * tile_size.height()), - tile_size); - return tile_rect; + return gfx::Rect(gfx::Point(bounds.x() + col * tile_size.width(), + bounds.y() + row * tile_size.height()), + tile_size); } bool AppsGridView::IsLastPossibleDropTarget(const Index& index) const { @@ -2222,7 +2210,7 @@ views::View* AppsGridView::GetViewAtSlotOnCurrentPage(int slot) { // Calculate the original bound of the tile at |index|. int row = slot / cols_; int col = slot % cols_; - gfx::Rect tile_rect = GetTileBounds(row, col); + gfx::Rect tile_rect = GetExpectedTileBounds(row, col); for (int i = 0; i < view_model_.view_size(); ++i) { views::View* view = view_model_.view_at(i); diff --git a/ui/app_list/views/apps_grid_view.h b/ui/app_list/views/apps_grid_view.h index 17cb798b4198..f509284b54e6 100644 --- a/ui/app_list/views/apps_grid_view.h +++ b/ui/app_list/views/apps_grid_view.h @@ -405,8 +405,12 @@ class APP_LIST_EXPORT AppsGridView : public views::View, // 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 |row| and |col| on current page. - gfx::Rect GetTileBounds(int row, int col) const; + // Returns the size of the entire tile grid. + gfx::Size GetTileGridSize() const; + + // Gets the expected bounds of a tile located at |row| and |col| on the + // current page. + gfx::Rect GetExpectedTileBounds(int row, int col) const; // Returns true if the slot of |index| is the last possible slot to drop // an item, i.e. first empty slot next to the last item on the last page. -- 2.11.4.GIT