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

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

Issue 23228004: Prepare to use gfx::RenderText in views::Label. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments; simplify app list changes. Created 6 years, 5 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/views/app_list_item_view.h ('k') | ui/gfx/render_text.h » ('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/views/app_list_item_view.h" 5 #include "ui/app_list/views/app_list_item_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "grit/ui_strings.h" 10 #include "grit/ui_strings.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 layer()->SetTransform(gfx::GetScaleTransform( 180 layer()->SetTransform(gfx::GetScaleTransform(
181 bounds.CenterPoint(), 181 bounds.CenterPoint(),
182 kDraggingIconScale)); 182 kDraggingIconScale));
183 break; 183 break;
184 } 184 }
185 case UI_STATE_DROPPING_IN_FOLDER: 185 case UI_STATE_DROPPING_IN_FOLDER:
186 break; 186 break;
187 } 187 }
188 #endif // !OS_WIN 188 #endif // !OS_WIN
189 189
190 SetTitleSubpixelAA();
190 SchedulePaint(); 191 SchedulePaint();
191 } 192 }
192 193
193 void AppListItemView::SetTouchDragging(bool touch_dragging) { 194 void AppListItemView::SetTouchDragging(bool touch_dragging) {
194 if (touch_dragging_ == touch_dragging) 195 if (touch_dragging_ == touch_dragging)
195 return; 196 return;
196 197
197 touch_dragging_ = touch_dragging; 198 touch_dragging_ = touch_dragging;
198 SetUIState(touch_dragging_ ? UI_STATE_DRAGGING : UI_STATE_NORMAL); 199 SetUIState(touch_dragging_ ? UI_STATE_DRAGGING : UI_STATE_NORMAL);
199 } 200 }
200 201
201 void AppListItemView::OnMouseDragTimer() { 202 void AppListItemView::OnMouseDragTimer() {
202 DCHECK(apps_grid_view_->IsDraggedView(this)); 203 DCHECK(apps_grid_view_->IsDraggedView(this));
203 SetUIState(UI_STATE_DRAGGING); 204 SetUIState(UI_STATE_DRAGGING);
204 } 205 }
205 206
206 void AppListItemView::SetTitleSubpixelAA() { 207 void AppListItemView::SetTitleSubpixelAA() {
207 // TODO(tapted): Enable AA for folders as well, taking care to play nice with 208 // TODO(tapted): Enable AA for folders as well, taking care to play nice with
208 // the folder bubble animation. 209 // the folder bubble animation.
209 bool enable_aa = !item_->IsInFolder() && ui_state_ == UI_STATE_NORMAL && 210 bool enable_aa = !item_->IsInFolder() && ui_state_ == UI_STATE_NORMAL &&
210 !item_->highlighted() && 211 !item_->highlighted() &&
211 !apps_grid_view_->IsSelectedView(this) && 212 !apps_grid_view_->IsSelectedView(this) &&
212 !apps_grid_view_->IsAnimatingView(this); 213 !apps_grid_view_->IsAnimatingView(this);
tapted 2014/07/15 00:52:38 the hook was in a SchedulePaint override because t
msw 2014/07/15 01:29:31 Removing the SchedulePaint from Label::Recalculate
213 214
214 bool currently_enabled = title_->background() != NULL; 215 title_->SetSubpixelRenderingEnabled(enable_aa);
215 if (currently_enabled == enable_aa)
216 return;
217
218 if (enable_aa) { 216 if (enable_aa) {
219 title_->SetBackgroundColor(app_list::kContentsBackgroundColor); 217 title_->SetBackgroundColor(app_list::kContentsBackgroundColor);
220 title_->set_background(views::Background::CreateSolidBackground( 218 title_->set_background(views::Background::CreateSolidBackground(
221 app_list::kContentsBackgroundColor)); 219 app_list::kContentsBackgroundColor));
222 } else { 220 } else {
223 // In other cases, keep the background transparent to ensure correct 221 // In other cases, keep the background transparent to ensure correct
224 // interactions with animations. This will temporarily disable subpixel AA. 222 // interactions with animations. This will temporarily disable subpixel AA.
225 title_->SetBackgroundColor(0); 223 title_->SetBackgroundColor(0);
226 title_->set_background(NULL); 224 title_->set_background(NULL);
227 } 225 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 SetAccessibleName(item_->GetItemType() == AppListFolderItem::kItemType 269 SetAccessibleName(item_->GetItemType() == AppListFolderItem::kItemType
272 ? l10n_util::GetStringFUTF16( 270 ? l10n_util::GetStringFUTF16(
273 IDS_APP_LIST_FOLDER_BUTTON_ACCESSIBILE_NAME, 271 IDS_APP_LIST_FOLDER_BUTTON_ACCESSIBILE_NAME,
274 base::UTF8ToUTF16(item_->name())) 272 base::UTF8ToUTF16(item_->name()))
275 : base::UTF8ToUTF16(item_->name())); 273 : base::UTF8ToUTF16(item_->name()));
276 Layout(); 274 Layout();
277 } 275 }
278 276
279 void AppListItemView::ItemHighlightedChanged() { 277 void AppListItemView::ItemHighlightedChanged() {
280 apps_grid_view_->EnsureViewVisible(this); 278 apps_grid_view_->EnsureViewVisible(this);
279 SetTitleSubpixelAA();
281 SchedulePaint(); 280 SchedulePaint();
282 } 281 }
283 282
284 void AppListItemView::ItemIsInstallingChanged() { 283 void AppListItemView::ItemIsInstallingChanged() {
285 if (item_->is_installing()) 284 if (item_->is_installing())
286 apps_grid_view_->EnsureViewVisible(this); 285 apps_grid_view_->EnsureViewVisible(this);
287 title_->SetVisible(!item_->is_installing()); 286 title_->SetVisible(!item_->is_installing());
288 progress_bar_->SetVisible(item_->is_installing()); 287 progress_bar_->SetVisible(item_->is_installing());
288 SetTitleSubpixelAA();
289 SchedulePaint(); 289 SchedulePaint();
290 } 290 }
291 291
292 void AppListItemView::ItemPercentDownloadedChanged() { 292 void AppListItemView::ItemPercentDownloadedChanged() {
293 // A percent_downloaded() of -1 can mean it's not known how much percent is 293 // A percent_downloaded() of -1 can mean it's not known how much percent is
294 // completed, or the download hasn't been marked complete, as is the case 294 // completed, or the download hasn't been marked complete, as is the case
295 // while an extension is being installed after being downloaded. 295 // while an extension is being installed after being downloaded.
296 if (item_->percent_downloaded() == -1) 296 if (item_->percent_downloaded() == -1)
297 return; 297 return;
298 progress_bar_->SetValue(item_->percent_downloaded() / 100.0); 298 progress_bar_->SetValue(item_->percent_downloaded() / 100.0);
(...skipping 12 matching lines...) Expand all
311 const int y = rect.y(); 311 const int y = rect.y();
312 312
313 icon_->SetBoundsRect(GetIconBoundsForTargetViewBounds(GetContentsBounds())); 313 icon_->SetBoundsRect(GetIconBoundsForTargetViewBounds(GetContentsBounds()));
314 const gfx::Size title_size = title_->GetPreferredSize(); 314 const gfx::Size title_size = title_->GetPreferredSize();
315 gfx::Rect title_bounds(rect.x() + (rect.width() - title_size.width()) / 2, 315 gfx::Rect title_bounds(rect.x() + (rect.width() - title_size.width()) / 2,
316 y + icon_size_.height() + kIconTitleSpacing, 316 y + icon_size_.height() + kIconTitleSpacing,
317 title_size.width(), 317 title_size.width(),
318 title_size.height()); 318 title_size.height());
319 title_bounds.Intersect(rect); 319 title_bounds.Intersect(rect);
320 title_->SetBoundsRect(title_bounds); 320 title_->SetBoundsRect(title_bounds);
321 SetTitleSubpixelAA();
321 322
322 gfx::Rect progress_bar_bounds(progress_bar_->GetPreferredSize()); 323 gfx::Rect progress_bar_bounds(progress_bar_->GetPreferredSize());
323 progress_bar_bounds.set_x(GetContentsBounds().x() + 324 progress_bar_bounds.set_x(GetContentsBounds().x() +
324 kProgressBarHorizontalPadding); 325 kProgressBarHorizontalPadding);
325 progress_bar_bounds.set_y(title_bounds.y()); 326 progress_bar_bounds.set_y(title_bounds.y());
326 progress_bar_->SetBoundsRect(progress_bar_bounds); 327 progress_bar_->SetBoundsRect(progress_bar_bounds);
327 } 328 }
328 329
329 void AppListItemView::SchedulePaintInRect(const gfx::Rect& r) {
330 SetTitleSubpixelAA();
331 views::CustomButton::SchedulePaintInRect(r);
332 }
333
334 void AppListItemView::OnPaint(gfx::Canvas* canvas) { 330 void AppListItemView::OnPaint(gfx::Canvas* canvas) {
335 if (apps_grid_view_->IsDraggedView(this)) 331 if (apps_grid_view_->IsDraggedView(this))
336 return; 332 return;
337 333
338 gfx::Rect rect(GetContentsBounds()); 334 gfx::Rect rect(GetContentsBounds());
339 if (item_->highlighted() && !item_->is_installing()) { 335 if (item_->highlighted() && !item_->is_installing()) {
340 canvas->FillRect(rect, kHighlightedColor); 336 canvas->FillRect(rect, kHighlightedColor);
341 return; 337 return;
342 } 338 }
343 if (apps_grid_view_->IsSelectedView(this)) 339 if (apps_grid_view_->IsSelectedView(this))
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 if (state() == STATE_HOVERED || state() == STATE_PRESSED) { 380 if (state() == STATE_HOVERED || state() == STATE_PRESSED) {
385 if (!is_folder_ui_enabled) 381 if (!is_folder_ui_enabled)
386 apps_grid_view_->SetSelectedView(this); 382 apps_grid_view_->SetSelectedView(this);
387 title_->SetEnabledColor(kGridTitleHoverColor); 383 title_->SetEnabledColor(kGridTitleHoverColor);
388 } else { 384 } else {
389 if (!is_folder_ui_enabled) 385 if (!is_folder_ui_enabled)
390 apps_grid_view_->ClearSelectedView(this); 386 apps_grid_view_->ClearSelectedView(this);
391 item_->SetHighlighted(false); 387 item_->SetHighlighted(false);
392 title_->SetEnabledColor(kGridTitleColor); 388 title_->SetEnabledColor(kGridTitleColor);
393 } 389 }
394 title_->Invalidate(); 390 SetTitleSubpixelAA();
395 } 391 }
396 392
397 bool AppListItemView::ShouldEnterPushedState(const ui::Event& event) { 393 bool AppListItemView::ShouldEnterPushedState(const ui::Event& event) {
398 // Don't enter pushed state for ET_GESTURE_TAP_DOWN so that hover gray 394 // Don't enter pushed state for ET_GESTURE_TAP_DOWN so that hover gray
399 // background does not show up during scroll. 395 // background does not show up during scroll.
400 if (event.type() == ui::ET_GESTURE_TAP_DOWN) 396 if (event.type() == ui::ET_GESTURE_TAP_DOWN)
401 return false; 397 return false;
402 398
403 return views::CustomButton::ShouldEnterPushedState(event); 399 return views::CustomButton::ShouldEnterPushedState(event);
404 } 400 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 const int left_right_padding = 520 const int left_right_padding =
525 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); 521 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars);
526 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); 522 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0);
527 523
528 gfx::Rect icon_bounds(rect.x(), rect.y(), rect.width(), icon_size_.height()); 524 gfx::Rect icon_bounds(rect.x(), rect.y(), rect.width(), icon_size_.height());
529 icon_bounds.Inset(gfx::ShadowValue::GetMargin(icon_shadows_)); 525 icon_bounds.Inset(gfx::ShadowValue::GetMargin(icon_shadows_));
530 return icon_bounds; 526 return icon_bounds;
531 } 527 }
532 528
533 } // namespace app_list 529 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/app_list_item_view.h ('k') | ui/gfx/render_text.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698