Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / ash / system / tray / tray_bar_button_with_title.cc
blobcd7a7613052d51c2c0681226bf99b4c56c500fe2
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 "ui/base/resource/resource_bundle.h"
10 #include "ui/gfx/image/image_skia.h"
11 #include "ui/resources/grit/ui_resources.h"
12 #include "ui/views/controls/label.h"
13 #include "ui/views/painter.h"
14 #include "ui/views/resources/grit/views_resources.h"
16 namespace ash {
17 namespace {
19 const int kBarImagesActive[] = {
20 IDR_SLIDER_ACTIVE_LEFT,
21 IDR_SLIDER_ACTIVE_CENTER,
22 IDR_SLIDER_ACTIVE_RIGHT,
25 const int kBarImagesDisabled[] = {
26 IDR_SLIDER_DISABLED_LEFT,
27 IDR_SLIDER_DISABLED_CENTER,
28 IDR_SLIDER_DISABLED_RIGHT,
31 } // namespace
33 class TrayBarButtonWithTitle::TrayBarButton : public views::View {
34 public:
35 TrayBarButton(const int bar_active_images[], const int bar_disabled_images[])
36 : views::View(),
37 bar_active_images_(bar_active_images),
38 bar_disabled_images_(bar_disabled_images),
39 painter_(new views::HorizontalPainter(bar_active_images_)){
41 ~TrayBarButton() override {}
43 // Overriden from views::View:
44 void OnPaint(gfx::Canvas* canvas) override {
45 painter_->Paint(canvas, size());
48 void Update(bool control_on) {
49 painter_.reset(new views::HorizontalPainter(
50 control_on ? bar_active_images_ : bar_disabled_images_));
51 SchedulePaint();
54 private:
55 const int* bar_active_images_;
56 const int* bar_disabled_images_;
57 scoped_ptr<views::HorizontalPainter> painter_;
59 DISALLOW_COPY_AND_ASSIGN(TrayBarButton);
62 TrayBarButtonWithTitle::TrayBarButtonWithTitle(views::ButtonListener* listener,
63 int title_id,
64 int width)
65 : views::CustomButton(listener),
66 image_(new TrayBarButton(kBarImagesActive, kBarImagesDisabled)),
67 title_(NULL),
68 width_(width) {
69 AddChildView(image_);
70 if (title_id != -1) {
71 title_ = new views::Label;
72 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
73 base::string16 text = rb.GetLocalizedString(title_id);
74 title_->SetText(text);
75 AddChildView(title_);
78 image_height_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
79 kBarImagesActive[0]).ToImageSkia()->height();
82 TrayBarButtonWithTitle::~TrayBarButtonWithTitle() {}
84 void TrayBarButtonWithTitle::UpdateButton(bool control_on) {
85 image_->Update(control_on);
88 gfx::Size TrayBarButtonWithTitle::GetPreferredSize() const {
89 return gfx::Size(width_, kTrayPopupItemHeight);
92 void TrayBarButtonWithTitle::Layout() {
93 gfx::Rect rect(GetContentsBounds());
94 int bar_image_y = rect.height() / 2 - image_height_ / 2;
95 gfx::Rect bar_image_rect(rect.x(),
96 bar_image_y,
97 rect.width(),
98 image_height_);
99 image_->SetBoundsRect(bar_image_rect);
100 if (title_) {
101 // The image_ has some empty space below the bar image, move the title
102 // a little bit up to look closer to the bar.
103 gfx::Size title_size = title_->GetPreferredSize();
104 title_->SetBounds(rect.x(),
105 bar_image_y + image_height_ - 3,
106 rect.width(),
107 title_size.height());
111 } // namespace ash