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/base/native_theme/native_theme_base.h" | 5 #include "ui/base/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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 SkColorSetRGB(0xed, 0xed, 0xed), | 49 SkColorSetRGB(0xed, 0xed, 0xed), |
50 SkColorSetRGB(0xde, 0xde, 0xde) }; | 50 SkColorSetRGB(0xde, 0xde, 0xde) }; |
51 const SkColor kCheckboxGradientPressedColors[] = { | 51 const SkColor kCheckboxGradientPressedColors[] = { |
52 SkColorSetRGB(0xe7, 0xe7, 0xe7), | 52 SkColorSetRGB(0xe7, 0xe7, 0xe7), |
53 SkColorSetRGB(0xd7, 0xd7, 0xd7) }; | 53 SkColorSetRGB(0xd7, 0xd7, 0xd7) }; |
54 const SkColor kCheckboxGradientHoveredColors[] = { | 54 const SkColor kCheckboxGradientHoveredColors[] = { |
55 SkColorSetRGB(0xf0, 0xf0, 0xf0), | 55 SkColorSetRGB(0xf0, 0xf0, 0xf0), |
56 SkColorSetRGB(0xe0, 0xe0, 0xe0) }; | 56 SkColorSetRGB(0xe0, 0xe0, 0xe0) }; |
57 const SkColor kCheckboxGradientDisabledColors[] = { | 57 const SkColor kCheckboxGradientDisabledColors[] = { |
58 SkColorSetARGB(0xB3, 0xed, 0xed, 0xed), | 58 SkColorSetARGB(0xB3, 0xed, 0xed, 0xed), |
59 SkColorSetARGB(0xB3, 0xed, 0xed, 0xed) }; | 59 SkColorSetARGB(0xB3, 0xde, 0xde, 0xde) }; |
60 const SkColor kCheckboxBorderColor = SkColorSetARGB(0x40, 0, 0, 0); | 60 const SkColor kCheckboxBorderColor = SkColorSetARGB(0x40, 0, 0, 0); |
61 const SkColor kCheckboxBorderHoveredColor = SkColorSetARGB(0x4D, 0, 0, 0); | 61 const SkColor kCheckboxBorderHoveredColor = SkColorSetARGB(0x4D, 0, 0, 0); |
62 const SkColor kCheckboxBorderDisabledColor = SkColorSetARGB(0x30, 0, 0, 0); | 62 const SkColor kCheckboxBorderDisabledColor = SkColorSetARGB(0x30, 0, 0, 0); |
63 const SkColor kCheckboxStrokeColor = SkColorSetARGB(0xB3, 0, 0, 0); | 63 const SkColor kCheckboxStrokeColor = SkColorSetARGB(0xB3, 0, 0, 0); |
64 const SkColor kCheckboxStrokeDisabledColor = SkColorSetARGB(0x86, 0, 0, 0); | 64 const SkColor kCheckboxStrokeDisabledColor = SkColorSetARGB(0x86, 0, 0, 0); |
65 const SkColor kRadioDotColor = SkColorSetRGB(0x66, 0x66, 0x66); | 65 const SkColor kRadioDotColor = SkColorSetRGB(0x66, 0x66, 0x66); |
66 const SkColor kRadioDotDisabledColor = SkColorSetARGB(0xC0, 0x66, 0x66, 0x66); | 66 const SkColor kRadioDotDisabledColor = SkColorSetARGB(0xC0, 0x66, 0x66, 0x66); |
67 | 67 |
68 // Get lightness adjusted color. | 68 // Get lightness adjusted color. |
69 SkColor BrightenColor(const color_utils::HSL& hsl, SkAlpha alpha, | 69 SkColor BrightenColor(const color_utils::HSL& hsl, SkAlpha alpha, |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 DrawVertLine(canvas, | 461 DrawVertLine(canvas, |
462 midx + inter_grippy_offset, | 462 midx + inter_grippy_offset, |
463 midy - grippy_half_width, | 463 midy - grippy_half_width, |
464 midy + grippy_half_width, | 464 midy + grippy_half_width, |
465 paint); | 465 paint); |
466 } | 466 } |
467 } | 467 } |
468 } | 468 } |
469 | 469 |
470 bool NativeThemeBase::IsNewCheckboxStyleEnabled(SkCanvas* canvas) const { | 470 bool NativeThemeBase::IsNewCheckboxStyleEnabled(SkCanvas* canvas) const { |
471 // The new style is now the default. | 471 // Mostly this new style is experimental behind a flag. |
472 // TODO(rbyers): Remove this flag once we're sure the new behavior is fine. | 472 // TODO(rbyers): Enable new style by default. http://crbug.com/125773 |
473 // http://crbug.com/133991 | 473 if (CommandLine::ForCurrentProcess()->HasSwitch( |
474 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 474 switches::kNewCheckboxStyle)) |
475 switches::kOldCheckboxStyle)) | 475 return true; |
| 476 |
| 477 // Also enable explicitly when high-DPI is being used (since this is the only |
| 478 // way we have to get nice looking widgets in high-DPI. |
| 479 if (canvas->getTotalMatrix().getScaleX() > 1) |
476 return true; | 480 return true; |
477 | 481 |
478 return false; | 482 return false; |
479 } | 483 } |
480 | 484 |
481 void NativeThemeBase::PaintCheckbox(SkCanvas* canvas, | 485 void NativeThemeBase::PaintCheckbox(SkCanvas* canvas, |
482 State state, | 486 State state, |
483 const gfx::Rect& rect, | 487 const gfx::Rect& rect, |
484 const ButtonExtraParams& button) const { | 488 const ButtonExtraParams& button) const { |
485 if (IsNewCheckboxStyleEnabled(canvas)) { | 489 if (IsNewCheckboxStyleEnabled(canvas)) { |
(...skipping 26 matching lines...) Expand all Loading... |
512 // Returns the rectangle within which any additional decorations should be | 516 // Returns the rectangle within which any additional decorations should be |
513 // drawn, or empty if none. | 517 // drawn, or empty if none. |
514 SkRect NativeThemeBase::PaintCheckboxRadioNewCommon( | 518 SkRect NativeThemeBase::PaintCheckboxRadioNewCommon( |
515 SkCanvas* canvas, | 519 SkCanvas* canvas, |
516 State state, | 520 State state, |
517 const gfx::Rect& rect, | 521 const gfx::Rect& rect, |
518 const SkScalar borderRadius) const { | 522 const SkScalar borderRadius) const { |
519 | 523 |
520 SkRect skrect = gfx::RectToSkRect(rect); | 524 SkRect skrect = gfx::RectToSkRect(rect); |
521 | 525 |
522 // Use the largest square rectangle that fits inside the provided rectangle. | |
523 // No other browser seems to support non-square widget, so accidentally | |
524 // having non-square sizes is common (eg. amazon and webkit dev tools). | |
525 if (skrect.width() != skrect.height()) { | |
526 SkScalar size = SkMinScalar(skrect.width(), skrect.height()); | |
527 skrect.inset((skrect.width() - size) / 2, (skrect.height() - size) / 2); | |
528 } | |
529 | |
530 // If the rectangle is too small then paint only a rectangle. We don't want | 526 // If the rectangle is too small then paint only a rectangle. We don't want |
531 // to have to worry about '- 1' and '+ 1' calculations below having overflow | 527 // to have to worry about '- 1' and '+ 1' calculations below having overflow |
532 // or underflow. | 528 // or underflow. |
533 if (skrect.width() <= 2) { | 529 if (rect.width() <= 2 || rect.height() <= 2) { |
534 SkPaint paint; | 530 SkPaint paint; |
535 paint.setColor(kCheckboxTinyColor); | 531 paint.setColor(kCheckboxTinyColor); |
536 paint.setStyle(SkPaint::kFill_Style); | 532 paint.setStyle(SkPaint::kFill_Style); |
537 canvas->drawRect(skrect, paint); | 533 canvas->drawRect(skrect, paint); |
538 // Too small to draw anything more. | 534 // Too small to draw anything more. |
539 return SkRect::MakeEmpty(); | 535 return SkRect::MakeEmpty(); |
540 } | 536 } |
541 | 537 |
542 // Make room for the drop shadow. | 538 // Make room for the drop shadow. |
543 skrect.iset(skrect.x(), skrect.y(), skrect.right() - 1, skrect.bottom() - 1); | 539 skrect.iset(skrect.x(), skrect.y(), skrect.right() - 1, skrect.bottom() - 1); |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); | 1117 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); |
1122 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); | 1118 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); |
1123 | 1119 |
1124 if (hsv1[2] + hsv2[2] > 1.0) | 1120 if (hsv1[2] + hsv2[2] > 1.0) |
1125 diff = -diff; | 1121 diff = -diff; |
1126 | 1122 |
1127 return SaturateAndBrighten(hsv2, -0.2f, diff); | 1123 return SaturateAndBrighten(hsv2, -0.2f, diff); |
1128 } | 1124 } |
1129 | 1125 |
1130 } // namespace ui | 1126 } // namespace ui |
OLD | NEW |