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