summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-01 16:29:21 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-01 16:29:21 +0000
commitb9857bdd37282ba346cbb2ccb52b67175ef490c0 (patch)
tree373a6f5904ab4e71c7b407a26512267f0c7b109c
parent414d57a780c0f774a9e5c2a893f5189b88b43b6e (diff)
downloadchromium_src-b9857bdd37282ba346cbb2ccb52b67175ef490c0.zip
chromium_src-b9857bdd37282ba346cbb2ccb52b67175ef490c0.tar.gz
chromium_src-b9857bdd37282ba346cbb2ccb52b67175ef490c0.tar.bz2
ui: Let skia do the conversion work for us by using the integer version of set() function.
R=pkasting@chromium.org TBR=sky@chromium.org Review URL: https://chromiumcodereview.appspot.com/9544001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124416 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/gfx/canvas_skia.cc6
-rw-r--r--ui/gfx/native_theme_android.cc23
-rw-r--r--ui/gfx/native_theme_base.cc25
-rw-r--r--ui/gfx/native_theme_chromeos.cc28
-rw-r--r--ui/gfx/skia_util.cc4
-rw-r--r--ui/views/bubble/bubble_border.cc19
-rw-r--r--ui/views/controls/focusable_border.cc6
-rw-r--r--ui/views/controls/menu/menu_image_util.cc16
-rw-r--r--ui/views/controls/progress_bar.cc6
-rw-r--r--ui/views/painter.cc11
-rw-r--r--ui/views/touchui/touch_selection_controller_impl.cc12
-rw-r--r--ui/views/view_unittest.cc15
12 files changed, 61 insertions, 110 deletions
diff --git a/ui/gfx/canvas_skia.cc b/ui/gfx/canvas_skia.cc
index 6e44931..5ae821c 100644
--- a/ui/gfx/canvas_skia.cc
+++ b/ui/gfx/canvas_skia.cc
@@ -114,11 +114,7 @@ void CanvasSkia::SaveLayerAlpha(uint8 alpha) {
void CanvasSkia::SaveLayerAlpha(uint8 alpha, const gfx::Rect& layer_bounds) {
- SkRect bounds;
- bounds.set(SkIntToScalar(layer_bounds.x()),
- SkIntToScalar(layer_bounds.y()),
- SkIntToScalar(layer_bounds.right()),
- SkIntToScalar(layer_bounds.bottom()));
+ SkRect bounds(gfx::RectToSkRect(layer_bounds));
canvas_->saveLayerAlpha(&bounds, alpha);
}
diff --git a/ui/gfx/native_theme_android.cc b/ui/gfx/native_theme_android.cc
index 82c5ab4..a63f37a 100644
--- a/ui/gfx/native_theme_android.cc
+++ b/ui/gfx/native_theme_android.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -345,10 +345,8 @@ void NativeThemeAndroid::PaintButton(SkCanvas* canvas,
int kLightEnd = state == PRESSED ? 1 : 0;
int kDarkEnd = !kLightEnd;
SkPoint gradient_bounds[2];
- gradient_bounds[kLightEnd].set(SkIntToScalar(rect.x()),
- SkIntToScalar(rect.y()));
- gradient_bounds[kDarkEnd].set(SkIntToScalar(rect.x()),
- SkIntToScalar(kBottom - 1));
+ gradient_bounds[kLightEnd].iset(rect.x(), rect.y());
+ gradient_bounds[kDarkEnd].iset(rect.x(), kBottom - 1);
SkColor colors[2];
colors[0] = light_color;
colors[1] = base_color;
@@ -614,20 +612,15 @@ void NativeThemeAndroid::PaintProgressBar(
int dest_left_border_width = static_cast<int>(left_border_image->width() *
tile_scale);
- SkRect dest_rect = {
- SkIntToScalar(rect.x()),
- SkIntToScalar(rect.y()),
- SkIntToScalar(rect.x() + dest_left_border_width),
- SkIntToScalar(rect.bottom())
- };
+ SkRect dest_rect;
+ dest_rect.iset(rect.x(), rect.y(), rect.x() + dest_left_border_width,
+ rect.bottom());
canvas->drawBitmapRect(*left_border_image, NULL, dest_rect);
int dest_right_border_width = static_cast<int>(right_border_image->width() *
tile_scale);
- dest_rect.set(SkIntToScalar(rect.right() - dest_right_border_width),
- SkIntToScalar(rect.y()),
- SkIntToScalar(rect.right()),
- SkIntToScalar(rect.bottom()));
+ dest_rect.iset(rect.right() - dest_right_border_width, rect.y(), rect.right(),
+ rect.bottom());
canvas->drawBitmapRect(*right_border_image, NULL, dest_rect);
}
diff --git a/ui/gfx/native_theme_base.cc b/ui/gfx/native_theme_base.cc
index 2448d18..0355631 100644
--- a/ui/gfx/native_theme_base.cc
+++ b/ui/gfx/native_theme_base.cc
@@ -520,10 +520,8 @@ void NativeThemeBase::PaintButton(SkCanvas* canvas,
const int kLightEnd = state == kPressed ? 1 : 0;
const int kDarkEnd = !kLightEnd;
SkPoint gradient_bounds[2];
- gradient_bounds[kLightEnd].set(SkIntToScalar(rect.x()),
- SkIntToScalar(rect.y()));
- gradient_bounds[kDarkEnd].set(SkIntToScalar(rect.x()),
- SkIntToScalar(kBottom - 1));
+ gradient_bounds[kLightEnd].iset(rect.x(), rect.y());
+ gradient_bounds[kDarkEnd].iset(rect.x(), kBottom - 1);
SkColor colors[2];
colors[0] = light_color;
colors[1] = base_color;
@@ -804,25 +802,20 @@ void NativeThemeBase::PaintProgressBar(SkCanvas* canvas,
int dest_left_border_width = static_cast<int>(left_border_image->width() *
tile_scale);
- SkRect dest_rect = {
- SkIntToScalar(rect.x()),
- SkIntToScalar(rect.y()),
- SkIntToScalar(rect.x() + dest_left_border_width),
- SkIntToScalar(rect.bottom())
- };
+ SkRect dest_rect;
+ dest_rect.iset(rect.x(), rect.y(), rect.x() + dest_left_border_width,
+ rect.bottom());
canvas->drawBitmapRect(*left_border_image, NULL, dest_rect);
int dest_right_border_width = static_cast<int>(right_border_image->width() *
tile_scale);
- dest_rect.set(SkIntToScalar(rect.right() - dest_right_border_width),
- SkIntToScalar(rect.y()),
- SkIntToScalar(rect.right()),
- SkIntToScalar(rect.bottom()));
+ dest_rect.iset(rect.right() - dest_right_border_width, rect.y(), rect.right(),
+ rect.bottom());
canvas->drawBitmapRect(*right_border_image, NULL, dest_rect);
}
-bool NativeThemeBase::IntersectsClipRectInt(
- SkCanvas* canvas, int x, int y, int w, int h) const {
+bool NativeThemeBase::IntersectsClipRectInt(SkCanvas* canvas,
+ int x, int y, int w, int h) const {
SkRect clip;
return canvas->getClipBounds(&clip) &&
clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w),
diff --git a/ui/gfx/native_theme_chromeos.cc b/ui/gfx/native_theme_chromeos.cc
index df9d1b1..a18a337 100644
--- a/ui/gfx/native_theme_chromeos.cc
+++ b/ui/gfx/native_theme_chromeos.cc
@@ -7,10 +7,10 @@
#include "base/basictypes.h"
#include "base/logging.h"
#include "grit/gfx_resources.h"
-#include "third_party/skia/include/effects/SkGradientShader.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkShader.h"
+#include "third_party/skia/include/effects/SkGradientShader.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/insets.h"
#include "ui/gfx/rect.h"
@@ -136,8 +136,8 @@ void GetGradientPaintForRect(const gfx::Rect& rect,
paint->setAntiAlias(true);
SkPoint points[2];
- points[0].set(SkIntToScalar(rect.x()), SkIntToScalar(rect.y()));
- points[1].set(SkIntToScalar(rect.x()), SkIntToScalar(rect.bottom()));
+ points[0].iset(rect.x(), rect.y());
+ points[1].iset(rect.x(), rect.bottom());
SkShader* shader = SkGradientShader::CreateLinear(points,
colors, stops, count, SkShader::kClamp_TileMode);
@@ -225,8 +225,8 @@ void GetRadioIndicatorGradientPaint(const gfx::Rect bounds,
paint->setAntiAlias(true);
SkPoint points[2];
- points[0].set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()));
- points[1].set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.bottom()));
+ points[0].iset(bounds.x(), bounds.y());
+ points[1].iset(bounds.x(), bounds.bottom());
static const SkScalar kGradientPoints[2] = {
SkIntToScalar(0),
@@ -588,12 +588,11 @@ void NativeThemeChromeos::PaintTextField(SkCanvas* canvas,
};
SkPoint points[2];
- points[0].set(SkIntToScalar(rect.x()), SkIntToScalar(rect.y()));
- points[1].set(SkIntToScalar(rect.x()), SkIntToScalar(rect.bottom()));
+ points[0].iset(rect.x(), rect.y());
+ points[1].iset(rect.x(), rect.bottom());
- GetGradientPaintForRect(rect,
- gradient_colors, gradient_points, arraysize(gradient_points),
- &fill_paint);
+ GetGradientPaintForRect(rect, gradient_colors, gradient_points,
+ arraysize(gradient_points), &fill_paint);
}
SkPath border;
@@ -675,8 +674,8 @@ void NativeThemeChromeos::PaintMenuPopupBackground(
};
SkPoint points[2];
- points[0].set(SkIntToScalar(0), SkIntToScalar(0));
- points[1].set(SkIntToScalar(0), SkIntToScalar(rect.height()));
+ points[0].iset(0, 0);
+ points[1].iset(0, rect.height());
SkShader* shader = SkGradientShader::CreateLinear(points,
kGradientColors, kGradientPoints, arraysize(kGradientPoints),
@@ -690,10 +689,7 @@ void NativeThemeChromeos::PaintMenuPopupBackground(
paint.setStyle(SkPaint::kFill_Style);
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
- SkRect sk_rect;
- sk_rect.set(SkIntToScalar(0), SkIntToScalar(0),
- SkIntToScalar(rect.width()), SkIntToScalar(rect.height()));
- canvas->drawRect(sk_rect, paint);
+ canvas->drawRect(gfx::RectToSkRect(gfx::Rect(rect.size())), paint);
}
void NativeThemeChromeos::PaintProgressBar(SkCanvas* canvas,
diff --git a/ui/gfx/skia_util.cc b/ui/gfx/skia_util.cc
index d64f2b2..bfee378 100644
--- a/ui/gfx/skia_util.cc
+++ b/ui/gfx/skia_util.cc
@@ -37,8 +37,8 @@ SkShader* CreateGradientShader(int start_point,
SkColor end_color) {
SkColor grad_colors[2] = { start_color, end_color};
SkPoint grad_points[2];
- grad_points[0].set(SkIntToScalar(0), SkIntToScalar(start_point));
- grad_points[1].set(SkIntToScalar(0), SkIntToScalar(end_point));
+ grad_points[0].iset(0, start_point);
+ grad_points[1].iset(0, end_point);
return SkGradientShader::CreateLinear(
grad_points, grad_colors, NULL, 2, SkShader::kRepeat_TileMode);
diff --git a/ui/views/bubble/bubble_border.cc b/ui/views/bubble/bubble_border.cc
index 51f4ce2..372c24f 100644
--- a/ui/views/bubble/bubble_border.cc
+++ b/ui/views/bubble/bubble_border.cc
@@ -12,7 +12,7 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas_skia.h"
-#include "ui/gfx/path.h"
+#include "ui/gfx/skia_util.h"
namespace views {
@@ -480,7 +480,7 @@ void BubbleBorder::DrawArrowInterior(gfx::Canvas* canvas,
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
paint.setColor(background_color_);
- gfx::Path path;
+ SkPath path;
path.incReserve(4);
path.moveTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y));
path.lineTo(SkIntToScalar(tip_x + shift_x),
@@ -498,11 +498,7 @@ void BubbleBorder::DrawArrowInterior(gfx::Canvas* canvas,
void BubbleBackground::Paint(gfx::Canvas* canvas, views::View* view) const {
// Clip out the client bounds to prevent overlapping transparent widgets.
if (!border_->client_bounds().IsEmpty()) {
- SkRect client_rect;
- client_rect.set(SkIntToScalar(border_->client_bounds().x()),
- SkIntToScalar(border_->client_bounds().y()),
- SkIntToScalar(border_->client_bounds().right()),
- SkIntToScalar(border_->client_bounds().bottom()));
+ SkRect client_rect(gfx::RectToSkRect(border_->client_bounds()));
canvas->GetSkCanvas()->clipRect(client_rect, SkRegion::kDifference_Op);
}
@@ -514,14 +510,11 @@ void BubbleBackground::Paint(gfx::Canvas* canvas, views::View* view) const {
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kFill_Style);
paint.setColor(border_->background_color());
- gfx::Path path;
+ SkPath path;
gfx::Rect bounds(view->GetContentsBounds());
- SkRect rect;
- rect.set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()),
- SkIntToScalar(bounds.right()), SkIntToScalar(bounds.bottom()));
- rect.inset(-border_->border_thickness(), -border_->border_thickness());
+ bounds.Inset(-border_->border_thickness(), -border_->border_thickness());
SkScalar radius = SkIntToScalar(BubbleBorder::GetCornerRadius());
- path.addRoundRect(rect, radius, radius);
+ path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius);
canvas->GetSkCanvas()->drawPath(path, paint);
}
diff --git a/ui/views/controls/focusable_border.cc b/ui/views/controls/focusable_border.cc
index 5081358..6e87758 100644
--- a/ui/views/controls/focusable_border.cc
+++ b/ui/views/controls/focusable_border.cc
@@ -8,6 +8,7 @@
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/insets.h"
#include "ui/gfx/native_theme.h"
+#include "ui/gfx/skia_util.h"
namespace {
@@ -28,11 +29,8 @@ FocusableBorder::FocusableBorder()
}
void FocusableBorder::Paint(const View& view, gfx::Canvas* canvas) const {
- SkRect rect;
- rect.set(SkIntToScalar(0), SkIntToScalar(0),
- SkIntToScalar(view.width()), SkIntToScalar(view.height()));
SkPath path;
- path.addRect(rect, SkPath::kCW_Direction);
+ path.addRect(gfx::RectToSkRect(view.GetLocalBounds()), SkPath::kCW_Direction);
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
SkColor focus_color = gfx::NativeTheme::instance()->GetSystemColor(
diff --git a/ui/views/controls/menu/menu_image_util.cc b/ui/views/controls/menu/menu_image_util.cc
index ee71c69..b17d4e6 100644
--- a/ui/views/controls/menu/menu_image_util.cc
+++ b/ui/views/controls/menu/menu_image_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -35,11 +35,9 @@ SkBitmap* CreateRadioButtonImage(bool selected) {
canvas.Translate(gfx::Point(1, 1));
SkPoint gradient_points[3];
- gradient_points[0].set(SkIntToScalar(0), SkIntToScalar(0));
- gradient_points[1].set(
- SkIntToScalar(0),
- SkIntToScalar(static_cast<int>(kIndicatorSize * kGradientStop)));
- gradient_points[2].set(SkIntToScalar(0), SkIntToScalar(kIndicatorSize));
+ gradient_points[0].iset(0, 0);
+ gradient_points[1].iset(0, static_cast<int>(kIndicatorSize * kGradientStop));
+ gradient_points[2].iset(0, kIndicatorSize);
SkColor gradient_colors[3] = { kGradient0, kGradient1, kGradient2 };
SkShader* shader = SkGradientShader::CreateLinear(
gradient_points, gradient_colors, NULL, arraysize(gradient_points),
@@ -60,10 +58,8 @@ SkBitmap* CreateRadioButtonImage(bool selected) {
if (selected) {
SkPoint selected_gradient_points[2];
- selected_gradient_points[0].set(SkIntToScalar(0), SkIntToScalar(0));
- selected_gradient_points[1].set(
- SkIntToScalar(0),
- SkIntToScalar(kSelectedIndicatorSize));
+ selected_gradient_points[0].iset(0, 0);
+ selected_gradient_points[1].iset(0, kSelectedIndicatorSize);
SkColor selected_gradient_colors[2] = { kRadioButtonIndicatorGradient0,
kRadioButtonIndicatorGradient1 };
shader = SkGradientShader::CreateLinear(
diff --git a/ui/views/controls/progress_bar.cc b/ui/views/controls/progress_bar.cc
index 516c042..3abc820 100644
--- a/ui/views/controls/progress_bar.cc
+++ b/ui/views/controls/progress_bar.cc
@@ -75,11 +75,11 @@ void FillRoundRect(gfx::Canvas* canvas,
paint.setFlags(SkPaint::kAntiAlias_Flag);
SkPoint p[2];
- p[0].set(SkIntToScalar(x), SkIntToScalar(y));
+ p[0].iset(x, y);
if (gradient_horizontal) {
- p[1].set(SkIntToScalar(x + w), SkIntToScalar(y));
+ p[1].iset(x + w, y);
} else {
- p[1].set(SkIntToScalar(x), SkIntToScalar(y + h));
+ p[1].iset(x, y + h);
}
SkShader* s = SkGradientShader::CreateLinear(
p, colors, points, count, SkShader::kClamp_TileMode, NULL);
diff --git a/ui/views/painter.cc b/ui/views/painter.cc
index 4a83cb4..38e90d6 100644
--- a/ui/views/painter.cc
+++ b/ui/views/painter.cc
@@ -33,15 +33,14 @@ class GradientPainter : public Painter {
virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) OVERRIDE {
SkPaint paint;
SkPoint p[2];
- p[0].set(SkIntToScalar(0), SkIntToScalar(0));
+ p[0].iset(0, 0);
if (horizontal_)
- p[1].set(SkIntToScalar(size.width()), SkIntToScalar(0));
+ p[1].iset(size.width(), 0);
else
- p[1].set(SkIntToScalar(0), SkIntToScalar(size.height()));
+ p[1].iset(0, size.height());
- SkShader* s =
- SkGradientShader::CreateLinear(p, colors_, NULL, 2,
- SkShader::kClamp_TileMode, NULL);
+ SkShader* s = SkGradientShader::CreateLinear(p, colors_, NULL, 2,
+ SkShader::kClamp_TileMode, NULL);
paint.setStyle(SkPaint::kFill_Style);
paint.setShader(s);
// Need to unref shader, otherwise never deleted.
diff --git a/ui/views/touchui/touch_selection_controller_impl.cc b/ui/views/touchui/touch_selection_controller_impl.cc
index 47dedf6..694d5ee 100644
--- a/ui/views/touchui/touch_selection_controller_impl.cc
+++ b/ui/views/touchui/touch_selection_controller_impl.cc
@@ -12,7 +12,6 @@
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/canvas_skia.h"
-#include "ui/gfx/path.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/size.h"
@@ -72,16 +71,13 @@ void PaintCircle(const Circle& circle, gfx::Canvas* canvas) {
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kFill_Style);
paint.setColor(circle.color);
- gfx::Path path;
+ SkPath path;
gfx::Rect bounds(circle.center.x() - circle.radius,
circle.center.y() - circle.radius,
circle.radius * 2,
circle.radius * 2);
- SkRect rect;
- rect.set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()),
- SkIntToScalar(bounds.right()), SkIntToScalar(bounds.bottom()));
SkScalar radius = SkIntToScalar(circle.radius);
- path.addRoundRect(rect, radius, radius);
+ path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius);
canvas->GetSkCanvas()->drawPath(path, paint);
}
@@ -262,8 +258,8 @@ class TouchSelectionControllerImpl::TouchContextMenuView
};
SkPoint points[2];
- points[0].set(SkIntToScalar(0), SkIntToScalar(0));
- points[1].set(SkIntToScalar(0), SkIntToScalar(height()));
+ points[0].iset(0, 0);
+ points[1].iset(0, height());
SkShader* shader = SkGradientShader::CreateLinear(points,
kGradientColors, kGradientPoints, arraysize(kGradientPoints),
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index 1c1533c..32a027e 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -629,22 +629,13 @@ TEST_F(ViewTest, DISABLED_Painting) {
SkRect tmp_rect;
- tmp_rect.set(SkIntToScalar(10),
- SkIntToScalar(10),
- SkIntToScalar(20),
- SkIntToScalar(20));
+ tmp_rect.iset(10, 10, 20, 20);
CheckRect(v3->last_clip_, tmp_rect);
- tmp_rect.set(SkIntToScalar(20),
- SkIntToScalar(20),
- SkIntToScalar(30),
- SkIntToScalar(30));
+ tmp_rect.iset(20, 20, 30, 30);
CheckRect(v2->last_clip_, tmp_rect);
- tmp_rect.set(SkIntToScalar(30),
- SkIntToScalar(30),
- SkIntToScalar(40),
- SkIntToScalar(40));
+ tmp_rect.iset(30, 30, 40, 40);
CheckRect(v1->last_clip_, tmp_rect);
// Make sure v4 was not painted