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

Side by Side Diff: components/test_runner/mock_web_theme_engine.cc

Issue 2523673004: [NOT FOR COMMIT] Fully replace SkCanvas uses.
Patch Set: Support Android build. Created 3 years, 12 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/test_runner/mock_web_theme_engine.h" 5 #include "components/test_runner/mock_web_theme_engine.h"
6 6
7 #if !defined(OS_MACOSX) 7 #if !defined(OS_MACOSX)
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 retval.fTop = rect.fTop + (rect.height() / 2) - (controlSize / 2); 109 retval.fTop = rect.fTop + (rect.height() / 2) - (controlSize / 2);
110 retval.fBottom = retval.fTop + controlSize - 1; 110 retval.fBottom = retval.fTop + controlSize - 1;
111 111
112 return retval; 112 return retval;
113 } 113 }
114 default: 114 default:
115 return rect; 115 return rect;
116 } 116 }
117 } 117 }
118 118
119 void box(SkCanvas* canvas, const SkIRect& rect, SkColor fillColor) { 119 void box(CdlCanvas* canvas, const SkIRect& rect, SkColor fillColor) {
120 SkPaint paint; 120 CdlPaint paint;
121 121
122 paint.setStyle(SkPaint::kFill_Style); 122 paint.setStyle(CdlPaint::kFill_Style);
123 paint.setColor(fillColor); 123 paint.setColor(fillColor);
124 canvas->drawIRect(rect, paint); 124 canvas->drawIRect(rect, paint);
125 125
126 paint.setColor(edgeColor); 126 paint.setColor(edgeColor);
127 paint.setStyle(SkPaint::kStroke_Style); 127 paint.setStyle(CdlPaint::kStroke_Style);
128 canvas->drawIRect(rect, paint); 128 canvas->drawIRect(rect, paint);
129 } 129 }
130 130
131 void line(SkCanvas* canvas, int x0, int y0, int x1, int y1, SkColor color) { 131 void line(CdlCanvas* canvas, int x0, int y0, int x1, int y1, SkColor color) {
132 SkPaint paint; 132 CdlPaint paint;
133 paint.setColor(color); 133 paint.setColor(color);
134 canvas->drawLine(SkIntToScalar(x0), SkIntToScalar(y0), SkIntToScalar(x1), 134 canvas->drawLine(SkIntToScalar(x0), SkIntToScalar(y0), SkIntToScalar(x1),
135 SkIntToScalar(y1), paint); 135 SkIntToScalar(y1), paint);
136 } 136 }
137 137
138 void triangle(SkCanvas* canvas, 138 void triangle(CdlCanvas* canvas,
139 int x0, 139 int x0,
140 int y0, 140 int y0,
141 int x1, 141 int x1,
142 int y1, 142 int y1,
143 int x2, 143 int x2,
144 int y2, 144 int y2,
145 SkColor color) { 145 SkColor color) {
146 SkPath path; 146 SkPath path;
147 SkPaint paint; 147 CdlPaint paint;
148 148
149 paint.setColor(color); 149 paint.setColor(color);
150 paint.setStyle(SkPaint::kFill_Style); 150 paint.setStyle(CdlPaint::kFill_Style);
151 path.incReserve(4); 151 path.incReserve(4);
152 path.moveTo(SkIntToScalar(x0), SkIntToScalar(y0)); 152 path.moveTo(SkIntToScalar(x0), SkIntToScalar(y0));
153 path.lineTo(SkIntToScalar(x1), SkIntToScalar(y1)); 153 path.lineTo(SkIntToScalar(x1), SkIntToScalar(y1));
154 path.lineTo(SkIntToScalar(x2), SkIntToScalar(y2)); 154 path.lineTo(SkIntToScalar(x2), SkIntToScalar(y2));
155 path.close(); 155 path.close();
156 canvas->drawPath(path, paint); 156 canvas->drawPath(path, paint);
157 157
158 paint.setColor(edgeColor); 158 paint.setColor(edgeColor);
159 paint.setStyle(SkPaint::kStroke_Style); 159 paint.setStyle(CdlPaint::kStroke_Style);
160 canvas->drawPath(path, paint); 160 canvas->drawPath(path, paint);
161 } 161 }
162 162
163 void roundRect(SkCanvas* canvas, SkIRect irect, SkColor color) { 163 void roundRect(CdlCanvas* canvas, SkIRect irect, SkColor color) {
164 SkRect rect; 164 SkRect rect;
165 SkScalar radius = SkIntToScalar(5); 165 SkScalar radius = SkIntToScalar(5);
166 SkPaint paint; 166 CdlPaint paint;
167 167
168 rect.set(irect); 168 rect.set(irect);
169 paint.setColor(color); 169 paint.setColor(color);
170 paint.setStyle(SkPaint::kFill_Style); 170 paint.setStyle(CdlPaint::kFill_Style);
171 canvas->drawRoundRect(rect, radius, radius, paint); 171 canvas->drawRoundRect(rect, radius, radius, paint);
172 172
173 paint.setColor(edgeColor); 173 paint.setColor(edgeColor);
174 paint.setStyle(SkPaint::kStroke_Style); 174 paint.setStyle(CdlPaint::kStroke_Style);
175 canvas->drawRoundRect(rect, radius, radius, paint); 175 canvas->drawRoundRect(rect, radius, radius, paint);
176 } 176 }
177 177
178 void oval(SkCanvas* canvas, SkIRect irect, SkColor color) { 178 void oval(CdlCanvas* canvas, SkIRect irect, SkColor color) {
179 SkRect rect; 179 SkRect rect;
180 SkPaint paint; 180 CdlPaint paint;
181 181
182 rect.set(irect); 182 rect.set(irect);
183 paint.setColor(color); 183 paint.setColor(color);
184 paint.setStyle(SkPaint::kFill_Style); 184 paint.setStyle(CdlPaint::kFill_Style);
185 canvas->drawOval(rect, paint); 185 canvas->drawOval(rect, paint);
186 186
187 paint.setColor(edgeColor); 187 paint.setColor(edgeColor);
188 paint.setStyle(SkPaint::kStroke_Style); 188 paint.setStyle(CdlPaint::kStroke_Style);
189 canvas->drawOval(rect, paint); 189 canvas->drawOval(rect, paint);
190 } 190 }
191 191
192 void circle(SkCanvas* canvas, SkIRect irect, SkScalar radius, SkColor color) { 192 void circle(CdlCanvas* canvas, SkIRect irect, SkScalar radius, SkColor color) {
193 int left = irect.fLeft; 193 int left = irect.fLeft;
194 int width = irect.width(); 194 int width = irect.width();
195 int height = irect.height(); 195 int height = irect.height();
196 int top = irect.fTop; 196 int top = irect.fTop;
197 197
198 SkScalar cy = SkIntToScalar(top + height / 2); 198 SkScalar cy = SkIntToScalar(top + height / 2);
199 SkScalar cx = SkIntToScalar(left + width / 2); 199 SkScalar cx = SkIntToScalar(left + width / 2);
200 SkPaint paint; 200 CdlPaint paint;
201 201
202 paint.setColor(color); 202 paint.setColor(color);
203 paint.setStyle(SkPaint::kFill_Style); 203 paint.setStyle(CdlPaint::kFill_Style);
204 canvas->drawCircle(cx, cy, radius, paint); 204 canvas->drawCircle(cx, cy, radius, paint);
205 205
206 paint.setColor(edgeColor); 206 paint.setColor(edgeColor);
207 paint.setStyle(SkPaint::kStroke_Style); 207 paint.setStyle(CdlPaint::kStroke_Style);
208 canvas->drawCircle(cx, cy, radius, paint); 208 canvas->drawCircle(cx, cy, radius, paint);
209 } 209 }
210 210
211 void nestedBoxes(SkCanvas* canvas, 211 void nestedBoxes(CdlCanvas* canvas,
212 SkIRect irect, 212 SkIRect irect,
213 int indentLeft, 213 int indentLeft,
214 int indentTop, 214 int indentTop,
215 int indentRight, 215 int indentRight,
216 int indentBottom, 216 int indentBottom,
217 SkColor outerColor, 217 SkColor outerColor,
218 SkColor innerColor) { 218 SkColor innerColor) {
219 SkIRect lirect; 219 SkIRect lirect;
220 box(canvas, irect, outerColor); 220 box(canvas, irect, outerColor);
221 lirect.set(irect.fLeft + indentLeft, irect.fTop + indentTop, 221 lirect.set(irect.fLeft + indentLeft, irect.fTop + indentTop,
222 irect.fRight - indentRight, irect.fBottom - indentBottom); 222 irect.fRight - indentRight, irect.fBottom - indentBottom);
223 box(canvas, lirect, innerColor); 223 box(canvas, lirect, innerColor);
224 } 224 }
225 225
226 void insetBox(SkCanvas* canvas, 226 void insetBox(CdlCanvas* canvas,
227 SkIRect irect, 227 SkIRect irect,
228 int indentLeft, 228 int indentLeft,
229 int indentTop, 229 int indentTop,
230 int indentRight, 230 int indentRight,
231 int indentBottom, 231 int indentBottom,
232 SkColor color) { 232 SkColor color) {
233 SkIRect lirect; 233 SkIRect lirect;
234 lirect.set(irect.fLeft + indentLeft, irect.fTop + indentTop, 234 lirect.set(irect.fLeft + indentLeft, irect.fTop + indentTop,
235 irect.fRight - indentRight, irect.fBottom - indentBottom); 235 irect.fRight - indentRight, irect.fBottom - indentBottom);
236 box(canvas, lirect, color); 236 box(canvas, lirect, color);
237 } 237 }
238 238
239 void markState(SkCanvas* canvas, SkIRect irect, WebThemeEngine::State state) { 239 void markState(CdlCanvas* canvas, SkIRect irect, WebThemeEngine::State state) {
240 int left = irect.fLeft; 240 int left = irect.fLeft;
241 int right = irect.fRight; 241 int right = irect.fRight;
242 int top = irect.fTop; 242 int top = irect.fTop;
243 int bottom = irect.fBottom; 243 int bottom = irect.fBottom;
244 244
245 // The length of a triangle side for the corner marks. 245 // The length of a triangle side for the corner marks.
246 const int triangleSize = 5; 246 const int triangleSize = 5;
247 247
248 switch (state) { 248 switch (state) {
249 case WebThemeEngine::StateDisabled: 249 case WebThemeEngine::StateDisabled:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 break; 287 break;
288 } 288 }
289 } 289 }
290 290
291 void MockWebThemeEngine::paint(blink::WebCanvas* canvas, 291 void MockWebThemeEngine::paint(blink::WebCanvas* canvas,
292 WebThemeEngine::Part part, 292 WebThemeEngine::Part part,
293 WebThemeEngine::State state, 293 WebThemeEngine::State state,
294 const blink::WebRect& rect, 294 const blink::WebRect& rect,
295 const WebThemeEngine::ExtraParams* extraParams) { 295 const WebThemeEngine::ExtraParams* extraParams) {
296 SkIRect irect = webRectToSkIRect(rect); 296 SkIRect irect = webRectToSkIRect(rect);
297 SkPaint paint; 297 CdlPaint paint;
298 298
299 // Indent amounts for the check in a checkbox or radio button. 299 // Indent amounts for the check in a checkbox or radio button.
300 const int checkIndent = 3; 300 const int checkIndent = 3;
301 301
302 // Indent amounts for short and long sides of the scrollbar notches. 302 // Indent amounts for short and long sides of the scrollbar notches.
303 const int notchLongOffset = 1; 303 const int notchLongOffset = 1;
304 const int notchShortOffset = 4; 304 const int notchShortOffset = 4;
305 const int noOffset = 0; 305 const int noOffset = 0;
306 306
307 // Indent amounts for the short and long sides of a scroll thumb box. 307 // Indent amounts for the short and long sides of a scroll thumb box.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 insetBox(canvas, irect, longOffset, shortOffset, longOffset, noOffset, 414 insetBox(canvas, irect, longOffset, shortOffset, longOffset, noOffset,
415 edgeColor); 415 edgeColor);
416 markState(canvas, irect, state); 416 markState(canvas, irect, state);
417 break; 417 break;
418 } 418 }
419 419
420 case WebThemeEngine::PartScrollbarCorner: { 420 case WebThemeEngine::PartScrollbarCorner: {
421 SkIRect cornerRect = {rect.x, rect.y, rect.x + rect.width, 421 SkIRect cornerRect = {rect.x, rect.y, rect.x + rect.width,
422 rect.y + rect.height}; 422 rect.y + rect.height};
423 paint.setColor(SK_ColorWHITE); 423 paint.setColor(SK_ColorWHITE);
424 paint.setStyle(SkPaint::kFill_Style); 424 paint.setStyle(CdlPaint::kFill_Style);
425 paint.setBlendMode(SkBlendMode::kSrc); 425 paint.setBlendMode(SkBlendMode::kSrc);
426 paint.setAntiAlias(true); 426 paint.setAntiAlias(true);
427 canvas->drawIRect(cornerRect, paint); 427 canvas->drawIRect(cornerRect, paint);
428 break; 428 break;
429 } 429 }
430 430
431 case WebThemeEngine::PartCheckbox: 431 case WebThemeEngine::PartCheckbox:
432 if (extraParams->button.indeterminate) { 432 if (extraParams->button.indeterminate) {
433 nestedBoxes(canvas, irect, checkIndent, halfHeight, checkIndent, 433 nestedBoxes(canvas, irect, checkIndent, halfHeight, checkIndent,
434 halfHeight, bgColors(state), edgeColor); 434 halfHeight, bgColors(state), edgeColor);
(...skipping 19 matching lines...) Expand all
454 } 454 }
455 break; 455 break;
456 456
457 case WebThemeEngine::PartButton: 457 case WebThemeEngine::PartButton:
458 roundRect(canvas, irect, bgColors(state)); 458 roundRect(canvas, irect, bgColors(state));
459 markState(canvas, irect, state); 459 markState(canvas, irect, state);
460 break; 460 break;
461 461
462 case WebThemeEngine::PartTextField: 462 case WebThemeEngine::PartTextField:
463 paint.setColor(extraParams->textField.backgroundColor); 463 paint.setColor(extraParams->textField.backgroundColor);
464 paint.setStyle(SkPaint::kFill_Style); 464 paint.setStyle(CdlPaint::kFill_Style);
465 canvas->drawIRect(irect, paint); 465 canvas->drawIRect(irect, paint);
466 466
467 paint.setColor(edgeColor); 467 paint.setColor(edgeColor);
468 paint.setStyle(SkPaint::kStroke_Style); 468 paint.setStyle(CdlPaint::kStroke_Style);
469 canvas->drawIRect(irect, paint); 469 canvas->drawIRect(irect, paint);
470 470
471 markState(canvas, irect, state); 471 markState(canvas, irect, state);
472 break; 472 break;
473 473
474 case WebThemeEngine::PartMenuList: 474 case WebThemeEngine::PartMenuList:
475 if (extraParams->menuList.fillContentArea) { 475 if (extraParams->menuList.fillContentArea) {
476 box(canvas, irect, extraParams->menuList.backgroundColor); 476 box(canvas, irect, extraParams->menuList.backgroundColor);
477 } else { 477 } else {
478 SkPaint paint; 478 CdlPaint paint;
479 paint.setColor(edgeColor); 479 paint.setColor(edgeColor);
480 paint.setStyle(SkPaint::kStroke_Style); 480 paint.setStyle(CdlPaint::kStroke_Style);
481 canvas->drawIRect(irect, paint); 481 canvas->drawIRect(irect, paint);
482 } 482 }
483 483
484 // clip the drop-down arrow to be inside the select box 484 // clip the drop-down arrow to be inside the select box
485 irect.fLeft = 485 irect.fLeft =
486 std::max(irect.fLeft, extraParams->menuList.arrowX - 486 std::max(irect.fLeft, extraParams->menuList.arrowX -
487 (extraParams->menuList.arrowSize + 1) / 2); 487 (extraParams->menuList.arrowSize + 1) / 2);
488 irect.fRight = 488 irect.fRight =
489 std::min(irect.fLeft + extraParams->menuList.arrowSize, irect.fRight); 489 std::min(irect.fLeft + extraParams->menuList.arrowSize, irect.fRight);
490 490
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 quarterHeight = lirect.height() / 4; 554 quarterHeight = lirect.height() / 4;
555 box(canvas, lirect, bgColors(state)); 555 box(canvas, lirect, bgColors(state));
556 triangle(canvas, left + quarterWidth, top + quarterHeight, 556 triangle(canvas, left + quarterWidth, top + quarterHeight,
557 right - quarterWidth, top + quarterHeight, left + halfWidth, 557 right - quarterWidth, top + quarterHeight, left + halfWidth,
558 bottom - quarterHeight, edgeColor); 558 bottom - quarterHeight, edgeColor);
559 markState(canvas, irect, state); 559 markState(canvas, irect, state);
560 break; 560 break;
561 } 561 }
562 case WebThemeEngine::PartProgressBar: { 562 case WebThemeEngine::PartProgressBar: {
563 paint.setColor(bgColors(state)); 563 paint.setColor(bgColors(state));
564 paint.setStyle(SkPaint::kFill_Style); 564 paint.setStyle(CdlPaint::kFill_Style);
565 canvas->drawIRect(irect, paint); 565 canvas->drawIRect(irect, paint);
566 566
567 // Emulate clipping 567 // Emulate clipping
568 SkIRect tofill = irect; 568 SkIRect tofill = irect;
569 if (extraParams->progressBar.determinate) { 569 if (extraParams->progressBar.determinate) {
570 tofill.set(extraParams->progressBar.valueRectX, 570 tofill.set(extraParams->progressBar.valueRectX,
571 extraParams->progressBar.valueRectY, 571 extraParams->progressBar.valueRectY,
572 extraParams->progressBar.valueRectX + 572 extraParams->progressBar.valueRectX +
573 extraParams->progressBar.valueRectWidth - 1, 573 extraParams->progressBar.valueRectWidth - 1,
574 extraParams->progressBar.valueRectY + 574 extraParams->progressBar.valueRectY +
575 extraParams->progressBar.valueRectHeight); 575 extraParams->progressBar.valueRectHeight);
576 } 576 }
577 577
578 if (!tofill.intersect(irect)) 578 if (!tofill.intersect(irect))
579 tofill.setEmpty(); 579 tofill.setEmpty();
580 580
581 paint.setColor(edgeColor); 581 paint.setColor(edgeColor);
582 paint.setStyle(SkPaint::kFill_Style); 582 paint.setStyle(CdlPaint::kFill_Style);
583 canvas->drawIRect(tofill, paint); 583 canvas->drawIRect(tofill, paint);
584 584
585 markState(canvas, irect, state); 585 markState(canvas, irect, state);
586 break; 586 break;
587 } 587 }
588 default: 588 default:
589 // FIXME: Should we do something here to indicate that we got an invalid 589 // FIXME: Should we do something here to indicate that we got an invalid
590 // part? 590 // part?
591 // Unfortunately, we can't assert because we don't have access to WTF or 591 // Unfortunately, we can't assert because we don't have access to WTF or
592 // base. 592 // base.
593 break; 593 break;
594 } 594 }
595 } 595 }
596 596
597 } // namespace test_runner 597 } // namespace test_runner
598 598
599 #endif // !defined(OS_MACOSX) 599 #endif // !defined(OS_MACOSX)
OLDNEW
« no previous file with comments | « components/printing/renderer/print_web_view_helper_mac.mm ('k') | components/test_runner/pixel_dump.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698