OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/common/system/tray/tray_bar_button_with_title.h" | 5 #include "ash/common/system/tray/tray_bar_button_with_title.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "ash/common/system/tray/tray_constants.h" | 9 #include "ash/common/system/tray/tray_constants.h" |
10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
11 #include "ui/gfx/image/image_skia.h" | 11 #include "ui/gfx/image/image_skia.h" |
12 #include "ui/resources/grit/ui_resources.h" | 12 #include "ui/resources/grit/ui_resources.h" |
13 #include "ui/views/controls/label.h" | 13 #include "ui/views/controls/label.h" |
14 #include "ui/views/painter.h" | 14 #include "ui/views/painter.h" |
15 #include "ui/views/resources/grit/views_resources.h" | 15 #include "ui/views/resources/grit/views_resources.h" |
16 | 16 |
17 namespace ash { | 17 namespace ash { |
18 namespace { | 18 namespace { |
19 | 19 |
20 const int kBarImagesActive[] = { | 20 const int kBarImagesActive[] = { |
21 IDR_SLIDER_ACTIVE_LEFT, | 21 IDR_SLIDER_ACTIVE_LEFT, IDR_SLIDER_ACTIVE_CENTER, IDR_SLIDER_ACTIVE_RIGHT, |
22 IDR_SLIDER_ACTIVE_CENTER, | |
23 IDR_SLIDER_ACTIVE_RIGHT, | |
24 }; | 22 }; |
25 | 23 |
26 const int kBarImagesDisabled[] = { | 24 const int kBarImagesDisabled[] = { |
27 IDR_SLIDER_DISABLED_LEFT, | 25 IDR_SLIDER_DISABLED_LEFT, IDR_SLIDER_DISABLED_CENTER, |
28 IDR_SLIDER_DISABLED_CENTER, | |
29 IDR_SLIDER_DISABLED_RIGHT, | 26 IDR_SLIDER_DISABLED_RIGHT, |
30 }; | 27 }; |
31 | 28 |
32 } // namespace | 29 } // namespace |
33 | 30 |
34 class TrayBarButtonWithTitle::TrayBarButton : public views::View { | 31 class TrayBarButtonWithTitle::TrayBarButton : public views::View { |
35 public: | 32 public: |
36 TrayBarButton(const int bar_active_images[], const int bar_disabled_images[]) | 33 TrayBarButton(const int bar_active_images[], const int bar_disabled_images[]) |
37 : views::View(), | 34 : views::View(), |
38 bar_active_images_(bar_active_images), | 35 bar_active_images_(bar_active_images), |
39 bar_disabled_images_(bar_disabled_images), | 36 bar_disabled_images_(bar_disabled_images), |
40 painter_(new views::HorizontalPainter(bar_active_images_)){ | 37 painter_(new views::HorizontalPainter(bar_active_images_)) {} |
41 } | |
42 ~TrayBarButton() override {} | 38 ~TrayBarButton() override {} |
43 | 39 |
44 // Overriden from views::View: | 40 // Overriden from views::View: |
45 void OnPaint(gfx::Canvas* canvas) override { | 41 void OnPaint(gfx::Canvas* canvas) override { |
46 painter_->Paint(canvas, size()); | 42 painter_->Paint(canvas, size()); |
47 } | 43 } |
48 | 44 |
49 void Update(bool control_on) { | 45 void Update(bool control_on) { |
50 painter_.reset(new views::HorizontalPainter( | 46 painter_.reset(new views::HorizontalPainter( |
51 control_on ? bar_active_images_ : bar_disabled_images_)); | 47 control_on ? bar_active_images_ : bar_disabled_images_)); |
(...skipping 17 matching lines...) Expand all Loading... |
69 width_(width) { | 65 width_(width) { |
70 AddChildView(image_); | 66 AddChildView(image_); |
71 if (title_id != -1) { | 67 if (title_id != -1) { |
72 title_ = new views::Label; | 68 title_ = new views::Label; |
73 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 69 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
74 base::string16 text = rb.GetLocalizedString(title_id); | 70 base::string16 text = rb.GetLocalizedString(title_id); |
75 title_->SetText(text); | 71 title_->SetText(text); |
76 AddChildView(title_); | 72 AddChildView(title_); |
77 } | 73 } |
78 | 74 |
79 image_height_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 75 image_height_ = ui::ResourceBundle::GetSharedInstance() |
80 kBarImagesActive[0]).ToImageSkia()->height(); | 76 .GetImageNamed(kBarImagesActive[0]) |
| 77 .ToImageSkia() |
| 78 ->height(); |
81 } | 79 } |
82 | 80 |
83 TrayBarButtonWithTitle::~TrayBarButtonWithTitle() {} | 81 TrayBarButtonWithTitle::~TrayBarButtonWithTitle() {} |
84 | 82 |
85 void TrayBarButtonWithTitle::UpdateButton(bool control_on) { | 83 void TrayBarButtonWithTitle::UpdateButton(bool control_on) { |
86 image_->Update(control_on); | 84 image_->Update(control_on); |
87 } | 85 } |
88 | 86 |
89 gfx::Size TrayBarButtonWithTitle::GetPreferredSize() const { | 87 gfx::Size TrayBarButtonWithTitle::GetPreferredSize() const { |
90 return gfx::Size(width_, kTrayPopupItemHeight); | 88 return gfx::Size(width_, kTrayPopupItemHeight); |
91 } | 89 } |
92 | 90 |
93 void TrayBarButtonWithTitle::Layout() { | 91 void TrayBarButtonWithTitle::Layout() { |
94 gfx::Rect rect(GetContentsBounds()); | 92 gfx::Rect rect(GetContentsBounds()); |
95 int bar_image_y = rect.height() / 2 - image_height_ / 2; | 93 int bar_image_y = rect.height() / 2 - image_height_ / 2; |
96 gfx::Rect bar_image_rect(rect.x(), | 94 gfx::Rect bar_image_rect(rect.x(), bar_image_y, rect.width(), image_height_); |
97 bar_image_y, | |
98 rect.width(), | |
99 image_height_); | |
100 image_->SetBoundsRect(bar_image_rect); | 95 image_->SetBoundsRect(bar_image_rect); |
101 if (title_) { | 96 if (title_) { |
102 // The image_ has some empty space below the bar image, move the title | 97 // The image_ has some empty space below the bar image, move the title |
103 // a little bit up to look closer to the bar. | 98 // a little bit up to look closer to the bar. |
104 gfx::Size title_size = title_->GetPreferredSize(); | 99 gfx::Size title_size = title_->GetPreferredSize(); |
105 title_->SetBounds(rect.x(), | 100 title_->SetBounds(rect.x(), bar_image_y + image_height_ - 3, rect.width(), |
106 bar_image_y + image_height_ - 3, | |
107 rect.width(), | |
108 title_size.height()); | 101 title_size.height()); |
109 } | 102 } |
110 } | 103 } |
111 | 104 |
112 } // namespace ash | 105 } // namespace ash |
OLD | NEW |