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 14using views::Background; 15using views::View; 16using views::Widget; 17 18namespace { 19 20// Bubble metrics. 21const int kWidth = 350, kHeight = 100; 22const int kPadding = 20; 23const int kProgressBarWidth = 211; 24const int kProgressBarHeight = 17; 25 26} // namespace 27 28namespace chromeos { 29 30SettingLevelBubbleView::SettingLevelBubbleView() 31 : progress_bar_(NULL), 32 icon_(NULL) { 33} 34 35void 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 46void SettingLevelBubbleView::SetIcon(SkBitmap* icon) { 47 DCHECK(icon); 48 icon_ = icon; 49 SchedulePaint(); 50} 51 52void SettingLevelBubbleView::Update(int level_percent) { 53 DCHECK(level_percent >= 0 && level_percent <= 100); 54 progress_bar_->SetProgress(level_percent); 55} 56 57void SettingLevelBubbleView::OnPaint(gfx::Canvas* canvas) { 58 views::View::OnPaint(canvas); 59 canvas->DrawBitmapInt(*icon_, kPadding, (height() - icon_->height()) / 2); 60} 61 62void SettingLevelBubbleView::Layout() { 63 progress_bar_->SetBounds(width() - kPadding - kProgressBarWidth, 64 (height() - kProgressBarHeight) / 2, 65 kProgressBarWidth, kProgressBarHeight); 66} 67 68gfx::Size SettingLevelBubbleView::GetPreferredSize() { 69 return gfx::Size(kWidth, kHeight); 70} 71 72} // namespace chromeos 73