Chromium Code Reviews| Index: ui/app_list/views/tile_item_view.cc |
| diff --git a/ui/app_list/views/tile_item_view.cc b/ui/app_list/views/tile_item_view.cc |
| index dcc30c383749d85b751b3aab453b1e6b37860ec7..7afe2125f305895724956943ad1f4f79405b9d6a 100644 |
| --- a/ui/app_list/views/tile_item_view.cc |
| +++ b/ui/app_list/views/tile_item_view.cc |
| @@ -9,6 +9,7 @@ |
| #include "ui/app_list/app_list_item.h" |
| #include "ui/app_list/app_list_model.h" |
| #include "ui/app_list/app_list_view_delegate.h" |
| +#include "ui/app_list/search_result.h" |
| #include "ui/app_list/views/app_list_main_view.h" |
| #include "ui/gfx/canvas.h" |
| #include "ui/gfx/color_analysis.h" |
| @@ -93,7 +94,7 @@ TileItemView::TileItemView() |
| title_->SetFontList(rb.GetFontList(kItemTextFontStyle)); |
| title_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| - // When |item_| is NULL, the tile is invisible. Calling SetAppListItem with a |
| + // When |item_| is NULL, the tile is invisible. Calling SetSearchResult with a |
| // non-NULL item makes the tile visible. |
| SetVisible(false); |
| @@ -102,29 +103,32 @@ TileItemView::TileItemView() |
| } |
| TileItemView::~TileItemView() { |
| + if (item_) |
| + item_->RemoveObserver(this); |
| } |
| -void TileItemView::SetAppListItem(AppListItem* item) { |
| - // TODO(calamity): This will not update if the contents of |item_| have |
| - // changed since it was last assigned. Add an observer to refresh when the |
| - // item changes. |
| - if (item == item_) |
| - return; |
| +void TileItemView::SetSearchResult(SearchResult* item) { |
| + SetVisible(item != NULL); |
| + |
| + SearchResult* old_item = item_; |
| + if (old_item) |
| + old_item->RemoveObserver(this); |
| item_ = item; |
| - if (!item) { |
| - SetVisible(false); |
| - icon_->SetImage(NULL); |
| - title_->SetText(base::string16()); |
| + |
| + if (!item) |
| return; |
| - } |
| - SetVisible(true); |
| - icon_->SetImage(item_->icon()); |
| - title_->SetText(base::UTF8ToUTF16(item_->name())); |
| + item_->AddObserver(this); |
| - background_->set_strip_color( |
| - color_utils::CalculateKMeanColorOfBitmap(*item_->icon().bitmap())); |
| + title_->SetText(item_->title()); |
| + |
| + // Only refresh the icon if it's different from the old one. This prevents |
| + // flickering. |
| + if (old_item == NULL || |
| + !item->icon().BackedBySameObjectAs(old_item->icon())) { |
|
Matt Giuca
2014/08/06 08:54:53
Do this for AppListItem in a separate patch. (You
calamity
2014/08/12 05:03:37
As discussed, doing this for AppListItems could ha
|
| + OnIconChanged(); |
| + } |
| } |
| gfx::Size TileItemView::GetPreferredSize() const { |
| @@ -133,7 +137,20 @@ gfx::Size TileItemView::GetPreferredSize() const { |
| void TileItemView::ButtonPressed(views::Button* sender, |
| const ui::Event& event) { |
| - item_->Activate(event.flags()); |
| + item_->Open(event.flags()); |
| +} |
| + |
| +void TileItemView::OnIconChanged() { |
| + icon_->SetImage(item_->icon()); |
| + background_->set_strip_color( |
| + color_utils::CalculateKMeanColorOfBitmap(*item_->icon().bitmap())); |
| + SchedulePaint(); |
| +} |
| + |
| +void TileItemView::OnResultDestroying() { |
| + if (item_) |
| + item_->RemoveObserver(this); |
| + item_ = NULL; |
| } |
| } // namespace app_list |