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

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

Issue 2952303002: cros: add SUGGESTED APPS indicator to start page (Closed)
Patch Set: Created 3 years, 5 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
OLDNEW
(Empty)
1 // Copyright 2017 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/indicator_chip_view.h"
6
7 #include "ui/base/resource/resource_bundle.h"
8 #include "ui/gfx/canvas.h"
9 #include "ui/views/background.h"
10 #include "ui/views/border.h"
11 #include "ui/views/controls/label.h"
12 #include "ui/views/layout/fill_layout.h"
13
14 namespace app_list {
15
16 namespace {
17
18 constexpr int kIndicatorHeight = 16;
19 constexpr int kHorizontalPadding = 16;
20 constexpr int kBorderCornerRadius = 8;
21
22 constexpr SkColor kLabelColor = SkColorSetARGBMacro(0x8A, 0xFF, 0xFF, 0xFF);
23 constexpr SkColor kBackgroundColor =
24 SkColorSetARGBMacro(0x14, 0xFF, 0xFF, 0xFF);
25
26 class IndicatorBackground : public views::Background {
27 public:
28 IndicatorBackground() = default;
29 ~IndicatorBackground() override = default;
30
31 private:
32 // views::Background overrides:
33 void Paint(gfx::Canvas* canvas, views::View* view) const override {
34 cc::PaintFlags flags;
35 flags.setStyle(cc::PaintFlags::kFill_Style);
36 flags.setColor(kBackgroundColor);
37 flags.setAntiAlias(true);
38 canvas->DrawRoundRect(view->GetContentsBounds(), kBorderCornerRadius,
39 flags);
40 }
41
42 DISALLOW_COPY_AND_ASSIGN(IndicatorBackground);
43 };
44
45 } // namespace
46
47 IndicatorChipView::IndicatorChipView(base::string16 text) {
48 container_ = new views::View();
49 container_->set_can_process_events_within_subtree(false);
50 AddChildView(container_);
51
52 container_->SetBackground(base::MakeUnique<IndicatorBackground>());
53
54 label_ = new views::Label(text);
55 gfx::FontList small_font =
xiyuan 2017/06/22 22:33:51 gfx::FontList -> const gfx::FontList&
Qiang(Joe) Xu 2017/06/22 22:47:26 Done.
56 ui::ResourceBundle::GetSharedInstance().GetFontList(
57 ui::ResourceBundle::SmallFont);
58 label_->SetFontList(small_font.DeriveWithSizeDelta(-2));
59 label_->SetBorder(views::NullBorder());
xiyuan 2017/06/22 22:33:52 border is null by default. We probably can remove
Qiang(Joe) Xu 2017/06/22 22:47:27 Done.
60 label_->SetEnabledColor(kLabelColor);
61 label_->SetAutoColorReadabilityEnabled(false);
62 label_->SetBackgroundColor(SK_ColorTRANSPARENT);
xiyuan 2017/06/22 22:33:52 Try to avoid SK_ColorTRANSPARENT background. Font
Qiang(Joe) Xu 2017/06/22 22:47:26 acknowledged, done
63 label_->SetHandlesTooltips(false);
64 label_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
65
66 container_->AddChildView(label_);
67 }
68
69 IndicatorChipView::~IndicatorChipView() = default;
70
71 gfx::Size IndicatorChipView::CalculatePreferredSize() const {
72 const int label_width = label_->GetPreferredSize().width();
73 return gfx::Size(
74 label_width + 2 * kHorizontalPadding + 2 * kBorderCornerRadius,
75 kIndicatorHeight);
76 }
77
78 void IndicatorChipView::Layout() {
79 const int label_width = label_->GetPreferredSize().width();
80 container_->SetSize(
81 gfx::Size(label_width + 2 * kHorizontalPadding, kIndicatorHeight));
82 label_->SetBoundsRect(container_->GetContentsBounds());
83 }
84
85 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698