Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/views/controls/throbber.h" | 5 #include "ui/views/controls/throbber.h" |
| 6 | 6 |
| 7 #include "base/time.h" | 7 #include "base/time.h" |
| 8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
| 9 #include "third_party/skia/include/core/SkBitmap.h" | 9 #include "ui/gfx/image/image_skia.h" |
|
msw
2012/05/29 07:50:51
nit: alphabetize
| |
| 10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/image/image.h" | 12 #include "ui/gfx/image/image.h" |
| 13 | 13 |
| 14 using base::Time; | 14 using base::Time; |
| 15 using base::TimeDelta; | 15 using base::TimeDelta; |
| 16 | 16 |
| 17 namespace views { | 17 namespace views { |
| 18 | 18 |
| 19 Throbber::Throbber(int frame_time_ms, | 19 Throbber::Throbber(int frame_time_ms, |
| 20 bool paint_while_stopped) | 20 bool paint_while_stopped) |
| 21 : running_(false), | 21 : running_(false), |
| 22 paint_while_stopped_(paint_while_stopped), | 22 paint_while_stopped_(paint_while_stopped), |
| 23 frames_(NULL), | 23 frames_(NULL), |
| 24 frame_time_(TimeDelta::FromMilliseconds(frame_time_ms)) { | 24 frame_time_(TimeDelta::FromMilliseconds(frame_time_ms)) { |
| 25 SetFrames(ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 25 SetFrames(ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 26 IDR_THROBBER).ToSkBitmap()); | 26 IDR_THROBBER).ToImageSkia()); |
| 27 } | 27 } |
| 28 | 28 |
| 29 Throbber::~Throbber() { | 29 Throbber::~Throbber() { |
| 30 Stop(); | 30 Stop(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void Throbber::Start() { | 33 void Throbber::Start() { |
| 34 if (running_) | 34 if (running_) |
| 35 return; | 35 return; |
| 36 | 36 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 47 void Throbber::Stop() { | 47 void Throbber::Stop() { |
| 48 if (!running_) | 48 if (!running_) |
| 49 return; | 49 return; |
| 50 | 50 |
| 51 timer_.Stop(); | 51 timer_.Stop(); |
| 52 | 52 |
| 53 running_ = false; | 53 running_ = false; |
| 54 SchedulePaint(); // Important if we're not painting while stopped | 54 SchedulePaint(); // Important if we're not painting while stopped |
| 55 } | 55 } |
| 56 | 56 |
| 57 void Throbber::SetFrames(const SkBitmap* frames) { | 57 void Throbber::SetFrames(const gfx::ImageSkia* frames) { |
| 58 frames_ = frames; | 58 frames_ = frames; |
| 59 DCHECK(frames_->width() > 0 && frames_->height() > 0); | 59 DCHECK(frames_->width() > 0 && frames_->height() > 0); |
| 60 DCHECK(frames_->width() % frames_->height() == 0); | 60 DCHECK(frames_->width() % frames_->height() == 0); |
| 61 frame_count_ = frames_->width() / frames_->height(); | 61 frame_count_ = frames_->width() / frames_->height(); |
| 62 PreferredSizeChanged(); | 62 PreferredSizeChanged(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void Throbber::Run() { | 65 void Throbber::Run() { |
| 66 DCHECK(running_); | 66 DCHECK(running_); |
| 67 | 67 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 void SmoothedThrobber::StopDelayOver() { | 133 void SmoothedThrobber::StopDelayOver() { |
| 134 Throbber::Stop(); | 134 Throbber::Stop(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 // Checkmark throbber --------------------------------------------------------- | 137 // Checkmark throbber --------------------------------------------------------- |
| 138 | 138 |
| 139 CheckmarkThrobber::CheckmarkThrobber() | 139 CheckmarkThrobber::CheckmarkThrobber() |
| 140 : Throbber(kFrameTimeMs, false), | 140 : Throbber(kFrameTimeMs, false), |
| 141 checked_(false), | 141 checked_(false), |
| 142 checkmark_(ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 142 checkmark_(ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 143 IDR_CHECKMARK).ToSkBitmap()) { | 143 IDR_CHECKMARK).ToImageSkia()) { |
| 144 } | 144 } |
| 145 | 145 |
| 146 void CheckmarkThrobber::SetChecked(bool checked) { | 146 void CheckmarkThrobber::SetChecked(bool checked) { |
| 147 bool changed = checked != checked_; | 147 bool changed = checked != checked_; |
| 148 if (changed) { | 148 if (changed) { |
| 149 checked_ = checked; | 149 checked_ = checked; |
| 150 SchedulePaint(); | 150 SchedulePaint(); |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 | 153 |
| 154 void CheckmarkThrobber::OnPaint(gfx::Canvas* canvas) { | 154 void CheckmarkThrobber::OnPaint(gfx::Canvas* canvas) { |
| 155 if (running_) { | 155 if (running_) { |
| 156 // Let the throbber throb... | 156 // Let the throbber throb... |
| 157 Throbber::OnPaint(canvas); | 157 Throbber::OnPaint(canvas); |
| 158 return; | 158 return; |
| 159 } | 159 } |
| 160 // Otherwise we paint our tick mark or nothing depending on our state. | 160 // Otherwise we paint our tick mark or nothing depending on our state. |
| 161 if (checked_) { | 161 if (checked_) { |
| 162 int checkmark_x = (width() - checkmark_->width()) / 2; | 162 int checkmark_x = (width() - checkmark_->width()) / 2; |
| 163 int checkmark_y = (height() - checkmark_->height()) / 2; | 163 int checkmark_y = (height() - checkmark_->height()) / 2; |
| 164 canvas->DrawBitmapInt(*checkmark_, checkmark_x, checkmark_y); | 164 canvas->DrawBitmapInt(*checkmark_, checkmark_x, checkmark_y); |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 | 167 |
| 168 } // namespace views | 168 } // namespace views |
| OLD | NEW |