| OLD | NEW |
| 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" |
| 11 #include "skia/ext/platform_canvas.h" | 11 #include "cc/paint/paint_canvas.h" |
| 12 #include "cc/paint/paint_flags.h" |
| 12 #include "third_party/WebKit/public/platform/WebRect.h" | 13 #include "third_party/WebKit/public/platform/WebRect.h" |
| 13 #include "third_party/WebKit/public/platform/WebSize.h" | 14 #include "third_party/WebKit/public/platform/WebSize.h" |
| 14 #include "third_party/skia/include/core/SkPaint.h" | 15 #include "third_party/skia/include/core/SkPaint.h" |
| 15 #include "third_party/skia/include/core/SkPath.h" | 16 #include "third_party/skia/include/core/SkPath.h" |
| 16 #include "third_party/skia/include/core/SkRect.h" | 17 #include "third_party/skia/include/core/SkRect.h" |
| 17 | 18 |
| 18 using blink::WebCanvas; | 19 using blink::WebCanvas; |
| 19 using blink::WebColor; | 20 using blink::WebColor; |
| 20 using blink::WebRect; | 21 using blink::WebRect; |
| 21 using blink::WebThemeEngine; | 22 using blink::WebThemeEngine; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 retval.fTop = rect.fTop + (rect.height() / 2) - (controlSize / 2); | 110 retval.fTop = rect.fTop + (rect.height() / 2) - (controlSize / 2); |
| 110 retval.fBottom = retval.fTop + controlSize - 1; | 111 retval.fBottom = retval.fTop + controlSize - 1; |
| 111 | 112 |
| 112 return retval; | 113 return retval; |
| 113 } | 114 } |
| 114 default: | 115 default: |
| 115 return rect; | 116 return rect; |
| 116 } | 117 } |
| 117 } | 118 } |
| 118 | 119 |
| 119 void box(SkCanvas* canvas, const SkIRect& rect, SkColor fillColor) { | 120 void box(cc::PaintCanvas* canvas, const SkIRect& rect, SkColor fillColor) { |
| 120 SkPaint paint; | 121 cc::PaintFlags paint; |
| 121 | 122 |
| 122 paint.setStyle(SkPaint::kFill_Style); | 123 paint.setStyle(cc::PaintFlags::kFill_Style); |
| 123 paint.setColor(fillColor); | 124 paint.setColor(fillColor); |
| 124 canvas->drawIRect(rect, paint); | 125 canvas->drawIRect(rect, paint); |
| 125 | 126 |
| 126 paint.setColor(edgeColor); | 127 paint.setColor(edgeColor); |
| 127 paint.setStyle(SkPaint::kStroke_Style); | 128 paint.setStyle(cc::PaintFlags::kStroke_Style); |
| 128 canvas->drawIRect(rect, paint); | 129 canvas->drawIRect(rect, paint); |
| 129 } | 130 } |
| 130 | 131 |
| 131 void line(SkCanvas* canvas, int x0, int y0, int x1, int y1, SkColor color) { | 132 void line(cc::PaintCanvas* canvas, |
| 132 SkPaint paint; | 133 int x0, |
| 134 int y0, |
| 135 int x1, |
| 136 int y1, |
| 137 SkColor color) { |
| 138 cc::PaintFlags paint; |
| 133 paint.setColor(color); | 139 paint.setColor(color); |
| 134 canvas->drawLine(SkIntToScalar(x0), SkIntToScalar(y0), SkIntToScalar(x1), | 140 canvas->drawLine(SkIntToScalar(x0), SkIntToScalar(y0), SkIntToScalar(x1), |
| 135 SkIntToScalar(y1), paint); | 141 SkIntToScalar(y1), paint); |
| 136 } | 142 } |
| 137 | 143 |
| 138 void triangle(SkCanvas* canvas, | 144 void triangle(cc::PaintCanvas* canvas, |
| 139 int x0, | 145 int x0, |
| 140 int y0, | 146 int y0, |
| 141 int x1, | 147 int x1, |
| 142 int y1, | 148 int y1, |
| 143 int x2, | 149 int x2, |
| 144 int y2, | 150 int y2, |
| 145 SkColor color) { | 151 SkColor color) { |
| 146 SkPath path; | 152 SkPath path; |
| 147 SkPaint paint; | 153 cc::PaintFlags paint; |
| 148 | 154 |
| 149 paint.setColor(color); | 155 paint.setColor(color); |
| 150 paint.setStyle(SkPaint::kFill_Style); | 156 paint.setStyle(cc::PaintFlags::kFill_Style); |
| 151 path.incReserve(4); | 157 path.incReserve(4); |
| 152 path.moveTo(SkIntToScalar(x0), SkIntToScalar(y0)); | 158 path.moveTo(SkIntToScalar(x0), SkIntToScalar(y0)); |
| 153 path.lineTo(SkIntToScalar(x1), SkIntToScalar(y1)); | 159 path.lineTo(SkIntToScalar(x1), SkIntToScalar(y1)); |
| 154 path.lineTo(SkIntToScalar(x2), SkIntToScalar(y2)); | 160 path.lineTo(SkIntToScalar(x2), SkIntToScalar(y2)); |
| 155 path.close(); | 161 path.close(); |
| 156 canvas->drawPath(path, paint); | 162 canvas->drawPath(path, paint); |
| 157 | 163 |
| 158 paint.setColor(edgeColor); | 164 paint.setColor(edgeColor); |
| 159 paint.setStyle(SkPaint::kStroke_Style); | 165 paint.setStyle(cc::PaintFlags::kStroke_Style); |
| 160 canvas->drawPath(path, paint); | 166 canvas->drawPath(path, paint); |
| 161 } | 167 } |
| 162 | 168 |
| 163 void roundRect(SkCanvas* canvas, SkIRect irect, SkColor color) { | 169 void roundRect(cc::PaintCanvas* canvas, SkIRect irect, SkColor color) { |
| 164 SkRect rect; | 170 SkRect rect; |
| 165 SkScalar radius = SkIntToScalar(5); | 171 SkScalar radius = SkIntToScalar(5); |
| 166 SkPaint paint; | 172 cc::PaintFlags paint; |
| 167 | 173 |
| 168 rect.set(irect); | 174 rect.set(irect); |
| 169 paint.setColor(color); | 175 paint.setColor(color); |
| 170 paint.setStyle(SkPaint::kFill_Style); | 176 paint.setStyle(cc::PaintFlags::kFill_Style); |
| 171 canvas->drawRoundRect(rect, radius, radius, paint); | 177 canvas->drawRoundRect(rect, radius, radius, paint); |
| 172 | 178 |
| 173 paint.setColor(edgeColor); | 179 paint.setColor(edgeColor); |
| 174 paint.setStyle(SkPaint::kStroke_Style); | 180 paint.setStyle(cc::PaintFlags::kStroke_Style); |
| 175 canvas->drawRoundRect(rect, radius, radius, paint); | 181 canvas->drawRoundRect(rect, radius, radius, paint); |
| 176 } | 182 } |
| 177 | 183 |
| 178 void oval(SkCanvas* canvas, SkIRect irect, SkColor color) { | 184 void oval(cc::PaintCanvas* canvas, SkIRect irect, SkColor color) { |
| 179 SkRect rect; | 185 SkRect rect; |
| 180 SkPaint paint; | 186 cc::PaintFlags paint; |
| 181 | 187 |
| 182 rect.set(irect); | 188 rect.set(irect); |
| 183 paint.setColor(color); | 189 paint.setColor(color); |
| 184 paint.setStyle(SkPaint::kFill_Style); | 190 paint.setStyle(cc::PaintFlags::kFill_Style); |
| 185 canvas->drawOval(rect, paint); | 191 canvas->drawOval(rect, paint); |
| 186 | 192 |
| 187 paint.setColor(edgeColor); | 193 paint.setColor(edgeColor); |
| 188 paint.setStyle(SkPaint::kStroke_Style); | 194 paint.setStyle(cc::PaintFlags::kStroke_Style); |
| 189 canvas->drawOval(rect, paint); | 195 canvas->drawOval(rect, paint); |
| 190 } | 196 } |
| 191 | 197 |
| 192 void circle(SkCanvas* canvas, SkIRect irect, SkScalar radius, SkColor color) { | 198 void circle(cc::PaintCanvas* canvas, |
| 199 SkIRect irect, |
| 200 SkScalar radius, |
| 201 SkColor color) { |
| 193 int left = irect.fLeft; | 202 int left = irect.fLeft; |
| 194 int width = irect.width(); | 203 int width = irect.width(); |
| 195 int height = irect.height(); | 204 int height = irect.height(); |
| 196 int top = irect.fTop; | 205 int top = irect.fTop; |
| 197 | 206 |
| 198 SkScalar cy = SkIntToScalar(top + height / 2); | 207 SkScalar cy = SkIntToScalar(top + height / 2); |
| 199 SkScalar cx = SkIntToScalar(left + width / 2); | 208 SkScalar cx = SkIntToScalar(left + width / 2); |
| 200 SkPaint paint; | 209 cc::PaintFlags paint; |
| 201 | 210 |
| 202 paint.setColor(color); | 211 paint.setColor(color); |
| 203 paint.setStyle(SkPaint::kFill_Style); | 212 paint.setStyle(cc::PaintFlags::kFill_Style); |
| 204 canvas->drawCircle(cx, cy, radius, paint); | 213 canvas->drawCircle(cx, cy, radius, paint); |
| 205 | 214 |
| 206 paint.setColor(edgeColor); | 215 paint.setColor(edgeColor); |
| 207 paint.setStyle(SkPaint::kStroke_Style); | 216 paint.setStyle(cc::PaintFlags::kStroke_Style); |
| 208 canvas->drawCircle(cx, cy, radius, paint); | 217 canvas->drawCircle(cx, cy, radius, paint); |
| 209 } | 218 } |
| 210 | 219 |
| 211 void nestedBoxes(SkCanvas* canvas, | 220 void nestedBoxes(cc::PaintCanvas* canvas, |
| 212 SkIRect irect, | 221 SkIRect irect, |
| 213 int indentLeft, | 222 int indentLeft, |
| 214 int indentTop, | 223 int indentTop, |
| 215 int indentRight, | 224 int indentRight, |
| 216 int indentBottom, | 225 int indentBottom, |
| 217 SkColor outerColor, | 226 SkColor outerColor, |
| 218 SkColor innerColor) { | 227 SkColor innerColor) { |
| 219 SkIRect lirect; | 228 SkIRect lirect; |
| 220 box(canvas, irect, outerColor); | 229 box(canvas, irect, outerColor); |
| 221 lirect.set(irect.fLeft + indentLeft, irect.fTop + indentTop, | 230 lirect.set(irect.fLeft + indentLeft, irect.fTop + indentTop, |
| 222 irect.fRight - indentRight, irect.fBottom - indentBottom); | 231 irect.fRight - indentRight, irect.fBottom - indentBottom); |
| 223 box(canvas, lirect, innerColor); | 232 box(canvas, lirect, innerColor); |
| 224 } | 233 } |
| 225 | 234 |
| 226 void insetBox(SkCanvas* canvas, | 235 void insetBox(cc::PaintCanvas* canvas, |
| 227 SkIRect irect, | 236 SkIRect irect, |
| 228 int indentLeft, | 237 int indentLeft, |
| 229 int indentTop, | 238 int indentTop, |
| 230 int indentRight, | 239 int indentRight, |
| 231 int indentBottom, | 240 int indentBottom, |
| 232 SkColor color) { | 241 SkColor color) { |
| 233 SkIRect lirect; | 242 SkIRect lirect; |
| 234 lirect.set(irect.fLeft + indentLeft, irect.fTop + indentTop, | 243 lirect.set(irect.fLeft + indentLeft, irect.fTop + indentTop, |
| 235 irect.fRight - indentRight, irect.fBottom - indentBottom); | 244 irect.fRight - indentRight, irect.fBottom - indentBottom); |
| 236 box(canvas, lirect, color); | 245 box(canvas, lirect, color); |
| 237 } | 246 } |
| 238 | 247 |
| 239 void markState(SkCanvas* canvas, SkIRect irect, WebThemeEngine::State state) { | 248 void markState(cc::PaintCanvas* canvas, |
| 249 SkIRect irect, |
| 250 WebThemeEngine::State state) { |
| 240 int left = irect.fLeft; | 251 int left = irect.fLeft; |
| 241 int right = irect.fRight; | 252 int right = irect.fRight; |
| 242 int top = irect.fTop; | 253 int top = irect.fTop; |
| 243 int bottom = irect.fBottom; | 254 int bottom = irect.fBottom; |
| 244 | 255 |
| 245 // The length of a triangle side for the corner marks. | 256 // The length of a triangle side for the corner marks. |
| 246 const int triangleSize = 5; | 257 const int triangleSize = 5; |
| 247 | 258 |
| 248 switch (state) { | 259 switch (state) { |
| 249 case WebThemeEngine::StateDisabled: | 260 case WebThemeEngine::StateDisabled: |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 break; | 298 break; |
| 288 } | 299 } |
| 289 } | 300 } |
| 290 | 301 |
| 291 void MockWebThemeEngine::paint(blink::WebCanvas* canvas, | 302 void MockWebThemeEngine::paint(blink::WebCanvas* canvas, |
| 292 WebThemeEngine::Part part, | 303 WebThemeEngine::Part part, |
| 293 WebThemeEngine::State state, | 304 WebThemeEngine::State state, |
| 294 const blink::WebRect& rect, | 305 const blink::WebRect& rect, |
| 295 const WebThemeEngine::ExtraParams* extraParams) { | 306 const WebThemeEngine::ExtraParams* extraParams) { |
| 296 SkIRect irect = webRectToSkIRect(rect); | 307 SkIRect irect = webRectToSkIRect(rect); |
| 297 SkPaint paint; | 308 cc::PaintFlags paint; |
| 298 | 309 |
| 299 // Indent amounts for the check in a checkbox or radio button. | 310 // Indent amounts for the check in a checkbox or radio button. |
| 300 const int checkIndent = 3; | 311 const int checkIndent = 3; |
| 301 | 312 |
| 302 // Indent amounts for short and long sides of the scrollbar notches. | 313 // Indent amounts for short and long sides of the scrollbar notches. |
| 303 const int notchLongOffset = 1; | 314 const int notchLongOffset = 1; |
| 304 const int notchShortOffset = 4; | 315 const int notchShortOffset = 4; |
| 305 const int noOffset = 0; | 316 const int noOffset = 0; |
| 306 | 317 |
| 307 // 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 insetBox(canvas, irect, longOffset, shortOffset, longOffset, noOffset, | 425 insetBox(canvas, irect, longOffset, shortOffset, longOffset, noOffset, |
| 415 edgeColor); | 426 edgeColor); |
| 416 markState(canvas, irect, state); | 427 markState(canvas, irect, state); |
| 417 break; | 428 break; |
| 418 } | 429 } |
| 419 | 430 |
| 420 case WebThemeEngine::PartScrollbarCorner: { | 431 case WebThemeEngine::PartScrollbarCorner: { |
| 421 SkIRect cornerRect = {rect.x, rect.y, rect.x + rect.width, | 432 SkIRect cornerRect = {rect.x, rect.y, rect.x + rect.width, |
| 422 rect.y + rect.height}; | 433 rect.y + rect.height}; |
| 423 paint.setColor(SK_ColorWHITE); | 434 paint.setColor(SK_ColorWHITE); |
| 424 paint.setStyle(SkPaint::kFill_Style); | 435 paint.setStyle(cc::PaintFlags::kFill_Style); |
| 425 paint.setBlendMode(SkBlendMode::kSrc); | 436 paint.setBlendMode(SkBlendMode::kSrc); |
| 426 paint.setAntiAlias(true); | 437 paint.setAntiAlias(true); |
| 427 canvas->drawIRect(cornerRect, paint); | 438 canvas->drawIRect(cornerRect, paint); |
| 428 break; | 439 break; |
| 429 } | 440 } |
| 430 | 441 |
| 431 case WebThemeEngine::PartCheckbox: | 442 case WebThemeEngine::PartCheckbox: |
| 432 if (extraParams->button.indeterminate) { | 443 if (extraParams->button.indeterminate) { |
| 433 nestedBoxes(canvas, irect, checkIndent, halfHeight, checkIndent, | 444 nestedBoxes(canvas, irect, checkIndent, halfHeight, checkIndent, |
| 434 halfHeight, bgColors(state), edgeColor); | 445 halfHeight, bgColors(state), edgeColor); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 454 } | 465 } |
| 455 break; | 466 break; |
| 456 | 467 |
| 457 case WebThemeEngine::PartButton: | 468 case WebThemeEngine::PartButton: |
| 458 roundRect(canvas, irect, bgColors(state)); | 469 roundRect(canvas, irect, bgColors(state)); |
| 459 markState(canvas, irect, state); | 470 markState(canvas, irect, state); |
| 460 break; | 471 break; |
| 461 | 472 |
| 462 case WebThemeEngine::PartTextField: | 473 case WebThemeEngine::PartTextField: |
| 463 paint.setColor(extraParams->textField.backgroundColor); | 474 paint.setColor(extraParams->textField.backgroundColor); |
| 464 paint.setStyle(SkPaint::kFill_Style); | 475 paint.setStyle(cc::PaintFlags::kFill_Style); |
| 465 canvas->drawIRect(irect, paint); | 476 canvas->drawIRect(irect, paint); |
| 466 | 477 |
| 467 paint.setColor(edgeColor); | 478 paint.setColor(edgeColor); |
| 468 paint.setStyle(SkPaint::kStroke_Style); | 479 paint.setStyle(cc::PaintFlags::kStroke_Style); |
| 469 canvas->drawIRect(irect, paint); | 480 canvas->drawIRect(irect, paint); |
| 470 | 481 |
| 471 markState(canvas, irect, state); | 482 markState(canvas, irect, state); |
| 472 break; | 483 break; |
| 473 | 484 |
| 474 case WebThemeEngine::PartMenuList: | 485 case WebThemeEngine::PartMenuList: |
| 475 if (extraParams->menuList.fillContentArea) { | 486 if (extraParams->menuList.fillContentArea) { |
| 476 box(canvas, irect, extraParams->menuList.backgroundColor); | 487 box(canvas, irect, extraParams->menuList.backgroundColor); |
| 477 } else { | 488 } else { |
| 478 SkPaint paint; | 489 cc::PaintFlags paint; |
| 479 paint.setColor(edgeColor); | 490 paint.setColor(edgeColor); |
| 480 paint.setStyle(SkPaint::kStroke_Style); | 491 paint.setStyle(cc::PaintFlags::kStroke_Style); |
| 481 canvas->drawIRect(irect, paint); | 492 canvas->drawIRect(irect, paint); |
| 482 } | 493 } |
| 483 | 494 |
| 484 // clip the drop-down arrow to be inside the select box | 495 // clip the drop-down arrow to be inside the select box |
| 485 irect.fLeft = | 496 irect.fLeft = |
| 486 std::max(irect.fLeft, extraParams->menuList.arrowX - | 497 std::max(irect.fLeft, extraParams->menuList.arrowX - |
| 487 (extraParams->menuList.arrowSize + 1) / 2); | 498 (extraParams->menuList.arrowSize + 1) / 2); |
| 488 irect.fRight = | 499 irect.fRight = |
| 489 std::min(irect.fLeft + extraParams->menuList.arrowSize, irect.fRight); | 500 std::min(irect.fLeft + extraParams->menuList.arrowSize, irect.fRight); |
| 490 | 501 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 quarterHeight = lirect.height() / 4; | 565 quarterHeight = lirect.height() / 4; |
| 555 box(canvas, lirect, bgColors(state)); | 566 box(canvas, lirect, bgColors(state)); |
| 556 triangle(canvas, left + quarterWidth, top + quarterHeight, | 567 triangle(canvas, left + quarterWidth, top + quarterHeight, |
| 557 right - quarterWidth, top + quarterHeight, left + halfWidth, | 568 right - quarterWidth, top + quarterHeight, left + halfWidth, |
| 558 bottom - quarterHeight, edgeColor); | 569 bottom - quarterHeight, edgeColor); |
| 559 markState(canvas, irect, state); | 570 markState(canvas, irect, state); |
| 560 break; | 571 break; |
| 561 } | 572 } |
| 562 case WebThemeEngine::PartProgressBar: { | 573 case WebThemeEngine::PartProgressBar: { |
| 563 paint.setColor(bgColors(state)); | 574 paint.setColor(bgColors(state)); |
| 564 paint.setStyle(SkPaint::kFill_Style); | 575 paint.setStyle(cc::PaintFlags::kFill_Style); |
| 565 canvas->drawIRect(irect, paint); | 576 canvas->drawIRect(irect, paint); |
| 566 | 577 |
| 567 // Emulate clipping | 578 // Emulate clipping |
| 568 SkIRect tofill = irect; | 579 SkIRect tofill = irect; |
| 569 if (extraParams->progressBar.determinate) { | 580 if (extraParams->progressBar.determinate) { |
| 570 tofill.set(extraParams->progressBar.valueRectX, | 581 tofill.set(extraParams->progressBar.valueRectX, |
| 571 extraParams->progressBar.valueRectY, | 582 extraParams->progressBar.valueRectY, |
| 572 extraParams->progressBar.valueRectX + | 583 extraParams->progressBar.valueRectX + |
| 573 extraParams->progressBar.valueRectWidth - 1, | 584 extraParams->progressBar.valueRectWidth - 1, |
| 574 extraParams->progressBar.valueRectY + | 585 extraParams->progressBar.valueRectY + |
| 575 extraParams->progressBar.valueRectHeight); | 586 extraParams->progressBar.valueRectHeight); |
| 576 } | 587 } |
| 577 | 588 |
| 578 if (!tofill.intersect(irect)) | 589 if (!tofill.intersect(irect)) |
| 579 tofill.setEmpty(); | 590 tofill.setEmpty(); |
| 580 | 591 |
| 581 paint.setColor(edgeColor); | 592 paint.setColor(edgeColor); |
| 582 paint.setStyle(SkPaint::kFill_Style); | 593 paint.setStyle(cc::PaintFlags::kFill_Style); |
| 583 canvas->drawIRect(tofill, paint); | 594 canvas->drawIRect(tofill, paint); |
| 584 | 595 |
| 585 markState(canvas, irect, state); | 596 markState(canvas, irect, state); |
| 586 break; | 597 break; |
| 587 } | 598 } |
| 588 default: | 599 default: |
| 589 // 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 |
| 590 // part? | 601 // part? |
| 591 // 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 |
| 592 // base. | 603 // base. |
| 593 break; | 604 break; |
| 594 } | 605 } |
| 595 } | 606 } |
| 596 | 607 |
| 597 } // namespace test_runner | 608 } // namespace test_runner |
| 598 | 609 |
| 599 #endif // !defined(OS_MACOSX) | 610 #endif // !defined(OS_MACOSX) |
| OLD | NEW |