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/gfx/native_theme_base.h" | 5 #include "ui/gfx/native_theme_base.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "grit/gfx_resources.h" | 10 #include "grit/gfx_resources.h" |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 gfx::Rect bounds = rect.Center(gfx::Size(image->width(), image->height())); | 482 gfx::Rect bounds = rect.Center(gfx::Size(image->width(), image->height())); |
483 DrawBitmapInt(canvas, *image, 0, 0, image->width(), image->height(), | 483 DrawBitmapInt(canvas, *image, 0, 0, image->width(), image->height(), |
484 bounds.x(), bounds.y(), bounds.width(), bounds.height()); | 484 bounds.x(), bounds.y(), bounds.width(), bounds.height()); |
485 } | 485 } |
486 | 486 |
487 void NativeThemeBase::PaintButton(SkCanvas* canvas, | 487 void NativeThemeBase::PaintButton(SkCanvas* canvas, |
488 State state, | 488 State state, |
489 const gfx::Rect& rect, | 489 const gfx::Rect& rect, |
490 const ButtonExtraParams& button) const { | 490 const ButtonExtraParams& button) const { |
491 SkPaint paint; | 491 SkPaint paint; |
492 SkRect skrect; | |
493 const int kRight = rect.right(); | 492 const int kRight = rect.right(); |
494 const int kBottom = rect.bottom(); | 493 const int kBottom = rect.bottom(); |
| 494 SkRect skrect = SkRect::MakeLTRB(rect.x(), rect.y(), kRight, kBottom); |
495 SkColor base_color = button.background_color; | 495 SkColor base_color = button.background_color; |
496 | 496 |
497 color_utils::HSL base_hsl; | 497 color_utils::HSL base_hsl; |
498 color_utils::SkColorToHSL(base_color, &base_hsl); | 498 color_utils::SkColorToHSL(base_color, &base_hsl); |
499 | 499 |
500 // Our standard gradient is from 0xdd to 0xf8. This is the amount of | 500 // Our standard gradient is from 0xdd to 0xf8. This is the amount of |
501 // increased luminance between those values. | 501 // increased luminance between those values. |
502 SkColor light_color(BrightenColor(base_hsl, SkColorGetA(base_color), 0.105)); | 502 SkColor light_color(BrightenColor(base_hsl, SkColorGetA(base_color), 0.105)); |
503 | 503 |
504 // If the button is too small, fallback to drawing a single, solid color | 504 // If the button is too small, fallback to drawing a single, solid color |
505 if (rect.width() < 5 || rect.height() < 5) { | 505 if (rect.width() < 5 || rect.height() < 5) { |
506 paint.setColor(base_color); | 506 paint.setColor(base_color); |
507 skrect.set(rect.x(), rect.y(), kRight, kBottom); | |
508 canvas->drawRect(skrect, paint); | 507 canvas->drawRect(skrect, paint); |
509 return; | 508 return; |
510 } | 509 } |
511 | 510 |
512 if (button.has_border) { | |
513 const int kBorderAlpha = state == kHovered ? 0x80 : 0x55; | |
514 paint.setARGB(kBorderAlpha, 0, 0, 0); | |
515 canvas->drawLine(rect.x() + 1, rect.y(), kRight - 1, rect.y(), paint); | |
516 canvas->drawLine(kRight - 1, rect.y() + 1, kRight - 1, kBottom - 1, paint); | |
517 canvas->drawLine(rect.x() + 1, kBottom - 1, kRight - 1, kBottom - 1, paint); | |
518 canvas->drawLine(rect.x(), rect.y() + 1, rect.x(), kBottom - 1, paint); | |
519 } | |
520 | |
521 paint.setColor(SK_ColorBLACK); | 511 paint.setColor(SK_ColorBLACK); |
522 const int kLightEnd = state == kPressed ? 1 : 0; | 512 const int kLightEnd = state == kPressed ? 1 : 0; |
523 const int kDarkEnd = !kLightEnd; | 513 const int kDarkEnd = !kLightEnd; |
524 SkPoint gradient_bounds[2]; | 514 SkPoint gradient_bounds[2]; |
525 gradient_bounds[kLightEnd].iset(rect.x(), rect.y()); | 515 gradient_bounds[kLightEnd].iset(rect.x(), rect.y()); |
526 gradient_bounds[kDarkEnd].iset(rect.x(), kBottom - 1); | 516 gradient_bounds[kDarkEnd].iset(rect.x(), kBottom - 1); |
527 SkColor colors[2]; | 517 SkColor colors[2]; |
528 colors[0] = light_color; | 518 colors[0] = light_color; |
529 colors[1] = base_color; | 519 colors[1] = base_color; |
530 | 520 |
531 SkShader* shader = SkGradientShader::CreateLinear( | 521 SkShader* shader = SkGradientShader::CreateLinear( |
532 gradient_bounds, colors, NULL, 2, SkShader::kClamp_TileMode, NULL); | 522 gradient_bounds, colors, NULL, 2, SkShader::kClamp_TileMode, NULL); |
533 paint.setStyle(SkPaint::kFill_Style); | 523 paint.setStyle(SkPaint::kFill_Style); |
| 524 paint.setAntiAlias(true); |
534 paint.setShader(shader); | 525 paint.setShader(shader); |
535 shader->unref(); | 526 shader->unref(); |
536 | 527 |
537 if (button.has_border) { | 528 canvas->drawRoundRect(skrect, SkIntToScalar(1), SkIntToScalar(1), paint); |
538 skrect.set(rect.x() + 1, rect.y() + 1, kRight - 1, kBottom - 1); | |
539 } else { | |
540 skrect.set(rect.x(), rect.y(), kRight, kBottom); | |
541 } | |
542 canvas->drawRect(skrect, paint); | |
543 paint.setShader(NULL); | 529 paint.setShader(NULL); |
544 | 530 |
545 if (button.has_border) { | 531 if (button.has_border) { |
546 paint.setColor(BrightenColor(base_hsl, SkColorGetA(base_color), -0.0588)); | 532 const int kBorderAlpha = state == kHovered ? 0x80 : 0x55; |
547 canvas->drawPoint(rect.x() + 1, rect.y() + 1, paint); | 533 paint.setStyle(SkPaint::kStroke_Style); |
548 canvas->drawPoint(kRight - 2, rect.y() + 1, paint); | 534 paint.setStrokeWidth(SkIntToScalar(1)); |
549 canvas->drawPoint(rect.x() + 1, kBottom - 2, paint); | 535 paint.setARGB(kBorderAlpha, 0, 0, 0); |
550 canvas->drawPoint(kRight - 2, kBottom - 2, paint); | 536 skrect.inset(SkFloatToScalar(.5f), SkFloatToScalar(.5f)); |
| 537 canvas->drawRoundRect(skrect, SkIntToScalar(1), SkIntToScalar(1), paint); |
551 } | 538 } |
552 } | 539 } |
553 | 540 |
554 void NativeThemeBase::PaintTextField(SkCanvas* canvas, | 541 void NativeThemeBase::PaintTextField(SkCanvas* canvas, |
555 State state, | 542 State state, |
556 const gfx::Rect& rect, | 543 const gfx::Rect& rect, |
557 const TextFieldExtraParams& text) const { | 544 const TextFieldExtraParams& text) const { |
558 // The following drawing code simulates the user-agent css border for | 545 // The following drawing code simulates the user-agent css border for |
559 // text area and text input so that we do not break layout tests. Once we | 546 // text area and text input so that we do not break layout tests. Once we |
560 // have decided the desired looks, we should update the code here and | 547 // have decided the desired looks, we should update the code here and |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); | 964 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); |
978 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); | 965 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); |
979 | 966 |
980 if (hsv1[2] + hsv2[2] > 1.0) | 967 if (hsv1[2] + hsv2[2] > 1.0) |
981 diff = -diff; | 968 diff = -diff; |
982 | 969 |
983 return SaturateAndBrighten(hsv2, -0.2f, diff); | 970 return SaturateAndBrighten(hsv2, -0.2f, diff); |
984 } | 971 } |
985 | 972 |
986 } // namespace gfx | 973 } // namespace gfx |
OLD | NEW |