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/native_theme/native_theme_base.h" | 5 #include "ui/native_theme/native_theme_base.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 paint); | 463 paint); |
| 464 DrawVertLine(canvas, | 464 DrawVertLine(canvas, |
| 465 midx + inter_grippy_offset, | 465 midx + inter_grippy_offset, |
| 466 midy - grippy_half_width, | 466 midy - grippy_half_width, |
| 467 midy + grippy_half_width, | 467 midy + grippy_half_width, |
| 468 paint); | 468 paint); |
| 469 } | 469 } |
| 470 } | 470 } |
| 471 } | 471 } |
| 472 | 472 |
| 473 bool NativeThemeBase::IsNewCheckboxStyleEnabled(SkCanvas* canvas) const { | |
| 474 // The new style is now the default. | |
| 475 // TODO(rbyers): Remove this flag once we're sure the new behavior is fine. | |
| 476 // http://crbug.com/133991 | |
| 477 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
| 478 switches::kOldCheckboxStyle)) | |
| 479 return true; | |
| 480 | |
| 481 return false; | |
| 482 } | |
| 483 | |
| 484 void NativeThemeBase::PaintCheckbox(SkCanvas* canvas, | 473 void NativeThemeBase::PaintCheckbox(SkCanvas* canvas, |
| 485 State state, | 474 State state, |
| 486 const gfx::Rect& rect, | 475 const gfx::Rect& rect, |
| 487 const ButtonExtraParams& button) const { | 476 const ButtonExtraParams& button) const { |
| 488 if (IsNewCheckboxStyleEnabled(canvas)) { | 477 SkRect skrect = PaintCheckboxRadioCommon(canvas, state, rect, |
| 489 PaintCheckboxNew(canvas, state, rect, button); | 478 » » » » » » » » » » » SkIntToScalar(2)); |
| 490 return; | 479 if (!skrect.isEmpty()) { |
| 480 » // Draw the checkmark / dash. | |
|
sky
2013/03/05 17:01:00
It looks like spacing is all off here, and I'm see
| |
| 481 » SkPaint paint; | |
| 482 » paint.setAntiAlias(true); | |
| 483 » paint.setStyle(SkPaint::kStroke_Style); | |
| 484 » if (state == kDisabled) | |
| 485 » paint.setColor(kCheckboxStrokeDisabledColor); | |
| 486 » else | |
| 487 » paint.setColor(kCheckboxStrokeColor); | |
| 488 » if (button.indeterminate) { | |
| 489 » SkPath dash; | |
| 490 » dash.moveTo(skrect.x() + skrect.width() * 0.16, | |
| 491 » » » » (skrect.y() + skrect.bottom()) / 2); | |
| 492 » dash.rLineTo(skrect.width() * 0.68, 0); | |
| 493 » paint.setStrokeWidth(SkFloatToScalar(skrect.height() * 0.2)); | |
| 494 » canvas->drawPath(dash, paint); | |
| 495 » } else if (button.checked) { | |
| 496 » SkPath check; | |
| 497 » check.moveTo(skrect.x() + skrect.width() * 0.2, | |
| 498 » » » » skrect.y() + skrect.height() * 0.5); | |
| 499 » check.rLineTo(skrect.width() * 0.2, skrect.height() * 0.2); | |
| 500 » paint.setStrokeWidth(SkFloatToScalar(skrect.height() * 0.23)); | |
| 501 » check.lineTo(skrect.right() - skrect.width() * 0.2, | |
| 502 » » » » skrect.y() + skrect.height() * 0.2); | |
| 503 » canvas->drawPath(check, paint); | |
| 504 » } | |
| 491 } | 505 } |
| 492 | |
| 493 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 494 gfx::ImageSkia* image = NULL; | |
| 495 if (button.indeterminate) { | |
| 496 image = state == kDisabled ? | |
| 497 rb.GetImageSkiaNamed(IDR_CHECKBOX_DISABLED_INDETERMINATE) : | |
| 498 rb.GetImageSkiaNamed(IDR_CHECKBOX_INDETERMINATE); | |
| 499 } else if (button.checked) { | |
| 500 image = state == kDisabled ? | |
| 501 rb.GetImageSkiaNamed(IDR_CHECKBOX_DISABLED_ON) : | |
| 502 rb.GetImageSkiaNamed(IDR_CHECKBOX_ON); | |
| 503 } else { | |
| 504 image = state == kDisabled ? | |
| 505 rb.GetImageSkiaNamed(IDR_CHECKBOX_DISABLED_OFF) : | |
| 506 rb.GetImageSkiaNamed(IDR_CHECKBOX_OFF); | |
| 507 } | |
| 508 | |
| 509 gfx::Rect bounds = rect; | |
| 510 bounds.ClampToCenteredSize(gfx::Size(image->width(), image->height())); | |
| 511 DrawImageInt(canvas, *image, 0, 0, image->width(), image->height(), | |
| 512 bounds.x(), bounds.y(), bounds.width(), bounds.height()); | |
| 513 } | 506 } |
| 514 | 507 |
| 515 // Draws the common elements of checkboxes and radio buttons. | 508 // Draws the common elements of checkboxes and radio buttons. |
| 516 // Returns the rectangle within which any additional decorations should be | 509 // Returns the rectangle within which any additional decorations should be |
| 517 // drawn, or empty if none. | 510 // drawn, or empty if none. |
| 518 SkRect NativeThemeBase::PaintCheckboxRadioNewCommon( | 511 SkRect NativeThemeBase::PaintCheckboxRadioCommon( |
| 519 SkCanvas* canvas, | 512 SkCanvas* canvas, |
| 520 State state, | 513 State state, |
| 521 const gfx::Rect& rect, | 514 const gfx::Rect& rect, |
| 522 const SkScalar borderRadius) const { | 515 const SkScalar borderRadius) const { |
| 523 | 516 |
| 524 SkRect skrect = gfx::RectToSkRect(rect); | 517 SkRect skrect = gfx::RectToSkRect(rect); |
| 525 | 518 |
| 526 // Use the largest square that fits inside the provided rectangle. | 519 // Use the largest square that fits inside the provided rectangle. |
| 527 // No other browser seems to support non-square widget, so accidentally | 520 // No other browser seems to support non-square widget, so accidentally |
| 528 // having non-square sizes is common (eg. amazon and webkit dev tools). | 521 // having non-square sizes is common (eg. amazon and webkit dev tools). |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 597 paint.setStyle(SkPaint::kStroke_Style); | 590 paint.setStyle(SkPaint::kStroke_Style); |
| 598 paint.setStrokeWidth(SkIntToScalar(1)); | 591 paint.setStrokeWidth(SkIntToScalar(1)); |
| 599 skrect.inset(SkFloatToScalar(.5f), SkFloatToScalar(.5f)); | 592 skrect.inset(SkFloatToScalar(.5f), SkFloatToScalar(.5f)); |
| 600 canvas->drawRoundRect(skrect, borderRadius, borderRadius, paint); | 593 canvas->drawRoundRect(skrect, borderRadius, borderRadius, paint); |
| 601 | 594 |
| 602 // Return the rectangle excluding the drop shadow for drawing any additional | 595 // Return the rectangle excluding the drop shadow for drawing any additional |
| 603 // decorations. | 596 // decorations. |
| 604 return skrect; | 597 return skrect; |
| 605 } | 598 } |
| 606 | 599 |
| 607 void NativeThemeBase::PaintCheckboxNew(SkCanvas* canvas, | |
| 608 State state, | |
| 609 const gfx::Rect& rect, | |
| 610 const ButtonExtraParams& button) const { | |
| 611 SkRect skrect = PaintCheckboxRadioNewCommon(canvas, state, rect, | |
| 612 SkIntToScalar(2)); | |
| 613 if (!skrect.isEmpty()) { | |
| 614 // Draw the checkmark / dash. | |
| 615 SkPaint paint; | |
| 616 paint.setAntiAlias(true); | |
| 617 paint.setStyle(SkPaint::kStroke_Style); | |
| 618 if (state == kDisabled) | |
| 619 paint.setColor(kCheckboxStrokeDisabledColor); | |
| 620 else | |
| 621 paint.setColor(kCheckboxStrokeColor); | |
| 622 if (button.indeterminate) { | |
| 623 SkPath dash; | |
| 624 dash.moveTo(skrect.x() + skrect.width() * 0.16, | |
| 625 (skrect.y() + skrect.bottom()) / 2); | |
| 626 dash.rLineTo(skrect.width() * 0.68, 0); | |
| 627 paint.setStrokeWidth(SkFloatToScalar(skrect.height() * 0.2)); | |
| 628 canvas->drawPath(dash, paint); | |
| 629 } else if (button.checked) { | |
| 630 SkPath check; | |
| 631 check.moveTo(skrect.x() + skrect.width() * 0.2, | |
| 632 skrect.y() + skrect.height() * 0.5); | |
| 633 check.rLineTo(skrect.width() * 0.2, skrect.height() * 0.2); | |
| 634 paint.setStrokeWidth(SkFloatToScalar(skrect.height() * 0.23)); | |
| 635 check.lineTo(skrect.right() - skrect.width() * 0.2, | |
| 636 skrect.y() + skrect.height() * 0.2); | |
| 637 canvas->drawPath(check, paint); | |
| 638 } | |
| 639 } | |
| 640 } | |
| 641 | |
| 642 void NativeThemeBase::PaintRadio(SkCanvas* canvas, | 600 void NativeThemeBase::PaintRadio(SkCanvas* canvas, |
| 643 State state, | 601 State state, |
| 644 const gfx::Rect& rect, | 602 const gfx::Rect& rect, |
| 645 const ButtonExtraParams& button) const { | 603 const ButtonExtraParams& button) const { |
| 646 if (IsNewCheckboxStyleEnabled(canvas)) { | |
| 647 PaintRadioNew(canvas, state, rect, button); | |
| 648 return; | |
| 649 } | |
| 650 | |
| 651 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 652 gfx::ImageSkia* image = NULL; | |
| 653 if (state == kDisabled) { | |
| 654 image = button.checked ? | |
| 655 rb.GetImageSkiaNamed(IDR_RADIO_DISABLED_ON) : | |
| 656 rb.GetImageSkiaNamed(IDR_RADIO_DISABLED_OFF); | |
| 657 } else { | |
| 658 image = button.checked ? | |
| 659 rb.GetImageSkiaNamed(IDR_RADIO_ON) : | |
| 660 rb.GetImageSkiaNamed(IDR_RADIO_OFF); | |
| 661 } | |
| 662 | |
| 663 gfx::Rect bounds = rect; | |
| 664 bounds.ClampToCenteredSize(gfx::Size(image->width(), image->height())); | |
| 665 DrawImageInt(canvas, *image, 0, 0, image->width(), image->height(), | |
| 666 bounds.x(), bounds.y(), bounds.width(), bounds.height()); | |
| 667 } | |
| 668 | |
| 669 void NativeThemeBase::PaintRadioNew(SkCanvas* canvas, | |
| 670 State state, | |
| 671 const gfx::Rect& rect, | |
| 672 const ButtonExtraParams& button) const { | |
| 673 | 604 |
| 674 // Most of a radio button is the same as a checkbox, except the the rounded | 605 // Most of a radio button is the same as a checkbox, except the the rounded |
| 675 // square is a circle (i.e. border radius >= 100%). | 606 // square is a circle (i.e. border radius >= 100%). |
| 676 const SkScalar radius = SkFloatToScalar( | 607 const SkScalar radius = SkFloatToScalar( |
| 677 static_cast<float>(std::max(rect.width(), rect.height())) / 2); | 608 static_cast<float>(std::max(rect.width(), rect.height())) / 2); |
| 678 SkRect skrect = PaintCheckboxRadioNewCommon(canvas, state, rect, radius); | 609 SkRect skrect = PaintCheckboxRadioCommon(canvas, state, rect, radius); |
| 679 if (!skrect.isEmpty() && button.checked) { | 610 if (!skrect.isEmpty() && button.checked) { |
| 680 // Draw the dot. | 611 // Draw the dot. |
| 681 SkPaint paint; | 612 SkPaint paint; |
| 682 paint.setAntiAlias(true); | 613 paint.setAntiAlias(true); |
| 683 paint.setStyle(SkPaint::kFill_Style); | 614 paint.setStyle(SkPaint::kFill_Style); |
| 684 if (state == kDisabled) | 615 if (state == kDisabled) |
| 685 paint.setColor(kRadioDotDisabledColor); | 616 paint.setColor(kRadioDotDisabledColor); |
| 686 else | 617 else |
| 687 paint.setColor(kRadioDotColor); | 618 paint.setColor(kRadioDotColor); |
| 688 skrect.inset(skrect.width() * 0.25, skrect.height() * 0.25); | 619 skrect.inset(skrect.width() * 0.25, skrect.height() * 0.25); |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1132 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); | 1063 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); |
| 1133 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); | 1064 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); |
| 1134 | 1065 |
| 1135 if (hsv1[2] + hsv2[2] > 1.0) | 1066 if (hsv1[2] + hsv2[2] > 1.0) |
| 1136 diff = -diff; | 1067 diff = -diff; |
| 1137 | 1068 |
| 1138 return SaturateAndBrighten(hsv2, -0.2f, diff); | 1069 return SaturateAndBrighten(hsv2, -0.2f, diff); |
| 1139 } | 1070 } |
| 1140 | 1071 |
| 1141 } // namespace ui | 1072 } // namespace ui |
| OLD | NEW |