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

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

Issue 458983004: Move app list search result icon sizes to app_list_constants. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compile 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/search_result.cc ('k') | ui/app_list/views/tile_item_view.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_view.h" 5 #include "ui/app_list/views/search_result_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ui/app_list/app_list_constants.h" 9 #include "ui/app_list/app_list_constants.h"
10 #include "ui/app_list/search_result.h" 10 #include "ui/app_list/search_result.h"
11 #include "ui/app_list/views/progress_bar_view.h" 11 #include "ui/app_list/views/progress_bar_view.h"
12 #include "ui/app_list/views/search_result_actions_view.h" 12 #include "ui/app_list/views/search_result_actions_view.h"
13 #include "ui/app_list/views/search_result_list_view.h" 13 #include "ui/app_list/views/search_result_list_view.h"
14 #include "ui/gfx/canvas.h" 14 #include "ui/gfx/canvas.h"
15 #include "ui/gfx/font.h" 15 #include "ui/gfx/font.h"
16 #include "ui/gfx/image/image_skia_operations.h" 16 #include "ui/gfx/image/image_skia_operations.h"
17 #include "ui/gfx/render_text.h" 17 #include "ui/gfx/render_text.h"
18 #include "ui/views/controls/button/image_button.h" 18 #include "ui/views/controls/button/image_button.h"
19 #include "ui/views/controls/image_view.h" 19 #include "ui/views/controls/image_view.h"
20 #include "ui/views/controls/menu/menu_runner.h" 20 #include "ui/views/controls/menu/menu_runner.h"
21 21
22 namespace app_list { 22 namespace app_list {
23 23
24 namespace { 24 namespace {
25 25
26 const int kPreferredWidth = 300; 26 const int kPreferredWidth = 300;
27 const int kPreferredHeight = 52; 27 const int kPreferredHeight = 52;
28 const int kIconDimension = 32;
29 const int kIconPadding = 14; 28 const int kIconPadding = 14;
30 const int kIconViewWidth = kIconDimension + 2 * kIconPadding;
31 const int kTextTrailPadding = kIconPadding; 29 const int kTextTrailPadding = kIconPadding;
32 const int kBorderSize = 1; 30 const int kBorderSize = 1;
33 31
34 // Extra margin at the right of the rightmost action icon. 32 // Extra margin at the right of the rightmost action icon.
35 const int kActionButtonRightMargin = 8; 33 const int kActionButtonRightMargin = 8;
36 34
35 int GetIconViewWidth() {
36 return kListIconSize + 2 * kIconPadding;
37 }
38
37 // Creates a RenderText of given |text| and |styles|. Caller takes ownership 39 // Creates a RenderText of given |text| and |styles|. Caller takes ownership
38 // of returned RenderText. 40 // of returned RenderText.
39 gfx::RenderText* CreateRenderText(const base::string16& text, 41 gfx::RenderText* CreateRenderText(const base::string16& text,
40 const SearchResult::Tags& tags) { 42 const SearchResult::Tags& tags) {
41 gfx::RenderText* render_text = gfx::RenderText::CreateInstance(); 43 gfx::RenderText* render_text = gfx::RenderText::CreateInstance();
42 render_text->SetText(text); 44 render_text->SetText(text);
43 render_text->SetColor(kResultDefaultTextColor); 45 render_text->SetColor(kResultDefaultTextColor);
44 46
45 for (SearchResult::Tags::const_iterator it = tags.begin(); 47 for (SearchResult::Tags::const_iterator it = tags.begin();
46 it != tags.end(); 48 it != tags.end();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 gfx::Size SearchResultView::GetPreferredSize() const { 138 gfx::Size SearchResultView::GetPreferredSize() const {
137 return gfx::Size(kPreferredWidth, kPreferredHeight); 139 return gfx::Size(kPreferredWidth, kPreferredHeight);
138 } 140 }
139 141
140 void SearchResultView::Layout() { 142 void SearchResultView::Layout() {
141 gfx::Rect rect(GetContentsBounds()); 143 gfx::Rect rect(GetContentsBounds());
142 if (rect.IsEmpty()) 144 if (rect.IsEmpty())
143 return; 145 return;
144 146
145 gfx::Rect icon_bounds(rect); 147 gfx::Rect icon_bounds(rect);
146 icon_bounds.set_width(kIconViewWidth); 148 icon_bounds.set_width(GetIconViewWidth());
147 icon_bounds.Inset(kIconPadding, (rect.height() - kIconDimension) / 2); 149 icon_bounds.Inset(kIconPadding, (rect.height() - kListIconSize) / 2);
148 icon_bounds.Intersect(rect); 150 icon_bounds.Intersect(rect);
149 icon_->SetBoundsRect(icon_bounds); 151 icon_->SetBoundsRect(icon_bounds);
150 152
151 const int max_actions_width = 153 const int max_actions_width =
152 (rect.right() - kActionButtonRightMargin - icon_bounds.right()) / 2; 154 (rect.right() - kActionButtonRightMargin - icon_bounds.right()) / 2;
153 int actions_width = std::min(max_actions_width, 155 int actions_width = std::min(max_actions_width,
154 actions_view_->GetPreferredSize().width()); 156 actions_view_->GetPreferredSize().width());
155 157
156 gfx::Rect actions_bounds(rect); 158 gfx::Rect actions_bounds(rect);
157 actions_bounds.set_x(rect.right() - kActionButtonRightMargin - actions_width); 159 actions_bounds.set_x(rect.right() - kActionButtonRightMargin - actions_width);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 canvas->FillRect(content_rect, kSelectedColor); 216 canvas->FillRect(content_rect, kSelectedColor);
215 else if (hover) 217 else if (hover)
216 canvas->FillRect(content_rect, kHighlightedColor); 218 canvas->FillRect(content_rect, kHighlightedColor);
217 else 219 else
218 canvas->FillRect(content_rect, kContentsBackgroundColor); 220 canvas->FillRect(content_rect, kContentsBackgroundColor);
219 221
220 gfx::Rect border_bottom = gfx::SubtractRects(rect, content_rect); 222 gfx::Rect border_bottom = gfx::SubtractRects(rect, content_rect);
221 canvas->FillRect(border_bottom, kResultBorderColor); 223 canvas->FillRect(border_bottom, kResultBorderColor);
222 224
223 gfx::Rect text_bounds(rect); 225 gfx::Rect text_bounds(rect);
224 text_bounds.set_x(kIconViewWidth); 226 text_bounds.set_x(GetIconViewWidth());
225 if (actions_view_->visible()) { 227 if (actions_view_->visible()) {
226 text_bounds.set_width( 228 text_bounds.set_width(
227 rect.width() - kIconViewWidth - kTextTrailPadding - 229 rect.width() - GetIconViewWidth() - kTextTrailPadding -
228 actions_view_->bounds().width() - 230 actions_view_->bounds().width() -
229 (actions_view_->has_children() ? kActionButtonRightMargin : 0)); 231 (actions_view_->has_children() ? kActionButtonRightMargin : 0));
230 } else { 232 } else {
231 text_bounds.set_width( 233 text_bounds.set_width(rect.width() - GetIconViewWidth() -
232 rect.width() - kIconViewWidth - kTextTrailPadding - 234 kTextTrailPadding - progress_bar_->bounds().width() -
233 progress_bar_->bounds().width() - kActionButtonRightMargin); 235 kActionButtonRightMargin);
234 } 236 }
235 text_bounds.set_x(GetMirroredXWithWidthInView(text_bounds.x(), 237 text_bounds.set_x(GetMirroredXWithWidthInView(text_bounds.x(),
236 text_bounds.width())); 238 text_bounds.width()));
237 239
238 if (title_text_ && details_text_) { 240 if (title_text_ && details_text_) {
239 gfx::Size title_size(text_bounds.width(), 241 gfx::Size title_size(text_bounds.width(),
240 title_text_->GetStringSize().height()); 242 title_text_->GetStringSize().height());
241 gfx::Size details_size(text_bounds.width(), 243 gfx::Size details_size(text_bounds.width(),
242 details_text_->GetStringSize().height()); 244 details_text_->GetStringSize().height());
243 int total_height = title_size.height() + + details_size.height(); 245 int total_height = title_size.height() + + details_size.height();
(...skipping 28 matching lines...) Expand all
272 gfx::ImageSkia image(result_ ? result_->icon() : gfx::ImageSkia()); 274 gfx::ImageSkia image(result_ ? result_->icon() : gfx::ImageSkia());
273 // Note this might leave the view with an old icon. But it is needed to avoid 275 // Note this might leave the view with an old icon. But it is needed to avoid
274 // flash when a SearchResult's icon is loaded asynchronously. In this case, it 276 // flash when a SearchResult's icon is loaded asynchronously. In this case, it
275 // looks nicer to keep the stale icon for a little while on screen instead of 277 // looks nicer to keep the stale icon for a little while on screen instead of
276 // clearing it out. It should work correctly as long as the SearchResult does 278 // clearing it out. It should work correctly as long as the SearchResult does
277 // not forget to SetIcon when it's ready. 279 // not forget to SetIcon when it's ready.
278 if (image.isNull()) 280 if (image.isNull())
279 return; 281 return;
280 282
281 // Scales down big icons but leave small ones unchanged. 283 // Scales down big icons but leave small ones unchanged.
282 if (image.width() > kIconDimension || image.height() > kIconDimension) { 284 if (image.width() > kListIconSize || image.height() > kListIconSize) {
283 image = gfx::ImageSkiaOperations::CreateResizedImage( 285 image = gfx::ImageSkiaOperations::CreateResizedImage(
284 image, 286 image,
285 skia::ImageOperations::RESIZE_BEST, 287 skia::ImageOperations::RESIZE_BEST,
286 gfx::Size(kIconDimension, kIconDimension)); 288 gfx::Size(kListIconSize, kListIconSize));
287 } else { 289 } else {
288 icon_->ResetImageSize(); 290 icon_->ResetImageSize();
289 } 291 }
290 292
291 // Set the image to an empty image before we reset the image because 293 // Set the image to an empty image before we reset the image because
292 // since we're using the same backing store for our images, sometimes 294 // since we're using the same backing store for our images, sometimes
293 // ImageView won't detect that we have a new image set due to the pixel 295 // ImageView won't detect that we have a new image set due to the pixel
294 // buffer pointers remaining the same despite the image changing. 296 // buffer pointers remaining the same despite the image changing.
295 icon_->SetImage(gfx::ImageSkia()); 297 icon_->SetImage(gfx::ImageSkia());
296 icon_->SetImage(image); 298 icon_->SetImage(image);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 if (context_menu_runner_->RunMenuAt(GetWidget(), 348 if (context_menu_runner_->RunMenuAt(GetWidget(),
347 NULL, 349 NULL,
348 gfx::Rect(point, gfx::Size()), 350 gfx::Rect(point, gfx::Size()),
349 views::MENU_ANCHOR_TOPLEFT, 351 views::MENU_ANCHOR_TOPLEFT,
350 source_type) == 352 source_type) ==
351 views::MenuRunner::MENU_DELETED) 353 views::MenuRunner::MENU_DELETED)
352 return; 354 return;
353 } 355 }
354 356
355 } // namespace app_list 357 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/search_result.cc ('k') | ui/app_list/views/tile_item_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698