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

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: oopz 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/apps_grid_view.h ('k') | no next file » | 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 #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::Size grid_size = GetTileGridSize();
1166 if (rect.IsEmpty())
1167 return;
1168
1169 gfx::Size tile_size(kPreferredTileWidth, kPreferredTileHeight);
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 1163
1175 // Page size including padding pixels. A tile.x + page_width means the same 1164 // 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. 1165 // tile slot in the next page; similarly for tile.y + page_height.
1177 const int page_width = grid_rect.width() + kPagePadding; 1166 const int page_width = grid_size.width() + kPagePadding;
1178 const int page_height = grid_rect.height() + kPagePadding; 1167 const int page_height = grid_size.height() + kPagePadding;
1179 1168
1180 // If there is a transition, calculates offset for current and target page. 1169 // If there is a transition, calculates offset for current and target page.
1181 const int current_page = pagination_model_.selected_page(); 1170 const int current_page = pagination_model_.selected_page();
1182 const PaginationModel::Transition& transition = 1171 const PaginationModel::Transition& transition =
1183 pagination_model_.transition(); 1172 pagination_model_.transition();
1184 const bool is_valid = pagination_model_.is_valid_page(transition.target_page); 1173 const bool is_valid = pagination_model_.is_valid_page(transition.target_page);
1185 1174
1186 // Transition to previous page means negative offset. 1175 // Transition to previous page means negative offset.
1187 const int dir = transition.target_page > current_page ? -1 : 1; 1176 const int dir = transition.target_page > current_page ? -1 : 1;
1188 1177
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 if (is_valid) { 1223 if (is_valid) {
1235 if (view_index.page == current_page || 1224 if (view_index.page == current_page ||
1236 view_index.page == transition.target_page) { 1225 view_index.page == transition.target_page) {
1237 y_offset += transition.progress * page_height * dir; 1226 y_offset += transition.progress * page_height * dir;
1238 } 1227 }
1239 } 1228 }
1240 } 1229 }
1241 1230
1242 const int row = view_index.slot / cols_; 1231 const int row = view_index.slot / cols_;
1243 const int col = view_index.slot % cols_; 1232 const int col = view_index.slot % cols_;
1244 gfx::Rect tile_slot( 1233 gfx::Rect tile_slot = GetExpectedTileBounds(row, col);
1245 gfx::Point(grid_rect.x() + col * tile_size.width() + x_offset, 1234 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()) { 1235 if (i < view_model_.view_size()) {
1249 view_model_.set_ideal_bounds(i, tile_slot); 1236 view_model_.set_ideal_bounds(i, tile_slot);
1250 } else { 1237 } else {
1251 pulsing_blocks_model_.set_ideal_bounds(i - view_model_.view_size(), 1238 pulsing_blocks_model_.set_ideal_bounds(i - view_model_.view_size(),
1252 tile_slot); 1239 tile_slot);
1253 } 1240 }
1254 1241
1255 ++slot_index; 1242 ++slot_index;
1256 } 1243 }
1257 } 1244 }
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after
2181 // Check if |point| is outside of contents bounds. 2168 // Check if |point| is outside of contents bounds.
2182 gfx::Rect bounds(GetContentsBounds()); 2169 gfx::Rect bounds(GetContentsBounds());
2183 if (!bounds.Contains(point)) 2170 if (!bounds.Contains(point))
2184 return gfx::Rect(); 2171 return gfx::Rect();
2185 2172
2186 // Calculate which tile |point| is enclosed in. 2173 // Calculate which tile |point| is enclosed in.
2187 int x = point.x(); 2174 int x = point.x();
2188 int y = point.y(); 2175 int y = point.y();
2189 int col = (x - bounds.x()) / kPreferredTileWidth; 2176 int col = (x - bounds.x()) / kPreferredTileWidth;
2190 int row = (y - bounds.y()) / kPreferredTileHeight; 2177 int row = (y - bounds.y()) / kPreferredTileHeight;
2191 gfx::Rect tile_rect = GetTileBounds(row, col); 2178 gfx::Rect tile_rect = GetExpectedTileBounds(row, col);
2192 2179
2193 // Check if |point| is outside a valid item's tile. 2180 // Check if |point| is outside a valid item's tile.
2194 Index index(pagination_model_.selected_page(), row * cols_ + col); 2181 Index index(pagination_model_.selected_page(), row * cols_ + col);
2195 *tile_index = index; 2182 *tile_index = index;
2196 return tile_rect; 2183 return tile_rect;
2197 } 2184 }
2198 2185
2199 gfx::Rect AppsGridView::GetTileBounds(int row, int col) const { 2186 gfx::Size AppsGridView::GetTileGridSize() const {
2187 gfx::Rect bounds = GetExpectedTileBounds(0, 0);
2188 bounds.Union(GetExpectedTileBounds(rows_per_page_ - 1, cols_ - 1));
2189 return bounds.size();
2190 }
2191
2192 gfx::Rect AppsGridView::GetExpectedTileBounds(int row, int col) const {
2200 gfx::Rect bounds(GetContentsBounds()); 2193 gfx::Rect bounds(GetContentsBounds());
2201 gfx::Size tile_size(kPreferredTileWidth, kPreferredTileHeight); 2194 gfx::Size tile_size(kPreferredTileWidth, kPreferredTileHeight);
2202 gfx::Rect grid_rect(gfx::Size(tile_size.width() * cols_, 2195 return gfx::Rect(gfx::Point(bounds.x() + col * tile_size.width(),
2203 tile_size.height() * rows_per_page_)); 2196 bounds.y() + row * tile_size.height()),
2204 grid_rect.Intersect(bounds); 2197 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;
2210 } 2198 }
2211 2199
2212 bool AppsGridView::IsLastPossibleDropTarget(const Index& index) const { 2200 bool AppsGridView::IsLastPossibleDropTarget(const Index& index) const {
2213 int last_possible_slot = view_model_.view_size() % tiles_per_page(); 2201 int last_possible_slot = view_model_.view_size() % tiles_per_page();
2214 return (index.page == pagination_model_.total_pages() - 1 && 2202 return (index.page == pagination_model_.total_pages() - 1 &&
2215 index.slot == last_possible_slot + 1); 2203 index.slot == last_possible_slot + 1);
2216 } 2204 }
2217 2205
2218 views::View* AppsGridView::GetViewAtSlotOnCurrentPage(int slot) { 2206 views::View* AppsGridView::GetViewAtSlotOnCurrentPage(int slot) {
2219 if (slot < 0) 2207 if (slot < 0)
2220 return NULL; 2208 return NULL;
2221 2209
2222 // Calculate the original bound of the tile at |index|. 2210 // Calculate the original bound of the tile at |index|.
2223 int row = slot / cols_; 2211 int row = slot / cols_;
2224 int col = slot % cols_; 2212 int col = slot % cols_;
2225 gfx::Rect tile_rect = GetTileBounds(row, col); 2213 gfx::Rect tile_rect = GetExpectedTileBounds(row, col);
2226 2214
2227 for (int i = 0; i < view_model_.view_size(); ++i) { 2215 for (int i = 0; i < view_model_.view_size(); ++i) {
2228 views::View* view = view_model_.view_at(i); 2216 views::View* view = view_model_.view_at(i);
2229 if (view->bounds() == tile_rect && view != drag_view_) 2217 if (view->bounds() == tile_rect && view != drag_view_)
2230 return view; 2218 return view;
2231 } 2219 }
2232 return NULL; 2220 return NULL;
2233 } 2221 }
2234 2222
2235 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index, 2223 void AppsGridView::SetAsFolderDroppingTarget(const Index& target_index,
2236 bool is_target_folder) { 2224 bool is_target_folder) {
2237 AppListItemView* target_view = 2225 AppListItemView* target_view =
2238 static_cast<AppListItemView*>( 2226 static_cast<AppListItemView*>(
2239 GetViewAtSlotOnCurrentPage(target_index.slot)); 2227 GetViewAtSlotOnCurrentPage(target_index.slot));
2240 if (target_view) 2228 if (target_view)
2241 target_view->SetAsAttemptedFolderTarget(is_target_folder); 2229 target_view->SetAsAttemptedFolderTarget(is_target_folder);
2242 } 2230 }
2243 2231
2244 } // namespace app_list 2232 } // namespace app_list
OLDNEW
« no previous file with comments | « 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