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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/app_list/views/tile_item_view.h ('k') | 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"
11 #include "ui/app_list/app_list_view_delegate.h" 11 #include "ui/app_list/app_list_view_delegate.h"
12 #include "ui/app_list/search_result.h"
12 #include "ui/app_list/views/app_list_main_view.h" 13 #include "ui/app_list/views/app_list_main_view.h"
13 #include "ui/gfx/canvas.h" 14 #include "ui/gfx/canvas.h"
14 #include "ui/gfx/color_analysis.h" 15 #include "ui/gfx/color_analysis.h"
15 #include "ui/gfx/color_utils.h" 16 #include "ui/gfx/color_utils.h"
16 #include "ui/views/background.h" 17 #include "ui/views/background.h"
17 #include "ui/views/controls/image_view.h" 18 #include "ui/views/controls/image_view.h"
18 #include "ui/views/controls/label.h" 19 #include "ui/views/controls/label.h"
19 #include "ui/views/layout/box_layout.h" 20 #include "ui/views/layout/box_layout.h"
20 21
21 namespace { 22 namespace {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 SetLayoutManager(layout_manager); 86 SetLayoutManager(layout_manager);
86 87
87 icon_->SetImageSize(gfx::Size(kTileIconSize, kTileIconSize)); 88 icon_->SetImageSize(gfx::Size(kTileIconSize, kTileIconSize));
88 89
89 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 90 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
90 title_->SetAutoColorReadabilityEnabled(false); 91 title_->SetAutoColorReadabilityEnabled(false);
91 title_->SetEnabledColor(kGridTitleColor); 92 title_->SetEnabledColor(kGridTitleColor);
92 title_->SetFontList(rb.GetFontList(kItemTextFontStyle)); 93 title_->SetFontList(rb.GetFontList(kItemTextFontStyle));
93 title_->SetHorizontalAlignment(gfx::ALIGN_CENTER); 94 title_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
94 95
95 // When |item_| is NULL, the tile is invisible. Calling SetAppListItem with a 96 // When |item_| is NULL, the tile is invisible. Calling SetSearchResult with a
96 // non-NULL item makes the tile visible. 97 // non-NULL item makes the tile visible.
97 SetVisible(false); 98 SetVisible(false);
98 99
99 AddChildView(icon_); 100 AddChildView(icon_);
100 AddChildView(title_); 101 AddChildView(title_);
101 } 102 }
102 103
103 TileItemView::~TileItemView() { 104 TileItemView::~TileItemView() {
105 if (item_)
106 item_->RemoveObserver(this);
104 } 107 }
105 108
106 void TileItemView::SetAppListItem(AppListItem* item) { 109 void TileItemView::SetSearchResult(SearchResult* item) {
107 // TODO(calamity): This will not update if the contents of |item_| have 110 SetVisible(item != NULL);
108 // changed since it was last assigned. Add an observer to refresh when the 111
109 // item changes. 112 SearchResult* old_item = item_;
110 if (item == item_) 113 if (old_item)
114 old_item->RemoveObserver(this);
115
116 item_ = item;
117
118 if (!item)
111 return; 119 return;
112 120
113 item_ = item; 121 item_->AddObserver(this);
114 if (!item) { 122
115 SetVisible(false); 123 title_->SetText(item_->title());
116 icon_->SetImage(NULL); 124
117 title_->SetText(base::string16()); 125 // Only refresh the icon if it's different from the old one. This prevents
118 return; 126 // flickering.
127 if (old_item == NULL ||
128 !item->icon().BackedBySameObjectAs(old_item->icon())) {
129 OnIconChanged();
119 } 130 }
120
121 SetVisible(true);
122 icon_->SetImage(item_->icon());
123 title_->SetText(base::UTF8ToUTF16(item_->name()));
124
125 background_->set_strip_color(
126 color_utils::CalculateKMeanColorOfBitmap(*item_->icon().bitmap()));
127 } 131 }
128 132
129 gfx::Size TileItemView::GetPreferredSize() const { 133 gfx::Size TileItemView::GetPreferredSize() const {
130 return gfx::Size(kTileSize, kTileSize); 134 return gfx::Size(kTileSize, kTileSize);
131 } 135 }
132 136
133 void TileItemView::ButtonPressed(views::Button* sender, 137 void TileItemView::ButtonPressed(views::Button* sender,
134 const ui::Event& event) { 138 const ui::Event& event) {
135 item_->Activate(event.flags()); 139 item_->Open(event.flags());
140 }
141
142 void TileItemView::OnIconChanged() {
143 icon_->SetImage(item_->icon());
144 background_->set_strip_color(
145 color_utils::CalculateKMeanColorOfBitmap(*item_->icon().bitmap()));
146 SchedulePaint();
147 }
148
149 void TileItemView::OnResultDestroying() {
150 if (item_)
151 item_->RemoveObserver(this);
152 item_ = NULL;
136 } 153 }
137 154
138 } // namespace app_list 155 } // namespace app_list
OLDNEW
« 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