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

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

Issue 11418217: Add skia::RefPtr class to wrap ref counted classes from Skia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Drop TNoRef Created 8 years 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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 const SkColor* startEndColors; 569 const SkColor* startEndColors;
570 if (state == kPressed) 570 if (state == kPressed)
571 startEndColors = kCheckboxGradientPressedColors; 571 startEndColors = kCheckboxGradientPressedColors;
572 else if (state == kHovered) 572 else if (state == kHovered)
573 startEndColors = kCheckboxGradientHoveredColors; 573 startEndColors = kCheckboxGradientHoveredColors;
574 else if (state == kDisabled) 574 else if (state == kDisabled)
575 startEndColors = kCheckboxGradientDisabledColors; 575 startEndColors = kCheckboxGradientDisabledColors;
576 else /* kNormal */ 576 else /* kNormal */
577 startEndColors = kCheckboxGradientColors; 577 startEndColors = kCheckboxGradientColors;
578 SkColor colors[3] = {startEndColors[0], startEndColors[0], startEndColors[1]}; 578 SkColor colors[3] = {startEndColors[0], startEndColors[0], startEndColors[1]};
579 SkShader* shader = SkGradientShader::CreateLinear( 579 skia::RefPtr<SkShader> shader = SkGradientShader::CreateLinear(
580 gradient_bounds, colors, NULL, 3, SkShader::kClamp_TileMode, NULL); 580 gradient_bounds, colors, NULL, 3, SkShader::kClamp_TileMode, NULL);
581 SkPaint paint; 581 SkPaint paint;
582 paint.setAntiAlias(true); 582 paint.setAntiAlias(true);
583 paint.setShader(shader); 583 paint.setShader(shader.get());
584 shader->unref();
585 paint.setStyle(SkPaint::kFill_Style); 584 paint.setStyle(SkPaint::kFill_Style);
586 canvas->drawRoundRect(skrect, borderRadius, borderRadius, paint); 585 canvas->drawRoundRect(skrect, borderRadius, borderRadius, paint);
587 paint.setShader(NULL); 586 paint.setShader(NULL);
588 587
589 // Draw the border. 588 // Draw the border.
590 if (state == kHovered) 589 if (state == kHovered)
591 paint.setColor(kCheckboxBorderHoveredColor); 590 paint.setColor(kCheckboxBorderHoveredColor);
592 else if (state == kDisabled) 591 else if (state == kDisabled)
593 paint.setColor(kCheckboxBorderDisabledColor); 592 paint.setColor(kCheckboxBorderDisabledColor);
594 else 593 else
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 paint.setColor(SK_ColorBLACK); 717 paint.setColor(SK_ColorBLACK);
719 const int kLightEnd = state == kPressed ? 1 : 0; 718 const int kLightEnd = state == kPressed ? 1 : 0;
720 const int kDarkEnd = !kLightEnd; 719 const int kDarkEnd = !kLightEnd;
721 SkPoint gradient_bounds[2]; 720 SkPoint gradient_bounds[2];
722 gradient_bounds[kLightEnd].iset(rect.x(), rect.y()); 721 gradient_bounds[kLightEnd].iset(rect.x(), rect.y());
723 gradient_bounds[kDarkEnd].iset(rect.x(), kBottom - 1); 722 gradient_bounds[kDarkEnd].iset(rect.x(), kBottom - 1);
724 SkColor colors[2]; 723 SkColor colors[2];
725 colors[0] = light_color; 724 colors[0] = light_color;
726 colors[1] = base_color; 725 colors[1] = base_color;
727 726
728 SkShader* shader = SkGradientShader::CreateLinear( 727 skia::RefPtr<SkShader> shader = SkGradientShader::CreateLinear(
729 gradient_bounds, colors, NULL, 2, SkShader::kClamp_TileMode, NULL); 728 gradient_bounds, colors, NULL, 2, SkShader::kClamp_TileMode, NULL);
730 paint.setStyle(SkPaint::kFill_Style); 729 paint.setStyle(SkPaint::kFill_Style);
731 paint.setAntiAlias(true); 730 paint.setAntiAlias(true);
732 paint.setShader(shader); 731 paint.setShader(shader.get());
733 shader->unref();
734 732
735 canvas->drawRoundRect(skrect, SkIntToScalar(1), SkIntToScalar(1), paint); 733 canvas->drawRoundRect(skrect, SkIntToScalar(1), SkIntToScalar(1), paint);
736 paint.setShader(NULL); 734 paint.setShader(NULL);
737 735
738 if (button.has_border) { 736 if (button.has_border) {
739 int border_alpha = state == kHovered ? 0x80 : 0x55; 737 int border_alpha = state == kHovered ? 0x80 : 0x55;
740 if (button.is_focused) { 738 if (button.is_focused) {
741 border_alpha = 0xff; 739 border_alpha = 0xff;
742 paint.setColor(GetSystemColor(kColorId_FocusedBorderColor)); 740 paint.setColor(GetSystemColor(kColorId_FocusedBorderColor));
743 } 741 }
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); 1127 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f);
1130 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); 1128 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f);
1131 1129
1132 if (hsv1[2] + hsv2[2] > 1.0) 1130 if (hsv1[2] + hsv2[2] > 1.0)
1133 diff = -diff; 1131 diff = -diff;
1134 1132
1135 return SaturateAndBrighten(hsv2, -0.2f, diff); 1133 return SaturateAndBrighten(hsv2, -0.2f, diff);
1136 } 1134 }
1137 1135
1138 } // namespace ui 1136 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698