summaryrefslogtreecommitdiffstats
path: root/ash/system
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-14 07:10:04 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-14 07:10:04 +0000
commitc436af1cb4f71d6ec97e0394263e9d84ecdff796 (patch)
treedcdb527988864e8f52557234e1c456bf6d4f4af8 /ash/system
parentd64fd67ee5c0d5a6fb16f999dbe9be9b8aa7d892 (diff)
downloadchromium_src-c436af1cb4f71d6ec97e0394263e9d84ecdff796.zip
chromium_src-c436af1cb4f71d6ec97e0394263e9d84ecdff796.tar.gz
chromium_src-c436af1cb4f71d6ec97e0394263e9d84ecdff796.tar.bz2
ash: Extract TrayBarButtonWithTitle into its own component (.cc,.h).
BUG=174228 R=jamescook@chromium.org,jennyz@chromium.org Review URL: https://chromiumcodereview.appspot.com/12564006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188011 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/system')
-rw-r--r--ash/system/audio/tray_volume.cc9
-rw-r--r--ash/system/tray/tray_bar_button_with_title.cc113
-rw-r--r--ash/system/tray/tray_bar_button_with_title.h49
-rw-r--r--ash/system/tray/tray_views.cc94
-rw-r--r--ash/system/tray/tray_views.h28
5 files changed, 167 insertions, 126 deletions
diff --git a/ash/system/audio/tray_volume.cc b/ash/system/audio/tray_volume.cc
index 45e8f80..ff9c979 100644
--- a/ash/system/audio/tray_volume.cc
+++ b/ash/system/audio/tray_volume.cc
@@ -10,8 +10,8 @@
#include "ash/shell.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
+#include "ash/system/tray/tray_bar_button_with_title.h"
#include "ash/system/tray/tray_constants.h"
-#include "ash/system/tray/tray_views.h"
#include "ash/volume_control_delegate.h"
#include "base/utf_string_conversions.h"
#include "grit/ash_resources.h"
@@ -102,12 +102,12 @@ class VolumeButton : public views::ToggleImageButton {
DISALLOW_COPY_AND_ASSIGN(VolumeButton);
};
-class MuteButton : public ash::internal::TrayBarButtonWithTitle {
+class MuteButton : public TrayBarButtonWithTitle {
public:
explicit MuteButton(views::ButtonListener* listener)
: TrayBarButtonWithTitle(listener,
- -1, // no title under mute button
- kTrayBarButtonWidth) {
+ -1, // no title under mute button
+ kTrayBarButtonWidth) {
Update();
}
virtual ~MuteButton() {}
@@ -117,6 +117,7 @@ class MuteButton : public ash::internal::TrayBarButtonWithTitle {
SchedulePaint();
}
+ private:
DISALLOW_COPY_AND_ASSIGN(MuteButton);
};
diff --git a/ash/system/tray/tray_bar_button_with_title.cc b/ash/system/tray/tray_bar_button_with_title.cc
new file mode 100644
index 0000000..d8b6895
--- /dev/null
+++ b/ash/system/tray/tray_bar_button_with_title.cc
@@ -0,0 +1,113 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/system/tray/tray_bar_button_with_title.h"
+
+#include "ash/system/tray/tray_constants.h"
+#include "base/memory/scoped_ptr.h"
+#include "grit/ui_resources.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/image/image_skia.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/painter.h"
+
+namespace ash {
+namespace internal {
+
+namespace {
+
+const int kBarImagesActive[] = {
+ IDR_SLIDER_ACTIVE_LEFT,
+ IDR_SLIDER_ACTIVE_CENTER,
+ IDR_SLIDER_ACTIVE_RIGHT,
+};
+
+const int kBarImagesDisabled[] = {
+ IDR_SLIDER_DISABLED_LEFT,
+ IDR_SLIDER_DISABLED_CENTER,
+ IDR_SLIDER_DISABLED_RIGHT,
+};
+
+} // namespace
+
+class TrayBarButtonWithTitle::TrayBarButton : public views::View {
+ public:
+ TrayBarButton(const int bar_active_images[], const int bar_disabled_images[])
+ : views::View(),
+ bar_active_images_(bar_active_images),
+ bar_disabled_images_(bar_disabled_images),
+ painter_(new views::HorizontalPainter(bar_active_images_)){
+ }
+ virtual ~TrayBarButton() {}
+
+ // Overriden from views::View:
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
+ painter_->Paint(canvas, size());
+ }
+
+ void Update(bool control_on) {
+ painter_.reset(new views::HorizontalPainter(
+ control_on ? bar_active_images_ : bar_disabled_images_));
+ SchedulePaint();
+ }
+
+ private:
+ const int* bar_active_images_;
+ const int* bar_disabled_images_;
+ scoped_ptr<views::HorizontalPainter> painter_;
+
+ DISALLOW_COPY_AND_ASSIGN(TrayBarButton);
+};
+
+TrayBarButtonWithTitle::TrayBarButtonWithTitle(views::ButtonListener* listener,
+ int title_id,
+ int width)
+ : views::CustomButton(listener),
+ image_(new TrayBarButton(kBarImagesActive, kBarImagesDisabled)),
+ title_(NULL),
+ width_(width) {
+ AddChildView(image_);
+ if (title_id != -1) {
+ title_ = new views::Label;
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ string16 text = rb.GetLocalizedString(title_id);
+ title_->SetText(text);
+ AddChildView(title_);
+ }
+
+ image_height_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
+ kBarImagesActive[0]).ToImageSkia()->height();
+}
+
+TrayBarButtonWithTitle::~TrayBarButtonWithTitle() {}
+
+void TrayBarButtonWithTitle::UpdateButton(bool control_on) {
+ image_->Update(control_on);
+}
+
+gfx::Size TrayBarButtonWithTitle::GetPreferredSize() {
+ return gfx::Size(width_, kTrayPopupItemHeight);
+}
+
+void TrayBarButtonWithTitle::Layout() {
+ gfx::Rect rect(GetContentsBounds());
+ int bar_image_y = rect.height() / 2 - image_height_ / 2;
+ gfx::Rect bar_image_rect(rect.x(),
+ bar_image_y,
+ rect.width(),
+ image_height_);
+ image_->SetBoundsRect(bar_image_rect);
+ if (title_) {
+ // The image_ has some empty space below the bar image, move the title
+ // a little bit up to look closer to the bar.
+ gfx::Size title_size = title_->GetPreferredSize();
+ title_->SetBounds(rect.x(),
+ bar_image_y + image_height_ - 3,
+ rect.width(),
+ title_size.height());
+ }
+}
+
+} // namespace internal
+} // namespace ash
diff --git a/ash/system/tray/tray_bar_button_with_title.h b/ash/system/tray/tray_bar_button_with_title.h
new file mode 100644
index 0000000..8b63d4f
--- /dev/null
+++ b/ash/system/tray/tray_bar_button_with_title.h
@@ -0,0 +1,49 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_SYSTEM_TRAY_TRAY_BAR_BUTTON_WITH_TITLE_H_
+#define ASH_SYSTEM_TRAY_TRAY_BAR_BUTTON_WITH_TITLE_H_
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/views/controls/button/custom_button.h"
+
+namespace views {
+class Label;
+}
+
+namespace ash {
+namespace internal {
+
+// A button with a bar image and title text below the bar image. These buttons
+// will be used in audio and brightness control UI, which can be toggled with
+// on/off states.
+class TrayBarButtonWithTitle : public views::CustomButton {
+ public:
+ TrayBarButtonWithTitle(views::ButtonListener* listener,
+ int title_id,
+ int width);
+ virtual ~TrayBarButtonWithTitle();
+
+ void UpdateButton(bool control_on);
+
+ private:
+ class TrayBarButton;
+
+ // Overridden from views::CustomButton:
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
+ virtual void Layout() OVERRIDE;
+
+ TrayBarButton* image_;
+ views::Label* title_;
+ int width_;
+ int image_height_;
+
+ DISALLOW_COPY_AND_ASSIGN(TrayBarButtonWithTitle);
+};
+
+} // namespace internal
+} // namespace ash
+
+#endif // ASH_SYSTEM_TRAY_TRAY_BAR_BUTTON_WITH_TITLE_H_
diff --git a/ash/system/tray/tray_views.cc b/ash/system/tray/tray_views.cc
index 644600a..c18ee82 100644
--- a/ash/system/tray/tray_views.cc
+++ b/ash/system/tray/tray_views.cc
@@ -37,18 +37,6 @@ namespace {
const int kTrayPopupLabelButtonPaddingHorizontal = 16;
const int kTrayPopupLabelButtonPaddingVertical = 8;
-const int kBarImagesActive[] = {
- IDR_SLIDER_ACTIVE_LEFT,
- IDR_SLIDER_ACTIVE_CENTER,
- IDR_SLIDER_ACTIVE_RIGHT,
-};
-
-const int kBarImagesDisabled[] = {
- IDR_SLIDER_DISABLED_LEFT,
- IDR_SLIDER_DISABLED_CENTER,
- IDR_SLIDER_DISABLED_RIGHT,
-};
-
const int kTrayPopupLabelButtonBorderImagesNormal[] = {
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
IDR_AURA_TRAY_POPUP_LABEL_BUTTON_NORMAL_BACKGROUND,
@@ -209,88 +197,6 @@ void TrayPopupHeaderButton::StateChanged() {
SchedulePaint();
}
-////////////////////////////////////////////////////////////////////////////////
-// TrayBarButtonWithTitle
-
-class TrayBarButtonWithTitle::TrayBarButton
- : public views::View {
- public:
- TrayBarButton(const int bar_active_images[], const int bar_disabled_images[])
- : views::View(),
- bar_active_images_(bar_active_images),
- bar_disabled_images_(bar_disabled_images),
- painter_(new views::HorizontalPainter(bar_active_images_)){
- }
- virtual ~TrayBarButton() {}
-
- // Overriden from views::View
- virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
- painter_->Paint(canvas, size());
- }
-
- void Update(bool control_on) {
- painter_.reset(new views::HorizontalPainter(
- control_on ? bar_active_images_ : bar_disabled_images_));
- SchedulePaint();
- }
-
- private:
- const int* bar_active_images_;
- const int* bar_disabled_images_;
- scoped_ptr<views::HorizontalPainter> painter_;
-
- DISALLOW_COPY_AND_ASSIGN(TrayBarButton);
-};
-
-TrayBarButtonWithTitle::TrayBarButtonWithTitle(views::ButtonListener* listener,
- int title_id,
- int width)
- : views::CustomButton(listener),
- image_(new TrayBarButton(kBarImagesActive, kBarImagesDisabled)),
- title_(NULL),
- width_(width) {
- AddChildView(image_);
- if (title_id != -1) {
- title_ = new views::Label;
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- string16 text = rb.GetLocalizedString(title_id);
- title_->SetText(text);
- AddChildView(title_);
- }
-
- image_height_ = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
- kBarImagesActive[0]).ToImageSkia()->height();
-}
-
-TrayBarButtonWithTitle::~TrayBarButtonWithTitle() {}
-
-gfx::Size TrayBarButtonWithTitle::GetPreferredSize() {
- return gfx::Size(width_, kTrayPopupItemHeight);
-}
-
-void TrayBarButtonWithTitle::Layout() {
- gfx::Rect rect(GetContentsBounds());
- int bar_image_y = rect.height() / 2 - image_height_ / 2;
- gfx::Rect bar_image_rect(rect.x(),
- bar_image_y,
- rect.width(),
- image_height_);
- image_->SetBoundsRect(bar_image_rect);
- if (title_) {
- // The image_ has some empty space below the bar image, move the title
- // a little bit up to look closer to the bar.
- gfx::Size title_size = title_->GetPreferredSize();
- title_->SetBounds(rect.x(),
- bar_image_y + image_height_ - 3,
- rect.width(),
- title_size.height());
- }
-}
-
-void TrayBarButtonWithTitle::UpdateButton(bool control_on) {
- image_->Update(control_on);
-}
-
void SetupLabelForTray(views::Label* label) {
// Making label_font static to avoid the time penalty of DeriveFont for
// all but the first call.
diff --git a/ash/system/tray/tray_views.h b/ash/system/tray/tray_views.h
index d50c946..e3e50bc 100644
--- a/ash/system/tray/tray_views.h
+++ b/ash/system/tray/tray_views.h
@@ -9,7 +9,6 @@
#include "ash/shelf/shelf_types.h"
#include "ui/gfx/font.h"
#include "ui/gfx/size.h"
-#include "ui/views/controls/button/custom_button.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/label_button_border.h"
@@ -84,33 +83,6 @@ class TrayPopupHeaderButton : public views::ToggleImageButton {
DISALLOW_COPY_AND_ASSIGN(TrayPopupHeaderButton);
};
-// A button with a bar image and title text below the bar image. These buttons
-// will be used in audio and brightness control UI, which can be toggled with
-// on/off states.
-class TrayBarButtonWithTitle : public views::CustomButton {
- public:
- TrayBarButtonWithTitle(views::ButtonListener* listener,
- int title_id,
- int width);
- virtual ~TrayBarButtonWithTitle();
-
- // Overridden from views::View.
- virtual gfx::Size GetPreferredSize() OVERRIDE;
- virtual void Layout() OVERRIDE;
-
- void UpdateButton(bool control_on);
-
- private:
- class TrayBarButton;
-
- TrayBarButton* image_;
- views::Label* title_;
- int width_;
- int image_height_;
-
- DISALLOW_COPY_AND_ASSIGN(TrayBarButtonWithTitle);
-};
-
// Sets up a Label properly for the tray (sets color, font etc.).
void SetupLabelForTray(views::Label* label);