• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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/setting_level_bubble_view.h"
6 
7 #include <string>
8 
9 #include "base/logging.h"
10 #include "third_party/skia/include/core/SkBitmap.h"
11 #include "ui/gfx/canvas.h"
12 #include "views/controls/progress_bar.h"
13 
14 using views::Background;
15 using views::View;
16 using views::Widget;
17 
18 namespace {
19 
20 // Bubble metrics.
21 const int kWidth = 350, kHeight = 100;
22 const int kPadding = 20;
23 const int kProgressBarWidth = 211;
24 const int kProgressBarHeight = 17;
25 
26 }  // namespace
27 
28 namespace chromeos {
29 
SettingLevelBubbleView()30 SettingLevelBubbleView::SettingLevelBubbleView()
31     : progress_bar_(NULL),
32       icon_(NULL) {
33 }
34 
Init(SkBitmap * icon,int level_percent)35 void SettingLevelBubbleView::Init(SkBitmap* icon, int level_percent) {
36   DCHECK(icon);
37   DCHECK(level_percent >= 0 && level_percent <= 100);
38   icon_ = icon;
39   progress_bar_ = new views::ProgressBar();
40   AddChildView(progress_bar_);
41   Update(level_percent);
42   progress_bar_->EnableCanvasFlippingForRTLUI(true);
43   EnableCanvasFlippingForRTLUI(true);
44 }
45 
SetIcon(SkBitmap * icon)46 void SettingLevelBubbleView::SetIcon(SkBitmap* icon) {
47   DCHECK(icon);
48   icon_ = icon;
49   SchedulePaint();
50 }
51 
Update(int level_percent)52 void SettingLevelBubbleView::Update(int level_percent) {
53   DCHECK(level_percent >= 0 && level_percent <= 100);
54   progress_bar_->SetProgress(level_percent);
55 }
56 
OnPaint(gfx::Canvas * canvas)57 void SettingLevelBubbleView::OnPaint(gfx::Canvas* canvas) {
58   views::View::OnPaint(canvas);
59   canvas->DrawBitmapInt(*icon_, kPadding, (height() - icon_->height()) / 2);
60 }
61 
Layout()62 void SettingLevelBubbleView::Layout() {
63   progress_bar_->SetBounds(width() - kPadding - kProgressBarWidth,
64                            (height() - kProgressBarHeight) / 2,
65                            kProgressBarWidth, kProgressBarHeight);
66 }
67 
GetPreferredSize()68 gfx::Size SettingLevelBubbleView::GetPreferredSize() {
69   return gfx::Size(kWidth, kHeight);
70 }
71 
72 }  // namespace chromeos
73