This source file includes following definitions.
- bar_painter_
- GetPreferredSize
- OnPaint
#include "ui/app_list/views/progress_bar_view.h"
#include <algorithm>
#include "grit/ui_resources.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/insets.h"
#include "ui/views/painter.h"
namespace app_list {
namespace {
const int kProgressBarImages[] = {
IDR_APP_LIST_ITEM_PROGRESS_LEFT,
IDR_APP_LIST_ITEM_PROGRESS_CENTER,
IDR_APP_LIST_ITEM_PROGRESS_RIGHT
};
}
ProgressBarView::ProgressBarView()
: background_painter_(views::Painter::CreateImagePainter(
*ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
IDR_APP_LIST_ITEM_PROGRESS_BACKGROUND),
gfx::Insets(2, 2, 2, 2))),
bar_painter_(new views::HorizontalPainter(kProgressBarImages)) {}
ProgressBarView::~ProgressBarView() {}
gfx::Size ProgressBarView::GetPreferredSize() {
return background_painter_->GetMinimumSize();
}
void ProgressBarView::OnPaint(gfx::Canvas* canvas) {
gfx::Size paint_size = size();
const gfx::Size min_size(background_painter_->GetMinimumSize());
if (paint_size.width() < min_size.width() ||
paint_size.height() < min_size.height()) {
return;
}
background_painter_->Paint(canvas, paint_size);
const int kBarEndWidth = 4;
const int bar_width = paint_size.width() - kBarEndWidth;
DCHECK_GE(bar_width, 0);
paint_size.set_width(kBarEndWidth + bar_width * GetNormalizedValue());
bar_painter_->Paint(canvas, paint_size);
}
}