OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/native_theme/native_theme_base.h" | 5 #include "ui/native_theme/native_theme_base.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "third_party/skia/include/core/SkPaint.h" | 12 #include "cc/paint/paint_flags.h" |
| 13 #include "cc/paint/paint_shader.h" |
13 #include "third_party/skia/include/core/SkPath.h" | 14 #include "third_party/skia/include/core/SkPath.h" |
14 #include "third_party/skia/include/effects/SkGradientShader.h" | 15 #include "third_party/skia/include/effects/SkGradientShader.h" |
15 #include "ui/base/layout.h" | 16 #include "ui/base/layout.h" |
16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
17 #include "ui/base/ui_base_switches.h" | 18 #include "ui/base/ui_base_switches.h" |
18 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
19 #include "ui/gfx/color_palette.h" | 20 #include "ui/gfx/color_palette.h" |
20 #include "ui/gfx/color_utils.h" | 21 #include "ui/gfx/color_utils.h" |
21 #include "ui/gfx/geometry/rect.h" | 22 #include "ui/gfx/geometry/rect.h" |
22 #include "ui/gfx/geometry/rect_f.h" | 23 #include "ui/gfx/geometry/rect_f.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 case kWindowResizeGripper: | 150 case kWindowResizeGripper: |
150 NOTIMPLEMENTED(); | 151 NOTIMPLEMENTED(); |
151 break; | 152 break; |
152 default: | 153 default: |
153 NOTREACHED() << "Unknown theme part: " << part; | 154 NOTREACHED() << "Unknown theme part: " << part; |
154 break; | 155 break; |
155 } | 156 } |
156 return gfx::Size(); | 157 return gfx::Size(); |
157 } | 158 } |
158 | 159 |
159 void NativeThemeBase::Paint(SkCanvas* canvas, | 160 void NativeThemeBase::Paint(cc::PaintCanvas* canvas, |
160 Part part, | 161 Part part, |
161 State state, | 162 State state, |
162 const gfx::Rect& rect, | 163 const gfx::Rect& rect, |
163 const ExtraParams& extra) const { | 164 const ExtraParams& extra) const { |
164 if (rect.IsEmpty()) | 165 if (rect.IsEmpty()) |
165 return; | 166 return; |
166 | 167 |
167 canvas->save(); | 168 canvas->save(); |
168 canvas->clipRect(gfx::RectToSkRect(rect)); | 169 canvas->clipRect(gfx::RectToSkRect(rect)); |
169 | 170 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } | 252 } |
252 | 253 |
253 NativeThemeBase::NativeThemeBase() | 254 NativeThemeBase::NativeThemeBase() |
254 : scrollbar_width_(kDefaultScrollbarWidth), | 255 : scrollbar_width_(kDefaultScrollbarWidth), |
255 scrollbar_button_length_(kDefaultScrollbarButtonLength) { | 256 scrollbar_button_length_(kDefaultScrollbarButtonLength) { |
256 } | 257 } |
257 | 258 |
258 NativeThemeBase::~NativeThemeBase() { | 259 NativeThemeBase::~NativeThemeBase() { |
259 } | 260 } |
260 | 261 |
261 void NativeThemeBase::PaintArrowButton( | 262 void NativeThemeBase::PaintArrowButton(cc::PaintCanvas* canvas, |
262 SkCanvas* canvas, | 263 const gfx::Rect& rect, |
263 const gfx::Rect& rect, Part direction, State state) const { | 264 Part direction, |
264 SkPaint paint; | 265 State state) const { |
| 266 cc::PaintFlags paint; |
265 | 267 |
266 // Calculate button color. | 268 // Calculate button color. |
267 SkScalar trackHSV[3]; | 269 SkScalar trackHSV[3]; |
268 SkColorToHSV(track_color_, trackHSV); | 270 SkColorToHSV(track_color_, trackHSV); |
269 SkColor buttonColor = SaturateAndBrighten(trackHSV, 0, 0.2f); | 271 SkColor buttonColor = SaturateAndBrighten(trackHSV, 0, 0.2f); |
270 SkColor backgroundColor = buttonColor; | 272 SkColor backgroundColor = buttonColor; |
271 if (state == kPressed) { | 273 if (state == kPressed) { |
272 SkScalar buttonHSV[3]; | 274 SkScalar buttonHSV[3]; |
273 SkColorToHSV(buttonColor, buttonHSV); | 275 SkColorToHSV(buttonColor, buttonHSV); |
274 buttonColor = SaturateAndBrighten(buttonHSV, 0, -0.1f); | 276 buttonColor = SaturateAndBrighten(buttonHSV, 0, -0.1f); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 outline.rLineTo(-2, 2); | 320 outline.rLineTo(-2, 2); |
319 outline.rLineTo(0, rect.height() - 5); | 321 outline.rLineTo(0, rect.height() - 5); |
320 outline.rLineTo(2, 2); | 322 outline.rLineTo(2, 2); |
321 outline.rLineTo(rect.width() - 2, 0); | 323 outline.rLineTo(rect.width() - 2, 0); |
322 break; | 324 break; |
323 default: | 325 default: |
324 break; | 326 break; |
325 } | 327 } |
326 outline.close(); | 328 outline.close(); |
327 | 329 |
328 paint.setStyle(SkPaint::kFill_Style); | 330 paint.setStyle(cc::PaintFlags::kFill_Style); |
329 paint.setColor(buttonColor); | 331 paint.setColor(buttonColor); |
330 canvas->drawPath(outline, paint); | 332 canvas->drawPath(outline, paint); |
331 | 333 |
332 paint.setAntiAlias(true); | 334 paint.setAntiAlias(true); |
333 paint.setStyle(SkPaint::kStroke_Style); | 335 paint.setStyle(cc::PaintFlags::kStroke_Style); |
334 SkScalar thumbHSV[3]; | 336 SkScalar thumbHSV[3]; |
335 SkColorToHSV(thumb_inactive_color_, thumbHSV); | 337 SkColorToHSV(thumb_inactive_color_, thumbHSV); |
336 paint.setColor(OutlineColor(trackHSV, thumbHSV)); | 338 paint.setColor(OutlineColor(trackHSV, thumbHSV)); |
337 canvas->drawPath(outline, paint); | 339 canvas->drawPath(outline, paint); |
338 | 340 |
339 PaintArrow(canvas, rect, direction, GetArrowColor(state)); | 341 PaintArrow(canvas, rect, direction, GetArrowColor(state)); |
340 } | 342 } |
341 | 343 |
342 void NativeThemeBase::PaintArrow(SkCanvas* gc, | 344 void NativeThemeBase::PaintArrow(cc::PaintCanvas* gc, |
343 const gfx::Rect& rect, | 345 const gfx::Rect& rect, |
344 Part direction, | 346 Part direction, |
345 SkColor color) const { | 347 SkColor color) const { |
346 SkPaint paint; | 348 cc::PaintFlags paint; |
347 paint.setColor(color); | 349 paint.setColor(color); |
348 | 350 |
349 SkPath path = PathForArrow(rect, direction); | 351 SkPath path = PathForArrow(rect, direction); |
350 | 352 |
351 gc->drawPath(path, paint); | 353 gc->drawPath(path, paint); |
352 } | 354 } |
353 | 355 |
354 SkPath NativeThemeBase::PathForArrow(const gfx::Rect& rect, | 356 SkPath NativeThemeBase::PathForArrow(const gfx::Rect& rect, |
355 Part direction) const { | 357 Part direction) const { |
356 gfx::Rect bounding_rect = BoundingRectForArrow(rect); | 358 gfx::Rect bounding_rect = BoundingRectForArrow(rect); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 std::minmax(rect.width(), rect.height()); | 391 std::minmax(rect.width(), rect.height()); |
390 const int side_length_inset = 2 * std::ceil(rect_sides.second / 4.f); | 392 const int side_length_inset = 2 * std::ceil(rect_sides.second / 4.f); |
391 const int side_length = | 393 const int side_length = |
392 std::min(rect_sides.first, rect_sides.second - side_length_inset); | 394 std::min(rect_sides.first, rect_sides.second - side_length_inset); |
393 // When there are an odd number of pixels, put the extra on the top/left. | 395 // When there are an odd number of pixels, put the extra on the top/left. |
394 return gfx::Rect(rect.x() + (rect.width() - side_length + 1) / 2, | 396 return gfx::Rect(rect.x() + (rect.width() - side_length + 1) / 2, |
395 rect.y() + (rect.height() - side_length + 1) / 2, | 397 rect.y() + (rect.height() - side_length + 1) / 2, |
396 side_length, side_length); | 398 side_length, side_length); |
397 } | 399 } |
398 | 400 |
399 void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas, | 401 void NativeThemeBase::PaintScrollbarTrack( |
| 402 cc::PaintCanvas* canvas, |
400 Part part, | 403 Part part, |
401 State state, | 404 State state, |
402 const ScrollbarTrackExtraParams& extra_params, | 405 const ScrollbarTrackExtraParams& extra_params, |
403 const gfx::Rect& rect) const { | 406 const gfx::Rect& rect) const { |
404 SkPaint paint; | 407 cc::PaintFlags paint; |
405 SkIRect skrect; | 408 SkIRect skrect; |
406 | 409 |
407 skrect.set(rect.x(), rect.y(), rect.right(), rect.bottom()); | 410 skrect.set(rect.x(), rect.y(), rect.right(), rect.bottom()); |
408 SkScalar track_hsv[3]; | 411 SkScalar track_hsv[3]; |
409 SkColorToHSV(track_color_, track_hsv); | 412 SkColorToHSV(track_color_, track_hsv); |
410 paint.setColor(SaturateAndBrighten(track_hsv, 0, 0)); | 413 paint.setColor(SaturateAndBrighten(track_hsv, 0, 0)); |
411 canvas->drawIRect(skrect, paint); | 414 canvas->drawIRect(skrect, paint); |
412 | 415 |
413 SkScalar thumb_hsv[3]; | 416 SkScalar thumb_hsv[3]; |
414 SkColorToHSV(thumb_inactive_color_, thumb_hsv); | 417 SkColorToHSV(thumb_inactive_color_, thumb_hsv); |
415 | 418 |
416 paint.setColor(OutlineColor(track_hsv, thumb_hsv)); | 419 paint.setColor(OutlineColor(track_hsv, thumb_hsv)); |
417 DrawBox(canvas, rect, paint); | 420 DrawBox(canvas, rect, paint); |
418 } | 421 } |
419 | 422 |
420 void NativeThemeBase::PaintScrollbarThumb(SkCanvas* canvas, | 423 void NativeThemeBase::PaintScrollbarThumb(cc::PaintCanvas* canvas, |
421 Part part, | 424 Part part, |
422 State state, | 425 State state, |
423 const gfx::Rect& rect, | 426 const gfx::Rect& rect, |
424 ScrollbarOverlayColorTheme) const { | 427 ScrollbarOverlayColorTheme) const { |
425 const bool hovered = state == kHovered; | 428 const bool hovered = state == kHovered; |
426 const int midx = rect.x() + rect.width() / 2; | 429 const int midx = rect.x() + rect.width() / 2; |
427 const int midy = rect.y() + rect.height() / 2; | 430 const int midy = rect.y() + rect.height() / 2; |
428 const bool vertical = part == kScrollbarVerticalThumb; | 431 const bool vertical = part == kScrollbarVerticalThumb; |
429 | 432 |
430 SkScalar thumb[3]; | 433 SkScalar thumb[3]; |
431 SkColorToHSV(hovered ? thumb_active_color_ : thumb_inactive_color_, thumb); | 434 SkColorToHSV(hovered ? thumb_active_color_ : thumb_inactive_color_, thumb); |
432 | 435 |
433 SkPaint paint; | 436 cc::PaintFlags paint; |
434 paint.setColor(SaturateAndBrighten(thumb, 0, 0.02f)); | 437 paint.setColor(SaturateAndBrighten(thumb, 0, 0.02f)); |
435 | 438 |
436 SkIRect skrect; | 439 SkIRect skrect; |
437 if (vertical) | 440 if (vertical) |
438 skrect.set(rect.x(), rect.y(), midx + 1, rect.y() + rect.height()); | 441 skrect.set(rect.x(), rect.y(), midx + 1, rect.y() + rect.height()); |
439 else | 442 else |
440 skrect.set(rect.x(), rect.y(), rect.x() + rect.width(), midy + 1); | 443 skrect.set(rect.x(), rect.y(), rect.x() + rect.width(), midy + 1); |
441 | 444 |
442 canvas->drawIRect(skrect, paint); | 445 canvas->drawIRect(skrect, paint); |
443 | 446 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 paint); | 493 paint); |
491 DrawVertLine(canvas, | 494 DrawVertLine(canvas, |
492 midx + inter_grippy_offset, | 495 midx + inter_grippy_offset, |
493 midy - grippy_half_width, | 496 midy - grippy_half_width, |
494 midy + grippy_half_width, | 497 midy + grippy_half_width, |
495 paint); | 498 paint); |
496 } | 499 } |
497 } | 500 } |
498 } | 501 } |
499 | 502 |
500 void NativeThemeBase::PaintScrollbarCorner(SkCanvas* canvas, | 503 void NativeThemeBase::PaintScrollbarCorner(cc::PaintCanvas* canvas, |
501 State state, | 504 State state, |
502 const gfx::Rect& rect) const { | 505 const gfx::Rect& rect) const {} |
503 } | |
504 | 506 |
505 void NativeThemeBase::PaintCheckbox(SkCanvas* canvas, | 507 void NativeThemeBase::PaintCheckbox(cc::PaintCanvas* canvas, |
506 State state, | 508 State state, |
507 const gfx::Rect& rect, | 509 const gfx::Rect& rect, |
508 const ButtonExtraParams& button) const { | 510 const ButtonExtraParams& button) const { |
509 SkRect skrect = PaintCheckboxRadioCommon(canvas, state, rect, | 511 SkRect skrect = PaintCheckboxRadioCommon(canvas, state, rect, |
510 SkIntToScalar(2)); | 512 SkIntToScalar(2)); |
511 if (!skrect.isEmpty()) { | 513 if (!skrect.isEmpty()) { |
512 // Draw the checkmark / dash. | 514 // Draw the checkmark / dash. |
513 SkPaint paint; | 515 cc::PaintFlags paint; |
514 paint.setAntiAlias(true); | 516 paint.setAntiAlias(true); |
515 paint.setStyle(SkPaint::kStroke_Style); | 517 paint.setStyle(cc::PaintFlags::kStroke_Style); |
516 if (state == kDisabled) | 518 if (state == kDisabled) |
517 paint.setColor(kCheckboxStrokeDisabledColor); | 519 paint.setColor(kCheckboxStrokeDisabledColor); |
518 else | 520 else |
519 paint.setColor(kCheckboxStrokeColor); | 521 paint.setColor(kCheckboxStrokeColor); |
520 if (button.indeterminate) { | 522 if (button.indeterminate) { |
521 SkPath dash; | 523 SkPath dash; |
522 dash.moveTo(skrect.x() + skrect.width() * 0.16, | 524 dash.moveTo(skrect.x() + skrect.width() * 0.16, |
523 (skrect.y() + skrect.bottom()) / 2); | 525 (skrect.y() + skrect.bottom()) / 2); |
524 dash.rLineTo(skrect.width() * 0.68, 0); | 526 dash.rLineTo(skrect.width() * 0.68, 0); |
525 paint.setStrokeWidth(SkFloatToScalar(skrect.height() * 0.2)); | 527 paint.setStrokeWidth(SkFloatToScalar(skrect.height() * 0.2)); |
526 canvas->drawPath(dash, paint); | 528 canvas->drawPath(dash, paint); |
527 } else if (button.checked) { | 529 } else if (button.checked) { |
528 SkPath check; | 530 SkPath check; |
529 check.moveTo(skrect.x() + skrect.width() * 0.2, | 531 check.moveTo(skrect.x() + skrect.width() * 0.2, |
530 skrect.y() + skrect.height() * 0.5); | 532 skrect.y() + skrect.height() * 0.5); |
531 check.rLineTo(skrect.width() * 0.2, skrect.height() * 0.2); | 533 check.rLineTo(skrect.width() * 0.2, skrect.height() * 0.2); |
532 paint.setStrokeWidth(SkFloatToScalar(skrect.height() * 0.23)); | 534 paint.setStrokeWidth(SkFloatToScalar(skrect.height() * 0.23)); |
533 check.lineTo(skrect.right() - skrect.width() * 0.2, | 535 check.lineTo(skrect.right() - skrect.width() * 0.2, |
534 skrect.y() + skrect.height() * 0.2); | 536 skrect.y() + skrect.height() * 0.2); |
535 canvas->drawPath(check, paint); | 537 canvas->drawPath(check, paint); |
536 } | 538 } |
537 } | 539 } |
538 } | 540 } |
539 | 541 |
540 // Draws the common elements of checkboxes and radio buttons. | 542 // Draws the common elements of checkboxes and radio buttons. |
541 // Returns the rectangle within which any additional decorations should be | 543 // Returns the rectangle within which any additional decorations should be |
542 // drawn, or empty if none. | 544 // drawn, or empty if none. |
543 SkRect NativeThemeBase::PaintCheckboxRadioCommon( | 545 SkRect NativeThemeBase::PaintCheckboxRadioCommon( |
544 SkCanvas* canvas, | 546 cc::PaintCanvas* canvas, |
545 State state, | 547 State state, |
546 const gfx::Rect& rect, | 548 const gfx::Rect& rect, |
547 const SkScalar borderRadius) const { | 549 const SkScalar borderRadius) const { |
548 | |
549 SkRect skrect = gfx::RectToSkRect(rect); | 550 SkRect skrect = gfx::RectToSkRect(rect); |
550 | 551 |
551 // Use the largest square that fits inside the provided rectangle. | 552 // Use the largest square that fits inside the provided rectangle. |
552 // No other browser seems to support non-square widget, so accidentally | 553 // No other browser seems to support non-square widget, so accidentally |
553 // having non-square sizes is common (eg. amazon and webkit dev tools). | 554 // having non-square sizes is common (eg. amazon and webkit dev tools). |
554 if (skrect.width() != skrect.height()) { | 555 if (skrect.width() != skrect.height()) { |
555 SkScalar size = SkMinScalar(skrect.width(), skrect.height()); | 556 SkScalar size = SkMinScalar(skrect.width(), skrect.height()); |
556 skrect.inset((skrect.width() - size) / 2, (skrect.height() - size) / 2); | 557 skrect.inset((skrect.width() - size) / 2, (skrect.height() - size) / 2); |
557 } | 558 } |
558 | 559 |
559 // If the rectangle is too small then paint only a rectangle. We don't want | 560 // If the rectangle is too small then paint only a rectangle. We don't want |
560 // to have to worry about '- 1' and '+ 1' calculations below having overflow | 561 // to have to worry about '- 1' and '+ 1' calculations below having overflow |
561 // or underflow. | 562 // or underflow. |
562 if (skrect.width() <= 2) { | 563 if (skrect.width() <= 2) { |
563 SkPaint paint; | 564 cc::PaintFlags paint; |
564 paint.setColor(kCheckboxTinyColor); | 565 paint.setColor(kCheckboxTinyColor); |
565 paint.setStyle(SkPaint::kFill_Style); | 566 paint.setStyle(cc::PaintFlags::kFill_Style); |
566 canvas->drawRect(skrect, paint); | 567 canvas->drawRect(skrect, paint); |
567 // Too small to draw anything more. | 568 // Too small to draw anything more. |
568 return SkRect::MakeEmpty(); | 569 return SkRect::MakeEmpty(); |
569 } | 570 } |
570 | 571 |
571 // Make room for padding/drop shadow. | 572 // Make room for padding/drop shadow. |
572 AdjustCheckboxRadioRectForPadding(&skrect); | 573 AdjustCheckboxRadioRectForPadding(&skrect); |
573 | 574 |
574 // Draw the drop shadow below the widget. | 575 // Draw the drop shadow below the widget. |
575 if (state != kPressed) { | 576 if (state != kPressed) { |
576 SkPaint paint; | 577 cc::PaintFlags paint; |
577 paint.setAntiAlias(true); | 578 paint.setAntiAlias(true); |
578 SkRect shadowRect = skrect; | 579 SkRect shadowRect = skrect; |
579 shadowRect.offset(0, 1); | 580 shadowRect.offset(0, 1); |
580 if (state == kDisabled) | 581 if (state == kDisabled) |
581 paint.setColor(kCheckboxShadowDisabledColor); | 582 paint.setColor(kCheckboxShadowDisabledColor); |
582 else if (state == kHovered) | 583 else if (state == kHovered) |
583 paint.setColor(kCheckboxShadowHoveredColor); | 584 paint.setColor(kCheckboxShadowHoveredColor); |
584 else | 585 else |
585 paint.setColor(kCheckboxShadowColor); | 586 paint.setColor(kCheckboxShadowColor); |
586 paint.setStyle(SkPaint::kFill_Style); | 587 paint.setStyle(cc::PaintFlags::kFill_Style); |
587 canvas->drawRoundRect(shadowRect, borderRadius, borderRadius, paint); | 588 canvas->drawRoundRect(shadowRect, borderRadius, borderRadius, paint); |
588 } | 589 } |
589 | 590 |
590 // Draw the gradient-filled rectangle | 591 // Draw the gradient-filled rectangle |
591 SkPoint gradient_bounds[3]; | 592 SkPoint gradient_bounds[3]; |
592 gradient_bounds[0].set(skrect.x(), skrect.y()); | 593 gradient_bounds[0].set(skrect.x(), skrect.y()); |
593 gradient_bounds[1].set(skrect.x(), skrect.y() + skrect.height() * 0.38); | 594 gradient_bounds[1].set(skrect.x(), skrect.y() + skrect.height() * 0.38); |
594 gradient_bounds[2].set(skrect.x(), skrect.bottom()); | 595 gradient_bounds[2].set(skrect.x(), skrect.bottom()); |
595 const SkColor* startEndColors; | 596 const SkColor* startEndColors; |
596 if (state == kPressed) | 597 if (state == kPressed) |
597 startEndColors = kCheckboxGradientPressedColors; | 598 startEndColors = kCheckboxGradientPressedColors; |
598 else if (state == kHovered) | 599 else if (state == kHovered) |
599 startEndColors = kCheckboxGradientHoveredColors; | 600 startEndColors = kCheckboxGradientHoveredColors; |
600 else if (state == kDisabled) | 601 else if (state == kDisabled) |
601 startEndColors = kCheckboxGradientDisabledColors; | 602 startEndColors = kCheckboxGradientDisabledColors; |
602 else /* kNormal */ | 603 else /* kNormal */ |
603 startEndColors = kCheckboxGradientColors; | 604 startEndColors = kCheckboxGradientColors; |
604 SkColor colors[3] = {startEndColors[0], startEndColors[0], startEndColors[1]}; | 605 SkColor colors[3] = {startEndColors[0], startEndColors[0], startEndColors[1]}; |
605 SkPaint paint; | 606 cc::PaintFlags paint; |
606 paint.setAntiAlias(true); | 607 paint.setAntiAlias(true); |
607 paint.setShader(SkGradientShader::MakeLinear(gradient_bounds, colors, NULL, 3, | 608 paint.setShader(cc::WrapSkShader(SkGradientShader::MakeLinear( |
608 SkShader::kClamp_TileMode)); | 609 gradient_bounds, colors, NULL, 3, SkShader::kClamp_TileMode))); |
609 paint.setStyle(SkPaint::kFill_Style); | 610 paint.setStyle(cc::PaintFlags::kFill_Style); |
610 canvas->drawRoundRect(skrect, borderRadius, borderRadius, paint); | 611 canvas->drawRoundRect(skrect, borderRadius, borderRadius, paint); |
611 paint.setShader(NULL); | 612 paint.setShader(NULL); |
612 | 613 |
613 // Draw the border. | 614 // Draw the border. |
614 if (state == kHovered) | 615 if (state == kHovered) |
615 paint.setColor(kCheckboxBorderHoveredColor); | 616 paint.setColor(kCheckboxBorderHoveredColor); |
616 else if (state == kDisabled) | 617 else if (state == kDisabled) |
617 paint.setColor(kCheckboxBorderDisabledColor); | 618 paint.setColor(kCheckboxBorderDisabledColor); |
618 else | 619 else |
619 paint.setColor(kCheckboxBorderColor); | 620 paint.setColor(kCheckboxBorderColor); |
620 paint.setStyle(SkPaint::kStroke_Style); | 621 paint.setStyle(cc::PaintFlags::kStroke_Style); |
621 paint.setStrokeWidth(SkIntToScalar(1)); | 622 paint.setStrokeWidth(SkIntToScalar(1)); |
622 skrect.inset(SkFloatToScalar(.5f), SkFloatToScalar(.5f)); | 623 skrect.inset(SkFloatToScalar(.5f), SkFloatToScalar(.5f)); |
623 canvas->drawRoundRect(skrect, borderRadius, borderRadius, paint); | 624 canvas->drawRoundRect(skrect, borderRadius, borderRadius, paint); |
624 | 625 |
625 // Return the rectangle excluding the drop shadow for drawing any additional | 626 // Return the rectangle excluding the drop shadow for drawing any additional |
626 // decorations. | 627 // decorations. |
627 return skrect; | 628 return skrect; |
628 } | 629 } |
629 | 630 |
630 void NativeThemeBase::PaintRadio(SkCanvas* canvas, | 631 void NativeThemeBase::PaintRadio(cc::PaintCanvas* canvas, |
631 State state, | 632 State state, |
632 const gfx::Rect& rect, | 633 const gfx::Rect& rect, |
633 const ButtonExtraParams& button) const { | 634 const ButtonExtraParams& button) const { |
634 | |
635 // Most of a radio button is the same as a checkbox, except the the rounded | 635 // Most of a radio button is the same as a checkbox, except the the rounded |
636 // square is a circle (i.e. border radius >= 100%). | 636 // square is a circle (i.e. border radius >= 100%). |
637 const SkScalar radius = SkFloatToScalar( | 637 const SkScalar radius = SkFloatToScalar( |
638 static_cast<float>(std::max(rect.width(), rect.height())) / 2); | 638 static_cast<float>(std::max(rect.width(), rect.height())) / 2); |
639 SkRect skrect = PaintCheckboxRadioCommon(canvas, state, rect, radius); | 639 SkRect skrect = PaintCheckboxRadioCommon(canvas, state, rect, radius); |
640 if (!skrect.isEmpty() && button.checked) { | 640 if (!skrect.isEmpty() && button.checked) { |
641 // Draw the dot. | 641 // Draw the dot. |
642 SkPaint paint; | 642 cc::PaintFlags paint; |
643 paint.setAntiAlias(true); | 643 paint.setAntiAlias(true); |
644 paint.setStyle(SkPaint::kFill_Style); | 644 paint.setStyle(cc::PaintFlags::kFill_Style); |
645 if (state == kDisabled) | 645 if (state == kDisabled) |
646 paint.setColor(kRadioDotDisabledColor); | 646 paint.setColor(kRadioDotDisabledColor); |
647 else | 647 else |
648 paint.setColor(kRadioDotColor); | 648 paint.setColor(kRadioDotColor); |
649 skrect.inset(skrect.width() * 0.25, skrect.height() * 0.25); | 649 skrect.inset(skrect.width() * 0.25, skrect.height() * 0.25); |
650 // Use drawRoundedRect instead of drawOval to be completely consistent | 650 // Use drawRoundedRect instead of drawOval to be completely consistent |
651 // with the border in PaintCheckboxRadioNewCommon. | 651 // with the border in PaintCheckboxRadioNewCommon. |
652 canvas->drawRoundRect(skrect, radius, radius, paint); | 652 canvas->drawRoundRect(skrect, radius, radius, paint); |
653 } | 653 } |
654 } | 654 } |
655 | 655 |
656 void NativeThemeBase::PaintButton(SkCanvas* canvas, | 656 void NativeThemeBase::PaintButton(cc::PaintCanvas* canvas, |
657 State state, | 657 State state, |
658 const gfx::Rect& rect, | 658 const gfx::Rect& rect, |
659 const ButtonExtraParams& button) const { | 659 const ButtonExtraParams& button) const { |
660 SkPaint paint; | 660 cc::PaintFlags paint; |
661 SkRect skrect = gfx::RectToSkRect(rect); | 661 SkRect skrect = gfx::RectToSkRect(rect); |
662 SkColor base_color = button.background_color; | 662 SkColor base_color = button.background_color; |
663 | 663 |
664 color_utils::HSL base_hsl; | 664 color_utils::HSL base_hsl; |
665 color_utils::SkColorToHSL(base_color, &base_hsl); | 665 color_utils::SkColorToHSL(base_color, &base_hsl); |
666 | 666 |
667 // Our standard gradient is from 0xdd to 0xf8. This is the amount of | 667 // Our standard gradient is from 0xdd to 0xf8. This is the amount of |
668 // increased luminance between those values. | 668 // increased luminance between those values. |
669 SkColor light_color(BrightenColor(base_hsl, SkColorGetA(base_color), 0.105)); | 669 SkColor light_color(BrightenColor(base_hsl, SkColorGetA(base_color), 0.105)); |
670 | 670 |
671 // If the button is too small, fallback to drawing a single, solid color | 671 // If the button is too small, fallback to drawing a single, solid color |
672 if (rect.width() < 5 || rect.height() < 5) { | 672 if (rect.width() < 5 || rect.height() < 5) { |
673 paint.setColor(base_color); | 673 paint.setColor(base_color); |
674 canvas->drawRect(skrect, paint); | 674 canvas->drawRect(skrect, paint); |
675 return; | 675 return; |
676 } | 676 } |
677 | 677 |
678 paint.setColor(SK_ColorBLACK); | 678 paint.setColor(SK_ColorBLACK); |
679 SkPoint gradient_bounds[2] = { | 679 SkPoint gradient_bounds[2] = { |
680 gfx::PointToSkPoint(rect.origin()), | 680 gfx::PointToSkPoint(rect.origin()), |
681 gfx::PointToSkPoint(rect.bottom_left() - gfx::Vector2d(0, 1)) | 681 gfx::PointToSkPoint(rect.bottom_left() - gfx::Vector2d(0, 1)) |
682 }; | 682 }; |
683 if (state == kPressed) | 683 if (state == kPressed) |
684 std::swap(gradient_bounds[0], gradient_bounds[1]); | 684 std::swap(gradient_bounds[0], gradient_bounds[1]); |
685 SkColor colors[2] = { light_color, base_color }; | 685 SkColor colors[2] = { light_color, base_color }; |
686 | 686 |
687 paint.setStyle(SkPaint::kFill_Style); | 687 paint.setStyle(cc::PaintFlags::kFill_Style); |
688 paint.setAntiAlias(true); | 688 paint.setAntiAlias(true); |
689 paint.setShader( | 689 paint.setShader(cc::WrapSkShader(SkGradientShader::MakeLinear( |
690 SkGradientShader::MakeLinear( | 690 gradient_bounds, colors, NULL, 2, SkShader::kClamp_TileMode))); |
691 gradient_bounds, colors, NULL, 2, SkShader::kClamp_TileMode)); | |
692 | 691 |
693 canvas->drawRoundRect(skrect, SkIntToScalar(1), SkIntToScalar(1), paint); | 692 canvas->drawRoundRect(skrect, SkIntToScalar(1), SkIntToScalar(1), paint); |
694 paint.setShader(NULL); | 693 paint.setShader(NULL); |
695 | 694 |
696 if (button.has_border) { | 695 if (button.has_border) { |
697 int border_alpha = state == kHovered ? 0x80 : 0x55; | 696 int border_alpha = state == kHovered ? 0x80 : 0x55; |
698 if (button.is_focused) { | 697 if (button.is_focused) { |
699 border_alpha = 0xff; | 698 border_alpha = 0xff; |
700 paint.setColor(GetSystemColor(kColorId_FocusedBorderColor)); | 699 paint.setColor(GetSystemColor(kColorId_FocusedBorderColor)); |
701 } | 700 } |
702 paint.setStyle(SkPaint::kStroke_Style); | 701 paint.setStyle(cc::PaintFlags::kStroke_Style); |
703 paint.setStrokeWidth(SkIntToScalar(1)); | 702 paint.setStrokeWidth(SkIntToScalar(1)); |
704 paint.setAlpha(border_alpha); | 703 paint.setAlpha(border_alpha); |
705 skrect.inset(SkFloatToScalar(.5f), SkFloatToScalar(.5f)); | 704 skrect.inset(SkFloatToScalar(.5f), SkFloatToScalar(.5f)); |
706 canvas->drawRoundRect(skrect, SkIntToScalar(1), SkIntToScalar(1), paint); | 705 canvas->drawRoundRect(skrect, SkIntToScalar(1), SkIntToScalar(1), paint); |
707 } | 706 } |
708 } | 707 } |
709 | 708 |
710 void NativeThemeBase::PaintTextField(SkCanvas* canvas, | 709 void NativeThemeBase::PaintTextField(cc::PaintCanvas* canvas, |
711 State state, | 710 State state, |
712 const gfx::Rect& rect, | 711 const gfx::Rect& rect, |
713 const TextFieldExtraParams& text) const { | 712 const TextFieldExtraParams& text) const { |
714 SkRect bounds; | 713 SkRect bounds; |
715 bounds.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1); | 714 bounds.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1); |
716 | 715 |
717 SkPaint fill_paint; | 716 cc::PaintFlags fill_paint; |
718 fill_paint.setStyle(SkPaint::kFill_Style); | 717 fill_paint.setStyle(cc::PaintFlags::kFill_Style); |
719 fill_paint.setColor(text.background_color); | 718 fill_paint.setColor(text.background_color); |
720 canvas->drawRect(bounds, fill_paint); | 719 canvas->drawRect(bounds, fill_paint); |
721 | 720 |
722 // Text INPUT, listbox SELECT, and TEXTAREA have consistent borders. | 721 // Text INPUT, listbox SELECT, and TEXTAREA have consistent borders. |
723 // border: 1px solid #a9a9a9 | 722 // border: 1px solid #a9a9a9 |
724 SkPaint stroke_paint; | 723 cc::PaintFlags stroke_paint; |
725 stroke_paint.setStyle(SkPaint::kStroke_Style); | 724 stroke_paint.setStyle(cc::PaintFlags::kStroke_Style); |
726 stroke_paint.setColor(kTextBorderColor); | 725 stroke_paint.setColor(kTextBorderColor); |
727 canvas->drawRect(bounds, stroke_paint); | 726 canvas->drawRect(bounds, stroke_paint); |
728 } | 727 } |
729 | 728 |
730 void NativeThemeBase::PaintMenuList( | 729 void NativeThemeBase::PaintMenuList( |
731 SkCanvas* canvas, | 730 cc::PaintCanvas* canvas, |
732 State state, | 731 State state, |
733 const gfx::Rect& rect, | 732 const gfx::Rect& rect, |
734 const MenuListExtraParams& menu_list) const { | 733 const MenuListExtraParams& menu_list) const { |
735 // If a border radius is specified, we let the WebCore paint the background | 734 // If a border radius is specified, we let the WebCore paint the background |
736 // and the border of the control. | 735 // and the border of the control. |
737 if (!menu_list.has_border_radius) { | 736 if (!menu_list.has_border_radius) { |
738 ButtonExtraParams button = { 0 }; | 737 ButtonExtraParams button = { 0 }; |
739 button.background_color = menu_list.background_color; | 738 button.background_color = menu_list.background_color; |
740 button.has_border = menu_list.has_border; | 739 button.has_border = menu_list.has_border; |
741 PaintButton(canvas, state, rect, button); | 740 PaintButton(canvas, state, rect, button); |
742 } | 741 } |
743 | 742 |
744 SkPaint paint; | 743 cc::PaintFlags paint; |
745 paint.setColor(menu_list.arrow_color); | 744 paint.setColor(menu_list.arrow_color); |
746 paint.setAntiAlias(true); | 745 paint.setAntiAlias(true); |
747 paint.setStyle(SkPaint::kFill_Style); | 746 paint.setStyle(cc::PaintFlags::kFill_Style); |
748 | 747 |
749 int arrow_size = menu_list.arrow_size; | 748 int arrow_size = menu_list.arrow_size; |
750 gfx::Rect arrow( | 749 gfx::Rect arrow( |
751 menu_list.arrow_x, | 750 menu_list.arrow_x, |
752 menu_list.arrow_y - (arrow_size / 2), | 751 menu_list.arrow_y - (arrow_size / 2), |
753 arrow_size, | 752 arrow_size, |
754 arrow_size); | 753 arrow_size); |
755 | 754 |
756 // Constrain to the paint rect. | 755 // Constrain to the paint rect. |
757 arrow.Intersect(rect); | 756 arrow.Intersect(rect); |
758 | 757 |
759 SkPath path; | 758 SkPath path; |
760 path.moveTo(arrow.x(), arrow.y()); | 759 path.moveTo(arrow.x(), arrow.y()); |
761 path.lineTo(arrow.right(), arrow.y()); | 760 path.lineTo(arrow.right(), arrow.y()); |
762 path.lineTo(arrow.x() + arrow.width() / 2, arrow.bottom()); | 761 path.lineTo(arrow.x() + arrow.width() / 2, arrow.bottom()); |
763 path.close(); | 762 path.close(); |
764 canvas->drawPath(path, paint); | 763 canvas->drawPath(path, paint); |
765 } | 764 } |
766 | 765 |
767 void NativeThemeBase::PaintMenuPopupBackground( | 766 void NativeThemeBase::PaintMenuPopupBackground( |
768 SkCanvas* canvas, | 767 cc::PaintCanvas* canvas, |
769 const gfx::Size& size, | 768 const gfx::Size& size, |
770 const MenuBackgroundExtraParams& menu_background) const { | 769 const MenuBackgroundExtraParams& menu_background) const { |
771 canvas->drawColor(kMenuPopupBackgroundColor, SkBlendMode::kSrc); | 770 canvas->drawColor(kMenuPopupBackgroundColor, SkBlendMode::kSrc); |
772 } | 771 } |
773 | 772 |
774 void NativeThemeBase::PaintMenuItemBackground( | 773 void NativeThemeBase::PaintMenuItemBackground( |
775 SkCanvas* canvas, | 774 cc::PaintCanvas* canvas, |
776 State state, | 775 State state, |
777 const gfx::Rect& rect, | 776 const gfx::Rect& rect, |
778 const MenuItemExtraParams& menu_item) const { | 777 const MenuItemExtraParams& menu_item) const { |
779 // By default don't draw anything over the normal background. | 778 // By default don't draw anything over the normal background. |
780 } | 779 } |
781 | 780 |
782 void NativeThemeBase::PaintMenuSeparator( | 781 void NativeThemeBase::PaintMenuSeparator( |
783 SkCanvas* canvas, | 782 cc::PaintCanvas* canvas, |
784 State state, | 783 State state, |
785 const gfx::Rect& rect, | 784 const gfx::Rect& rect, |
786 const MenuSeparatorExtraParams& menu_separator) const { | 785 const MenuSeparatorExtraParams& menu_separator) const { |
787 SkPaint paint; | 786 cc::PaintFlags paint; |
788 paint.setColor(GetSystemColor(ui::NativeTheme::kColorId_MenuSeparatorColor)); | 787 paint.setColor(GetSystemColor(ui::NativeTheme::kColorId_MenuSeparatorColor)); |
789 canvas->drawRect(gfx::RectToSkRect(*menu_separator.paint_rect), paint); | 788 canvas->drawRect(gfx::RectToSkRect(*menu_separator.paint_rect), paint); |
790 } | 789 } |
791 | 790 |
792 void NativeThemeBase::PaintSliderTrack(SkCanvas* canvas, | 791 void NativeThemeBase::PaintSliderTrack(cc::PaintCanvas* canvas, |
793 State state, | 792 State state, |
794 const gfx::Rect& rect, | 793 const gfx::Rect& rect, |
795 const SliderExtraParams& slider) const { | 794 const SliderExtraParams& slider) const { |
796 const int kMidX = rect.x() + rect.width() / 2; | 795 const int kMidX = rect.x() + rect.width() / 2; |
797 const int kMidY = rect.y() + rect.height() / 2; | 796 const int kMidY = rect.y() + rect.height() / 2; |
798 | 797 |
799 SkPaint paint; | 798 cc::PaintFlags paint; |
800 paint.setColor(kSliderTrackBackgroundColor); | 799 paint.setColor(kSliderTrackBackgroundColor); |
801 | 800 |
802 SkRect skrect; | 801 SkRect skrect; |
803 if (slider.vertical) { | 802 if (slider.vertical) { |
804 skrect.set(std::max(rect.x(), kMidX - 2), | 803 skrect.set(std::max(rect.x(), kMidX - 2), |
805 rect.y(), | 804 rect.y(), |
806 std::min(rect.right(), kMidX + 2), | 805 std::min(rect.right(), kMidX + 2), |
807 rect.bottom()); | 806 rect.bottom()); |
808 } else { | 807 } else { |
809 skrect.set(rect.x(), | 808 skrect.set(rect.x(), |
810 std::max(rect.y(), kMidY - 2), | 809 std::max(rect.y(), kMidY - 2), |
811 rect.right(), | 810 rect.right(), |
812 std::min(rect.bottom(), kMidY + 2)); | 811 std::min(rect.bottom(), kMidY + 2)); |
813 } | 812 } |
814 canvas->drawRect(skrect, paint); | 813 canvas->drawRect(skrect, paint); |
815 } | 814 } |
816 | 815 |
817 void NativeThemeBase::PaintSliderThumb(SkCanvas* canvas, | 816 void NativeThemeBase::PaintSliderThumb(cc::PaintCanvas* canvas, |
818 State state, | 817 State state, |
819 const gfx::Rect& rect, | 818 const gfx::Rect& rect, |
820 const SliderExtraParams& slider) const { | 819 const SliderExtraParams& slider) const { |
821 const bool hovered = (state == kHovered) || slider.in_drag; | 820 const bool hovered = (state == kHovered) || slider.in_drag; |
822 const int kMidX = rect.x() + rect.width() / 2; | 821 const int kMidX = rect.x() + rect.width() / 2; |
823 const int kMidY = rect.y() + rect.height() / 2; | 822 const int kMidY = rect.y() + rect.height() / 2; |
824 | 823 |
825 SkPaint paint; | 824 cc::PaintFlags paint; |
826 paint.setColor(hovered ? SK_ColorWHITE : kSliderThumbLightGrey); | 825 paint.setColor(hovered ? SK_ColorWHITE : kSliderThumbLightGrey); |
827 | 826 |
828 SkIRect skrect; | 827 SkIRect skrect; |
829 if (slider.vertical) | 828 if (slider.vertical) |
830 skrect.set(rect.x(), rect.y(), kMidX + 1, rect.bottom()); | 829 skrect.set(rect.x(), rect.y(), kMidX + 1, rect.bottom()); |
831 else | 830 else |
832 skrect.set(rect.x(), rect.y(), rect.right(), kMidY + 1); | 831 skrect.set(rect.x(), rect.y(), rect.right(), kMidY + 1); |
833 | 832 |
834 canvas->drawIRect(skrect, paint); | 833 canvas->drawIRect(skrect, paint); |
835 | 834 |
836 paint.setColor(hovered ? kSliderThumbLightGrey : kSliderThumbDarkGrey); | 835 paint.setColor(hovered ? kSliderThumbLightGrey : kSliderThumbDarkGrey); |
837 | 836 |
838 if (slider.vertical) | 837 if (slider.vertical) |
839 skrect.set(kMidX + 1, rect.y(), rect.right(), rect.bottom()); | 838 skrect.set(kMidX + 1, rect.y(), rect.right(), rect.bottom()); |
840 else | 839 else |
841 skrect.set(rect.x(), kMidY + 1, rect.right(), rect.bottom()); | 840 skrect.set(rect.x(), kMidY + 1, rect.right(), rect.bottom()); |
842 | 841 |
843 canvas->drawIRect(skrect, paint); | 842 canvas->drawIRect(skrect, paint); |
844 | 843 |
845 paint.setColor(kSliderThumbBorderDarkGrey); | 844 paint.setColor(kSliderThumbBorderDarkGrey); |
846 DrawBox(canvas, rect, paint); | 845 DrawBox(canvas, rect, paint); |
847 | 846 |
848 if (rect.height() > 10 && rect.width() > 10) { | 847 if (rect.height() > 10 && rect.width() > 10) { |
849 DrawHorizLine(canvas, kMidX - 2, kMidX + 2, kMidY, paint); | 848 DrawHorizLine(canvas, kMidX - 2, kMidX + 2, kMidY, paint); |
850 DrawHorizLine(canvas, kMidX - 2, kMidX + 2, kMidY - 3, paint); | 849 DrawHorizLine(canvas, kMidX - 2, kMidX + 2, kMidY - 3, paint); |
851 DrawHorizLine(canvas, kMidX - 2, kMidX + 2, kMidY + 3, paint); | 850 DrawHorizLine(canvas, kMidX - 2, kMidX + 2, kMidY + 3, paint); |
852 } | 851 } |
853 } | 852 } |
854 | 853 |
855 void NativeThemeBase::PaintInnerSpinButton(SkCanvas* canvas, | 854 void NativeThemeBase::PaintInnerSpinButton( |
| 855 cc::PaintCanvas* canvas, |
856 State state, | 856 State state, |
857 const gfx::Rect& rect, | 857 const gfx::Rect& rect, |
858 const InnerSpinButtonExtraParams& spin_button) const { | 858 const InnerSpinButtonExtraParams& spin_button) const { |
859 if (spin_button.read_only) | 859 if (spin_button.read_only) |
860 state = kDisabled; | 860 state = kDisabled; |
861 | 861 |
862 State north_state = state; | 862 State north_state = state; |
863 State south_state = state; | 863 State south_state = state; |
864 if (spin_button.spin_up) | 864 if (spin_button.spin_up) |
865 south_state = south_state != kDisabled ? kNormal : kDisabled; | 865 south_state = south_state != kDisabled ? kNormal : kDisabled; |
866 else | 866 else |
867 north_state = north_state != kDisabled ? kNormal : kDisabled; | 867 north_state = north_state != kDisabled ? kNormal : kDisabled; |
868 | 868 |
869 gfx::Rect half = rect; | 869 gfx::Rect half = rect; |
870 half.set_height(rect.height() / 2); | 870 half.set_height(rect.height() / 2); |
871 PaintArrowButton(canvas, half, kScrollbarUpArrow, north_state); | 871 PaintArrowButton(canvas, half, kScrollbarUpArrow, north_state); |
872 | 872 |
873 half.set_y(rect.y() + rect.height() / 2); | 873 half.set_y(rect.y() + rect.height() / 2); |
874 PaintArrowButton(canvas, half, kScrollbarDownArrow, south_state); | 874 PaintArrowButton(canvas, half, kScrollbarDownArrow, south_state); |
875 } | 875 } |
876 | 876 |
877 void NativeThemeBase::PaintProgressBar( | 877 void NativeThemeBase::PaintProgressBar( |
878 SkCanvas* canvas, | 878 cc::PaintCanvas* canvas, |
879 State state, | 879 State state, |
880 const gfx::Rect& rect, | 880 const gfx::Rect& rect, |
881 const ProgressBarExtraParams& progress_bar) const { | 881 const ProgressBarExtraParams& progress_bar) const { |
882 DCHECK(!rect.IsEmpty()); | 882 DCHECK(!rect.IsEmpty()); |
883 | 883 |
884 canvas->drawColor(SK_ColorWHITE); | 884 canvas->drawColor(SK_ColorWHITE); |
885 | 885 |
886 // Draw the tick marks. The spacing between the tick marks is adjusted to | 886 // Draw the tick marks. The spacing between the tick marks is adjusted to |
887 // evenly divide into the width. | 887 // evenly divide into the width. |
888 SkPath path; | 888 SkPath path; |
889 int stroke_width = std::max(1, rect.height() / 18); | 889 int stroke_width = std::max(1, rect.height() / 18); |
890 int tick_width = 16 * stroke_width; | 890 int tick_width = 16 * stroke_width; |
891 int ticks = rect.width() / tick_width + (rect.width() % tick_width ? 1 : 0); | 891 int ticks = rect.width() / tick_width + (rect.width() % tick_width ? 1 : 0); |
892 SkScalar tick_spacing = SkIntToScalar(rect.width()) / ticks; | 892 SkScalar tick_spacing = SkIntToScalar(rect.width()) / ticks; |
893 for (int i = 1; i < ticks; ++i) { | 893 for (int i = 1; i < ticks; ++i) { |
894 path.moveTo(rect.x() + i * tick_spacing, rect.y()); | 894 path.moveTo(rect.x() + i * tick_spacing, rect.y()); |
895 path.rLineTo(0, rect.height()); | 895 path.rLineTo(0, rect.height()); |
896 } | 896 } |
897 SkPaint stroke_paint; | 897 cc::PaintFlags stroke_paint; |
898 stroke_paint.setColor(kProgressTickColor); | 898 stroke_paint.setColor(kProgressTickColor); |
899 stroke_paint.setStyle(SkPaint::kStroke_Style); | 899 stroke_paint.setStyle(cc::PaintFlags::kStroke_Style); |
900 stroke_paint.setStrokeWidth(stroke_width); | 900 stroke_paint.setStrokeWidth(stroke_width); |
901 canvas->drawPath(path, stroke_paint); | 901 canvas->drawPath(path, stroke_paint); |
902 | 902 |
903 // Draw progress. | 903 // Draw progress. |
904 gfx::Rect progress_rect(progress_bar.value_rect_x, progress_bar.value_rect_y, | 904 gfx::Rect progress_rect(progress_bar.value_rect_x, progress_bar.value_rect_y, |
905 progress_bar.value_rect_width, | 905 progress_bar.value_rect_width, |
906 progress_bar.value_rect_height); | 906 progress_bar.value_rect_height); |
907 SkPaint progress_paint; | 907 cc::PaintFlags progress_paint; |
908 progress_paint.setColor(kProgressValueColor); | 908 progress_paint.setColor(kProgressValueColor); |
909 progress_paint.setStyle(SkPaint::kFill_Style); | 909 progress_paint.setStyle(cc::PaintFlags::kFill_Style); |
910 canvas->drawRect(gfx::RectToSkRect(progress_rect), progress_paint); | 910 canvas->drawRect(gfx::RectToSkRect(progress_rect), progress_paint); |
911 | 911 |
912 // Draw the border. | 912 // Draw the border. |
913 gfx::RectF border_rect(rect); | 913 gfx::RectF border_rect(rect); |
914 border_rect.Inset(stroke_width / 2.0f, stroke_width / 2.0f); | 914 border_rect.Inset(stroke_width / 2.0f, stroke_width / 2.0f); |
915 stroke_paint.setColor(kProgressBorderColor); | 915 stroke_paint.setColor(kProgressBorderColor); |
916 canvas->drawRect(gfx::RectFToSkRect(border_rect), stroke_paint); | 916 canvas->drawRect(gfx::RectFToSkRect(border_rect), stroke_paint); |
917 } | 917 } |
918 | 918 |
919 void NativeThemeBase::PaintFrameTopArea( | 919 void NativeThemeBase::PaintFrameTopArea( |
(...skipping 25 matching lines...) Expand all Loading... |
945 if (state != kDisabled) | 945 if (state != kDisabled) |
946 return SK_ColorBLACK; | 946 return SK_ColorBLACK; |
947 | 947 |
948 SkScalar track_hsv[3]; | 948 SkScalar track_hsv[3]; |
949 SkColorToHSV(track_color_, track_hsv); | 949 SkColorToHSV(track_color_, track_hsv); |
950 SkScalar thumb_hsv[3]; | 950 SkScalar thumb_hsv[3]; |
951 SkColorToHSV(thumb_inactive_color_, thumb_hsv); | 951 SkColorToHSV(thumb_inactive_color_, thumb_hsv); |
952 return OutlineColor(track_hsv, thumb_hsv); | 952 return OutlineColor(track_hsv, thumb_hsv); |
953 } | 953 } |
954 | 954 |
955 void NativeThemeBase::DrawVertLine(SkCanvas* canvas, | 955 void NativeThemeBase::DrawVertLine(cc::PaintCanvas* canvas, |
956 int x, | 956 int x, |
957 int y1, | 957 int y1, |
958 int y2, | 958 int y2, |
959 const SkPaint& paint) const { | 959 const cc::PaintFlags& paint) const { |
960 SkIRect skrect; | 960 SkIRect skrect; |
961 skrect.set(x, y1, x + 1, y2 + 1); | 961 skrect.set(x, y1, x + 1, y2 + 1); |
962 canvas->drawIRect(skrect, paint); | 962 canvas->drawIRect(skrect, paint); |
963 } | 963 } |
964 | 964 |
965 void NativeThemeBase::DrawHorizLine(SkCanvas* canvas, | 965 void NativeThemeBase::DrawHorizLine(cc::PaintCanvas* canvas, |
966 int x1, | 966 int x1, |
967 int x2, | 967 int x2, |
968 int y, | 968 int y, |
969 const SkPaint& paint) const { | 969 const cc::PaintFlags& paint) const { |
970 SkIRect skrect; | 970 SkIRect skrect; |
971 skrect.set(x1, y, x2 + 1, y + 1); | 971 skrect.set(x1, y, x2 + 1, y + 1); |
972 canvas->drawIRect(skrect, paint); | 972 canvas->drawIRect(skrect, paint); |
973 } | 973 } |
974 | 974 |
975 void NativeThemeBase::DrawBox(SkCanvas* canvas, | 975 void NativeThemeBase::DrawBox(cc::PaintCanvas* canvas, |
976 const gfx::Rect& rect, | 976 const gfx::Rect& rect, |
977 const SkPaint& paint) const { | 977 const cc::PaintFlags& paint) const { |
978 const int right = rect.x() + rect.width() - 1; | 978 const int right = rect.x() + rect.width() - 1; |
979 const int bottom = rect.y() + rect.height() - 1; | 979 const int bottom = rect.y() + rect.height() - 1; |
980 DrawHorizLine(canvas, rect.x(), right, rect.y(), paint); | 980 DrawHorizLine(canvas, rect.x(), right, rect.y(), paint); |
981 DrawVertLine(canvas, right, rect.y(), bottom, paint); | 981 DrawVertLine(canvas, right, rect.y(), bottom, paint); |
982 DrawHorizLine(canvas, rect.x(), right, bottom, paint); | 982 DrawHorizLine(canvas, rect.x(), right, bottom, paint); |
983 DrawVertLine(canvas, rect.x(), rect.y(), bottom, paint); | 983 DrawVertLine(canvas, rect.x(), rect.y(), bottom, paint); |
984 } | 984 } |
985 | 985 |
986 SkScalar NativeThemeBase::Clamp(SkScalar value, | 986 SkScalar NativeThemeBase::Clamp(SkScalar value, |
987 SkScalar min, | 987 SkScalar min, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); | 1020 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); |
1021 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); | 1021 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); |
1022 | 1022 |
1023 if (hsv1[2] + hsv2[2] > 1.0) | 1023 if (hsv1[2] + hsv2[2] > 1.0) |
1024 diff = -diff; | 1024 diff = -diff; |
1025 | 1025 |
1026 return SaturateAndBrighten(hsv2, -0.2f, diff); | 1026 return SaturateAndBrighten(hsv2, -0.2f, diff); |
1027 } | 1027 } |
1028 | 1028 |
1029 } // namespace ui | 1029 } // namespace ui |
OLD | NEW |