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

Unified Diff: ui/app_list/views/tile_item_view.cc

Issue 439703002: Allow app list tiles to show search results in the experimental app list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix merge Created 6 years, 4 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
« no previous file with comments | « ui/app_list/views/tile_item_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9997fabeac571975eb45303fc0ea9c8d23448b3f..029df192478145d9ea55550621bee8bd2f548870 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"
@@ -92,7 +93,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);
@@ -101,29 +102,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())) {
+ OnIconChanged();
+ }
}
gfx::Size TileItemView::GetPreferredSize() const {
@@ -132,7 +136,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
« no previous file with comments | « ui/app_list/views/tile_item_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698