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

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: peter review 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
« no previous file with comments | « ui/gfx/native_theme_base.cc ('k') | ui/gfx/skia_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 canvas->drawRect(gfx::RectToSkRect(gfx::Rect(rect.size())), paint);
695 sk_rect.set(SkIntToScalar(0), SkIntToScalar(0),
696 SkIntToScalar(rect.width()), SkIntToScalar(rect.height()));
697 canvas->drawRect(sk_rect, paint);
698 } 694 }
699 695
700 void NativeThemeChromeos::PaintProgressBar(SkCanvas* canvas, 696 void NativeThemeChromeos::PaintProgressBar(SkCanvas* canvas,
701 State state, 697 State state,
702 const gfx::Rect& rect, 698 const gfx::Rect& rect,
703 const ProgressBarExtraParams& progress_bar) const { 699 const ProgressBarExtraParams& progress_bar) const {
704 static const int kBorderWidth = 1; 700 static const int kBorderWidth = 1;
705 static const SkColor kBackgroundColors[] = { 701 static const SkColor kBackgroundColors[] = {
706 kProgressBarBackgroundGradient0, 702 kProgressBarBackgroundGradient0,
707 kProgressBarBackgroundGradient1, 703 kProgressBarBackgroundGradient1,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 831
836 if (stroke_border) { 832 if (stroke_border) {
837 SkPaint stroke_paint; 833 SkPaint stroke_paint;
838 GetStrokePaint(state, &stroke_paint); 834 GetStrokePaint(state, &stroke_paint);
839 canvas->drawPath(border, stroke_paint); 835 canvas->drawPath(border, stroke_paint);
840 } 836 }
841 } 837 }
842 838
843 } // namespace gfx 839 } // namespace gfx
844 840
OLDNEW
« no previous file with comments | « ui/gfx/native_theme_base.cc ('k') | ui/gfx/skia_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698