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

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

Issue 2952823002: cros: Make SearchResultTileItemView layout per DisplayType customized (Closed)
Patch Set: nits Created 3 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
« no previous file with comments | « ui/app_list/views/search_result_tile_item_view.h ('k') | ui/app_list/views/tile_item_view.h » ('j') | 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/search_result_tile_item_view.h" 5 #include "ui/app_list/views/search_result_tile_item_view.h"
6 6
7 #include "ui/app_list/app_list_constants.h"
8 #include "ui/app_list/app_list_features.h"
7 #include "ui/app_list/app_list_view_delegate.h" 9 #include "ui/app_list/app_list_view_delegate.h"
8 #include "ui/app_list/search_result.h" 10 #include "ui/app_list/search_result.h"
9 #include "ui/app_list/views/search_result_container_view.h" 11 #include "ui/app_list/views/search_result_container_view.h"
12 #include "ui/views/controls/image_view.h"
13 #include "ui/views/controls/label.h"
10 #include "ui/views/controls/menu/menu_runner.h" 14 #include "ui/views/controls/menu/menu_runner.h"
11 15
12 namespace app_list { 16 namespace app_list {
13 17
18 namespace {
19
20 constexpr int kRecommendationTileWidth = 96;
21 constexpr int kRecommendationTileHeight = 99;
22 constexpr int kRecommendationIconTopPadding = 24;
23 constexpr int kRecommendationTitleSpacing = 10;
24 constexpr int kRecommendationTileMaxWidth = 80;
25
26 constexpr int kSearchTileTopPadding = 4;
27 constexpr int kSearchTitleSpacing = 6;
28
29 constexpr SkColor kRecommendationTileColor = SK_ColorWHITE;
30
31 } // namespace
32
14 SearchResultTileItemView::SearchResultTileItemView( 33 SearchResultTileItemView::SearchResultTileItemView(
15 SearchResultContainerView* result_container, 34 SearchResultContainerView* result_container,
16 AppListViewDelegate* view_delegate) 35 AppListViewDelegate* view_delegate)
17 : result_container_(result_container), 36 : result_container_(result_container),
18 item_(nullptr), 37 item_(nullptr),
19 view_delegate_(view_delegate) { 38 view_delegate_(view_delegate),
39 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) {
20 // When |item_| is null, the tile is invisible. Calling SetSearchResult with a 40 // When |item_| is null, the tile is invisible. Calling SetSearchResult with a
21 // non-null item makes the tile visible. 41 // non-null item makes the tile visible.
22 SetVisible(false); 42 SetVisible(false);
23 43
24 set_context_menu_controller(this); 44 set_context_menu_controller(this);
25 } 45 }
26 46
27 SearchResultTileItemView::~SearchResultTileItemView() { 47 SearchResultTileItemView::~SearchResultTileItemView() {
28 if (item_) 48 if (item_)
29 item_->RemoveObserver(this); 49 item_->RemoveObserver(this);
30 } 50 }
31 51
32 void SearchResultTileItemView::SetSearchResult(SearchResult* item) { 52 void SearchResultTileItemView::SetSearchResult(SearchResult* item) {
33 // Handle the case where this may be called from a nested run loop while its 53 // Handle the case where this may be called from a nested run loop while its
34 // context menu is showing. This cancels the menu (it's for the old item). 54 // context menu is showing. This cancels the menu (it's for the old item).
35 context_menu_runner_.reset(); 55 context_menu_runner_.reset();
36 56
37 SetVisible(item != NULL); 57 SetVisible(!!item);
38 58
39 SearchResult* old_item = item_; 59 SearchResult* old_item = item_;
40 if (old_item) 60 if (old_item)
41 old_item->RemoveObserver(this); 61 old_item->RemoveObserver(this);
42 62
43 item_ = item; 63 item_ = item;
44 64
45 if (!item) 65 if (!item)
46 return; 66 return;
47 67
48 item_->AddObserver(this); 68 item_->AddObserver(this);
49 69
50 SetTitle(item_->title()); 70 SetTitle(item_->title());
51 71
72 // Customize title UI
73 gfx::FontList base_font = ui::ResourceBundle::GetSharedInstance().GetFontList(
74 ui::ResourceBundle::BaseFont);
75 if (is_fullscreen_app_list_enabled_ &&
76 item_->display_type() == SearchResult::DISPLAY_RECOMMENDATION) {
77 title()->SetFontList(base_font.DeriveWithSizeDelta(1));
78 title()->SetEnabledColor(kRecommendationTileColor);
79 }
80
52 // Only refresh the icon if it's different from the old one. This prevents 81 // Only refresh the icon if it's different from the old one. This prevents
53 // flickering. 82 // flickering.
54 if (old_item == NULL || 83 if (!old_item || !item->icon().BackedBySameObjectAs(old_item->icon())) {
55 !item->icon().BackedBySameObjectAs(old_item->icon())) {
56 OnIconChanged(); 84 OnIconChanged();
57 } 85 }
58 } 86 }
59 87
60 void SearchResultTileItemView::ButtonPressed(views::Button* sender, 88 void SearchResultTileItemView::ButtonPressed(views::Button* sender,
61 const ui::Event& event) { 89 const ui::Event& event) {
62 view_delegate_->OpenSearchResult(item_, false, event.flags()); 90 view_delegate_->OpenSearchResult(item_, false, event.flags());
63 } 91 }
64 92
65 bool SearchResultTileItemView::OnKeyPressed(const ui::KeyEvent& event) { 93 bool SearchResultTileItemView::OnKeyPressed(const ui::KeyEvent& event) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 if (!selected()) 132 if (!selected())
105 result_container_->ClearSelectedIndex(); 133 result_container_->ClearSelectedIndex();
106 134
107 context_menu_runner_.reset( 135 context_menu_runner_.reset(
108 new views::MenuRunner(menu_model, views::MenuRunner::HAS_MNEMONICS)); 136 new views::MenuRunner(menu_model, views::MenuRunner::HAS_MNEMONICS));
109 context_menu_runner_->RunMenuAt(GetWidget(), nullptr, 137 context_menu_runner_->RunMenuAt(GetWidget(), nullptr,
110 gfx::Rect(point, gfx::Size()), 138 gfx::Rect(point, gfx::Size()),
111 views::MENU_ANCHOR_TOPLEFT, source_type); 139 views::MENU_ANCHOR_TOPLEFT, source_type);
112 } 140 }
113 141
142 void SearchResultTileItemView::Layout() {
143 gfx::Rect rect(GetContentsBounds());
144 if (rect.IsEmpty())
145 return;
146
147 if (!is_fullscreen_app_list_enabled_ || !item_) {
148 TileItemView::Layout();
149 return;
150 }
151
152 if (item_->display_type() == SearchResult::DISPLAY_RECOMMENDATION) {
153 rect.Inset(0, kRecommendationIconTopPadding, 0, 0);
154 icon()->SetBoundsRect(rect);
155
156 rect.Inset(0, kGridIconDimension + kRecommendationTitleSpacing, 0, 0);
157 rect.set_height(title()->GetPreferredSize().height());
158 rect.set_width(kRecommendationTileMaxWidth);
159 title()->SetBoundsRect(rect);
160 } else if (item_->display_type() == SearchResult::DISPLAY_TILE) {
161 rect.Inset(0, kSearchTileTopPadding, 0, 0);
162 icon()->SetBoundsRect(rect);
163
164 if (badge()) {
165 gfx::Rect badge_rect(rect);
166 gfx::Size icon_size = icon()->GetImage().size();
167 badge_rect.Offset(
168 (icon_size.width() - kAppBadgeIconSize) / 2,
169 icon_size.height() - kBadgeBackgroundRadius - kAppBadgeIconSize / 2);
170 badge()->SetBoundsRect(badge_rect);
171 }
172
173 rect.Inset(0, kGridIconDimension + kSearchTitleSpacing, 0, 0);
174 rect.set_height(title()->GetPreferredSize().height());
175 title()->SetBoundsRect(rect);
176 } else {
177 TileItemView::Layout();
178 }
179 }
180
181 gfx::Size SearchResultTileItemView::CalculatePreferredSize() const {
182 if (is_fullscreen_app_list_enabled_ && item_ &&
183 item_->display_type() == SearchResult::DISPLAY_RECOMMENDATION) {
184 return gfx::Size(kRecommendationTileWidth, kRecommendationTileHeight);
185 }
186
187 return TileItemView::CalculatePreferredSize();
188 }
189
114 } // namespace app_list 190 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/search_result_tile_item_view.h ('k') | ui/app_list/views/tile_item_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698