Bluetooth: don't connect to unconnectable devices or disconnect
[chromium-blink-merge.git] / ash / system / tray / tray_bar_button_with_title.cc
blob0fd94d848926720448c8634c59bb4c32203af159
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.
5 #include "ash/system/tray/tray_bar_button_with_title.h"
7 #include "ash/system/tray/tray_constants.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "grit/ui_resources.h"
10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/image/image_skia.h"
12 #include "ui/views/controls/label.h"
13 #include "ui/views/painter.h"
15 namespace ash {
16 namespace internal {
18 namespace {
20 const int kBarImagesActive[] = {
21 IDR_SLIDER_ACTIVE_LEFT,
22 IDR_SLIDER_ACTIVE_CENTER,
23 IDR_SLIDER_ACTIVE_RIGHT,
26 const int kBarImagesDisabled[] = {
27 IDR_SLIDER_DISABLED_LEFT,
28 IDR_SLIDER_DISABLED_CENTER,
29 IDR_SLIDER_DISABLED_RIGHT,
32 } // namespace
34 class TrayBarButtonWithTitle::TrayBarButton : public views::View {
35 public:
36 TrayBarButton(const int bar_active_images[], const int bar_disabled_images[])
37 : views::View(),
38 bar_active_images_(bar_active_images),
39 bar_disabled_images_(bar_disabled_images),
40 painter_(new views::HorizontalPainter(bar_active_images_)){
42 virtual ~TrayBarButton() {}
44 // Overriden from views::View:
45 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
46 painter_->Paint(canvas, size());
49 void Update(bool control_on) {
50 painter_.reset(new views::HorizontalPainter(
51 control_on ? bar_active_images_ : bar_disabled_images_));
52 SchedulePaint();
55 private:
56 const int* bar_active_images_;
57 const int* bar_disabled_images_;
58 scoped_ptr<views::HorizontalPainter> painter_;
60 DISALLOW_COPY_AND_ASSIGN(TrayBarButton);
63 TrayBarButtonWithTitle::TrayBarButtonWithTitle(views::ButtonListener* listener,
64 int title_id,
65 int width)
66 : views::CustomButton(listener),
67 image_(new TrayBarButton(kBarImagesActive, kBarImagesDisabled)),
68 title_(NULL),
69 width_(width) {
70 AddChildView(image_);
71 if (title_id != -1) {
72 title_ = new views::Label;
73 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
74 base::string16 text = rb.GetLocalizedString(title_id);
75 title_->SetText(text);
76 AddChildView(title_);
79 image_height_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
80 kBarImagesActive[0]).ToImageSkia()->height();
83 TrayBarButtonWithTitle::~TrayBarButtonWithTitle() {}
85 void TrayBarButtonWithTitle::UpdateButton(bool control_on) {
86 image_->Update(control_on);
89 gfx::Size TrayBarButtonWithTitle::GetPreferredSize() {
90 return gfx::Size(width_, kTrayPopupItemHeight);
93 void TrayBarButtonWithTitle::Layout() {
94 gfx::Rect rect(GetContentsBounds());
95 int bar_image_y = rect.height() / 2 - image_height_ / 2;
96 gfx::Rect bar_image_rect(rect.x(),
97 bar_image_y,
98 rect.width(),
99 image_height_);
100 image_->SetBoundsRect(bar_image_rect);
101 if (title_) {
102 // The image_ has some empty space below the bar image, move the title
103 // a little bit up to look closer to the bar.
104 gfx::Size title_size = title_->GetPreferredSize();
105 title_->SetBounds(rect.x(),
106 bar_image_y + image_height_ - 3,
107 rect.width(),
108 title_size.height());
112 } // namespace internal
113 } // namespace ash