Views Omnibox: tolerate minor click-to-select-all dragging.
[chromium-blink-merge.git] / ui / app_list / views / progress_bar_view.cc
blobaaf52c0f6fb43a8f8838e0c7fe681d306fa5343a
1 // Copyright 2013 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.
5 #include "ui/app_list/views/progress_bar_view.h"
7 #include <algorithm>
9 #include "grit/ui_resources.h"
10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/image/image_skia.h"
12 #include "ui/gfx/insets.h"
13 #include "ui/views/painter.h"
15 namespace app_list {
17 namespace {
19 // Image assets for the bar part.
20 const int kProgressBarImages[] = {
21 IDR_APP_LIST_ITEM_PROGRESS_LEFT,
22 IDR_APP_LIST_ITEM_PROGRESS_CENTER,
23 IDR_APP_LIST_ITEM_PROGRESS_RIGHT
26 } // namespace
28 ProgressBarView::ProgressBarView()
29 : background_painter_(views::Painter::CreateImagePainter(
30 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
31 IDR_APP_LIST_ITEM_PROGRESS_BACKGROUND),
32 gfx::Insets(2, 2, 2, 2))),
33 bar_painter_(new views::HorizontalPainter(kProgressBarImages)) {}
35 ProgressBarView::~ProgressBarView() {}
37 gfx::Size ProgressBarView::GetPreferredSize() {
38 return background_painter_->GetMinimumSize();
41 void ProgressBarView::OnPaint(gfx::Canvas* canvas) {
42 gfx::Size paint_size = size();
44 const gfx::Size min_size(background_painter_->GetMinimumSize());
45 if (paint_size.width() < min_size.width() ||
46 paint_size.height() < min_size.height()) {
47 return;
50 background_painter_->Paint(canvas, paint_size);
52 const int kBarEndWidth = 4;
53 const int bar_width = paint_size.width() - kBarEndWidth;
54 DCHECK_GE(bar_width, 0);
56 // Map normalized value in [0,1] to the pixel width in
57 // [kBarEndWidth, view_size.width()].
58 paint_size.set_width(kBarEndWidth + bar_width * GetNormalizedValue());
59 bar_painter_->Paint(canvas, paint_size);
62 } // namespace app_list