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

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: 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
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 (item_->display_type() == SearchResult::DISPLAY_RECOMMENDATION) {
76 title()->SetFontList(base_font.DeriveWithSizeDelta(1));
77 title()->SetEnabledColor(kRecommendationTileColor);
78 }
79
52 // Only refresh the icon if it's different from the old one. This prevents 80 // Only refresh the icon if it's different from the old one. This prevents
53 // flickering. 81 // flickering.
54 if (old_item == NULL || 82 if (!old_item || !item->icon().BackedBySameObjectAs(old_item->icon())) {
55 !item->icon().BackedBySameObjectAs(old_item->icon())) {
56 OnIconChanged(); 83 OnIconChanged();
57 } 84 }
58 } 85 }
59 86
60 void SearchResultTileItemView::ButtonPressed(views::Button* sender, 87 void SearchResultTileItemView::ButtonPressed(views::Button* sender,
61 const ui::Event& event) { 88 const ui::Event& event) {
62 view_delegate_->OpenSearchResult(item_, false, event.flags()); 89 view_delegate_->OpenSearchResult(item_, false, event.flags());
63 } 90 }
64 91
65 bool SearchResultTileItemView::OnKeyPressed(const ui::KeyEvent& event) { 92 bool SearchResultTileItemView::OnKeyPressed(const ui::KeyEvent& event) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 if (!selected()) 131 if (!selected())
105 result_container_->ClearSelectedIndex(); 132 result_container_->ClearSelectedIndex();
106 133
107 context_menu_runner_.reset( 134 context_menu_runner_.reset(
108 new views::MenuRunner(menu_model, views::MenuRunner::HAS_MNEMONICS)); 135 new views::MenuRunner(menu_model, views::MenuRunner::HAS_MNEMONICS));
109 context_menu_runner_->RunMenuAt(GetWidget(), nullptr, 136 context_menu_runner_->RunMenuAt(GetWidget(), nullptr,
110 gfx::Rect(point, gfx::Size()), 137 gfx::Rect(point, gfx::Size()),
111 views::MENU_ANCHOR_TOPLEFT, source_type); 138 views::MENU_ANCHOR_TOPLEFT, source_type);
112 } 139 }
113 140
141 void SearchResultTileItemView::Layout() {
142 gfx::Rect rect(GetContentsBounds());
143 if (rect.IsEmpty())
144 return;
145
146 if (is_fullscreen_app_list_enabled_ && item_) {
xiyuan 2017/06/21 18:24:00 nit: revise to bail early to have less indent. i.
Qiang(Joe) Xu 2017/06/21 18:50:12 Done.
147 if (item_->display_type() == SearchResult::DISPLAY_RECOMMENDATION) {
148 rect.Inset(0, kRecommendationIconTopPadding, 0, 0);
149 icon()->SetBoundsRect(rect);
150
151 rect.Inset(0, kGridIconDimension + kRecommendationTitleSpacing, 0, 0);
152 rect.set_height(title()->GetPreferredSize().height());
153 rect.set_width(kRecommendationTileMaxWidth);
154 title()->SetBoundsRect(rect);
155 } else if (item_->display_type() == SearchResult::DISPLAY_TILE) {
156 rect.Inset(0, kSearchTileTopPadding, 0, 0);
157 icon()->SetBoundsRect(rect);
158 if (badge()) {
159 gfx::Rect badge_rect(rect);
160 gfx::Size icon_size = icon()->GetImage().size();
161 badge_rect.Offset((icon_size.width() - kAppBadgeIconSize) / 2,
162 icon_size.height() - kBadgeBackgroundRadius -
163 kAppBadgeIconSize / 2);
164 badge()->SetBoundsRect(badge_rect);
165
166 rect.Inset(0, kGridIconDimension + kSearchTitleSpacing, 0, 0);
167 rect.set_height(title()->GetPreferredSize().height());
168 title()->SetBoundsRect(rect);
169 }
170 }
171 } else {
172 TileItemView::Layout();
173 }
174 }
175
176 gfx::Size SearchResultTileItemView::CalculatePreferredSize() const {
177 if (is_fullscreen_app_list_enabled_ && item_ &&
178 item_->display_type() == SearchResult::DISPLAY_RECOMMENDATION) {
179 return gfx::Size(kRecommendationTileWidth, kRecommendationTileHeight);
180 }
181
182 return TileItemView::CalculatePreferredSize();
183 }
184
114 } // namespace app_list 185 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698