Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: chrome/browser/ui/views/web_intent_picker_views.cc

Issue 10437006: Converts ui/views/controls, ui/views/examples, ui/base/models to ImageSkia (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "chrome/browser/tab_contents/tab_util.h" 10 #include "chrome/browser/tab_contents/tab_util.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 public: 137 public:
138 ThrobberNativeTextButton(views::ButtonListener* listener, 138 ThrobberNativeTextButton(views::ButtonListener* listener,
139 const string16& text); 139 const string16& text);
140 virtual ~ThrobberNativeTextButton(); 140 virtual ~ThrobberNativeTextButton();
141 141
142 // Start or stop the throbber. 142 // Start or stop the throbber.
143 void StartThrobber(); 143 void StartThrobber();
144 void StopThrobber(); 144 void StopThrobber();
145 145
146 // Set the throbber bitmap to use. IDR_THROBBER is used by default. 146 // Set the throbber bitmap to use. IDR_THROBBER is used by default.
147 void SetFrames(const SkBitmap* frames); 147 void SetFrames(const gfx::ImageSkia* frames);
148 148
149 protected: 149 protected:
150 virtual const SkBitmap& GetImageToPaint() const OVERRIDE; 150 virtual const gfx::ImageSkia& GetImageToPaint() const OVERRIDE;
151 151
152 private: 152 private:
153 // The timer callback to schedule painting this view. 153 // The timer callback to schedule painting this view.
154 void Run(); 154 void Run();
155 155
156 // Bitmap that contains the throbber frames. 156 // Image that contains the throbber frames.
157 const SkBitmap* frames_; 157 const gfx::ImageSkia* frames_;
158 158
159 // The currently displayed frame, given to GetImageToPaint. 159 // The currently displayed frame, given to GetImageToPaint.
160 mutable SkBitmap this_frame_; 160 mutable gfx::ImageSkia this_frame_;
161 161
162 // How long one frame is displayed. 162 // How long one frame is displayed.
163 base::TimeDelta frame_time_; 163 base::TimeDelta frame_time_;
164 164
165 // Used to schedule Run calls. 165 // Used to schedule Run calls.
166 base::RepeatingTimer<ThrobberNativeTextButton> timer_; 166 base::RepeatingTimer<ThrobberNativeTextButton> timer_;
167 167
168 // How many frames we have. 168 // How many frames we have.
169 int frame_count_; 169 int frame_count_;
170 170
171 // Time when StartThrobber was called. 171 // Time when StartThrobber was called.
172 base::TimeTicks start_time_; 172 base::TimeTicks start_time_;
173 173
174 // Whether the throbber is shown an animating. 174 // Whether the throbber is shown an animating.
175 bool running_; 175 bool running_;
176 176
177 DISALLOW_COPY_AND_ASSIGN(ThrobberNativeTextButton); 177 DISALLOW_COPY_AND_ASSIGN(ThrobberNativeTextButton);
178 }; 178 };
179 179
180 ThrobberNativeTextButton::ThrobberNativeTextButton( 180 ThrobberNativeTextButton::ThrobberNativeTextButton(
181 views::ButtonListener* listener, const string16& text) 181 views::ButtonListener* listener, const string16& text)
182 : NativeTextButton(listener, text), 182 : NativeTextButton(listener, text),
183 frame_time_(base::TimeDelta::FromMilliseconds(kThrobberFrameTimeMs)), 183 frame_time_(base::TimeDelta::FromMilliseconds(kThrobberFrameTimeMs)),
184 frame_count_(0), 184 frame_count_(0),
185 running_(false) { 185 running_(false) {
186 SetFrames(ui::ResourceBundle::GetSharedInstance().GetImageNamed( 186 SetFrames(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
187 IDR_THROBBER).ToSkBitmap()); 187 IDR_THROBBER).ToImageSkia());
188 } 188 }
189 189
190 ThrobberNativeTextButton::~ThrobberNativeTextButton() { 190 ThrobberNativeTextButton::~ThrobberNativeTextButton() {
191 StopThrobber(); 191 StopThrobber();
192 } 192 }
193 193
194 void ThrobberNativeTextButton::StartThrobber() { 194 void ThrobberNativeTextButton::StartThrobber() {
195 if (running_) 195 if (running_)
196 return; 196 return;
197 197
198 start_time_ = base::TimeTicks::Now(); 198 start_time_ = base::TimeTicks::Now();
199 timer_.Start(FROM_HERE, frame_time_, this, &ThrobberNativeTextButton::Run); 199 timer_.Start(FROM_HERE, frame_time_, this, &ThrobberNativeTextButton::Run);
200 running_ = true; 200 running_ = true;
201 201
202 SchedulePaint(); 202 SchedulePaint();
203 } 203 }
204 204
205 void ThrobberNativeTextButton::StopThrobber() { 205 void ThrobberNativeTextButton::StopThrobber() {
206 if (!running_) 206 if (!running_)
207 return; 207 return;
208 208
209 timer_.Stop(); 209 timer_.Stop();
210 running_ = false; 210 running_ = false;
211 } 211 }
212 212
213 void ThrobberNativeTextButton::SetFrames(const SkBitmap* frames) { 213 void ThrobberNativeTextButton::SetFrames(const gfx::ImageSkia* frames) {
214 frames_ = frames; 214 frames_ = frames;
215 DCHECK(frames_->width() > 0 && frames_->height() > 0); 215 DCHECK(frames_->width() > 0 && frames_->height() > 0);
216 DCHECK(frames_->width() % frames_->height() == 0); 216 DCHECK(frames_->width() % frames_->height() == 0);
217 frame_count_ = frames_->width() / frames_->height(); 217 frame_count_ = frames_->width() / frames_->height();
218 PreferredSizeChanged(); 218 PreferredSizeChanged();
219 } 219 }
220 220
221 const SkBitmap& ThrobberNativeTextButton::GetImageToPaint() const { 221 const gfx::ImageSkia& ThrobberNativeTextButton::GetImageToPaint() const {
222 if (!running_) 222 if (!running_)
223 return NativeTextButton::GetImageToPaint(); 223 return NativeTextButton::GetImageToPaint();
224 224
225 const base::TimeDelta elapsed_time = base::TimeTicks::Now() - start_time_; 225 const base::TimeDelta elapsed_time = base::TimeTicks::Now() - start_time_;
226 const int current_frame = 226 const int current_frame =
227 static_cast<int>(elapsed_time / frame_time_) % frame_count_; 227 static_cast<int>(elapsed_time / frame_time_) % frame_count_;
228 const int image_size = frames_->height(); 228 const int image_size = frames_->height();
229 const int image_offset = current_frame * image_size; 229 const int image_offset = current_frame * image_size;
230 230
231 SkIRect subset_rect = SkIRect::MakeXYWH(image_offset, 0, 231 SkIRect subset_rect = SkIRect::MakeXYWH(image_offset, 0,
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 views::ImageButton* close_button = new views::ImageButton(this); 1165 views::ImageButton* close_button = new views::ImageButton(this);
1166 close_button->SetImage(views::CustomButton::BS_NORMAL, 1166 close_button->SetImage(views::CustomButton::BS_NORMAL,
1167 rb.GetImageSkiaNamed(IDR_CLOSE_BAR)); 1167 rb.GetImageSkiaNamed(IDR_CLOSE_BAR));
1168 close_button->SetImage(views::CustomButton::BS_HOT, 1168 close_button->SetImage(views::CustomButton::BS_HOT,
1169 rb.GetImageSkiaNamed(IDR_CLOSE_BAR_H)); 1169 rb.GetImageSkiaNamed(IDR_CLOSE_BAR_H));
1170 close_button->SetImage(views::CustomButton::BS_PUSHED, 1170 close_button->SetImage(views::CustomButton::BS_PUSHED,
1171 rb.GetImageSkiaNamed(IDR_CLOSE_BAR_P)); 1171 rb.GetImageSkiaNamed(IDR_CLOSE_BAR_P));
1172 return close_button; 1172 return close_button;
1173 } 1173 }
1174 #endif 1174 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698