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

Unified 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: Fix multiline LabelButton layout and sizing. 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 side-by-side diff with in-line comments
Download patch
Index: ui/app_list/views/app_list_item_view.cc
diff --git a/ui/app_list/views/app_list_item_view.cc b/ui/app_list/views/app_list_item_view.cc
index 3d4897c00e3ca168aa31cdbe9775135cc22994d4..b551e0e548ffc7af2cbc08da73dfde7ea52ef797 100644
--- a/ui/app_list/views/app_list_item_view.cc
+++ b/ui/app_list/views/app_list_item_view.cc
@@ -13,7 +13,6 @@
#include "ui/app_list/app_list_folder_item.h"
#include "ui/app_list/app_list_item.h"
#include "ui/app_list/views/apps_grid_view.h"
-#include "ui/app_list/views/cached_label.h"
#include "ui/app_list/views/progress_bar_view.h"
#include "ui/base/dragdrop/drag_utils.h"
#include "ui/base/l10n/l10n_util.h"
@@ -71,22 +70,18 @@ AppListItemView::AppListItemView(AppsGridView* apps_grid_view,
item_(item),
apps_grid_view_(apps_grid_view),
icon_(new views::ImageView),
- title_(new CachedLabel),
+ title_(new views::Label),
progress_bar_(new ProgressBarView),
ui_state_(UI_STATE_NORMAL),
touch_dragging_(false) {
icon_->set_interactive(false);
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- title_->SetBackgroundColor(0);
title_->SetAutoColorReadabilityEnabled(false);
title_->SetEnabledColor(kGridTitleColor);
title_->SetFontList(
rb.GetFontList(kItemTextFontStyle).DeriveWithSizeDelta(kFontSizeDelta));
- title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
title_->SetVisible(!item_->is_installing());
- title_->Invalidate();
- SetTitleSubpixelAA();
const gfx::ShadowValue kIconShadows[] = {
gfx::ShadowValue(gfx::Point(0, 2), 2, SkColorSetARGB(0x24, 0, 0, 0)),
@@ -187,7 +182,7 @@ void AppListItemView::SetUIState(UIState state) {
}
#endif // !OS_WIN
- SchedulePaint();
+ Layout();
}
void AppListItemView::SetTouchDragging(bool touch_dragging) {
@@ -203,36 +198,6 @@ void AppListItemView::OnMouseDragTimer() {
SetUIState(UI_STATE_DRAGGING);
}
-void AppListItemView::SetTitleSubpixelAA() {
- // TODO(tapted): Enable AA for folders as well, taking care to play nice with
- // the folder bubble animation.
- bool enable_aa = !item_->IsInFolder() && ui_state_ == UI_STATE_NORMAL &&
- !item_->highlighted() &&
- !apps_grid_view_->IsSelectedView(this) &&
- !apps_grid_view_->IsAnimatingView(this);
-
- bool currently_enabled = title_->background() != NULL;
- if (currently_enabled == enable_aa)
- return;
-
- if (enable_aa) {
- title_->SetBackgroundColor(app_list::kContentsBackgroundColor);
- title_->set_background(views::Background::CreateSolidBackground(
- app_list::kContentsBackgroundColor));
- } else {
- // In other cases, keep the background transparent to ensure correct
- // interactions with animations. This will temporarily disable subpixel AA.
- title_->SetBackgroundColor(0);
- title_->set_background(NULL);
- }
- title_->Invalidate();
- title_->SchedulePaint();
-}
-
-void AppListItemView::Prerender() {
- title_->PaintToBackingImage();
-}
-
void AppListItemView::CancelContextMenu() {
if (context_menu_runner_)
context_menu_runner_->Cancel();
@@ -265,7 +230,6 @@ void AppListItemView::ItemIconChanged() {
void AppListItemView::ItemNameChanged() {
title_->SetText(base::UTF8ToUTF16(item_->GetDisplayName()));
- title_->Invalidate();
UpdateTooltip();
// Use full name for accessibility.
SetAccessibleName(item_->GetItemType() == AppListFolderItem::kItemType
@@ -278,7 +242,7 @@ void AppListItemView::ItemNameChanged() {
void AppListItemView::ItemHighlightedChanged() {
apps_grid_view_->EnsureViewVisible(this);
- SchedulePaint();
+ Layout();
}
void AppListItemView::ItemIsInstallingChanged() {
@@ -286,7 +250,7 @@ void AppListItemView::ItemIsInstallingChanged() {
apps_grid_view_->EnsureViewVisible(this);
title_->SetVisible(!item_->is_installing());
progress_bar_->SetVisible(item_->is_installing());
- SchedulePaint();
+ Layout();
}
void AppListItemView::ItemPercentDownloadedChanged() {
@@ -303,46 +267,33 @@ const char* AppListItemView::GetClassName() const {
}
void AppListItemView::Layout() {
- gfx::Rect rect(GetContentsBounds());
-
- const int left_right_padding =
- title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars);
- rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0);
- const int y = rect.y();
+ SkColor color = app_list::kContentsBackgroundColor;
+ if (item_->highlighted() && !item_->is_installing())
+ color = kHighlightedColor;
+ else if (apps_grid_view_->IsSelectedView(this))
+ color = kSelectedColor;
+ set_background(views::Background::CreateSolidBackground(color));
icon_->SetBoundsRect(GetIconBoundsForTargetViewBounds(GetContentsBounds()));
- const gfx::Size title_size = title_->GetPreferredSize();
- gfx::Rect title_bounds(rect.x() + (rect.width() - title_size.width()) / 2,
- y + icon_size_.height() + kIconTitleSpacing,
- title_size.width(),
- title_size.height());
- title_bounds.Intersect(rect);
- title_->SetBoundsRect(title_bounds);
+
+ gfx::Rect rect(icon_->bounds());
+ rect.set_y(icon_->bounds().bottom() + kIconTitleSpacing);
+ rect.set_height(title_->GetPreferredSize().height());
+ rect.Intersect(GetContentsBounds());
+ title_->SetBoundsRect(rect);
+ title_->SetBackgroundColor(color);
gfx::Rect progress_bar_bounds(progress_bar_->GetPreferredSize());
progress_bar_bounds.set_x(GetContentsBounds().x() +
kProgressBarHorizontalPadding);
- progress_bar_bounds.set_y(title_bounds.y());
+ progress_bar_bounds.set_y(rect.y());
progress_bar_->SetBoundsRect(progress_bar_bounds);
-}
-void AppListItemView::SchedulePaintInRect(const gfx::Rect& r) {
- SetTitleSubpixelAA();
- views::CustomButton::SchedulePaintInRect(r);
+ SchedulePaint();
}
void AppListItemView::OnPaint(gfx::Canvas* canvas) {
- if (apps_grid_view_->IsDraggedView(this))
- return;
-
- gfx::Rect rect(GetContentsBounds());
- if (item_->highlighted() && !item_->is_installing()) {
- canvas->FillRect(rect, kHighlightedColor);
- return;
- }
- if (apps_grid_view_->IsSelectedView(this))
- canvas->FillRect(rect, kSelectedColor);
-
+ CustomButton::OnPaint(canvas);
if (ui_state_ == UI_STATE_DROPPING_IN_FOLDER) {
DCHECK(apps_grid_view_->model()->folders_enabled());
@@ -384,6 +335,7 @@ void AppListItemView::StateChanged() {
if (state() == STATE_HOVERED || state() == STATE_PRESSED) {
if (!is_folder_ui_enabled)
apps_grid_view_->SetSelectedView(this);
+ item_->SetHighlighted(true);
title_->SetEnabledColor(kGridTitleHoverColor);
} else {
if (!is_folder_ui_enabled)
@@ -391,7 +343,7 @@ void AppListItemView::StateChanged() {
item_->SetHighlighted(false);
title_->SetEnabledColor(kGridTitleColor);
}
- title_->Invalidate();
+ Layout();
}
bool AppListItemView::ShouldEnterPushedState(const ui::Event& event) {

Powered by Google App Engine
This is Rietveld 408576698