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

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

Issue 326023002: App list: TileItemView::SetAppListItem exits early if item already set. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test failure (TileItemView is invisible by default). Created 6 years, 6 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 | « no previous file | 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/tile_item_view.h" 5 #include "ui/app_list/views/tile_item_view.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/app_list/app_list_constants.h" 8 #include "ui/app_list/app_list_constants.h"
9 #include "ui/app_list/app_list_item.h" 9 #include "ui/app_list/app_list_item.h"
10 #include "ui/app_list/app_list_model.h" 10 #include "ui/app_list/app_list_model.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 SetLayoutManager(layout_manager); 87 SetLayoutManager(layout_manager);
88 88
89 icon_->SetImageSize(gfx::Size(kTileImageSize, kTileImageSize)); 89 icon_->SetImageSize(gfx::Size(kTileImageSize, kTileImageSize));
90 90
91 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 91 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
92 title_->SetAutoColorReadabilityEnabled(false); 92 title_->SetAutoColorReadabilityEnabled(false);
93 title_->SetEnabledColor(kGridTitleColor); 93 title_->SetEnabledColor(kGridTitleColor);
94 title_->SetFontList(rb.GetFontList(kItemTextFontStyle)); 94 title_->SetFontList(rb.GetFontList(kItemTextFontStyle));
95 title_->SetHorizontalAlignment(gfx::ALIGN_CENTER); 95 title_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
96 96
97 // When |item_| is NULL, the tile is invisible. Calling SetAppListItem with a
98 // non-NULL item makes the tile visible.
99 SetVisible(false);
Matt Giuca 2014/06/16 00:29:28 I don't think adding this actually changes any beh
100
97 AddChildView(icon_); 101 AddChildView(icon_);
98 AddChildView(title_); 102 AddChildView(title_);
99 } 103 }
100 104
101 TileItemView::~TileItemView() { 105 TileItemView::~TileItemView() {
102 } 106 }
103 107
104 void TileItemView::SetAppListItem(AppListItem* item) { 108 void TileItemView::SetAppListItem(AppListItem* item) {
109 // TODO(calamity): This will not update if the contents of |item_| have
110 // changed since it was last assigned. Add an observer to refresh when the
111 // item changes.
112 if (item == item_)
113 return;
114
105 item_ = item; 115 item_ = item;
106 if (!item) { 116 if (!item) {
107 SetVisible(false); 117 SetVisible(false);
108 icon_->SetImage(NULL); 118 icon_->SetImage(NULL);
109 title_->SetText(base::string16()); 119 title_->SetText(base::string16());
110 return; 120 return;
111 } 121 }
112 122
113 SetVisible(true); 123 SetVisible(true);
114 icon_->SetImage(item_->icon()); 124 icon_->SetImage(item_->icon());
115 title_->SetText(base::UTF8ToUTF16(item_->name())); 125 title_->SetText(base::UTF8ToUTF16(item_->name()));
116 126
117 background_->set_strip_color( 127 background_->set_strip_color(
118 color_utils::CalculateKMeanColorOfBitmap(*item_->icon().bitmap())); 128 color_utils::CalculateKMeanColorOfBitmap(*item_->icon().bitmap()));
119 } 129 }
120 130
121 gfx::Size TileItemView::GetPreferredSize() const { 131 gfx::Size TileItemView::GetPreferredSize() const {
122 return gfx::Size(kTileSize, kTileSize); 132 return gfx::Size(kTileSize, kTileSize);
123 } 133 }
124 134
125 void TileItemView::ButtonPressed(views::Button* sender, 135 void TileItemView::ButtonPressed(views::Button* sender,
126 const ui::Event& event) { 136 const ui::Event& event) {
127 item_->Activate(event.flags()); 137 item_->Activate(event.flags());
128 } 138 }
129 139
130 } // namespace app_list 140 } // namespace app_list
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698