| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "ui/app_list/views/progress_bar_view.h" | 5 #include "ui/app_list/views/progress_bar_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "grit/ui_resources.h" | 9 #include "grit/ui_resources.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 ProgressBarView::ProgressBarView() | 28 ProgressBarView::ProgressBarView() |
| 29 : background_painter_(views::Painter::CreateImagePainter( | 29 : background_painter_(views::Painter::CreateImagePainter( |
| 30 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 30 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 31 IDR_APP_LIST_ITEM_PROGRESS_BACKGROUND), | 31 IDR_APP_LIST_ITEM_PROGRESS_BACKGROUND), |
| 32 gfx::Insets(2, 2, 2, 2))), | 32 gfx::Insets(2, 2, 2, 2))), |
| 33 bar_painter_(new views::HorizontalPainter(kProgressBarImages)) {} | 33 bar_painter_(new views::HorizontalPainter(kProgressBarImages)) {} |
| 34 | 34 |
| 35 ProgressBarView::~ProgressBarView() {} | 35 ProgressBarView::~ProgressBarView() {} |
| 36 | 36 |
| 37 gfx::Size ProgressBarView::GetPreferredSize() { | 37 gfx::Size ProgressBarView::GetPreferredSize() const { |
| 38 return background_painter_->GetMinimumSize(); | 38 return background_painter_->GetMinimumSize(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void ProgressBarView::OnPaint(gfx::Canvas* canvas) { | 41 void ProgressBarView::OnPaint(gfx::Canvas* canvas) { |
| 42 gfx::Size paint_size = size(); | 42 gfx::Size paint_size = size(); |
| 43 | 43 |
| 44 const gfx::Size min_size(background_painter_->GetMinimumSize()); | 44 const gfx::Size min_size(background_painter_->GetMinimumSize()); |
| 45 if (paint_size.width() < min_size.width() || | 45 if (paint_size.width() < min_size.width() || |
| 46 paint_size.height() < min_size.height()) { | 46 paint_size.height() < min_size.height()) { |
| 47 return; | 47 return; |
| 48 } | 48 } |
| 49 | 49 |
| 50 background_painter_->Paint(canvas, paint_size); | 50 background_painter_->Paint(canvas, paint_size); |
| 51 | 51 |
| 52 const int kBarEndWidth = 4; | 52 const int kBarEndWidth = 4; |
| 53 const int bar_width = paint_size.width() - kBarEndWidth; | 53 const int bar_width = paint_size.width() - kBarEndWidth; |
| 54 DCHECK_GE(bar_width, 0); | 54 DCHECK_GE(bar_width, 0); |
| 55 | 55 |
| 56 // Map normalized value in [0,1] to the pixel width in | 56 // Map normalized value in [0,1] to the pixel width in |
| 57 // [kBarEndWidth, view_size.width()]. | 57 // [kBarEndWidth, view_size.width()]. |
| 58 paint_size.set_width(kBarEndWidth + bar_width * GetNormalizedValue()); | 58 paint_size.set_width(kBarEndWidth + bar_width * GetNormalizedValue()); |
| 59 bar_painter_->Paint(canvas, paint_size); | 59 bar_painter_->Paint(canvas, paint_size); |
| 60 } | 60 } |
| 61 | 61 |
| 62 } // namespace app_list | 62 } // namespace app_list |
| OLD | NEW |