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

Side by Side Diff: ash/common/system/tray/tray_bar_button_with_title.cc

Issue 2186153002: Removed unused TrayBarButtonWithTitle class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed IDR_SLIDER_ACTIVE_RIGHT resources. Created 4 years, 4 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 2013 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 "ash/common/system/tray/tray_bar_button_with_title.h"
6
7 #include <memory>
8
9 #include "ash/common/system/tray/tray_constants.h"
10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/image/image_skia.h"
12 #include "ui/resources/grit/ui_resources.h"
13 #include "ui/views/controls/label.h"
14 #include "ui/views/painter.h"
15 #include "ui/views/resources/grit/views_resources.h"
16
17 namespace ash {
18 namespace {
19
20 const int kBarImagesActive[] = {
21 IDR_SLIDER_ACTIVE_LEFT, IDR_SLIDER_ACTIVE_CENTER, IDR_SLIDER_ACTIVE_RIGHT,
22 };
23
24 const int kBarImagesDisabled[] = {
25 IDR_SLIDER_DISABLED_LEFT, IDR_SLIDER_DISABLED_CENTER,
26 IDR_SLIDER_DISABLED_RIGHT,
27 };
28
29 } // namespace
30
31 class TrayBarButtonWithTitle::TrayBarButton : public views::View {
32 public:
33 TrayBarButton(const int bar_active_images[], const int bar_disabled_images[])
34 : views::View(),
35 bar_active_images_(bar_active_images),
36 bar_disabled_images_(bar_disabled_images),
37 painter_(new views::HorizontalPainter(bar_active_images_)) {}
38 ~TrayBarButton() override {}
39
40 // Overriden from views::View:
41 void OnPaint(gfx::Canvas* canvas) override {
42 painter_->Paint(canvas, size());
43 }
44
45 void Update(bool control_on) {
46 painter_.reset(new views::HorizontalPainter(
47 control_on ? bar_active_images_ : bar_disabled_images_));
48 SchedulePaint();
49 }
50
51 private:
52 const int* bar_active_images_;
53 const int* bar_disabled_images_;
54 std::unique_ptr<views::HorizontalPainter> painter_;
55
56 DISALLOW_COPY_AND_ASSIGN(TrayBarButton);
57 };
58
59 TrayBarButtonWithTitle::TrayBarButtonWithTitle(views::ButtonListener* listener,
60 int title_id,
61 int width)
62 : views::CustomButton(listener),
63 image_(new TrayBarButton(kBarImagesActive, kBarImagesDisabled)),
64 title_(NULL),
65 width_(width) {
66 AddChildView(image_);
67 if (title_id != -1) {
68 title_ = new views::Label;
69 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
70 base::string16 text = rb.GetLocalizedString(title_id);
71 title_->SetText(text);
72 AddChildView(title_);
73 }
74
75 image_height_ = ui::ResourceBundle::GetSharedInstance()
76 .GetImageNamed(kBarImagesActive[0])
77 .ToImageSkia()
78 ->height();
79 }
80
81 TrayBarButtonWithTitle::~TrayBarButtonWithTitle() {}
82
83 void TrayBarButtonWithTitle::UpdateButton(bool control_on) {
84 image_->Update(control_on);
85 }
86
87 gfx::Size TrayBarButtonWithTitle::GetPreferredSize() const {
88 return gfx::Size(width_, kTrayPopupItemHeight);
89 }
90
91 void TrayBarButtonWithTitle::Layout() {
92 gfx::Rect rect(GetContentsBounds());
93 int bar_image_y = rect.height() / 2 - image_height_ / 2;
94 gfx::Rect bar_image_rect(rect.x(), bar_image_y, rect.width(), image_height_);
95 image_->SetBoundsRect(bar_image_rect);
96 if (title_) {
97 // The image_ has some empty space below the bar image, move the title
98 // a little bit up to look closer to the bar.
99 gfx::Size title_size = title_->GetPreferredSize();
100 title_->SetBounds(rect.x(), bar_image_y + image_height_ - 3, rect.width(),
101 title_size.height());
102 }
103 }
104
105 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/tray/tray_bar_button_with_title.h ('k') | ui/views/resources/default_100_percent/slider_right_active.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698