| OLD | NEW |
| 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_skia.h" | 11 #include "gfx/canvas.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 Loading... |
| 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->AsCanvasSkia()->saveLayerAlpha(NULL, | 259 canvas->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->AsCanvasSkia()->drawARGB(0, 255, 255, 255, | 262 canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); |
| 263 SkXfermode::kClear_Mode); | |
| 264 PaintBorder(canvas); | 263 PaintBorder(canvas); |
| 265 canvas->AsCanvasSkia()->restore(); | 264 canvas->restore(); |
| 266 } else if ((show_highlighted_ && | 265 } else if ((show_highlighted_ && |
| 267 (state_ == BS_HOT || state_ == BS_PUSHED)) || | 266 (state_ == BS_HOT || state_ == BS_PUSHED)) || |
| 268 (state_ == BS_NORMAL && normal_has_border_)) { | 267 (state_ == BS_NORMAL && normal_has_border_)) { |
| 269 PaintBorder(canvas); | 268 PaintBorder(canvas); |
| 270 } | 269 } |
| 271 | 270 |
| 272 PaintFocusBorder(canvas); | 271 PaintFocusBorder(canvas); |
| 273 } | 272 } |
| 274 | 273 |
| 275 SkBitmap icon; | 274 SkBitmap icon; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 // Due to the above, we must perform the flipping manually for RTL UIs. | 323 // Due to the above, we must perform the flipping manually for RTL UIs. |
| 325 gfx::Rect text_bounds(text_x, text_y, text_width, text_size_.height()); | 324 gfx::Rect text_bounds(text_x, text_y, text_width, text_size_.height()); |
| 326 text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); | 325 text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); |
| 327 | 326 |
| 328 SkColor text_color; | 327 SkColor text_color; |
| 329 if (show_highlighted_ && (state() == BS_HOT || state() == BS_PUSHED)) | 328 if (show_highlighted_ && (state() == BS_HOT || state() == BS_PUSHED)) |
| 330 text_color = color_hover_; | 329 text_color = color_hover_; |
| 331 else | 330 else |
| 332 text_color = color_; | 331 text_color = color_; |
| 333 | 332 |
| 334 int draw_string_flags = gfx::CanvasSkia::DefaultCanvasTextAlignment() | | 333 int draw_string_flags = gfx::Canvas::DefaultCanvasTextAlignment() | |
| 335 PrefixTypeToCanvasType(prefix_type_); | 334 PrefixTypeToCanvasType(prefix_type_); |
| 336 | 335 |
| 337 if (for_drag) { | 336 if (for_drag) { |
| 338 #if defined(OS_WIN) | 337 #if defined(OS_WIN) |
| 339 // TODO(erg): Either port DrawStringWithHalo to linux or find an | 338 // TODO(erg): Either port DrawStringWithHalo to linux or find an |
| 340 // alternative here. | 339 // alternative here. |
| 341 canvas->AsCanvasSkia()->DrawStringWithHalo( | 340 canvas->DrawStringWithHalo(text_, font_, text_color, color_highlight_, |
| 342 text_, font_, text_color, color_highlight_, text_bounds.x(), | 341 text_bounds.x(), |
| 343 text_bounds.y(), text_bounds.width(), text_bounds.height(), | 342 text_bounds.y(), |
| 344 draw_string_flags); | 343 text_bounds.width(), |
| 344 text_bounds.height(), |
| 345 draw_string_flags); |
| 345 #else | 346 #else |
| 346 canvas->DrawStringInt(text_, | 347 canvas->DrawStringInt(text_, |
| 347 font_, | 348 font_, |
| 348 text_color, | 349 text_color, |
| 349 text_bounds.x(), | 350 text_bounds.x(), |
| 350 text_bounds.y(), | 351 text_bounds.y(), |
| 351 text_bounds.width(), | 352 text_bounds.width(), |
| 352 text_bounds.height(), | 353 text_bounds.height(), |
| 353 draw_string_flags); | 354 draw_string_flags); |
| 354 #endif | 355 #endif |
| (...skipping 18 matching lines...) Expand all Loading... |
| 373 canvas->DrawBitmapInt(icon, icon_bounds.x(), icon_bounds.y()); | 374 canvas->DrawBitmapInt(icon, icon_bounds.x(), icon_bounds.y()); |
| 374 } | 375 } |
| 375 } | 376 } |
| 376 | 377 |
| 377 void TextButton::UpdateColor() { | 378 void TextButton::UpdateColor() { |
| 378 color_ = IsEnabled() ? color_enabled_ : color_disabled_; | 379 color_ = IsEnabled() ? color_enabled_ : color_disabled_; |
| 379 } | 380 } |
| 380 | 381 |
| 381 void TextButton::UpdateTextSize() { | 382 void TextButton::UpdateTextSize() { |
| 382 int width = 0, height = 0; | 383 int width = 0, height = 0; |
| 383 gfx::CanvasSkia::SizeStringInt( | 384 gfx::Canvas::SizeStringInt( |
| 384 text_, font_, &width, &height, | 385 text_, font_, &width, &height, |
| 385 gfx::Canvas::NO_ELLIPSIS | PrefixTypeToCanvasType(prefix_type_)); | 386 gfx::Canvas::NO_ELLIPSIS | PrefixTypeToCanvasType(prefix_type_)); |
| 386 text_size_.SetSize(width, font_.height()); | 387 text_size_.SetSize(width, font_.height()); |
| 387 max_text_size_.SetSize(std::max(max_text_size_.width(), text_size_.width()), | 388 max_text_size_.SetSize(std::max(max_text_size_.width(), text_size_.width()), |
| 388 std::max(max_text_size_.height(), | 389 std::max(max_text_size_.height(), |
| 389 text_size_.height())); | 390 text_size_.height())); |
| 390 } | 391 } |
| 391 | 392 |
| 392 //////////////////////////////////////////////////////////////////////////////// | 393 //////////////////////////////////////////////////////////////////////////////// |
| 393 // TextButton, View overrides: | 394 // TextButton, View overrides: |
| (...skipping 27 matching lines...) Expand all Loading... |
| 421 // changed by other functions like CustomButton::SetState(). | 422 // changed by other functions like CustomButton::SetState(). |
| 422 UpdateColor(); | 423 UpdateColor(); |
| 423 SchedulePaint(); | 424 SchedulePaint(); |
| 424 } | 425 } |
| 425 | 426 |
| 426 void TextButton::Paint(gfx::Canvas* canvas) { | 427 void TextButton::Paint(gfx::Canvas* canvas) { |
| 427 Paint(canvas, false); | 428 Paint(canvas, false); |
| 428 } | 429 } |
| 429 | 430 |
| 430 } // namespace views | 431 } // namespace views |
| OLD | NEW |