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

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

Issue 297643002: Add tiles to the experimental app list start page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
OLDNEW
(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 = 0X80D0D0D0;
tapted 2014/05/20 05:22:31 use SkColorSetARGB(0x80, 0xD0, 0xD0, 0xD0);
calamity 2014/05/22 03:31:16 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() {}
35 virtual ~TileItemBackground() {}
36
37 void set_strip_color(SkColor strip_color) { strip_color_ = strip_color; }
38
39 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE {
tapted 2014/05/20 05:22:31 nit: // Overidden from views::Background::Paint:
calamity 2014/05/22 03:31:16 Done.
40 // Paint a rectangle for the color strip.
41 SkPaint paint;
42 paint.setColor(SkColorSetA(strip_color_, kTileColorStripOpacity));
43 paint.setFlags(SkPaint::kAntiAlias_Flag);
44 canvas->DrawRoundRect(view->GetContentsBounds(), kTileCornerRadius, paint);
tapted 2014/05/20 05:22:31 The tiles in the screenshot look a little glitchy
calamity 2014/05/22 03:31:16 Switched the border drawing to use fill rather tha
45
46 // Paint the main background rectangle, leaving part of the color strip
47 // unobscured.
48 gfx::Rect static_background_rect(view->GetContentsBounds());
49 static_background_rect.set_height(static_background_rect.height() -
50 kTileColorStripHeight);
51 paint.setColor(kTileBackgroundColor);
52 canvas->DrawRoundRect(static_background_rect, kTileCornerRadius, paint);
53
54 // Paint the border.
55 paint.setColor(kTileBorderColor);
56 paint.setStyle(SkPaint::kStroke_Style);
57 canvas->DrawRoundRect(view->GetContentsBounds(), kTileCornerRadius, paint);
58 }
59
60 private:
61 SkColor strip_color_;
62 };
tapted 2014/05/20 05:22:31 nit: DISALLOW_COPY_AND_ASSIGN(..)
calamity 2014/05/22 03:31:16 Done.
63
64 } // namespace
65
66 namespace app_list {
67
68 TileItemView::TileItemView()
69 : views::CustomButton(this),
70 item_(NULL),
71 icon_(new views::ImageView),
tapted 2014/05/20 05:22:31 Does this need a drop-shadow to match the grid? Pr
calamity 2014/05/22 03:31:16 Unknown. Mocks don't have them.
72 title_(new views::Label),
73 background_(new TileItemBackground()) {
74 set_background(background_);
75
76 views::BoxLayout* layout_manager =
77 new views::BoxLayout(views::BoxLayout::kVertical, 10, 0, 0);
78 layout_manager->set_main_axis_alignment(
79 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
80 SetLayoutManager(layout_manager);
81
82 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
83 title_->SetAutoColorReadabilityEnabled(false);
84 title_->SetEnabledColor(kGridTitleColor);
85 title_->SetFontList(rb.GetFontList(kItemTextFontStyle));
86 title_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
tapted 2014/05/20 05:22:31 You should set set the background color on title_
tapted 2014/05/20 05:24:40 Actually, it looks like views can find an opaque b
87
88 AddChildView(icon_);
89 AddChildView(title_);
90 }
91
92 TileItemView::~TileItemView() {
93 }
94
95 void TileItemView::SetAppListItem(AppListItem* item) {
96 item_ = item;
97 if (!item) {
98 SetVisible(false);
99 icon_->SetImage(NULL);
100 title_->SetText(base::string16());
101 return;
102 }
103
104 SetVisible(true);
105 icon_->SetImage(item_->icon());
106 title_->SetText(base::UTF8ToUTF16(item_->name()));
107
108 background_->set_strip_color(
109 color_utils::CalculateKMeanColorOfBitmap(*item_->icon().bitmap()));
110 }
111
112 gfx::Size TileItemView::GetPreferredSize() {
113 return gfx::Size(kTileSize, kTileSize);
114 }
115
116 void TileItemView::ButtonPressed(views::Button* sender,
117 const ui::Event& event) {
118 item_->Activate(event.flags());
119 }
120
121 } // namespace app_list
OLDNEW
« ui/app_list/views/tile_item_view.h ('K') | « ui/app_list/views/tile_item_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698