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

Side by Side Diff: ui/gfx/native_theme_chromeos.cc

Issue 9544001: ui: Let skia do the conversion work for us by using the integer version of set() function. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: simplify FocusableBorder::Paint Created 8 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/gfx/native_theme_chromeos.h" 5 #include "ui/gfx/native_theme_chromeos.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "grit/gfx_resources.h" 9 #include "grit/gfx_resources.h"
10 #include "third_party/skia/include/effects/SkGradientShader.h"
11 #include "third_party/skia/include/core/SkPaint.h" 10 #include "third_party/skia/include/core/SkPaint.h"
12 #include "third_party/skia/include/core/SkPath.h" 11 #include "third_party/skia/include/core/SkPath.h"
13 #include "third_party/skia/include/core/SkShader.h" 12 #include "third_party/skia/include/core/SkShader.h"
13 #include "third_party/skia/include/effects/SkGradientShader.h"
14 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/gfx/insets.h" 15 #include "ui/gfx/insets.h"
16 #include "ui/gfx/rect.h" 16 #include "ui/gfx/rect.h"
17 #include "ui/gfx/size.h" 17 #include "ui/gfx/size.h"
18 #include "ui/gfx/skbitmap_operations.h" 18 #include "ui/gfx/skbitmap_operations.h"
19 19
20 namespace { 20 namespace {
21 21
22 // Color constants. See theme_draw for details. 22 // Color constants. See theme_draw for details.
23 23
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 void GetGradientPaintForRect(const gfx::Rect& rect, 131 void GetGradientPaintForRect(const gfx::Rect& rect,
132 const SkColor* colors, 132 const SkColor* colors,
133 const SkScalar* stops, 133 const SkScalar* stops,
134 int count, 134 int count,
135 SkPaint* paint) { 135 SkPaint* paint) {
136 paint->setStyle(SkPaint::kFill_Style); 136 paint->setStyle(SkPaint::kFill_Style);
137 paint->setAntiAlias(true); 137 paint->setAntiAlias(true);
138 138
139 SkPoint points[2]; 139 SkPoint points[2];
140 points[0].set(SkIntToScalar(rect.x()), SkIntToScalar(rect.y())); 140 points[0].iset(rect.x(), rect.y());
141 points[1].set(SkIntToScalar(rect.x()), SkIntToScalar(rect.bottom())); 141 points[1].iset(rect.x(), rect.bottom());
142 142
143 SkShader* shader = SkGradientShader::CreateLinear(points, 143 SkShader* shader = SkGradientShader::CreateLinear(points,
144 colors, stops, count, SkShader::kClamp_TileMode); 144 colors, stops, count, SkShader::kClamp_TileMode);
145 145
146 paint->setShader(shader); 146 paint->setShader(shader);
147 // Unref shader after paint takes ownership, otherwise never deleted. 147 // Unref shader after paint takes ownership, otherwise never deleted.
148 shader->unref(); 148 shader->unref();
149 } 149 }
150 150
151 void GetGradientPaintForRect(const gfx::Rect& rect, 151 void GetGradientPaintForRect(const gfx::Rect& rect,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 paint->setColor(kIndicatorStrokeColor); 219 paint->setColor(kIndicatorStrokeColor);
220 } 220 }
221 221
222 void GetRadioIndicatorGradientPaint(const gfx::Rect bounds, 222 void GetRadioIndicatorGradientPaint(const gfx::Rect bounds,
223 gfx::NativeThemeBase::State state, 223 gfx::NativeThemeBase::State state,
224 SkPaint* paint) { 224 SkPaint* paint) {
225 paint->setStyle(SkPaint::kFill_Style); 225 paint->setStyle(SkPaint::kFill_Style);
226 paint->setAntiAlias(true); 226 paint->setAntiAlias(true);
227 227
228 SkPoint points[2]; 228 SkPoint points[2];
229 points[0].set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y())); 229 points[0].iset(bounds.x(), bounds.y());
230 points[1].set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.bottom())); 230 points[1].iset(bounds.x(), bounds.bottom());
231 231
232 static const SkScalar kGradientPoints[2] = { 232 static const SkScalar kGradientPoints[2] = {
233 SkIntToScalar(0), 233 SkIntToScalar(0),
234 SkIntToScalar(1) 234 SkIntToScalar(1)
235 }; 235 };
236 236
237 if (state == gfx::NativeThemeBase::kDisabled) { 237 if (state == gfx::NativeThemeBase::kDisabled) {
238 static const SkColor kGradientColors[2] = { 238 static const SkColor kGradientColors[2] = {
239 kRadioIndicatorDisabledGradient0, 239 kRadioIndicatorDisabledGradient0,
240 kRadioIndicatorDisabledGradient1 240 kRadioIndicatorDisabledGradient1
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 background_color 582 background_color
583 }; 583 };
584 584
585 const SkScalar gradient_points[3] = { 585 const SkScalar gradient_points[3] = {
586 SkIntToScalar(0), 586 SkIntToScalar(0),
587 SkDoubleToScalar(4.0 / rect.height()), 587 SkDoubleToScalar(4.0 / rect.height()),
588 SkIntToScalar(1) 588 SkIntToScalar(1)
589 }; 589 };
590 590
591 SkPoint points[2]; 591 SkPoint points[2];
592 points[0].set(SkIntToScalar(rect.x()), SkIntToScalar(rect.y())); 592 points[0].iset(rect.x(), rect.y());
593 points[1].set(SkIntToScalar(rect.x()), SkIntToScalar(rect.bottom())); 593 points[1].iset(rect.x(), rect.bottom());
594 594
595 GetGradientPaintForRect(rect, 595 GetGradientPaintForRect(rect, gradient_colors, gradient_points,
596 gradient_colors, gradient_points, arraysize(gradient_points), 596 arraysize(gradient_points), &fill_paint);
597 &fill_paint);
598 } 597 }
599 598
600 SkPath border; 599 SkPath border;
601 GetRoundRectPath(rect, kBorderCornerRadius, &border); 600 GetRoundRectPath(rect, kBorderCornerRadius, &border);
602 canvas->drawPath(border, fill_paint); 601 canvas->drawPath(border, fill_paint);
603 602
604 SkPaint stroke_paint; 603 SkPaint stroke_paint;
605 GetStrokePaint(state, &stroke_paint); 604 GetStrokePaint(state, &stroke_paint);
606 canvas->drawPath(border, stroke_paint); 605 canvas->drawPath(border, stroke_paint);
607 } 606 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 State state, 652 State state,
654 const gfx::Rect& rect, 653 const gfx::Rect& rect,
655 const InnerSpinButtonExtraParams& spin_button) const { 654 const InnerSpinButtonExtraParams& spin_button) const {
656 // Adjust bounds to compensate the overridden "2px inset" parent border. 655 // Adjust bounds to compensate the overridden "2px inset" parent border.
657 gfx::Rect bounds = rect; 656 gfx::Rect bounds = rect;
658 bounds.Inset(0, -1, -1, -1); 657 bounds.Inset(0, -1, -1, -1);
659 658
660 NativeThemeBase::PaintInnerSpinButton(canvas, state, bounds, spin_button); 659 NativeThemeBase::PaintInnerSpinButton(canvas, state, bounds, spin_button);
661 } 660 }
662 661
663 void NativeThemeChromeos::PaintMenuPopupBackground( 662 void NativeThemeChromeos::PaintMenuPopupBackground(
Peter Kasting 2012/02/29 20:40:31 Nit: It looks to me as if no implementers use |sta
664 SkCanvas* canvas, 663 SkCanvas* canvas,
665 State state, 664 State state,
666 const gfx::Rect& rect, 665 const gfx::Rect& rect,
667 const MenuListExtraParams& menu_list) const { 666 const MenuListExtraParams& menu_list) const {
668 static const SkColor kGradientColors[2] = { 667 static const SkColor kGradientColors[2] = {
669 SK_ColorWHITE, 668 SK_ColorWHITE,
670 SkColorSetRGB(0xF0, 0xF0, 0xF0) 669 SkColorSetRGB(0xF0, 0xF0, 0xF0)
671 }; 670 };
672 671
673 static const SkScalar kGradientPoints[2] = { 672 static const SkScalar kGradientPoints[2] = {
674 SkIntToScalar(0), 673 SkIntToScalar(0),
675 SkIntToScalar(1) 674 SkIntToScalar(1)
676 }; 675 };
677 676
678 SkPoint points[2]; 677 SkPoint points[2];
679 points[0].set(SkIntToScalar(0), SkIntToScalar(0)); 678 points[0].iset(0, 0);
680 points[1].set(SkIntToScalar(0), SkIntToScalar(rect.height())); 679 points[1].iset(0, rect.height());
681 680
682 SkShader* shader = SkGradientShader::CreateLinear(points, 681 SkShader* shader = SkGradientShader::CreateLinear(points,
683 kGradientColors, kGradientPoints, arraysize(kGradientPoints), 682 kGradientColors, kGradientPoints, arraysize(kGradientPoints),
684 SkShader::kRepeat_TileMode); 683 SkShader::kRepeat_TileMode);
685 DCHECK(shader); 684 DCHECK(shader);
686 685
687 SkPaint paint; 686 SkPaint paint;
688 paint.setShader(shader); 687 paint.setShader(shader);
689 shader->unref(); 688 shader->unref();
690 689
691 paint.setStyle(SkPaint::kFill_Style); 690 paint.setStyle(SkPaint::kFill_Style);
692 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 691 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
693 692
694 SkRect sk_rect; 693 SkRect sk_rect;
Peter Kasting 2012/02/29 20:40:31 Nit: Shorter: canvas->drawRect(gfx::RectToSkRec
tfarina 2012/02/29 22:42:14 Done.
695 sk_rect.set(SkIntToScalar(0), SkIntToScalar(0), 694 sk_rect.iset(0, 0, rect.width(), rect.height());
696 SkIntToScalar(rect.width()), SkIntToScalar(rect.height()));
697 canvas->drawRect(sk_rect, paint); 695 canvas->drawRect(sk_rect, paint);
698 } 696 }
699 697
700 void NativeThemeChromeos::PaintProgressBar(SkCanvas* canvas, 698 void NativeThemeChromeos::PaintProgressBar(SkCanvas* canvas,
701 State state, 699 State state,
702 const gfx::Rect& rect, 700 const gfx::Rect& rect,
703 const ProgressBarExtraParams& progress_bar) const { 701 const ProgressBarExtraParams& progress_bar) const {
704 static const int kBorderWidth = 1; 702 static const int kBorderWidth = 1;
705 static const SkColor kBackgroundColors[] = { 703 static const SkColor kBackgroundColors[] = {
706 kProgressBarBackgroundGradient0, 704 kProgressBarBackgroundGradient0,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 833
836 if (stroke_border) { 834 if (stroke_border) {
837 SkPaint stroke_paint; 835 SkPaint stroke_paint;
838 GetStrokePaint(state, &stroke_paint); 836 GetStrokePaint(state, &stroke_paint);
839 canvas->drawPath(border, stroke_paint); 837 canvas->drawPath(border, stroke_paint);
840 } 838 }
841 } 839 }
842 840
843 } // namespace gfx 841 } // namespace gfx
844 842
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698