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

Side by Side Diff: ui/native_theme/native_theme_base.cc

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

Powered by Google App Engine
This is Rietveld 408576698