OLD | NEW |
(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(const 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 const gfx::FontList& small_font = |
| 56 ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 57 ui::ResourceBundle::SmallFont); |
| 58 label_->SetFontList(small_font.DeriveWithSizeDelta(-2)); |
| 59 label_->SetEnabledColor(kLabelColor); |
| 60 label_->SetAutoColorReadabilityEnabled(false); |
| 61 label_->SetBackgroundColor(kBackgroundColor); |
| 62 label_->SetHandlesTooltips(false); |
| 63 label_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 64 |
| 65 container_->AddChildView(label_); |
| 66 } |
| 67 |
| 68 IndicatorChipView::~IndicatorChipView() = default; |
| 69 |
| 70 gfx::Size IndicatorChipView::CalculatePreferredSize() const { |
| 71 const int label_width = label_->GetPreferredSize().width(); |
| 72 return gfx::Size( |
| 73 label_width + 2 * kHorizontalPadding + 2 * kBorderCornerRadius, |
| 74 kIndicatorHeight); |
| 75 } |
| 76 |
| 77 void IndicatorChipView::Layout() { |
| 78 const int label_width = label_->GetPreferredSize().width(); |
| 79 container_->SetSize( |
| 80 gfx::Size(label_width + 2 * kHorizontalPadding, kIndicatorHeight)); |
| 81 label_->SetBoundsRect(container_->GetContentsBounds()); |
| 82 } |
| 83 |
| 84 } // namespace app_list |
OLD | NEW |