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/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
15 #include "ui/gfx/color_analysis.h" | 15 #include "ui/gfx/color_analysis.h" |
16 #include "ui/gfx/color_utils.h" | 16 #include "ui/gfx/color_utils.h" |
17 #include "ui/views/background.h" | |
18 #include "ui/views/controls/image_view.h" | 17 #include "ui/views/controls/image_view.h" |
19 #include "ui/views/controls/label.h" | 18 #include "ui/views/controls/label.h" |
20 #include "ui/views/layout/box_layout.h" | 19 #include "ui/views/layout/box_layout.h" |
21 | 20 |
22 namespace { | 21 namespace { |
23 | 22 |
24 const int kTileSize = 90; | 23 const int kTileSize = 90; |
25 const int kTileHorizontalPadding = 10; | 24 const int kTileHorizontalPadding = 10; |
26 | 25 |
27 const SkColor kTileBackgroundColor = SK_ColorWHITE; | |
28 const int kTileColorStripHeight = 2; | |
29 const SkAlpha kTileColorStripOpacity = 0X5F; | |
30 const int kTileCornerRadius = 2; | |
31 | |
32 } // namespace | 26 } // namespace |
33 | 27 |
34 namespace app_list { | 28 namespace app_list { |
35 | 29 |
36 // A background for the start page item view which consists of a rounded rect | |
37 // with a dominant color strip at the bottom. | |
38 class TileItemView::TileItemBackground : public views::Background { | |
39 public: | |
40 TileItemBackground() : strip_color_(SK_ColorBLACK) {} | |
41 virtual ~TileItemBackground() {} | |
42 | |
43 void set_strip_color(SkColor strip_color) { strip_color_ = strip_color; } | |
44 | |
45 // Overridden from views::Background: | |
46 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { | |
47 SkPaint paint; | |
48 paint.setFlags(SkPaint::kAntiAlias_Flag); | |
49 | |
50 // Paint the border. | |
51 paint.setColor(kStartPageBorderColor); | |
52 canvas->DrawRoundRect(view->GetContentsBounds(), kTileCornerRadius, paint); | |
53 | |
54 // Paint a rectangle for the color strip. | |
55 gfx::Rect color_strip_rect(view->GetContentsBounds()); | |
56 color_strip_rect.Inset(1, 1, 1, 1); | |
57 paint.setColor(SkColorSetA(strip_color_, kTileColorStripOpacity)); | |
58 canvas->DrawRoundRect(color_strip_rect, kTileCornerRadius, paint); | |
59 | |
60 // Paint the main background rectangle, leaving part of the color strip | |
61 // unobscured. | |
62 gfx::Rect static_background_rect(color_strip_rect); | |
63 static_background_rect.Inset(0, 0, 0, kTileColorStripHeight); | |
64 paint.setColor(kTileBackgroundColor); | |
65 canvas->DrawRoundRect(static_background_rect, kTileCornerRadius, paint); | |
66 } | |
67 | |
68 private: | |
69 SkColor strip_color_; | |
70 | |
71 DISALLOW_COPY_AND_ASSIGN(TileItemBackground); | |
72 }; | |
73 | |
74 TileItemView::TileItemView() | 30 TileItemView::TileItemView() |
75 : views::CustomButton(this), | 31 : views::CustomButton(this), |
76 item_(NULL), | 32 item_(NULL), |
77 icon_(new views::ImageView), | 33 icon_(new views::ImageView), |
78 title_(new views::Label), | 34 title_(new views::Label) { |
79 background_(new TileItemBackground()) { | |
80 set_background(background_); | |
81 | |
82 views::BoxLayout* layout_manager = new views::BoxLayout( | 35 views::BoxLayout* layout_manager = new views::BoxLayout( |
83 views::BoxLayout::kVertical, kTileHorizontalPadding, 0, 0); | 36 views::BoxLayout::kVertical, kTileHorizontalPadding, 0, 0); |
84 layout_manager->set_main_axis_alignment( | 37 layout_manager->set_main_axis_alignment( |
85 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | 38 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
86 SetLayoutManager(layout_manager); | 39 SetLayoutManager(layout_manager); |
87 | 40 |
88 icon_->SetImageSize(gfx::Size(kTileIconSize, kTileIconSize)); | 41 icon_->SetImageSize(gfx::Size(kTileIconSize, kTileIconSize)); |
89 | 42 |
90 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 43 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
91 title_->SetAutoColorReadabilityEnabled(false); | 44 title_->SetAutoColorReadabilityEnabled(false); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 return gfx::Size(kTileSize, kTileSize); | 87 return gfx::Size(kTileSize, kTileSize); |
135 } | 88 } |
136 | 89 |
137 void TileItemView::ButtonPressed(views::Button* sender, | 90 void TileItemView::ButtonPressed(views::Button* sender, |
138 const ui::Event& event) { | 91 const ui::Event& event) { |
139 item_->Open(event.flags()); | 92 item_->Open(event.flags()); |
140 } | 93 } |
141 | 94 |
142 void TileItemView::OnIconChanged() { | 95 void TileItemView::OnIconChanged() { |
143 icon_->SetImage(item_->icon()); | 96 icon_->SetImage(item_->icon()); |
144 background_->set_strip_color( | |
145 color_utils::CalculateKMeanColorOfBitmap(*item_->icon().bitmap())); | |
146 SchedulePaint(); | |
147 } | 97 } |
148 | 98 |
149 void TileItemView::OnResultDestroying() { | 99 void TileItemView::OnResultDestroying() { |
150 if (item_) | 100 if (item_) |
151 item_->RemoveObserver(this); | 101 item_->RemoveObserver(this); |
152 item_ = NULL; | 102 item_ = NULL; |
153 } | 103 } |
154 | 104 |
155 } // namespace app_list | 105 } // namespace app_list |
OLD | NEW |