Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/app_list/views/tile_item_view.h" | |
| 6 | |
| 7 #include "base/strings/utf_string_conversions.h" | |
| 8 #include "ui/app_list/app_list_constants.h" | |
| 9 #include "ui/app_list/app_list_item.h" | |
| 10 #include "ui/app_list/app_list_model.h" | |
| 11 #include "ui/app_list/app_list_view_delegate.h" | |
| 12 #include "ui/app_list/views/app_list_main_view.h" | |
| 13 #include "ui/gfx/canvas.h" | |
| 14 #include "ui/gfx/color_analysis.h" | |
| 15 #include "ui/gfx/color_utils.h" | |
| 16 #include "ui/views/background.h" | |
| 17 #include "ui/views/controls/image_view.h" | |
| 18 #include "ui/views/controls/label.h" | |
| 19 #include "ui/views/layout/box_layout.h" | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 const int kTileSize = 90; | |
| 24 const SkColor kTileBackgroundColor = SK_ColorWHITE; | |
| 25 const SkColor kTileBorderColor = SkColorSetARGB(0X30, 0xD0, 0xD0, 0xD0); | |
|
tapted
2014/05/22 04:56:11
nit: the first 'x', in '0X30', should be lowercase
calamity
2014/05/27 04:29:11
Done.
| |
| 26 const int kTileColorStripHeight = 2; | |
| 27 const SkAlpha kTileColorStripOpacity = 0X5F; | |
| 28 const int kTileCornerRadius = 2; | |
| 29 | |
| 30 // A background for the start page item view which consists of a rounded rect | |
| 31 // with a dominant color strip at the bottom. | |
| 32 class TileItemBackground : public views::Background { | |
| 33 public: | |
| 34 TileItemBackground() {} | |
|
tapted
2014/05/22 04:56:11
initialize strip_color_?
calamity
2014/05/27 04:29:11
Done.
| |
| 35 virtual ~TileItemBackground() {} | |
| 36 | |
| 37 void set_strip_color(SkColor strip_color) { strip_color_ = strip_color; } | |
| 38 | |
| 39 // Overridden from views::Background: | |
| 40 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { | |
| 41 SkPaint paint; | |
| 42 paint.setFlags(SkPaint::kAntiAlias_Flag); | |
| 43 | |
| 44 // Paint the border. | |
| 45 paint.setColor(kTileBorderColor); | |
| 46 canvas->DrawRoundRect(view->GetContentsBounds(), kTileCornerRadius, paint); | |
| 47 | |
| 48 // Paint a rectangle for the color strip. | |
| 49 gfx::Rect color_strip_rect(view->GetContentsBounds()); | |
| 50 color_strip_rect.Inset(1, 1, 1, 1); | |
| 51 paint.setColor(SkColorSetA(strip_color_, kTileColorStripOpacity)); | |
| 52 canvas->DrawRoundRect(color_strip_rect, kTileCornerRadius, paint); | |
| 53 | |
| 54 // Paint the main background rectangle, leaving part of the color strip | |
| 55 // unobscured. | |
| 56 gfx::Rect static_background_rect(color_strip_rect); | |
| 57 static_background_rect.Inset(0, 0, 0, kTileColorStripHeight); | |
| 58 paint.setColor(kTileBackgroundColor); | |
| 59 canvas->DrawRoundRect(static_background_rect, kTileCornerRadius, paint); | |
| 60 } | |
| 61 | |
| 62 private: | |
| 63 SkColor strip_color_; | |
| 64 | |
| 65 DISALLOW_COPY_AND_ASSIGN(TileItemBackground); | |
| 66 }; | |
| 67 | |
| 68 } // namespace | |
| 69 | |
| 70 namespace app_list { | |
| 71 | |
| 72 TileItemView::TileItemView() | |
| 73 : views::CustomButton(this), | |
| 74 item_(NULL), | |
| 75 icon_(new views::ImageView), | |
| 76 title_(new views::Label), | |
| 77 background_(new TileItemBackground()) { | |
| 78 set_background(background_); | |
| 79 | |
| 80 views::BoxLayout* layout_manager = | |
| 81 new views::BoxLayout(views::BoxLayout::kVertical, 10, 0, 0); | |
|
tapted
2014/05/22 04:56:11
nit 10 -> some constant? kSomethingGapSpacingSepar
calamity
2014/05/27 04:29:11
Done.
| |
| 82 layout_manager->set_main_axis_alignment( | |
| 83 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | |
| 84 SetLayoutManager(layout_manager); | |
| 85 | |
| 86 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 87 title_->SetAutoColorReadabilityEnabled(false); | |
| 88 title_->SetEnabledColor(kGridTitleColor); | |
| 89 title_->SetFontList(rb.GetFontList(kItemTextFontStyle)); | |
| 90 title_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | |
| 91 | |
| 92 AddChildView(icon_); | |
| 93 AddChildView(title_); | |
| 94 } | |
| 95 | |
| 96 TileItemView::~TileItemView() { | |
| 97 } | |
| 98 | |
| 99 void TileItemView::SetAppListItem(AppListItem* item) { | |
| 100 item_ = item; | |
| 101 if (!item) { | |
| 102 SetVisible(false); | |
| 103 icon_->SetImage(NULL); | |
| 104 title_->SetText(base::string16()); | |
| 105 return; | |
| 106 } | |
| 107 | |
| 108 SetVisible(true); | |
| 109 icon_->SetImage(item_->icon()); | |
|
tapted
2014/05/22 04:56:11
I think when an item is installing it's not guaran
calamity
2014/05/27 04:29:11
Done.
| |
| 110 title_->SetText(base::UTF8ToUTF16(item_->name())); | |
| 111 | |
| 112 background_->set_strip_color( | |
| 113 color_utils::CalculateKMeanColorOfBitmap(*item_->icon().bitmap())); | |
| 114 } | |
|
tapted
2014/05/22 04:56:11
This will need to observe icon/title updates. Also
calamity
2014/05/27 04:29:11
Done.
| |
| 115 | |
| 116 gfx::Size TileItemView::GetPreferredSize() { | |
| 117 return gfx::Size(kTileSize, kTileSize); | |
| 118 } | |
| 119 | |
| 120 void TileItemView::ButtonPressed(views::Button* sender, | |
| 121 const ui::Event& event) { | |
| 122 item_->Activate(event.flags()); | |
| 123 } | |
| 124 | |
| 125 } // namespace app_list | |
| OLD | NEW |