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

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

Issue 8359029: ui/gfx: Convert Canvas::DrawFocusRect() to use gfx::Rect. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address Peter's review Created 9 years, 1 month 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/canvas_skia.h ('k') | views/controls/button/checkbox.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/canvas_skia.h" 5 #include "ui/gfx/canvas_skia.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 void CanvasSkia::DrawLineInt(const SkColor& color, 174 void CanvasSkia::DrawLineInt(const SkColor& color,
175 int x1, int y1, 175 int x1, int y1,
176 int x2, int y2) { 176 int x2, int y2) {
177 SkPaint paint; 177 SkPaint paint;
178 paint.setColor(color); 178 paint.setColor(color);
179 paint.setStrokeWidth(SkIntToScalar(1)); 179 paint.setStrokeWidth(SkIntToScalar(1));
180 canvas_->drawLine(SkIntToScalar(x1), SkIntToScalar(y1), SkIntToScalar(x2), 180 canvas_->drawLine(SkIntToScalar(x1), SkIntToScalar(y1), SkIntToScalar(x2),
181 SkIntToScalar(y2), paint); 181 SkIntToScalar(y2), paint);
182 } 182 }
183 183
184 void CanvasSkia::DrawFocusRect(int x, int y, int width, int height) { 184 void CanvasSkia::DrawFocusRect(const gfx::Rect& rect) {
185 // Create a 2D bitmap containing alternating on/off pixels - we do this 185 // Create a 2D bitmap containing alternating on/off pixels - we do this
186 // so that you never get two pixels of the same color around the edges 186 // so that you never get two pixels of the same color around the edges
187 // of the focus rect (this may mean that opposing edges of the rect may 187 // of the focus rect (this may mean that opposing edges of the rect may
188 // have a dot pattern out of phase to each other). 188 // have a dot pattern out of phase to each other).
189 static SkBitmap* dots = NULL; 189 static SkBitmap* dots = NULL;
190 if (!dots) { 190 if (!dots) {
191 int col_pixels = 32; 191 int col_pixels = 32;
192 int row_pixels = 32; 192 int row_pixels = 32;
193 193
194 dots = new SkBitmap; 194 dots = new SkBitmap;
195 dots->setConfig(SkBitmap::kARGB_8888_Config, col_pixels, row_pixels); 195 dots->setConfig(SkBitmap::kARGB_8888_Config, col_pixels, row_pixels);
196 dots->allocPixels(); 196 dots->allocPixels();
197 dots->eraseARGB(0, 0, 0, 0); 197 dots->eraseARGB(0, 0, 0, 0);
198 198
199 uint32_t* dot = dots->getAddr32(0, 0); 199 uint32_t* dot = dots->getAddr32(0, 0);
200 for (int i = 0; i < row_pixels; i++) { 200 for (int i = 0; i < row_pixels; i++) {
201 for (int u = 0; u < col_pixels; u++) { 201 for (int u = 0; u < col_pixels; u++) {
202 if ((u % 2 + i % 2) % 2 != 0) { 202 if ((u % 2 + i % 2) % 2 != 0) {
203 dot[i * row_pixels + u] = SK_ColorGRAY; 203 dot[i * row_pixels + u] = SK_ColorGRAY;
204 } 204 }
205 } 205 }
206 } 206 }
207 } 207 }
208 208
209 // First the horizontal lines.
210
211 // Make a shader for the bitmap with an origin of the box we'll draw. This 209 // Make a shader for the bitmap with an origin of the box we'll draw. This
212 // shader is refcounted and will have an initial refcount of 1. 210 // shader is refcounted and will have an initial refcount of 1.
213 SkShader* shader = SkShader::CreateBitmapShader( 211 SkShader* shader = SkShader::CreateBitmapShader(
214 *dots, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); 212 *dots, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);
215 // Assign the shader to the paint & release our reference. The paint will 213 // Assign the shader to the paint & release our reference. The paint will
216 // now own the shader and the shader will be destroyed when the paint goes 214 // now own the shader and the shader will be destroyed when the paint goes
217 // out of scope. 215 // out of scope.
218 SkPaint paint; 216 SkPaint paint;
219 paint.setShader(shader); 217 paint.setShader(shader);
220 shader->unref(); 218 shader->unref();
221 219
222 DrawRectInt(x, y, width, 1, paint); 220 DrawRectInt(rect.x(), rect.y(), rect.width(), 1, paint);
223 DrawRectInt(x, y + height - 1, width, 1, paint); 221 DrawRectInt(rect.x(), rect.y() + rect.height() - 1, rect.width(), 1, paint);
224 DrawRectInt(x, y, 1, height, paint); 222 DrawRectInt(rect.x(), rect.y(), 1, rect.height(), paint);
225 DrawRectInt(x + width - 1, y, 1, height, paint); 223 DrawRectInt(rect.x() + rect.width() - 1, rect.y(), 1, rect.height(), paint);
226 } 224 }
227 225
228 void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap, int x, int y) { 226 void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap, int x, int y) {
229 canvas_->drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y)); 227 canvas_->drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y));
230 } 228 }
231 229
232 void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap, 230 void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap,
233 int x, int y, 231 int x, int y,
234 const SkPaint& paint) { 232 const SkPaint& paint) {
235 canvas_->drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y), &paint); 233 canvas_->drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y), &paint);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 415
418 CanvasPaint* CanvasPaint::CreateCanvasPaint(gfx::NativeView view) { 416 CanvasPaint* CanvasPaint::CreateCanvasPaint(gfx::NativeView view) {
419 #if defined(OS_WIN) && !defined(USE_AURA) 417 #if defined(OS_WIN) && !defined(USE_AURA)
420 return new CanvasPaintWin(view); 418 return new CanvasPaintWin(view);
421 #else 419 #else
422 return NULL; 420 return NULL;
423 #endif 421 #endif
424 } 422 }
425 423
426 } // namespace gfx 424 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/canvas_skia.h ('k') | views/controls/button/checkbox.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698