| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /* |
| 6 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 7 * |
| 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions are |
| 10 * met: |
| 11 * |
| 12 * * Redistributions of source code must retain the above copyright |
| 13 * notice, this list of conditions and the following disclaimer. |
| 14 * * Redistributions in binary form must reproduce the above |
| 15 * copyright notice, this list of conditions and the following disclaimer |
| 16 * in the documentation and/or other materials provided with the |
| 17 * distribution. |
| 18 * * Neither the name of Google Inc. nor the names of its |
| 19 * contributors may be used to endorse or promote products derived from |
| 20 * this software without specific prior written permission. |
| 21 * |
| 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 */ |
| 34 |
| 35 // FIXME: This code is largely cloned from WebTestThemeEngineWin.cpp |
| 36 // and WebTestThemeControlWin.cpp. We should delete that code once the |
| 37 // cutover to Aura is final. |
| 38 |
| 39 #include "content/test/layout_tests/runner/WebTestThemeEngineMock.h" |
| 40 |
| 41 #include "third_party/WebKit/public/platform/WebRect.h" |
| 42 #include "third_party/WebKit/public/platform/WebSize.h" |
| 43 #include "skia/ext/platform_canvas.h" |
| 44 #include "third_party/skia/include/core/SkRect.h" |
| 45 |
| 46 using blink::WebCanvas; |
| 47 using blink::WebColor; |
| 48 using blink::WebRect; |
| 49 using blink::WebThemeEngine; |
| 50 |
| 51 namespace WebTestRunner { |
| 52 |
| 53 static const SkColor edgeColor = SK_ColorBLACK; |
| 54 static const SkColor readOnlyColor = SkColorSetRGB(0xe9, 0xc2, 0xa6); |
| 55 static const SkColor bgColors[] = { |
| 56 SkColorSetRGB(0xc9, 0xc9, 0xc9), // Disabled |
| 57 SkColorSetRGB(0x43, 0xf9, 0xff), // Hover (Win's "Hot") |
| 58 SkColorSetRGB(0x89, 0xc4, 0xff), // Normal |
| 59 SkColorSetRGB(0xa9, 0xff, 0x12), // Pressed |
| 60 SkColorSetRGB(0x00, 0xf3, 0xac), // Focused |
| 61 SkColorSetRGB(0xf3, 0xe0, 0xd0), // Readonly |
| 62 }; |
| 63 |
| 64 |
| 65 blink::WebSize WebTestThemeEngineMock::getSize(WebThemeEngine::Part part) |
| 66 { |
| 67 // FIXME: We use this constant to indicate we are being asked for the size o
f |
| 68 // a part that we don't expect to be asked about. We return a garbage value |
| 69 // rather than just asserting because this code doesn't have access to eithe
r |
| 70 // WTF or base to raise an assertion or do any logging :(. |
| 71 const blink::WebSize invalidPartSize = blink::WebSize(100, 100); |
| 72 |
| 73 switch (part) { |
| 74 case WebThemeEngine::PartScrollbarLeftArrow: |
| 75 return blink::WebSize(17, 15); |
| 76 case WebThemeEngine::PartScrollbarRightArrow: |
| 77 return invalidPartSize; |
| 78 case WebThemeEngine::PartScrollbarUpArrow: |
| 79 return blink::WebSize(15, 17); |
| 80 case WebThemeEngine::PartScrollbarDownArrow: |
| 81 return invalidPartSize; |
| 82 case WebThemeEngine::PartScrollbarHorizontalThumb: |
| 83 return blink::WebSize(15, 15); |
| 84 case WebThemeEngine::PartScrollbarVerticalThumb: |
| 85 return blink::WebSize(15, 15); |
| 86 case WebThemeEngine::PartScrollbarHorizontalTrack: |
| 87 return blink::WebSize(0, 15); |
| 88 case WebThemeEngine::PartScrollbarVerticalTrack: |
| 89 return blink::WebSize(15, 0); |
| 90 case WebThemeEngine::PartCheckbox: |
| 91 case WebThemeEngine::PartRadio: |
| 92 return blink::WebSize(13, 13); |
| 93 case WebThemeEngine::PartSliderThumb: |
| 94 return blink::WebSize(11, 21); |
| 95 case WebThemeEngine::PartInnerSpinButton: |
| 96 return blink::WebSize(15, 8); |
| 97 default: |
| 98 return invalidPartSize; |
| 99 } |
| 100 } |
| 101 |
| 102 static SkIRect webRectToSkIRect(const WebRect& webRect) |
| 103 { |
| 104 SkIRect irect; |
| 105 irect.set(webRect.x, webRect.y, |
| 106 webRect.x + webRect.width - 1, webRect.y + webRect.height - 1); |
| 107 return irect; |
| 108 } |
| 109 |
| 110 static SkIRect validate(const SkIRect& rect, WebThemeEngine::Part part) |
| 111 { |
| 112 switch (part) { |
| 113 case WebThemeEngine::PartCheckbox: |
| 114 case WebThemeEngine::PartRadio: { |
| 115 SkIRect retval = rect; |
| 116 |
| 117 // The maximum width and height is 13. |
| 118 // Center the square in the passed rectangle. |
| 119 const int maxControlSize = 13; |
| 120 int controlSize = std::min(rect.width(), rect.height()); |
| 121 controlSize = std::min(controlSize, maxControlSize); |
| 122 |
| 123 retval.fLeft = rect.fLeft + (rect.width() / 2) - (controlSize / 2); |
| 124 retval.fRight = retval.fLeft + controlSize - 1; |
| 125 retval.fTop = rect.fTop + (rect.height() / 2) - (controlSize / 2); |
| 126 retval.fBottom = retval.fTop + controlSize - 1; |
| 127 |
| 128 return retval; |
| 129 } |
| 130 default: |
| 131 return rect; |
| 132 } |
| 133 } |
| 134 |
| 135 |
| 136 void box(SkCanvas *canvas, const SkIRect& rect, SkColor fillColor) |
| 137 { |
| 138 SkPaint paint; |
| 139 |
| 140 paint.setStyle(SkPaint::kFill_Style); |
| 141 paint.setColor(fillColor); |
| 142 canvas->drawIRect(rect, paint); |
| 143 |
| 144 paint.setColor(edgeColor); |
| 145 paint.setStyle(SkPaint::kStroke_Style); |
| 146 canvas->drawIRect(rect, paint); |
| 147 } |
| 148 |
| 149 void line(SkCanvas *canvas, int x0, int y0, int x1, int y1, SkColor color) |
| 150 { |
| 151 SkPaint paint; |
| 152 paint.setColor(color); |
| 153 canvas->drawLine(SkIntToScalar(x0), SkIntToScalar(y0), |
| 154 SkIntToScalar(x1), SkIntToScalar(y1), paint); |
| 155 } |
| 156 |
| 157 void triangle(SkCanvas *canvas, |
| 158 int x0, int y0, |
| 159 int x1, int y1, |
| 160 int x2, int y2, |
| 161 SkColor color) |
| 162 { |
| 163 SkPath path; |
| 164 SkPaint paint; |
| 165 |
| 166 paint.setColor(color); |
| 167 paint.setStyle(SkPaint::kFill_Style); |
| 168 path.incReserve(4); |
| 169 path.moveTo(SkIntToScalar(x0), SkIntToScalar(y0)); |
| 170 path.lineTo(SkIntToScalar(x1), SkIntToScalar(y1)); |
| 171 path.lineTo(SkIntToScalar(x2), SkIntToScalar(y2)); |
| 172 path.close(); |
| 173 canvas->drawPath(path, paint); |
| 174 |
| 175 paint.setColor(edgeColor); |
| 176 paint.setStyle(SkPaint::kStroke_Style); |
| 177 canvas->drawPath(path, paint); |
| 178 } |
| 179 |
| 180 void roundRect(SkCanvas *canvas, SkIRect irect, SkColor color) |
| 181 { |
| 182 SkRect rect; |
| 183 SkScalar radius = SkIntToScalar(5); |
| 184 SkPaint paint; |
| 185 |
| 186 rect.set(irect); |
| 187 paint.setColor(color); |
| 188 paint.setStyle(SkPaint::kFill_Style); |
| 189 canvas->drawRoundRect(rect, radius, radius, paint); |
| 190 |
| 191 paint.setColor(edgeColor); |
| 192 paint.setStyle(SkPaint::kStroke_Style); |
| 193 canvas->drawRoundRect(rect, radius, radius, paint); |
| 194 } |
| 195 |
| 196 void oval(SkCanvas* canvas, SkIRect irect, SkColor color) |
| 197 { |
| 198 SkRect rect; |
| 199 SkPaint paint; |
| 200 |
| 201 rect.set(irect); |
| 202 paint.setColor(color); |
| 203 paint.setStyle(SkPaint::kFill_Style); |
| 204 canvas->drawOval(rect, paint); |
| 205 |
| 206 paint.setColor(edgeColor); |
| 207 paint.setStyle(SkPaint::kStroke_Style); |
| 208 canvas->drawOval(rect, paint); |
| 209 } |
| 210 |
| 211 void circle(SkCanvas *canvas, SkIRect irect, SkScalar radius, SkColor color) |
| 212 { |
| 213 int left = irect.fLeft; |
| 214 int width = irect.width(); |
| 215 int height = irect.height(); |
| 216 int top = irect.fTop; |
| 217 |
| 218 SkScalar cy = SkIntToScalar(top + height / 2); |
| 219 SkScalar cx = SkIntToScalar(left + width / 2); |
| 220 SkPaint paint; |
| 221 |
| 222 paint.setColor(color); |
| 223 paint.setStyle(SkPaint::kFill_Style); |
| 224 canvas->drawCircle(cx, cy, radius, paint); |
| 225 |
| 226 paint.setColor(edgeColor); |
| 227 paint.setStyle(SkPaint::kStroke_Style); |
| 228 canvas->drawCircle(cx, cy, radius, paint); |
| 229 } |
| 230 |
| 231 void nestedBoxes(SkCanvas *canvas, |
| 232 SkIRect irect, |
| 233 int indentLeft, |
| 234 int indentTop, |
| 235 int indentRight, |
| 236 int indentBottom, |
| 237 SkColor outerColor, |
| 238 SkColor innerColor) |
| 239 { |
| 240 SkIRect lirect; |
| 241 box(canvas, irect, outerColor); |
| 242 lirect.set(irect.fLeft + indentLeft, |
| 243 irect.fTop + indentTop, |
| 244 irect.fRight - indentRight, |
| 245 irect.fBottom - indentBottom); |
| 246 box(canvas, lirect, innerColor); |
| 247 } |
| 248 |
| 249 void markState(SkCanvas *canvas, SkIRect irect, WebThemeEngine::State state) |
| 250 { |
| 251 int left = irect.fLeft; |
| 252 int right = irect.fRight; |
| 253 int top = irect.fTop; |
| 254 int bottom = irect.fBottom; |
| 255 |
| 256 // The length of a triangle side for the corner marks. |
| 257 const int triangleSize = 5; |
| 258 |
| 259 switch (state) { |
| 260 case WebThemeEngine::StateDisabled: |
| 261 case WebThemeEngine::StateNormal: |
| 262 // Don't visually mark these states (color is enough). |
| 263 break; |
| 264 |
| 265 case WebThemeEngine::StateReadonly: { |
| 266 // The horizontal lines in a read only control are spaced by this amount
. |
| 267 const int readOnlyLineOffset = 5; |
| 268 |
| 269 // Drawing lines across the control. |
| 270 for (int i = top + readOnlyLineOffset; i < bottom; i += readOnlyLineOffs
et) |
| 271 line(canvas, left + 1, i, right - 1, i, readOnlyColor); |
| 272 break; |
| 273 } |
| 274 case WebThemeEngine::StateHover: |
| 275 // Draw a triangle in the upper left corner of the control. (Win's "hot"
) |
| 276 triangle(canvas, |
| 277 left, top, |
| 278 left + triangleSize, top, |
| 279 left, top + triangleSize, |
| 280 edgeColor); |
| 281 break; |
| 282 |
| 283 case WebThemeEngine::StateFocused: |
| 284 // Draw a triangle in the bottom right corner of the control. |
| 285 triangle(canvas, |
| 286 right, bottom, |
| 287 right - triangleSize, bottom, |
| 288 right, bottom - triangleSize, |
| 289 edgeColor); |
| 290 break; |
| 291 |
| 292 case WebThemeEngine::StatePressed: |
| 293 // Draw a triangle in the bottom left corner of the control. |
| 294 triangle(canvas, |
| 295 left, bottom, |
| 296 left, bottom - triangleSize, |
| 297 left + triangleSize, bottom, |
| 298 edgeColor); |
| 299 break; |
| 300 |
| 301 default: |
| 302 // FIXME: Should we do something here to indicate that we got an invalid
state? |
| 303 // Unfortunately, we can't assert because we don't have access to WTF or
base. |
| 304 break; |
| 305 } |
| 306 } |
| 307 |
| 308 void WebTestThemeEngineMock::paint( |
| 309 blink::WebCanvas* canvas, |
| 310 WebThemeEngine::Part part, |
| 311 WebThemeEngine::State state, |
| 312 const blink::WebRect& rect, |
| 313 const WebThemeEngine::ExtraParams* extraParams) |
| 314 { |
| 315 SkIRect irect = webRectToSkIRect(rect); |
| 316 SkPaint paint; |
| 317 |
| 318 // Indent amounts for the check in a checkbox or radio button. |
| 319 const int checkIndent = 3; |
| 320 |
| 321 // Indent amounts for short and long sides of the scrollbar notches. |
| 322 const int notchLongOffset = 1; |
| 323 const int notchShortOffset = 4; |
| 324 const int noOffset = 0; |
| 325 |
| 326 // Indent amounts for the short and long sides of a scroll thumb box. |
| 327 const int thumbLongIndent = 0; |
| 328 const int thumbShortIndent = 2; |
| 329 |
| 330 // Indents for the crosshatch on a scroll grip. |
| 331 const int gripLongIndent = 3; |
| 332 const int gripShortIndent = 5; |
| 333 |
| 334 // Indents for the the slider track. |
| 335 const int sliderIndent = 2; |
| 336 |
| 337 int halfHeight = irect.height() / 2; |
| 338 int halfWidth = irect.width() / 2; |
| 339 int quarterHeight = irect.height() / 4; |
| 340 int quarterWidth = irect.width() / 4; |
| 341 int left = irect.fLeft; |
| 342 int right = irect.fRight; |
| 343 int top = irect.fTop; |
| 344 int bottom = irect.fBottom; |
| 345 |
| 346 switch (part) { |
| 347 case WebThemeEngine::PartScrollbarDownArrow: |
| 348 box(canvas, irect, bgColors[state]); |
| 349 triangle(canvas, |
| 350 left + quarterWidth, top + quarterHeight, |
| 351 right - quarterWidth, top + quarterHeight, |
| 352 left + halfWidth, bottom - quarterHeight, |
| 353 edgeColor); |
| 354 markState(canvas, irect, state); |
| 355 break; |
| 356 |
| 357 case WebThemeEngine::PartScrollbarLeftArrow: |
| 358 box(canvas, irect, bgColors[state]); |
| 359 triangle(canvas, |
| 360 right - quarterWidth, top + quarterHeight, |
| 361 right - quarterWidth, bottom - quarterHeight, |
| 362 left + quarterWidth, top + halfHeight, |
| 363 edgeColor); |
| 364 break; |
| 365 |
| 366 case WebThemeEngine::PartScrollbarRightArrow: |
| 367 box(canvas, irect, bgColors[state]); |
| 368 triangle(canvas, |
| 369 left + quarterWidth, top + quarterHeight, |
| 370 right - quarterWidth, top + halfHeight, |
| 371 left + quarterWidth, bottom - quarterHeight, |
| 372 edgeColor); |
| 373 break; |
| 374 |
| 375 case WebThemeEngine::PartScrollbarUpArrow: |
| 376 box(canvas, irect, bgColors[state]); |
| 377 triangle(canvas, |
| 378 left + quarterWidth, bottom - quarterHeight, |
| 379 left + halfWidth, top + quarterHeight, |
| 380 right - quarterWidth, bottom - quarterHeight, |
| 381 edgeColor); |
| 382 markState(canvas, irect, state); |
| 383 break; |
| 384 |
| 385 case WebThemeEngine::PartScrollbarHorizontalThumb: { |
| 386 // Draw a narrower box on top of the outside box. |
| 387 nestedBoxes(canvas, irect, thumbLongIndent, thumbShortIndent, |
| 388 thumbLongIndent, thumbShortIndent, |
| 389 bgColors[state], bgColors[state]); |
| 390 // Draw a horizontal crosshatch for the grip. |
| 391 int longOffset = halfWidth - gripLongIndent; |
| 392 line(canvas, |
| 393 left + gripLongIndent, top + halfHeight, |
| 394 right - gripLongIndent, top + halfHeight, |
| 395 edgeColor); |
| 396 line(canvas, |
| 397 left + longOffset, top + gripShortIndent, |
| 398 left + longOffset, bottom - gripShortIndent, |
| 399 edgeColor); |
| 400 line(canvas, |
| 401 right - longOffset, top + gripShortIndent, |
| 402 right - longOffset, bottom - gripShortIndent, |
| 403 edgeColor); |
| 404 markState(canvas, irect, state); |
| 405 break; |
| 406 } |
| 407 |
| 408 case WebThemeEngine::PartScrollbarVerticalThumb: { |
| 409 // Draw a shorter box on top of the outside box. |
| 410 nestedBoxes(canvas, irect, thumbShortIndent, thumbLongIndent, |
| 411 thumbShortIndent, thumbLongIndent, |
| 412 bgColors[state], bgColors[state]); |
| 413 // Draw a vertical crosshatch for the grip. |
| 414 int longOffset = halfHeight - gripLongIndent; |
| 415 line(canvas, |
| 416 left + halfWidth, top + gripLongIndent, |
| 417 left + halfWidth, bottom - gripLongIndent, |
| 418 edgeColor); |
| 419 line(canvas, |
| 420 left + gripShortIndent, top + longOffset, |
| 421 right - gripShortIndent, top + longOffset, |
| 422 edgeColor); |
| 423 line(canvas, |
| 424 left + gripShortIndent, bottom - longOffset, |
| 425 right - gripShortIndent, bottom - longOffset, |
| 426 edgeColor); |
| 427 markState(canvas, irect, state); |
| 428 break; |
| 429 } |
| 430 |
| 431 case WebThemeEngine::PartScrollbarHorizontalTrack: { |
| 432 int longOffset = halfHeight - notchLongOffset; |
| 433 int shortOffset = irect.width() - notchShortOffset; |
| 434 if (extraParams->scrollbarTrack.isBack) { |
| 435 // back, notch on left |
| 436 nestedBoxes(canvas, irect, noOffset, longOffset, shortOffset, |
| 437 longOffset, bgColors[state], edgeColor); |
| 438 } else { |
| 439 // forward, notch on right |
| 440 nestedBoxes(canvas, irect, shortOffset, longOffset, noOffset, |
| 441 longOffset, bgColors[state], edgeColor); |
| 442 } |
| 443 |
| 444 markState(canvas, irect, state); |
| 445 break; |
| 446 } |
| 447 |
| 448 case WebThemeEngine::PartScrollbarVerticalTrack: { |
| 449 int longOffset = halfWidth - notchLongOffset; |
| 450 int shortOffset = irect.height() - notchShortOffset; |
| 451 if (extraParams->scrollbarTrack.isBack) { |
| 452 // back, notch at top |
| 453 nestedBoxes(canvas, irect, longOffset, noOffset, longOffset, |
| 454 shortOffset, bgColors[state], edgeColor); |
| 455 } else { |
| 456 // forward, notch at bottom |
| 457 nestedBoxes(canvas, irect, longOffset, shortOffset, longOffset, |
| 458 noOffset, bgColors[state], edgeColor); |
| 459 } |
| 460 |
| 461 markState(canvas, irect, state); |
| 462 break; |
| 463 } |
| 464 |
| 465 case WebThemeEngine::PartCheckbox: |
| 466 if (extraParams->button.indeterminate) { |
| 467 nestedBoxes(canvas, irect, |
| 468 checkIndent, halfHeight, |
| 469 checkIndent, halfHeight, |
| 470 bgColors[state], edgeColor); |
| 471 } else if (extraParams->button.checked) { |
| 472 irect = validate(irect, part); |
| 473 nestedBoxes(canvas, irect, |
| 474 checkIndent, checkIndent, |
| 475 checkIndent, checkIndent, |
| 476 bgColors[state], edgeColor); |
| 477 } else { |
| 478 irect = validate(irect, part); |
| 479 box(canvas, irect, bgColors[state]); |
| 480 } |
| 481 break; |
| 482 |
| 483 case WebThemeEngine::PartRadio: |
| 484 irect = validate(irect, part); |
| 485 halfHeight = irect.height() / 2; |
| 486 if (extraParams->button.checked) { |
| 487 circle(canvas, irect, SkIntToScalar(halfHeight), bgColors[state]); |
| 488 circle(canvas, irect, SkIntToScalar(halfHeight - checkIndent), edgeC
olor); |
| 489 } else { |
| 490 circle(canvas, irect, SkIntToScalar(halfHeight), bgColors[state]); |
| 491 } |
| 492 break; |
| 493 |
| 494 case WebThemeEngine::PartButton: |
| 495 roundRect(canvas, irect, bgColors[state]); |
| 496 markState(canvas, irect, state); |
| 497 break; |
| 498 |
| 499 case WebThemeEngine::PartTextField: |
| 500 paint.setColor(extraParams->textField.backgroundColor); |
| 501 paint.setStyle(SkPaint::kFill_Style); |
| 502 canvas->drawIRect(irect, paint); |
| 503 |
| 504 paint.setColor(edgeColor); |
| 505 paint.setStyle(SkPaint::kStroke_Style); |
| 506 canvas->drawIRect(irect, paint); |
| 507 |
| 508 markState(canvas, irect, state); |
| 509 break; |
| 510 |
| 511 case WebThemeEngine::PartMenuList: |
| 512 if (extraParams->menuList.fillContentArea) { |
| 513 box(canvas, irect, extraParams->menuList.backgroundColor); |
| 514 } else { |
| 515 SkPaint paint; |
| 516 paint.setColor(edgeColor); |
| 517 paint.setStyle(SkPaint::kStroke_Style); |
| 518 canvas->drawIRect(irect, paint); |
| 519 } |
| 520 |
| 521 // clip the drop-down arrow to be inside the select box |
| 522 if (extraParams->menuList.arrowX - 4 > irect.fLeft) |
| 523 irect.fLeft = extraParams->menuList.arrowX - 4; |
| 524 if (extraParams->menuList.arrowX + 12 < irect.fRight) |
| 525 irect.fRight = extraParams->menuList.arrowX + 12; |
| 526 |
| 527 irect.fTop = extraParams->menuList.arrowY - (extraParams->menuList.arrow
Height) / 2; |
| 528 irect.fBottom = extraParams->menuList.arrowY + (extraParams->menuList.ar
rowHeight - 1) / 2; |
| 529 halfWidth = irect.width() / 2; |
| 530 quarterWidth = irect.width() / 4; |
| 531 |
| 532 if (state == WebThemeEngine::StateFocused) // FIXME: draw differenty? |
| 533 state = WebThemeEngine::StateNormal; |
| 534 box(canvas, irect, bgColors[state]); |
| 535 triangle(canvas, |
| 536 irect.fLeft + quarterWidth, irect.fTop, |
| 537 irect.fRight - quarterWidth, irect.fTop, |
| 538 irect.fLeft + halfWidth, irect.fBottom, |
| 539 edgeColor); |
| 540 |
| 541 break; |
| 542 |
| 543 case WebThemeEngine::PartSliderTrack: { |
| 544 SkIRect lirect = irect; |
| 545 |
| 546 // Draw a narrow rect for the track plus box hatches on the ends. |
| 547 if (state == WebThemeEngine::StateFocused) // FIXME: draw differently? |
| 548 state = WebThemeEngine::StateNormal; |
| 549 if (extraParams->slider.vertical) { |
| 550 lirect.inset(halfWidth - sliderIndent, noOffset); |
| 551 box(canvas, lirect, bgColors[state]); |
| 552 line(canvas, left, top, right, top, edgeColor); |
| 553 line(canvas, left, bottom, right, bottom, edgeColor); |
| 554 } else { |
| 555 lirect.inset(noOffset, halfHeight - sliderIndent); |
| 556 box(canvas, lirect, bgColors[state]); |
| 557 line(canvas, left, top, left, bottom, edgeColor); |
| 558 line(canvas, right, top, right, bottom, edgeColor); |
| 559 } |
| 560 break; |
| 561 } |
| 562 |
| 563 case WebThemeEngine::PartSliderThumb: |
| 564 if (state == WebThemeEngine::StateFocused) // FIXME: draw differently? |
| 565 state = WebThemeEngine::StateNormal; |
| 566 oval(canvas, irect, bgColors[state]); |
| 567 break; |
| 568 |
| 569 case WebThemeEngine::PartInnerSpinButton: { |
| 570 // stack half-height up and down arrows on top of each other |
| 571 SkIRect lirect; |
| 572 int halfHeight = rect.height / 2; |
| 573 if (extraParams->innerSpin.readOnly) |
| 574 state = blink::WebThemeEngine::StateDisabled; |
| 575 |
| 576 lirect.set(rect.x, rect.y, rect.x + rect.width - 1, rect.y + halfHeight
- 1); |
| 577 box(canvas, lirect, bgColors[state]); |
| 578 bottom = lirect.fBottom; |
| 579 quarterHeight = lirect.height() / 4; |
| 580 triangle(canvas, |
| 581 left + quarterWidth, bottom - quarterHeight, |
| 582 right - quarterWidth, bottom - quarterHeight, |
| 583 left + halfWidth, top + quarterHeight, |
| 584 edgeColor); |
| 585 |
| 586 lirect.set(rect.x, rect.y + halfHeight, rect.x + rect.width - 1, |
| 587 rect.y + 2 * halfHeight - 1); |
| 588 top = lirect.fTop; |
| 589 bottom = lirect.fBottom; |
| 590 quarterHeight = lirect.height() / 4; |
| 591 box(canvas, lirect, bgColors[state]); |
| 592 triangle(canvas, |
| 593 left + quarterWidth, top + quarterHeight, |
| 594 right - quarterWidth, top + quarterHeight, |
| 595 left + halfWidth, bottom - quarterHeight, |
| 596 edgeColor); |
| 597 markState(canvas, irect, state); |
| 598 break; |
| 599 } |
| 600 case WebThemeEngine::PartProgressBar: { |
| 601 paint.setColor(bgColors[state]); |
| 602 paint.setStyle(SkPaint::kFill_Style); |
| 603 canvas->drawIRect(irect, paint); |
| 604 |
| 605 // Emulate clipping |
| 606 SkIRect tofill = irect; |
| 607 if (extraParams->progressBar.determinate) { |
| 608 tofill.set(extraParams->progressBar.valueRectX, |
| 609 extraParams->progressBar.valueRectY, |
| 610 extraParams->progressBar.valueRectX + |
| 611 extraParams->progressBar.valueRectWidth - 1, |
| 612 extraParams->progressBar.valueRectY + |
| 613 extraParams->progressBar.valueRectHeight); |
| 614 } |
| 615 |
| 616 tofill.intersect(irect, tofill); |
| 617 paint.setColor(edgeColor); |
| 618 paint.setStyle(SkPaint::kFill_Style); |
| 619 canvas->drawIRect(tofill, paint); |
| 620 |
| 621 markState(canvas, irect, state); |
| 622 break; |
| 623 } |
| 624 default: |
| 625 // FIXME: Should we do something here to indicate that we got an invalid
part? |
| 626 // Unfortunately, we can't assert because we don't have access to WTF or
base. |
| 627 break; |
| 628 } |
| 629 } |
| 630 |
| 631 } // namespace WebTestRunner |
| OLD | NEW |