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

Unified Diff: ash/system/tray/tray_views.cc

Issue 10808080: Implement new volume mute button. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: ash/system/tray/tray_views.cc
diff --git a/ash/system/tray/tray_views.cc b/ash/system/tray/tray_views.cc
index 573f58dbbcba91b3215b703ee734c58aa7078c36..7627e2c5e8a1f3c80116f9df35c797f998dd3b99 100644
--- a/ash/system/tray/tray_views.cc
+++ b/ash/system/tray/tray_views.cc
@@ -27,6 +27,18 @@ namespace {
const int kIconPaddingLeft = 5;
const int kPaddingAroundButtons = 5;
+const int kBarImagesActive[] = {
+ IDR_AURA_UBER_TRAY_BAR_BUTTON_ACTIVE_LEFT,
+ IDR_AURA_UBER_TRAY_BAR_BUTTON_ACTIVE_CENTER,
+ IDR_AURA_UBER_TRAY_BAR_BUTTON_ACTIVE_RIGHT,
+};
+
+const int kBarImagesDisabled[] = {
+ IDR_AURA_UBER_TRAY_BAR_BUTTON_DISABLED_LEFT,
+ IDR_AURA_UBER_TRAY_BAR_BUTTON_DISABLED_CENTER,
+ IDR_AURA_UBER_TRAY_BAR_BUTTON_DISABLED_RIGHT,
+};
+
views::View* CreatePopupHeaderButtonsContainer() {
views::View* view = new views::View;
view->SetLayoutManager(new
@@ -430,6 +442,83 @@ void TrayPopupHeaderButton::StateChanged() {
}
////////////////////////////////////////////////////////////////////////////////
+// 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_(new views::Label),
+ width_(width) {
+ AddChildView(image_);
+ 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::Size title_size = title_->GetPreferredSize();
+ 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);
+ // The image_ has some empty space below the bar image, move the title
+ // a little bit up to look closer to the bar.
+ title_->SetBounds(rect.x(),
+ bar_image_y + image_height_ - 3,
+ rect.width(),
sadrul 2012/07/23 21:02:30 Instead of doing this, could there be a box-layout
jennyz 2012/07/23 21:22:03 It seems more flexible to control the layout by pr
+ title_size.height());
+}
+
+void TrayBarButtonWithTitle::UpdateButton(bool control_on) {
+ image_->Update(control_on);
+}
+
+////////////////////////////////////////////////////////////////////////////////
// SpecialPopupRow
SpecialPopupRow::SpecialPopupRow()

Powered by Google App Engine
This is Rietveld 408576698