| OLD | NEW |
| 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; | 29 const int kIconViewWidth = kListIconSize + 2 * kIconPadding; |
| 31 const int kTextTrailPadding = kIconPadding; | 30 const int kTextTrailPadding = kIconPadding; |
| 32 const int kBorderSize = 1; | 31 const int kBorderSize = 1; |
| 33 | 32 |
| 34 // Extra margin at the right of the rightmost action icon. | 33 // Extra margin at the right of the rightmost action icon. |
| 35 const int kActionButtonRightMargin = 8; | 34 const int kActionButtonRightMargin = 8; |
| 36 | 35 |
| 37 // Creates a RenderText of given |text| and |styles|. Caller takes ownership | 36 // Creates a RenderText of given |text| and |styles|. Caller takes ownership |
| 38 // of returned RenderText. | 37 // of returned RenderText. |
| 39 gfx::RenderText* CreateRenderText(const base::string16& text, | 38 gfx::RenderText* CreateRenderText(const base::string16& text, |
| 40 const SearchResult::Tags& tags) { | 39 const SearchResult::Tags& tags) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 return gfx::Size(kPreferredWidth, kPreferredHeight); | 136 return gfx::Size(kPreferredWidth, kPreferredHeight); |
| 138 } | 137 } |
| 139 | 138 |
| 140 void SearchResultView::Layout() { | 139 void SearchResultView::Layout() { |
| 141 gfx::Rect rect(GetContentsBounds()); | 140 gfx::Rect rect(GetContentsBounds()); |
| 142 if (rect.IsEmpty()) | 141 if (rect.IsEmpty()) |
| 143 return; | 142 return; |
| 144 | 143 |
| 145 gfx::Rect icon_bounds(rect); | 144 gfx::Rect icon_bounds(rect); |
| 146 icon_bounds.set_width(kIconViewWidth); | 145 icon_bounds.set_width(kIconViewWidth); |
| 147 icon_bounds.Inset(kIconPadding, (rect.height() - kIconDimension) / 2); | 146 icon_bounds.Inset(kIconPadding, (rect.height() - kListIconSize) / 2); |
| 148 icon_bounds.Intersect(rect); | 147 icon_bounds.Intersect(rect); |
| 149 icon_->SetBoundsRect(icon_bounds); | 148 icon_->SetBoundsRect(icon_bounds); |
| 150 | 149 |
| 151 const int max_actions_width = | 150 const int max_actions_width = |
| 152 (rect.right() - kActionButtonRightMargin - icon_bounds.right()) / 2; | 151 (rect.right() - kActionButtonRightMargin - icon_bounds.right()) / 2; |
| 153 int actions_width = std::min(max_actions_width, | 152 int actions_width = std::min(max_actions_width, |
| 154 actions_view_->GetPreferredSize().width()); | 153 actions_view_->GetPreferredSize().width()); |
| 155 | 154 |
| 156 gfx::Rect actions_bounds(rect); | 155 gfx::Rect actions_bounds(rect); |
| 157 actions_bounds.set_x(rect.right() - kActionButtonRightMargin - actions_width); | 156 actions_bounds.set_x(rect.right() - kActionButtonRightMargin - actions_width); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 gfx::ImageSkia image(result_ ? result_->icon() : gfx::ImageSkia()); | 271 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 | 272 // 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 | 273 // 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 | 274 // 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 | 275 // clearing it out. It should work correctly as long as the SearchResult does |
| 277 // not forget to SetIcon when it's ready. | 276 // not forget to SetIcon when it's ready. |
| 278 if (image.isNull()) | 277 if (image.isNull()) |
| 279 return; | 278 return; |
| 280 | 279 |
| 281 // Scales down big icons but leave small ones unchanged. | 280 // Scales down big icons but leave small ones unchanged. |
| 282 if (image.width() > kIconDimension || image.height() > kIconDimension) { | 281 if (image.width() > kListIconSize || image.height() > kListIconSize) { |
| 283 image = gfx::ImageSkiaOperations::CreateResizedImage( | 282 image = gfx::ImageSkiaOperations::CreateResizedImage( |
| 284 image, | 283 image, |
| 285 skia::ImageOperations::RESIZE_BEST, | 284 skia::ImageOperations::RESIZE_BEST, |
| 286 gfx::Size(kIconDimension, kIconDimension)); | 285 gfx::Size(kListIconSize, kListIconSize)); |
| 287 } else { | 286 } else { |
| 288 icon_->ResetImageSize(); | 287 icon_->ResetImageSize(); |
| 289 } | 288 } |
| 290 | 289 |
| 291 // Set the image to an empty image before we reset the image because | 290 // 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 | 291 // 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 | 292 // 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. | 293 // buffer pointers remaining the same despite the image changing. |
| 295 icon_->SetImage(gfx::ImageSkia()); | 294 icon_->SetImage(gfx::ImageSkia()); |
| 296 icon_->SetImage(image); | 295 icon_->SetImage(image); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 if (context_menu_runner_->RunMenuAt(GetWidget(), | 345 if (context_menu_runner_->RunMenuAt(GetWidget(), |
| 347 NULL, | 346 NULL, |
| 348 gfx::Rect(point, gfx::Size()), | 347 gfx::Rect(point, gfx::Size()), |
| 349 views::MENU_ANCHOR_TOPLEFT, | 348 views::MENU_ANCHOR_TOPLEFT, |
| 350 source_type) == | 349 source_type) == |
| 351 views::MenuRunner::MENU_DELETED) | 350 views::MenuRunner::MENU_DELETED) |
| 352 return; | 351 return; |
| 353 } | 352 } |
| 354 | 353 |
| 355 } // namespace app_list | 354 } // namespace app_list |
| OLD | NEW |