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

Side by Side Diff: ui/app_list/app_list_item_view.cc

Issue 10383199: app_list: Update colors and sizes for v2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « ui/app_list/app_list_bubble_border.cc ('k') | ui/app_list/app_list_model_view.cc » ('j') | 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/app_list_item_view.h" 5 #include "ui/app_list/app_list_item_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 // FontSize/IconSize ratio = 24 / 128, which means we should get 24 font size 48 // FontSize/IconSize ratio = 24 / 128, which means we should get 24 font size
49 // when icon size is 128. 49 // when icon size is 128.
50 const float kFontSizeToIconSizeRatio = 0.1875f; 50 const float kFontSizeToIconSizeRatio = 0.1875f;
51 51
52 // Font smaller than kBoldFontSize needs to be bold. 52 // Font smaller than kBoldFontSize needs to be bold.
53 const int kBoldFontSize = 14; 53 const int kBoldFontSize = 14;
54 54
55 const int kMinFontSize = 12; 55 const int kMinFontSize = 12;
56 56
57 const int kFixedFontSize = 11; // Font size for fixed layout.
58
57 const int kMinTitleChars = 15; 59 const int kMinTitleChars = 15;
58 60
59 const int kLeftRightPaddingChars = 1; 61 const int kLeftRightPaddingChars = 1;
60 62
61 const gfx::Font& GetTitleFontForIconSize(const gfx::Size& size) { 63 const gfx::Font& GetTitleFontForIconSize(const gfx::Size& size, bool fixed) {
62 static int icon_height; 64 static int icon_height;
63 static gfx::Font* font = NULL; 65 static gfx::Font* font = NULL;
64 66
65 if (font && icon_height == size.height()) 67 // Reuses current font for fixed layout or icon height is the same.
68 if (font && (fixed || icon_height == size.height()))
66 return *font; 69 return *font;
67 70
68 delete font; 71 delete font;
69 72
70 icon_height = size.height(); 73 icon_height = size.height();
71 int font_size = std::max( 74 int font_size = fixed ? kFixedFontSize :
72 static_cast<int>(icon_height * kFontSizeToIconSizeRatio), 75 std::max(static_cast<int>(icon_height * kFontSizeToIconSizeRatio),
73 kMinFontSize); 76 kMinFontSize);
74 77
75 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 78 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
76 gfx::Font title_font(rb.GetFont(ui::ResourceBundle::BaseFont).GetFontName(), 79 gfx::Font title_font(rb.GetFont(ui::ResourceBundle::BaseFont).GetFontName(),
77 font_size); 80 font_size);
78 if (font_size <= kBoldFontSize) 81 if (font_size <= kBoldFontSize)
79 title_font = title_font.DeriveFont(0, gfx::Font::BOLD); 82 title_font = title_font.DeriveFont(0, gfx::Font::BOLD);
80 font = new gfx::Font(title_font); 83 font = new gfx::Font(title_font);
81 return *font; 84 return *font;
82 } 85 }
83 86
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 224
222 // static 225 // static
223 gfx::Size AppListItemView::GetPreferredSizeForIconSize( 226 gfx::Size AppListItemView::GetPreferredSizeForIconSize(
224 const gfx::Size& icon_size) { 227 const gfx::Size& icon_size) {
225 int min_title_width = g_min_title_width; 228 int min_title_width = g_min_title_width;
226 // Fixed 20px is used for left/right padding before switching to padding 229 // Fixed 20px is used for left/right padding before switching to padding
227 // based on number of chars. It is also a number used for test case 230 // based on number of chars. It is also a number used for test case
228 // AppList.ModelViewCalculateLayout. 231 // AppList.ModelViewCalculateLayout.
229 int left_right_padding = 20; 232 int left_right_padding = 20;
230 if (min_title_width == 0) { 233 if (min_title_width == 0) {
231 const gfx::Font& title_font = GetTitleFontForIconSize(icon_size); 234 // Assumes fixed layout is false since this function should only be called
235 // for dynamic layout.
236 const gfx::Font& title_font = GetTitleFontForIconSize(icon_size,
237 false /* fixed */);
232 // Use big char such as 'G' to calculate min title width. 238 // Use big char such as 'G' to calculate min title width.
233 min_title_width = kMinTitleChars * 239 min_title_width = kMinTitleChars *
234 title_font.GetStringWidth(ASCIIToUTF16("G")); 240 title_font.GetStringWidth(ASCIIToUTF16("G"));
235 left_right_padding = kLeftRightPaddingChars * 241 left_right_padding = kLeftRightPaddingChars *
236 title_font.GetAverageCharacterWidth(); 242 title_font.GetAverageCharacterWidth();
237 } 243 }
238 244
239 int dimension = std::max(icon_size.width() * 2, min_title_width); 245 int dimension = std::max(icon_size.width() * 2, min_title_width);
240 gfx::Size size(dimension, dimension); 246 gfx::Size size(dimension, dimension);
241 size.Enlarge(left_right_padding, kTopBottomPadding); 247 size.Enlarge(left_right_padding, kTopBottomPadding);
242 return size; 248 return size;
243 } 249 }
244 250
245 // static 251 // static
246 void AppListItemView::SetMinTitleWidth(int width) { 252 void AppListItemView::SetMinTitleWidth(int width) {
247 g_min_title_width = width; 253 g_min_title_width = width;
248 } 254 }
249 255
250 void AppListItemView::SetIconSize(const gfx::Size& size) { 256 void AppListItemView::SetIconSize(const gfx::Size& size) {
251 if (icon_size_ == size) 257 if (icon_size_ == size)
252 return; 258 return;
253 259
254 icon_size_ = size; 260 icon_size_ = size;
255 title_->SetFont(GetTitleFontForIconSize(size)); 261 title_->SetFont(GetTitleFontForIconSize(size,
262 list_model_view_->fixed_layout()));
256 UpdateIcon(); 263 UpdateIcon();
257 } 264 }
258 265
259 void AppListItemView::SetSelected(bool selected) { 266 void AppListItemView::SetSelected(bool selected) {
260 if (selected == selected_) 267 if (selected == selected_)
261 return; 268 return;
262 269
263 RequestFocus(); 270 RequestFocus();
264 selected_ = selected; 271 selected_ = selected;
265 SchedulePaint(); 272 SchedulePaint();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 int left_right_padding = kLeftRightPaddingChars * 345 int left_right_padding = kLeftRightPaddingChars *
339 title_->font().GetAverageCharacterWidth(); 346 title_->font().GetAverageCharacterWidth();
340 rect.Inset(left_right_padding, kTopBottomPadding); 347 rect.Inset(left_right_padding, kTopBottomPadding);
341 348
342 gfx::Size title_size = title_->GetPreferredSize(); 349 gfx::Size title_size = title_->GetPreferredSize();
343 int height = icon_size_.height() + kIconTitleSpacing + 350 int height = icon_size_.height() + kIconTitleSpacing +
344 title_size.height(); 351 title_size.height();
345 int y = rect.y() + (rect.height() - height) / 2; 352 int y = rect.y() + (rect.height() - height) / 2;
346 353
347 gfx::Rect icon_bounds(rect.x(), y, rect.width(), icon_size_.height()); 354 gfx::Rect icon_bounds(rect.x(), y, rect.width(), icon_size_.height());
348 icon_bounds.Inset(0, -IconOperation::kShadowPadding); 355 icon_bounds.Inset(-IconOperation::kShadowPadding,
356 -IconOperation::kShadowPadding);
349 icon_->SetBoundsRect(icon_bounds); 357 icon_->SetBoundsRect(icon_bounds);
350 358
351 title_->SetBounds(rect.x(), 359 title_->SetBounds(rect.x(),
352 y + icon_size_.height() + kIconTitleSpacing, 360 y + icon_size_.height() + kIconTitleSpacing,
353 rect.width(), 361 rect.width(),
354 title_size.height()); 362 title_size.height());
355 } 363 }
356 364
357 void AppListItemView::OnPaint(gfx::Canvas* canvas) { 365 void AppListItemView::OnPaint(gfx::Canvas* canvas) {
358 gfx::Rect rect(GetContentsBounds()); 366 gfx::Rect rect(GetContentsBounds());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 void AppListItemView::StateChanged() { 403 void AppListItemView::StateChanged() {
396 if (state() == BS_HOT || state() == BS_PUSHED) { 404 if (state() == BS_HOT || state() == BS_PUSHED) {
397 list_model_view_->SetSelectedItem(this); 405 list_model_view_->SetSelectedItem(this);
398 } else { 406 } else {
399 list_model_view_->ClearSelectedItem(this); 407 list_model_view_->ClearSelectedItem(this);
400 model_->SetHighlighted(false); 408 model_->SetHighlighted(false);
401 } 409 }
402 } 410 }
403 411
404 } // namespace app_list 412 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/app_list_bubble_border.cc ('k') | ui/app_list/app_list_model_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698