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

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

Issue 2682813002: components: Clean up naming of paint-related identifiers (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « components/favicon/core/fallback_icon_service.cc ('k') | components/test_runner/pixel_dump.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 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 retval.fBottom = retval.fTop + controlSize - 1; 111 retval.fBottom = retval.fTop + controlSize - 1;
112 112
113 return retval; 113 return retval;
114 } 114 }
115 default: 115 default:
116 return rect; 116 return rect;
117 } 117 }
118 } 118 }
119 119
120 void box(cc::PaintCanvas* canvas, const SkIRect& rect, SkColor fillColor) { 120 void box(cc::PaintCanvas* canvas, const SkIRect& rect, SkColor fillColor) {
121 cc::PaintFlags paint; 121 cc::PaintFlags flags;
122 122
123 paint.setStyle(cc::PaintFlags::kFill_Style); 123 flags.setStyle(cc::PaintFlags::kFill_Style);
124 paint.setColor(fillColor); 124 flags.setColor(fillColor);
125 canvas->drawIRect(rect, paint); 125 canvas->drawIRect(rect, flags);
126 126
127 paint.setColor(edgeColor); 127 flags.setColor(edgeColor);
128 paint.setStyle(cc::PaintFlags::kStroke_Style); 128 flags.setStyle(cc::PaintFlags::kStroke_Style);
129 canvas->drawIRect(rect, paint); 129 canvas->drawIRect(rect, flags);
130 } 130 }
131 131
132 void line(cc::PaintCanvas* canvas, 132 void line(cc::PaintCanvas* canvas,
133 int x0, 133 int x0,
134 int y0, 134 int y0,
135 int x1, 135 int x1,
136 int y1, 136 int y1,
137 SkColor color) { 137 SkColor color) {
138 cc::PaintFlags paint; 138 cc::PaintFlags flags;
139 paint.setColor(color); 139 flags.setColor(color);
140 canvas->drawLine(SkIntToScalar(x0), SkIntToScalar(y0), SkIntToScalar(x1), 140 canvas->drawLine(SkIntToScalar(x0), SkIntToScalar(y0), SkIntToScalar(x1),
141 SkIntToScalar(y1), paint); 141 SkIntToScalar(y1), flags);
142 } 142 }
143 143
144 void triangle(cc::PaintCanvas* canvas, 144 void triangle(cc::PaintCanvas* canvas,
145 int x0, 145 int x0,
146 int y0, 146 int y0,
147 int x1, 147 int x1,
148 int y1, 148 int y1,
149 int x2, 149 int x2,
150 int y2, 150 int y2,
151 SkColor color) { 151 SkColor color) {
152 SkPath path; 152 SkPath path;
153 cc::PaintFlags paint; 153 cc::PaintFlags flags;
154 154
155 paint.setColor(color); 155 flags.setColor(color);
156 paint.setStyle(cc::PaintFlags::kFill_Style); 156 flags.setStyle(cc::PaintFlags::kFill_Style);
157 path.incReserve(4); 157 path.incReserve(4);
158 path.moveTo(SkIntToScalar(x0), SkIntToScalar(y0)); 158 path.moveTo(SkIntToScalar(x0), SkIntToScalar(y0));
159 path.lineTo(SkIntToScalar(x1), SkIntToScalar(y1)); 159 path.lineTo(SkIntToScalar(x1), SkIntToScalar(y1));
160 path.lineTo(SkIntToScalar(x2), SkIntToScalar(y2)); 160 path.lineTo(SkIntToScalar(x2), SkIntToScalar(y2));
161 path.close(); 161 path.close();
162 canvas->drawPath(path, paint); 162 canvas->drawPath(path, flags);
163 163
164 paint.setColor(edgeColor); 164 flags.setColor(edgeColor);
165 paint.setStyle(cc::PaintFlags::kStroke_Style); 165 flags.setStyle(cc::PaintFlags::kStroke_Style);
166 canvas->drawPath(path, paint); 166 canvas->drawPath(path, flags);
167 } 167 }
168 168
169 void roundRect(cc::PaintCanvas* canvas, SkIRect irect, SkColor color) { 169 void roundRect(cc::PaintCanvas* canvas, SkIRect irect, SkColor color) {
170 SkRect rect; 170 SkRect rect;
171 SkScalar radius = SkIntToScalar(5); 171 SkScalar radius = SkIntToScalar(5);
172 cc::PaintFlags paint; 172 cc::PaintFlags flags;
173 173
174 rect.set(irect); 174 rect.set(irect);
175 paint.setColor(color); 175 flags.setColor(color);
176 paint.setStyle(cc::PaintFlags::kFill_Style); 176 flags.setStyle(cc::PaintFlags::kFill_Style);
177 canvas->drawRoundRect(rect, radius, radius, paint); 177 canvas->drawRoundRect(rect, radius, radius, flags);
178 178
179 paint.setColor(edgeColor); 179 flags.setColor(edgeColor);
180 paint.setStyle(cc::PaintFlags::kStroke_Style); 180 flags.setStyle(cc::PaintFlags::kStroke_Style);
181 canvas->drawRoundRect(rect, radius, radius, paint); 181 canvas->drawRoundRect(rect, radius, radius, flags);
182 } 182 }
183 183
184 void oval(cc::PaintCanvas* canvas, SkIRect irect, SkColor color) { 184 void oval(cc::PaintCanvas* canvas, SkIRect irect, SkColor color) {
185 SkRect rect; 185 SkRect rect;
186 cc::PaintFlags paint; 186 cc::PaintFlags flags;
187 187
188 rect.set(irect); 188 rect.set(irect);
189 paint.setColor(color); 189 flags.setColor(color);
190 paint.setStyle(cc::PaintFlags::kFill_Style); 190 flags.setStyle(cc::PaintFlags::kFill_Style);
191 canvas->drawOval(rect, paint); 191 canvas->drawOval(rect, flags);
192 192
193 paint.setColor(edgeColor); 193 flags.setColor(edgeColor);
194 paint.setStyle(cc::PaintFlags::kStroke_Style); 194 flags.setStyle(cc::PaintFlags::kStroke_Style);
195 canvas->drawOval(rect, paint); 195 canvas->drawOval(rect, flags);
196 } 196 }
197 197
198 void circle(cc::PaintCanvas* canvas, 198 void circle(cc::PaintCanvas* canvas,
199 SkIRect irect, 199 SkIRect irect,
200 SkScalar radius, 200 SkScalar radius,
201 SkColor color) { 201 SkColor color) {
202 int left = irect.fLeft; 202 int left = irect.fLeft;
203 int width = irect.width(); 203 int width = irect.width();
204 int height = irect.height(); 204 int height = irect.height();
205 int top = irect.fTop; 205 int top = irect.fTop;
206 206
207 SkScalar cy = SkIntToScalar(top + height / 2); 207 SkScalar cy = SkIntToScalar(top + height / 2);
208 SkScalar cx = SkIntToScalar(left + width / 2); 208 SkScalar cx = SkIntToScalar(left + width / 2);
209 cc::PaintFlags paint; 209 cc::PaintFlags flags;
210 210
211 paint.setColor(color); 211 flags.setColor(color);
212 paint.setStyle(cc::PaintFlags::kFill_Style); 212 flags.setStyle(cc::PaintFlags::kFill_Style);
213 canvas->drawCircle(cx, cy, radius, paint); 213 canvas->drawCircle(cx, cy, radius, flags);
214 214
215 paint.setColor(edgeColor); 215 flags.setColor(edgeColor);
216 paint.setStyle(cc::PaintFlags::kStroke_Style); 216 flags.setStyle(cc::PaintFlags::kStroke_Style);
217 canvas->drawCircle(cx, cy, radius, paint); 217 canvas->drawCircle(cx, cy, radius, flags);
218 } 218 }
219 219
220 void nestedBoxes(cc::PaintCanvas* canvas, 220 void nestedBoxes(cc::PaintCanvas* canvas,
221 SkIRect irect, 221 SkIRect irect,
222 int indentLeft, 222 int indentLeft,
223 int indentTop, 223 int indentTop,
224 int indentRight, 224 int indentRight,
225 int indentBottom, 225 int indentBottom,
226 SkColor outerColor, 226 SkColor outerColor,
227 SkColor innerColor) { 227 SkColor innerColor) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 break; 298 break;
299 } 299 }
300 } 300 }
301 301
302 void MockWebThemeEngine::paint(blink::WebCanvas* canvas, 302 void MockWebThemeEngine::paint(blink::WebCanvas* canvas,
303 WebThemeEngine::Part part, 303 WebThemeEngine::Part part,
304 WebThemeEngine::State state, 304 WebThemeEngine::State state,
305 const blink::WebRect& rect, 305 const blink::WebRect& rect,
306 const WebThemeEngine::ExtraParams* extraParams) { 306 const WebThemeEngine::ExtraParams* extraParams) {
307 SkIRect irect = webRectToSkIRect(rect); 307 SkIRect irect = webRectToSkIRect(rect);
308 cc::PaintFlags paint; 308 cc::PaintFlags flags;
309 309
310 // Indent amounts for the check in a checkbox or radio button. 310 // Indent amounts for the check in a checkbox or radio button.
311 const int checkIndent = 3; 311 const int checkIndent = 3;
312 312
313 // Indent amounts for short and long sides of the scrollbar notches. 313 // Indent amounts for short and long sides of the scrollbar notches.
314 const int notchLongOffset = 1; 314 const int notchLongOffset = 1;
315 const int notchShortOffset = 4; 315 const int notchShortOffset = 4;
316 const int noOffset = 0; 316 const int noOffset = 0;
317 317
318 // Indent amounts for the short and long sides of a scroll thumb box. 318 // Indent amounts for the short and long sides of a scroll thumb box.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 // forward, notch at bottom 424 // forward, notch at bottom
425 insetBox(canvas, irect, longOffset, shortOffset, longOffset, noOffset, 425 insetBox(canvas, irect, longOffset, shortOffset, longOffset, noOffset,
426 edgeColor); 426 edgeColor);
427 markState(canvas, irect, state); 427 markState(canvas, irect, state);
428 break; 428 break;
429 } 429 }
430 430
431 case WebThemeEngine::PartScrollbarCorner: { 431 case WebThemeEngine::PartScrollbarCorner: {
432 SkIRect cornerRect = {rect.x, rect.y, rect.x + rect.width, 432 SkIRect cornerRect = {rect.x, rect.y, rect.x + rect.width,
433 rect.y + rect.height}; 433 rect.y + rect.height};
434 paint.setColor(SK_ColorWHITE); 434 flags.setColor(SK_ColorWHITE);
435 paint.setStyle(cc::PaintFlags::kFill_Style); 435 flags.setStyle(cc::PaintFlags::kFill_Style);
436 paint.setBlendMode(SkBlendMode::kSrc); 436 flags.setBlendMode(SkBlendMode::kSrc);
437 paint.setAntiAlias(true); 437 flags.setAntiAlias(true);
438 canvas->drawIRect(cornerRect, paint); 438 canvas->drawIRect(cornerRect, flags);
439 break; 439 break;
440 } 440 }
441 441
442 case WebThemeEngine::PartCheckbox: 442 case WebThemeEngine::PartCheckbox:
443 if (extraParams->button.indeterminate) { 443 if (extraParams->button.indeterminate) {
444 nestedBoxes(canvas, irect, checkIndent, halfHeight, checkIndent, 444 nestedBoxes(canvas, irect, checkIndent, halfHeight, checkIndent,
445 halfHeight, bgColors(state), edgeColor); 445 halfHeight, bgColors(state), edgeColor);
446 } else if (extraParams->button.checked) { 446 } else if (extraParams->button.checked) {
447 irect = validate(irect, part); 447 irect = validate(irect, part);
448 nestedBoxes(canvas, irect, checkIndent, checkIndent, checkIndent, 448 nestedBoxes(canvas, irect, checkIndent, checkIndent, checkIndent,
(...skipping 15 matching lines...) Expand all
464 circle(canvas, irect, SkIntToScalar(halfHeight), bgColors(state)); 464 circle(canvas, irect, SkIntToScalar(halfHeight), bgColors(state));
465 } 465 }
466 break; 466 break;
467 467
468 case WebThemeEngine::PartButton: 468 case WebThemeEngine::PartButton:
469 roundRect(canvas, irect, bgColors(state)); 469 roundRect(canvas, irect, bgColors(state));
470 markState(canvas, irect, state); 470 markState(canvas, irect, state);
471 break; 471 break;
472 472
473 case WebThemeEngine::PartTextField: 473 case WebThemeEngine::PartTextField:
474 paint.setColor(extraParams->textField.backgroundColor); 474 flags.setColor(extraParams->textField.backgroundColor);
475 paint.setStyle(cc::PaintFlags::kFill_Style); 475 flags.setStyle(cc::PaintFlags::kFill_Style);
476 canvas->drawIRect(irect, paint); 476 canvas->drawIRect(irect, flags);
477 477
478 paint.setColor(edgeColor); 478 flags.setColor(edgeColor);
479 paint.setStyle(cc::PaintFlags::kStroke_Style); 479 flags.setStyle(cc::PaintFlags::kStroke_Style);
480 canvas->drawIRect(irect, paint); 480 canvas->drawIRect(irect, flags);
481 481
482 markState(canvas, irect, state); 482 markState(canvas, irect, state);
483 break; 483 break;
484 484
485 case WebThemeEngine::PartMenuList: 485 case WebThemeEngine::PartMenuList:
486 if (extraParams->menuList.fillContentArea) { 486 if (extraParams->menuList.fillContentArea) {
487 box(canvas, irect, extraParams->menuList.backgroundColor); 487 box(canvas, irect, extraParams->menuList.backgroundColor);
488 } else { 488 } else {
489 cc::PaintFlags paint; 489 cc::PaintFlags flags;
490 paint.setColor(edgeColor); 490 flags.setColor(edgeColor);
491 paint.setStyle(cc::PaintFlags::kStroke_Style); 491 flags.setStyle(cc::PaintFlags::kStroke_Style);
492 canvas->drawIRect(irect, paint); 492 canvas->drawIRect(irect, flags);
493 } 493 }
494 494
495 // clip the drop-down arrow to be inside the select box 495 // clip the drop-down arrow to be inside the select box
496 irect.fLeft = 496 irect.fLeft =
497 std::max(irect.fLeft, extraParams->menuList.arrowX - 497 std::max(irect.fLeft, extraParams->menuList.arrowX -
498 (extraParams->menuList.arrowSize + 1) / 2); 498 (extraParams->menuList.arrowSize + 1) / 2);
499 irect.fRight = 499 irect.fRight =
500 std::min(irect.fLeft + extraParams->menuList.arrowSize, irect.fRight); 500 std::min(irect.fLeft + extraParams->menuList.arrowSize, irect.fRight);
501 501
502 irect.fTop = extraParams->menuList.arrowY - 502 irect.fTop = extraParams->menuList.arrowY -
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 bottom = lirect.fBottom; 564 bottom = lirect.fBottom;
565 quarterHeight = lirect.height() / 4; 565 quarterHeight = lirect.height() / 4;
566 box(canvas, lirect, bgColors(state)); 566 box(canvas, lirect, bgColors(state));
567 triangle(canvas, left + quarterWidth, top + quarterHeight, 567 triangle(canvas, left + quarterWidth, top + quarterHeight,
568 right - quarterWidth, top + quarterHeight, left + halfWidth, 568 right - quarterWidth, top + quarterHeight, left + halfWidth,
569 bottom - quarterHeight, edgeColor); 569 bottom - quarterHeight, edgeColor);
570 markState(canvas, irect, state); 570 markState(canvas, irect, state);
571 break; 571 break;
572 } 572 }
573 case WebThemeEngine::PartProgressBar: { 573 case WebThemeEngine::PartProgressBar: {
574 paint.setColor(bgColors(state)); 574 flags.setColor(bgColors(state));
575 paint.setStyle(cc::PaintFlags::kFill_Style); 575 flags.setStyle(cc::PaintFlags::kFill_Style);
576 canvas->drawIRect(irect, paint); 576 canvas->drawIRect(irect, flags);
577 577
578 // Emulate clipping 578 // Emulate clipping
579 SkIRect tofill = irect; 579 SkIRect tofill = irect;
580 if (extraParams->progressBar.determinate) { 580 if (extraParams->progressBar.determinate) {
581 tofill.set(extraParams->progressBar.valueRectX, 581 tofill.set(extraParams->progressBar.valueRectX,
582 extraParams->progressBar.valueRectY, 582 extraParams->progressBar.valueRectY,
583 extraParams->progressBar.valueRectX + 583 extraParams->progressBar.valueRectX +
584 extraParams->progressBar.valueRectWidth - 1, 584 extraParams->progressBar.valueRectWidth - 1,
585 extraParams->progressBar.valueRectY + 585 extraParams->progressBar.valueRectY +
586 extraParams->progressBar.valueRectHeight); 586 extraParams->progressBar.valueRectHeight);
587 } 587 }
588 588
589 if (!tofill.intersect(irect)) 589 if (!tofill.intersect(irect))
590 tofill.setEmpty(); 590 tofill.setEmpty();
591 591
592 paint.setColor(edgeColor); 592 flags.setColor(edgeColor);
593 paint.setStyle(cc::PaintFlags::kFill_Style); 593 flags.setStyle(cc::PaintFlags::kFill_Style);
594 canvas->drawIRect(tofill, paint); 594 canvas->drawIRect(tofill, flags);
595 595
596 markState(canvas, irect, state); 596 markState(canvas, irect, state);
597 break; 597 break;
598 } 598 }
599 default: 599 default:
600 // FIXME: Should we do something here to indicate that we got an invalid 600 // FIXME: Should we do something here to indicate that we got an invalid
601 // part? 601 // part?
602 // Unfortunately, we can't assert because we don't have access to WTF or 602 // Unfortunately, we can't assert because we don't have access to WTF or
603 // base. 603 // base.
604 break; 604 break;
605 } 605 }
606 } 606 }
607 607
608 } // namespace test_runner 608 } // namespace test_runner
609 609
610 #endif // !defined(OS_MACOSX) 610 #endif // !defined(OS_MACOSX)
OLDNEW
« no previous file with comments | « components/favicon/core/fallback_icon_service.cc ('k') | components/test_runner/pixel_dump.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698