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

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

Issue 12771021: Make painting app list items more efficient by caching the labels. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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
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/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "grit/ui_resources.h" 10 #include "grit/ui_resources.h"
11 #include "ui/app_list/app_list_item_model.h" 11 #include "ui/app_list/app_list_item_model.h"
12 #include "ui/app_list/views/apps_grid_view.h" 12 #include "ui/app_list/views/apps_grid_view.h"
13 #include "ui/app_list/views/cached_label.h"
13 #include "ui/base/accessibility/accessible_view_state.h" 14 #include "ui/base/accessibility/accessible_view_state.h"
14 #include "ui/base/animation/throb_animation.h" 15 #include "ui/base/animation/throb_animation.h"
15 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/compositor/layer.h" 17 #include "ui/compositor/layer.h"
17 #include "ui/compositor/scoped_layer_animation_settings.h" 18 #include "ui/compositor/scoped_layer_animation_settings.h"
18 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/font.h" 20 #include "ui/gfx/font.h"
20 #include "ui/gfx/image/image_skia_operations.h" 21 #include "ui/gfx/image/image_skia_operations.h"
21 #include "ui/gfx/transform_util.h" 22 #include "ui/gfx/transform_util.h"
22 #include "ui/views/controls/image_view.h" 23 #include "ui/views/controls/image_view.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 59
59 // static 60 // static
60 const char AppListItemView::kViewClassName[] = "ui/app_list/AppListItemView"; 61 const char AppListItemView::kViewClassName[] = "ui/app_list/AppListItemView";
61 62
62 AppListItemView::AppListItemView(AppsGridView* apps_grid_view, 63 AppListItemView::AppListItemView(AppsGridView* apps_grid_view,
63 AppListItemModel* model) 64 AppListItemModel* model)
64 : CustomButton(apps_grid_view), 65 : CustomButton(apps_grid_view),
65 model_(model), 66 model_(model),
66 apps_grid_view_(apps_grid_view), 67 apps_grid_view_(apps_grid_view),
67 icon_(new views::ImageView), 68 icon_(new views::ImageView),
68 title_(new views::Label), 69 title_(new CachedLabel),
69 ui_state_(UI_STATE_NORMAL), 70 ui_state_(UI_STATE_NORMAL),
70 touch_dragging_(false) { 71 touch_dragging_(false) {
71 icon_->set_interactive(false); 72 icon_->set_interactive(false);
72 73
73 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 74 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
74 title_->SetBackgroundColor(0); 75 title_->SetBackgroundColor(0);
75 title_->SetAutoColorReadabilityEnabled(false); 76 title_->SetAutoColorReadabilityEnabled(false);
76 title_->SetEnabledColor(kTitleColor); 77 title_->SetEnabledColor(kTitleColor);
77 title_->SetFont(rb.GetFont(ui::ResourceBundle::SmallBoldFont)); 78 title_->SetFont(rb.GetFont(ui::ResourceBundle::SmallBoldFont));
78 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 79 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
79 title_->SetVisible(!model_->is_installing()); 80 title_->SetVisible(!model_->is_installing());
81 title_->Invalidate();
benwells 2013/03/12 04:58:11 nit: is this needed? CachedLabel initializes needs
koz (OOO until 15th September) 2013/03/13 00:30:36 Not needed, but needs_repaint_ could just as easil
80 82
81 const gfx::ShadowValue kIconShadows[] = { 83 const gfx::ShadowValue kIconShadows[] = {
82 gfx::ShadowValue(gfx::Point(0, 2), 2, SkColorSetARGB(0x24, 0, 0, 0)), 84 gfx::ShadowValue(gfx::Point(0, 2), 2, SkColorSetARGB(0x24, 0, 0, 0)),
83 }; 85 };
84 icon_shadows_.assign(kIconShadows, kIconShadows + arraysize(kIconShadows)); 86 icon_shadows_.assign(kIconShadows, kIconShadows + arraysize(kIconShadows));
85 87
86 AddChildView(icon_); 88 AddChildView(icon_);
87 AddChildView(title_); 89 AddChildView(title_);
88 90
89 ItemIconChanged(); 91 ItemIconChanged();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 DCHECK(apps_grid_view_->IsDraggedView(this)); 171 DCHECK(apps_grid_view_->IsDraggedView(this));
170 SetUIState(UI_STATE_DRAGGING); 172 SetUIState(UI_STATE_DRAGGING);
171 } 173 }
172 174
173 void AppListItemView::ItemIconChanged() { 175 void AppListItemView::ItemIconChanged() {
174 UpdateIcon(); 176 UpdateIcon();
175 } 177 }
176 178
177 void AppListItemView::ItemTitleChanged() { 179 void AppListItemView::ItemTitleChanged() {
178 title_->SetText(UTF8ToUTF16(model_->title())); 180 title_->SetText(UTF8ToUTF16(model_->title()));
181 title_->Invalidate();
179 } 182 }
180 183
181 void AppListItemView::ItemHighlightedChanged() { 184 void AppListItemView::ItemHighlightedChanged() {
182 apps_grid_view_->EnsureViewVisible(this); 185 apps_grid_view_->EnsureViewVisible(this);
183 SchedulePaint(); 186 SchedulePaint();
184 } 187 }
185 188
186 void AppListItemView::ItemIsInstallingChanged() { 189 void AppListItemView::ItemIsInstallingChanged() {
187 if (model_->is_installing()) 190 if (model_->is_installing())
188 apps_grid_view_->EnsureViewVisible(this); 191 apps_grid_view_->EnsureViewVisible(this);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 292
290 void AppListItemView::StateChanged() { 293 void AppListItemView::StateChanged() {
291 if (state() == STATE_HOVERED || state() == STATE_PRESSED) { 294 if (state() == STATE_HOVERED || state() == STATE_PRESSED) {
292 apps_grid_view_->SetSelectedView(this); 295 apps_grid_view_->SetSelectedView(this);
293 title_->SetEnabledColor(kTitleHoverColor); 296 title_->SetEnabledColor(kTitleHoverColor);
294 } else { 297 } else {
295 apps_grid_view_->ClearSelectedView(this); 298 apps_grid_view_->ClearSelectedView(this);
296 model_->SetHighlighted(false); 299 model_->SetHighlighted(false);
297 title_->SetEnabledColor(kTitleColor); 300 title_->SetEnabledColor(kTitleColor);
298 } 301 }
302 title_->Invalidate();
299 } 303 }
300 304
301 bool AppListItemView::ShouldEnterPushedState(const ui::Event& event) { 305 bool AppListItemView::ShouldEnterPushedState(const ui::Event& event) {
302 // Don't enter pushed state for ET_GESTURE_TAP_DOWN so that hover gray 306 // Don't enter pushed state for ET_GESTURE_TAP_DOWN so that hover gray
303 // background does not show up during scroll. 307 // background does not show up during scroll.
304 if (event.type() == ui::ET_GESTURE_TAP_DOWN) 308 if (event.type() == ui::ET_GESTURE_TAP_DOWN)
305 return false; 309 return false;
306 310
307 return views::CustomButton::ShouldEnterPushedState(event); 311 return views::CustomButton::ShouldEnterPushedState(event);
308 } 312 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 SetTouchDragging(false); 399 SetTouchDragging(false);
396 break; 400 break;
397 default: 401 default:
398 break; 402 break;
399 } 403 }
400 if (!event->handled()) 404 if (!event->handled())
401 CustomButton::OnGestureEvent(event); 405 CustomButton::OnGestureEvent(event);
402 } 406 }
403 407
404 } // namespace app_list 408 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698