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