OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/app_list/views/search_result_tile_item_view.h" |
| 6 |
| 7 #include "ui/app_list/search_result.h" |
| 8 |
| 9 namespace app_list { |
| 10 |
| 11 SearchResultTileItemView::SearchResultTileItemView() : item_(NULL) { |
| 12 } |
| 13 |
| 14 SearchResultTileItemView::~SearchResultTileItemView() { |
| 15 if (item_) |
| 16 item_->RemoveObserver(this); |
| 17 } |
| 18 |
| 19 void SearchResultTileItemView::SetSearchResult(SearchResult* item) { |
| 20 SetVisible(item != NULL); |
| 21 |
| 22 SearchResult* old_item = item_; |
| 23 if (old_item) |
| 24 old_item->RemoveObserver(this); |
| 25 |
| 26 item_ = item; |
| 27 |
| 28 if (!item) |
| 29 return; |
| 30 |
| 31 item_->AddObserver(this); |
| 32 |
| 33 SetTitle(item_->title()); |
| 34 |
| 35 // Only refresh the icon if it's different from the old one. This prevents |
| 36 // flickering. |
| 37 if (old_item == NULL || |
| 38 !item->icon().BackedBySameObjectAs(old_item->icon())) { |
| 39 OnIconChanged(); |
| 40 } |
| 41 } |
| 42 |
| 43 void SearchResultTileItemView::ButtonPressed(views::Button* sender, |
| 44 const ui::Event& event) { |
| 45 item_->Open(event.flags()); |
| 46 } |
| 47 |
| 48 void SearchResultTileItemView::OnIconChanged() { |
| 49 SetIcon(item_->icon()); |
| 50 } |
| 51 |
| 52 void SearchResultTileItemView::OnResultDestroying() { |
| 53 if (item_) |
| 54 item_->RemoveObserver(this); |
| 55 item_ = NULL; |
| 56 } |
| 57 |
| 58 } // namespace app_list |
OLD | NEW |