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

Side by Side Diff: views/controls/button/text_button.cc

Issue 2825018: Canvas refactoring part 3.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "views/controls/button/text_button.h" 5 #include "views/controls/button/text_button.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "app/throb_animation.h" 9 #include "app/throb_animation.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
11 #include "gfx/canvas.h" 11 #include "gfx/canvas_skia.h"
12 #include "views/controls/button/button.h" 12 #include "views/controls/button/button.h"
13 #include "views/event.h" 13 #include "views/event.h"
14 #include "grit/app_resources.h" 14 #include "grit/app_resources.h"
15 15
16 namespace views { 16 namespace views {
17 17
18 // Padding between the icon and text. 18 // Padding between the icon and text.
19 static const int kIconTextPadding = 5; 19 static const int kIconTextPadding = 5;
20 20
21 // Preferred padding between text and edge 21 // Preferred padding between text and edge
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 show_highlighted_ = show_highlighted; 249 show_highlighted_ = show_highlighted;
250 } 250 }
251 251
252 void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) { 252 void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) {
253 if (!for_drag) { 253 if (!for_drag) {
254 PaintBackground(canvas); 254 PaintBackground(canvas);
255 255
256 if (show_highlighted_ && hover_animation_->is_animating()) { 256 if (show_highlighted_ && hover_animation_->is_animating()) {
257 // Draw the hover bitmap into an offscreen buffer, then blend it 257 // Draw the hover bitmap into an offscreen buffer, then blend it
258 // back into the current canvas. 258 // back into the current canvas.
259 canvas->saveLayerAlpha(NULL, 259 canvas->AsCanvasSkia()->saveLayerAlpha(NULL,
260 static_cast<int>(hover_animation_->GetCurrentValue() * 255), 260 static_cast<int>(hover_animation_->GetCurrentValue() * 255),
261 SkCanvas::kARGB_NoClipLayer_SaveFlag); 261 SkCanvas::kARGB_NoClipLayer_SaveFlag);
262 canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); 262 canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255,
263 SkXfermode::kClear_Mode);
263 PaintBorder(canvas); 264 PaintBorder(canvas);
264 canvas->restore(); 265 canvas->AsCanvasSkia()->restore();
265 } else if ((show_highlighted_ && 266 } else if ((show_highlighted_ &&
266 (state_ == BS_HOT || state_ == BS_PUSHED)) || 267 (state_ == BS_HOT || state_ == BS_PUSHED)) ||
267 (state_ == BS_NORMAL && normal_has_border_)) { 268 (state_ == BS_NORMAL && normal_has_border_)) {
268 PaintBorder(canvas); 269 PaintBorder(canvas);
269 } 270 }
270 271
271 PaintFocusBorder(canvas); 272 PaintFocusBorder(canvas);
272 } 273 }
273 274
274 SkBitmap icon; 275 SkBitmap icon;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 // Due to the above, we must perform the flipping manually for RTL UIs. 324 // Due to the above, we must perform the flipping manually for RTL UIs.
324 gfx::Rect text_bounds(text_x, text_y, text_width, text_size_.height()); 325 gfx::Rect text_bounds(text_x, text_y, text_width, text_size_.height());
325 text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); 326 text_bounds.set_x(MirroredLeftPointForRect(text_bounds));
326 327
327 SkColor text_color; 328 SkColor text_color;
328 if (show_highlighted_ && (state() == BS_HOT || state() == BS_PUSHED)) 329 if (show_highlighted_ && (state() == BS_HOT || state() == BS_PUSHED))
329 text_color = color_hover_; 330 text_color = color_hover_;
330 else 331 else
331 text_color = color_; 332 text_color = color_;
332 333
333 int draw_string_flags = gfx::Canvas::DefaultCanvasTextAlignment() | 334 int draw_string_flags = gfx::CanvasSkia::DefaultCanvasTextAlignment() |
334 PrefixTypeToCanvasType(prefix_type_); 335 PrefixTypeToCanvasType(prefix_type_);
335 336
336 if (for_drag) { 337 if (for_drag) {
337 #if defined(OS_WIN) 338 #if defined(OS_WIN)
338 // TODO(erg): Either port DrawStringWithHalo to linux or find an 339 // TODO(erg): Either port DrawStringWithHalo to linux or find an
339 // alternative here. 340 // alternative here.
340 canvas->DrawStringWithHalo(text_, font_, text_color, color_highlight_, 341 canvas->AsCanvasSkia()->DrawStringWithHalo(
341 text_bounds.x(), 342 text_, font_, text_color, color_highlight_, text_bounds.x(),
342 text_bounds.y(), 343 text_bounds.y(), text_bounds.width(), text_bounds.height(),
343 text_bounds.width(), 344 draw_string_flags);
344 text_bounds.height(),
345 draw_string_flags);
346 #else 345 #else
347 canvas->DrawStringInt(text_, 346 canvas->DrawStringInt(text_,
348 font_, 347 font_,
349 text_color, 348 text_color,
350 text_bounds.x(), 349 text_bounds.x(),
351 text_bounds.y(), 350 text_bounds.y(),
352 text_bounds.width(), 351 text_bounds.width(),
353 text_bounds.height(), 352 text_bounds.height(),
354 draw_string_flags); 353 draw_string_flags);
355 #endif 354 #endif
(...skipping 18 matching lines...) Expand all
374 canvas->DrawBitmapInt(icon, icon_bounds.x(), icon_bounds.y()); 373 canvas->DrawBitmapInt(icon, icon_bounds.x(), icon_bounds.y());
375 } 374 }
376 } 375 }
377 376
378 void TextButton::UpdateColor() { 377 void TextButton::UpdateColor() {
379 color_ = IsEnabled() ? color_enabled_ : color_disabled_; 378 color_ = IsEnabled() ? color_enabled_ : color_disabled_;
380 } 379 }
381 380
382 void TextButton::UpdateTextSize() { 381 void TextButton::UpdateTextSize() {
383 int width = 0, height = 0; 382 int width = 0, height = 0;
384 gfx::Canvas::SizeStringInt( 383 gfx::CanvasSkia::SizeStringInt(
385 text_, font_, &width, &height, 384 text_, font_, &width, &height,
386 gfx::Canvas::NO_ELLIPSIS | PrefixTypeToCanvasType(prefix_type_)); 385 gfx::Canvas::NO_ELLIPSIS | PrefixTypeToCanvasType(prefix_type_));
387 text_size_.SetSize(width, font_.height()); 386 text_size_.SetSize(width, font_.height());
388 max_text_size_.SetSize(std::max(max_text_size_.width(), text_size_.width()), 387 max_text_size_.SetSize(std::max(max_text_size_.width(), text_size_.width()),
389 std::max(max_text_size_.height(), 388 std::max(max_text_size_.height(),
390 text_size_.height())); 389 text_size_.height()));
391 } 390 }
392 391
393 //////////////////////////////////////////////////////////////////////////////// 392 ////////////////////////////////////////////////////////////////////////////////
394 // TextButton, View overrides: 393 // TextButton, View overrides:
(...skipping 27 matching lines...) Expand all
422 // changed by other functions like CustomButton::SetState(). 421 // changed by other functions like CustomButton::SetState().
423 UpdateColor(); 422 UpdateColor();
424 SchedulePaint(); 423 SchedulePaint();
425 } 424 }
426 425
427 void TextButton::Paint(gfx::Canvas* canvas) { 426 void TextButton::Paint(gfx::Canvas* canvas) {
428 Paint(canvas, false); 427 Paint(canvas, false);
429 } 428 }
430 429
431 } // namespace views 430 } // namespace views
OLDNEW
« gfx/canvas.h ('K') | « views/background.cc ('k') | views/controls/label.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698