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

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

Issue 553763002: Clean up of tile sizing code for the Apps Grid View. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ares_fix_drag_point
Patch Set: 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
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 #include "ui/app_list/views/apps_grid_view.h" 5 #include "ui/app_list/views/apps_grid_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 v->Prerender(); 871 v->Prerender();
872 } 872 }
873 } 873 }
874 874
875 bool AppsGridView::IsAnimatingView(views::View* view) { 875 bool AppsGridView::IsAnimatingView(views::View* view) {
876 return bounds_animator_.IsAnimating(view); 876 return bounds_animator_.IsAnimating(view);
877 } 877 }
878 878
879 gfx::Size AppsGridView::GetPreferredSize() const { 879 gfx::Size AppsGridView::GetPreferredSize() const {
880 const gfx::Insets insets(GetInsets()); 880 const gfx::Insets insets(GetInsets());
881 const gfx::Size tile_size = gfx::Size(kPreferredTileWidth,
882 kPreferredTileHeight);
883 int page_switcher_height = kBottomPadding; 881 int page_switcher_height = kBottomPadding;
884 if (page_switcher_view_) 882 if (page_switcher_view_)
885 page_switcher_height = page_switcher_view_->GetPreferredSize().height(); 883 page_switcher_height = page_switcher_view_->GetPreferredSize().height();
886 return gfx::Size( 884 gfx::Size size = GetTileGridSize();
887 tile_size.width() * cols_ + insets.width(), 885 size.Enlarge(insets.width(), insets.height() + page_switcher_height);
888 tile_size.height() * rows_per_page_ + 886 return size;
889 page_switcher_height + insets.height());
890 } 887 }
891 888
892 bool AppsGridView::GetDropFormats( 889 bool AppsGridView::GetDropFormats(
893 int* formats, 890 int* formats,
894 std::set<OSExchangeData::CustomFormat>* custom_formats) { 891 std::set<OSExchangeData::CustomFormat>* custom_formats) {
895 // TODO(koz): Only accept a specific drag type for app shortcuts. 892 // TODO(koz): Only accept a specific drag type for app shortcuts.
896 *formats = OSExchangeData::FILE_NAME; 893 *formats = OSExchangeData::FILE_NAME;
897 return true; 894 return true;
898 } 895 }
899 896
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 target_slot = last_item_slot; 1152 target_slot = last_item_slot;
1156 } 1153 }
1157 } 1154 }
1158 1155
1159 int target_page = std::min(pagination_model_.total_pages() - 1, 1156 int target_page = std::min(pagination_model_.total_pages() - 1,
1160 std::max(selected.page + page_delta, 0)); 1157 std::max(selected.page + page_delta, 0));
1161 SetSelectedItemByIndex(Index(target_page, target_slot)); 1158 SetSelectedItemByIndex(Index(target_page, target_slot));
1162 } 1159 }
1163 1160
1164 void AppsGridView::CalculateIdealBounds() { 1161 void AppsGridView::CalculateIdealBounds() {
1165 gfx::Rect rect(GetContentsBounds()); 1162 gfx::Rect rect(GetContentsBounds());
Matt Giuca 2014/09/10 05:35:06 You should be able to delete this now (unless ther
calamity 2014/09/11 06:53:34 Done.
Matt Giuca 2014/09/12 01:04:46 Also delete rect itself. (That was my point.)
1166 if (rect.IsEmpty()) 1163 if (rect.IsEmpty())
1167 return; 1164 return;
1168 1165
1169 gfx::Size tile_size(kPreferredTileWidth, kPreferredTileHeight); 1166 gfx::Size grid_size = GetTileGridSize();
Matt Giuca 2014/09/10 05:35:06 This is actually fixing a subtle bug: calling grid
calamity 2014/09/11 06:53:34 Amended CL description as discussed.
Matt Giuca 2014/09/12 01:04:46 Acknowledged.
1170
1171 gfx::Rect grid_rect(gfx::Size(tile_size.width() * cols_,
1172 tile_size.height() * rows_per_page_));
1173 grid_rect.Intersect(rect);
1174 1167
1175 // Page size including padding pixels. A tile.x + page_width means the same 1168 // Page size including padding pixels. A tile.x + page_width means the same
1176 // tile slot in the next page; similarly for tile.y + page_height. 1169 // tile slot in the next page; similarly for tile.y + page_height.
1177 const int page_width = grid_rect.width() + kPagePadding; 1170 const int page_width = grid_size.width() + kPagePadding;
1178 const int page_height = grid_rect.height() + kPagePadding; 1171 const int page_height = grid_size.height() + kPagePadding;
1179 1172
1180 // If there is a transition, calculates offset for current and target page. 1173 // If there is a transition, calculates offset for current and target page.
1181 const int current_page = pagination_model_.selected_page(); 1174 const int current_page = pagination_model_.selected_page();
1182 const PaginationModel::Transition& transition = 1175 const PaginationModel::Transition& transition =
1183 pagination_model_.transition(); 1176 pagination_model_.transition();
1184 const bool is_valid = pagination_model_.is_valid_page(transition.target_page); 1177 const bool is_valid = pagination_model_.is_valid_page(transition.target_page);
1185 1178
1186 // Transition to previous page means negative offset. 1179 // Transition to previous page means negative offset.
1187 const int dir = transition.target_page > current_page ? -1 : 1; 1180 const int dir = transition.target_page > current_page ? -1 : 1;
1188 1181
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 if (is_valid) { 1227 if (is_valid) {
1235 if (view_index.page == current_page || 1228 if (view_index.page == current_page ||
1236 view_index.page == transition.target_page) { 1229 view_index.page == transition.target_page) {
1237 y_offset += transition.progress * page_height * dir; 1230 y_offset += transition.progress * page_height * dir;
1238 } 1231 }
1239 } 1232 }
1240 } 1233 }
1241 1234
1242 const int row = view_index.slot / cols_; 1235 const int row = view_index.slot / cols_;
1243 const int col = view_index.slot % cols_; 1236 const int col = view_index.slot % cols_;
1244 gfx::Rect tile_slot( 1237 gfx::Rect tile_slot = GetExpectedTileBounds(row, col);
1245 gfx::Point(grid_rect.x() + col * tile_size.width() + x_offset, 1238 tile_slot.Offset(x_offset, y_offset);
1246 grid_rect.y() + row * tile_size.height() + y_offset),
1247 tile_size);
1248 if (i < view_model_.view_size()) { 1239 if (i < view_model_.view_size()) {
1249 view_model_.set_ideal_bounds(i, tile_slot); 1240 view_model_.set_ideal_bounds(i, tile_slot);
1250 } else { 1241 } else {
1251 pulsing_blocks_model_.set_ideal_bounds(i - view_model_.view_size(), 1242 pulsing_blocks_model_.set_ideal_bounds(i - view_model_.view_size(),
1252 tile_slot); 1243 tile_slot);
1253 } 1244 }
1254 1245
1255 ++slot_index; 1246 ++slot_index;
1256 } 1247 }
1257 } 1248 }
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after
2181 // Check if |point| is outside of contents bounds. 2172 // Check if |point| is outside of contents bounds.
2182 gfx::Rect bounds(GetContentsBounds()); 2173 gfx::Rect bounds(GetContentsBounds());
2183 if (!bounds.Contains(point)) 2174 if (!bounds.Contains(point))
2184 return gfx::Rect(); 2175 return gfx::Rect();
2185 2176
2186 // Calculate which tile |point| is enclosed in. 2177 // Calculate which tile |point| is enclosed in.
2187 int x = point.x(); 2178 int x = point.x();
2188 int y = point.y(); 2179 int y = point.y();
2189 int col = (x - bounds.x()) / kPreferredTileWidth; 2180 int col = (x - bounds.x()) / kPreferredTileWidth;
2190 int row = (y - bounds.y()) / kPreferredTileHeight; 2181 int row = (y - bounds.y()) / kPreferredTileHeight;
2191 gfx::Rect tile_rect = GetTileBounds(row, col); 2182 gfx::Rect tile_rect = GetExpectedTileBounds(row, col);
2192 2183
2193 // Check if |point| is outside a valid item's tile. 2184 // Check if |point| is outside a valid item's tile.
2194 Index index(pagination_model_.selected_page(), row * cols_ + col); 2185 Index index(pagination_model_.selected_page(), row * cols_ + col);
2195 *tile_index = index; 2186 *tile_index = index;
2196 return tile_rect; 2187 return tile_rect;
2197 } 2188 }
2198 2189
2199 gfx::Rect AppsGridView::GetTileBounds(int row, int col) const { 2190 gfx::Size AppsGridView::GetTileGridSize() const {
2191 gfx::Rect bounds;
2192 bounds.Union(GetExpectedTileBounds(0, 0));
Matt Giuca 2014/09/10 05:35:06 No need to do this first union. Just: gfx::Rect bo
calamity 2014/09/11 06:53:35 Done.
2193 bounds.Union(GetExpectedTileBounds(rows_per_page_ - 1, cols_ - 1));
2194 return bounds.size();
2195 }
2196
2197 gfx::Rect AppsGridView::GetExpectedTileBounds(int row, int col) const {
2200 gfx::Rect bounds(GetContentsBounds()); 2198 gfx::Rect bounds(GetContentsBounds());
2201 gfx::Size tile_size(kPreferredTileWidth, kPreferredTileHeight); 2199 gfx::Size tile_size(kPreferredTileWidth, kPreferredTileHeight);
2202 gfx::Rect grid_rect(gfx::Size(tile_size.width() * cols_, 2200 gfx::Rect tile_rect(gfx::Point(bounds.x() + col * tile_size.width(),
Matt Giuca 2014/09/10 05:35:06 Just return this directly.
calamity 2014/09/11 06:53:35 Done.
2203 tile_size.height() * rows_per_page_)); 2201 bounds.y() + row * tile_size.height()),
2204 grid_rect.Intersect(bounds); 2202 tile_size);
2205 gfx::Rect tile_rect(
2206 gfx::Point(grid_rect.x() + col * tile_size.width(),
2207 grid_rect.y() + row * tile_size.height()),
2208 tile_size);
2209 return tile_rect; 2203 return tile_rect;
2210 } 2204 }
2211 2205
2212 bool AppsGridView::IsLastPossibleDropTarget(const Index& index) const { 2206 bool AppsGridView::IsLastPossibleDropTarget(const Index& index) const {
2213 int last_possible_slot = view_model_.view_size() % tiles_per_page(); 2207 int last_possible_slot = view_model_.view_size() % tiles_per_page();
2214 return (index.page == pagination_model_.total_pages() - 1 && 2208 return (index.page == pagination_model_.total_pages() - 1 &&
2215 index.slot == last_possible_slot + 1); 2209 index.slot == last_possible_slot + 1);
2216 } 2210 }
2217 2211
2218 views::View* AppsGridView::GetViewAtSlotOnCurrentPage(int slot) { 2212 views::View* AppsGridView::GetViewAtSlotOnCurrentPage(int slot) {
2219 if (slot < 0) 2213 if (slot < 0)
2220 return NULL; 2214 return NULL;
2221 2215
2222 // Calculate the original bound of the tile at |index|. 2216 // Calculate the original bound of the tile at |index|.
2223 int row = slot / cols_; 2217 int row = slot / cols_;
2224 int col = slot % cols_; 2218 int col = slot % cols_;
2225 gfx::Rect tile_rect = GetTileBounds(row, col); 2219 gfx::Rect tile_rect = GetExpectedTileBounds(row, col);
2226 2220
2227 for (int i = 0; i < view_model_.view_size(); ++i) { 2221 for (int i = 0; i < view_model_.view_size(); ++i) {
2228 views::View* view = view_model_.view_at(i); 2222 views::View* view = view_model_.view_at(i);
2229 if (view->bounds() == tile_rect && view != drag_view_) 2223 if (view->bounds() == tile_rect && view != drag_view_)
2230 return view; 2224 return view;
2231 } 2225 }
2232 return NULL; 2226 return NULL;
2233 } 2227 }
2234 2228
2235 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, 2229 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index,
2236 bool is_target_folder) { 2230 bool is_target_folder) {
2237 AppListItemView* target_view = 2231 AppListItemView* target_view =
2238 static_cast<AppListItemView*>( 2232 static_cast<AppListItemView*>(
2239 GetViewAtSlotOnCurrentPage(target_index.slot)); 2233 GetViewAtSlotOnCurrentPage(target_index.slot));
2240 if (target_view) 2234 if (target_view)
2241 target_view->SetAsAttemptedFolderTarget(is_target_folder); 2235 target_view->SetAsAttemptedFolderTarget(is_target_folder);
2242 } 2236 }
2243 2237
2244 } // namespace app_list 2238 } // namespace app_list
OLDNEW
« ui/app_list/views/apps_grid_view.h ('K') | « ui/app_list/views/apps_grid_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698