| OLD | NEW |
| 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/search_result.h" |
| 13 #include "ui/app_list/views/app_list_main_view.h" | 13 #include "ui/app_list/views/app_list_main_view.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | |
| 15 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
| 16 #include "ui/gfx/color_analysis.h" | 15 #include "ui/gfx/color_analysis.h" |
| 17 #include "ui/gfx/color_utils.h" | 16 #include "ui/gfx/color_utils.h" |
| 18 #include "ui/views/background.h" | 17 #include "ui/views/background.h" |
| 19 #include "ui/views/controls/image_view.h" | 18 #include "ui/views/controls/image_view.h" |
| 20 #include "ui/views/controls/label.h" | 19 #include "ui/views/controls/label.h" |
| 21 #include "ui/views/layout/box_layout.h" | 20 #include "ui/views/layout/box_layout.h" |
| 22 | 21 |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| 25 const int kTileSize = 90; | 24 const int kTileSize = 90; |
| 26 const int kTileHorizontalPadding = 10; | 25 const int kTileHorizontalPadding = 10; |
| 27 | 26 |
| 28 // In Windows, transparent background color will cause ugly text rendering, | |
| 29 // therefore kContentsBackgroundColor should be used. See crbug.com/406989 | |
| 30 #if defined(OS_CHROMEOS) | |
| 31 const SkColor kTitleBackgroundColor = SK_ColorTRANSPARENT; | |
| 32 #else | |
| 33 const SkColor kTitleBackgroundColor = app_list::kContentsBackgroundColor; | |
| 34 #endif | |
| 35 | |
| 36 } // namespace | 27 } // namespace |
| 37 | 28 |
| 38 namespace app_list { | 29 namespace app_list { |
| 39 | 30 |
| 40 TileItemView::TileItemView() | 31 TileItemView::TileItemView() |
| 41 : views::CustomButton(this), | 32 : views::CustomButton(this), |
| 42 item_(NULL), | 33 item_(NULL), |
| 43 icon_(new views::ImageView), | 34 icon_(new views::ImageView), |
| 44 title_(new views::Label) { | 35 title_(new views::Label) { |
| 45 views::BoxLayout* layout_manager = new views::BoxLayout( | 36 views::BoxLayout* layout_manager = new views::BoxLayout( |
| 46 views::BoxLayout::kVertical, kTileHorizontalPadding, 0, 0); | 37 views::BoxLayout::kVertical, kTileHorizontalPadding, 0, 0); |
| 47 layout_manager->set_main_axis_alignment( | 38 layout_manager->set_main_axis_alignment( |
| 48 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | 39 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
| 49 SetLayoutManager(layout_manager); | 40 SetLayoutManager(layout_manager); |
| 50 | 41 |
| 51 icon_->SetImageSize(gfx::Size(kTileIconSize, kTileIconSize)); | 42 icon_->SetImageSize(gfx::Size(kTileIconSize, kTileIconSize)); |
| 52 | 43 |
| 53 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 44 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 54 title_->SetAutoColorReadabilityEnabled(false); | 45 title_->SetAutoColorReadabilityEnabled(false); |
| 55 title_->SetEnabledColor(kGridTitleColor); | 46 title_->SetEnabledColor(kGridTitleColor); |
| 56 title_->set_background(views::Background::CreateSolidBackground( | 47 title_->set_background(views::Background::CreateSolidBackground( |
| 57 kTitleBackgroundColor)); | 48 app_list::kContentsBackgroundColor)); |
| 58 title_->SetFontList(rb.GetFontList(kItemTextFontStyle)); | 49 title_->SetFontList(rb.GetFontList(kItemTextFontStyle)); |
| 59 title_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 50 title_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 60 | 51 |
| 61 // When |item_| is NULL, the tile is invisible. Calling SetSearchResult with a | 52 // When |item_| is NULL, the tile is invisible. Calling SetSearchResult with a |
| 62 // non-NULL item makes the tile visible. | 53 // non-NULL item makes the tile visible. |
| 63 SetVisible(false); | 54 SetVisible(false); |
| 64 | 55 |
| 65 AddChildView(icon_); | 56 AddChildView(icon_); |
| 66 AddChildView(title_); | 57 AddChildView(title_); |
| 67 } | 58 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 icon_->SetImage(item_->icon()); | 99 icon_->SetImage(item_->icon()); |
| 109 } | 100 } |
| 110 | 101 |
| 111 void TileItemView::OnResultDestroying() { | 102 void TileItemView::OnResultDestroying() { |
| 112 if (item_) | 103 if (item_) |
| 113 item_->RemoveObserver(this); | 104 item_->RemoveObserver(this); |
| 114 item_ = NULL; | 105 item_ = NULL; |
| 115 } | 106 } |
| 116 | 107 |
| 117 } // namespace app_list | 108 } // namespace app_list |
| OLD | NEW |