OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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. |
| 4 |
| 5 #include "chrome/browser/chromeos/volume_bubble_view.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "app/l10n_util.h" |
| 10 #include "app/resource_bundle.h" |
| 11 #include "gfx/canvas.h" |
| 12 #include "grit/theme_resources.h" |
| 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 14 #include "views/controls/progress_bar.h" |
| 15 |
| 16 using views::Background; |
| 17 using views::View; |
| 18 using views::Widget; |
| 19 |
| 20 namespace { |
| 21 |
| 22 // Volume bubble metrics. |
| 23 const int kWidth = 300, kHeight = 75; |
| 24 const int kMargin = 25; |
| 25 const int kProgressBarHeight = 20; |
| 26 |
| 27 } // namespace |
| 28 |
| 29 namespace chromeos { |
| 30 |
| 31 VolumeBubbleView::VolumeBubbleView() : progress_bar_(NULL) { |
| 32 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 33 volume_icon_ = rb.GetBitmapNamed(IDR_VOLUMEBUBBLE_ICON); |
| 34 } |
| 35 |
| 36 void VolumeBubbleView::Init(int volume_level_percent) { |
| 37 DCHECK(volume_level_percent >= 0 && volume_level_percent <= 100); |
| 38 progress_bar_ = new views::ProgressBar(); |
| 39 AddChildView(progress_bar_); |
| 40 Update(volume_level_percent); |
| 41 } |
| 42 |
| 43 void VolumeBubbleView::Update(int volume_level_percent) { |
| 44 DCHECK(volume_level_percent >= 0 && volume_level_percent <= 100); |
| 45 progress_bar_->SetProgress(volume_level_percent); |
| 46 } |
| 47 |
| 48 void VolumeBubbleView::Paint(gfx::Canvas* canvas) { |
| 49 views::View::Paint(canvas); |
| 50 canvas->DrawBitmapInt(*volume_icon_, |
| 51 volume_icon_->width(), |
| 52 (height() - volume_icon_->height()) / 2); |
| 53 } |
| 54 |
| 55 void VolumeBubbleView::Layout() { |
| 56 progress_bar_->SetBounds(volume_icon_->width() + kMargin * 2, |
| 57 (height() - kProgressBarHeight) / 2, |
| 58 width() - volume_icon_->width() - kMargin * 3, |
| 59 kProgressBarHeight); |
| 60 } |
| 61 |
| 62 gfx::Size VolumeBubbleView::GetPreferredSize() { |
| 63 return gfx::Size(kWidth, kHeight); |
| 64 } |
| 65 |
| 66 } // namespace chromeos |
OLD | NEW |