| 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" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 scrollbar_button_length_(kDefaultScrollbarButtonLength) { | 256 scrollbar_button_length_(kDefaultScrollbarButtonLength) { |
| 257 } | 257 } |
| 258 | 258 |
| 259 NativeThemeBase::~NativeThemeBase() { | 259 NativeThemeBase::~NativeThemeBase() { |
| 260 } | 260 } |
| 261 | 261 |
| 262 void NativeThemeBase::PaintArrowButton(cc::PaintCanvas* canvas, | 262 void NativeThemeBase::PaintArrowButton(cc::PaintCanvas* canvas, |
| 263 const gfx::Rect& rect, | 263 const gfx::Rect& rect, |
| 264 Part direction, | 264 Part direction, |
| 265 State state) const { | 265 State state) const { |
| 266 cc::PaintFlags paint; | 266 cc::PaintFlags flags; |
| 267 | 267 |
| 268 // Calculate button color. | 268 // Calculate button color. |
| 269 SkScalar trackHSV[3]; | 269 SkScalar trackHSV[3]; |
| 270 SkColorToHSV(track_color_, trackHSV); | 270 SkColorToHSV(track_color_, trackHSV); |
| 271 SkColor buttonColor = SaturateAndBrighten(trackHSV, 0, 0.2f); | 271 SkColor buttonColor = SaturateAndBrighten(trackHSV, 0, 0.2f); |
| 272 SkColor backgroundColor = buttonColor; | 272 SkColor backgroundColor = buttonColor; |
| 273 if (state == kPressed) { | 273 if (state == kPressed) { |
| 274 SkScalar buttonHSV[3]; | 274 SkScalar buttonHSV[3]; |
| 275 SkColorToHSV(buttonColor, buttonHSV); | 275 SkColorToHSV(buttonColor, buttonHSV); |
| 276 buttonColor = SaturateAndBrighten(buttonHSV, 0, -0.1f); | 276 buttonColor = SaturateAndBrighten(buttonHSV, 0, -0.1f); |
| 277 } else if (state == kHovered) { | 277 } else if (state == kHovered) { |
| 278 SkScalar buttonHSV[3]; | 278 SkScalar buttonHSV[3]; |
| 279 SkColorToHSV(buttonColor, buttonHSV); | 279 SkColorToHSV(buttonColor, buttonHSV); |
| 280 buttonColor = SaturateAndBrighten(buttonHSV, 0, 0.05f); | 280 buttonColor = SaturateAndBrighten(buttonHSV, 0, 0.05f); |
| 281 } | 281 } |
| 282 | 282 |
| 283 SkIRect skrect; | 283 SkIRect skrect; |
| 284 skrect.set(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() | 284 skrect.set(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() |
| 285 + rect.height()); | 285 + rect.height()); |
| 286 // Paint the background (the area visible behind the rounded corners). | 286 // Paint the background (the area visible behind the rounded corners). |
| 287 paint.setColor(backgroundColor); | 287 flags.setColor(backgroundColor); |
| 288 canvas->drawIRect(skrect, paint); | 288 canvas->drawIRect(skrect, flags); |
| 289 | 289 |
| 290 // Paint the button's outline and fill the middle | 290 // Paint the button's outline and fill the middle |
| 291 SkPath outline; | 291 SkPath outline; |
| 292 switch (direction) { | 292 switch (direction) { |
| 293 case kScrollbarUpArrow: | 293 case kScrollbarUpArrow: |
| 294 outline.moveTo(rect.x() + 0.5, rect.y() + rect.height() + 0.5); | 294 outline.moveTo(rect.x() + 0.5, rect.y() + rect.height() + 0.5); |
| 295 outline.rLineTo(0, -(rect.height() - 2)); | 295 outline.rLineTo(0, -(rect.height() - 2)); |
| 296 outline.rLineTo(2, -2); | 296 outline.rLineTo(2, -2); |
| 297 outline.rLineTo(rect.width() - 5, 0); | 297 outline.rLineTo(rect.width() - 5, 0); |
| 298 outline.rLineTo(2, 2); | 298 outline.rLineTo(2, 2); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 320 outline.rLineTo(-2, 2); | 320 outline.rLineTo(-2, 2); |
| 321 outline.rLineTo(0, rect.height() - 5); | 321 outline.rLineTo(0, rect.height() - 5); |
| 322 outline.rLineTo(2, 2); | 322 outline.rLineTo(2, 2); |
| 323 outline.rLineTo(rect.width() - 2, 0); | 323 outline.rLineTo(rect.width() - 2, 0); |
| 324 break; | 324 break; |
| 325 default: | 325 default: |
| 326 break; | 326 break; |
| 327 } | 327 } |
| 328 outline.close(); | 328 outline.close(); |
| 329 | 329 |
| 330 paint.setStyle(cc::PaintFlags::kFill_Style); | 330 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 331 paint.setColor(buttonColor); | 331 flags.setColor(buttonColor); |
| 332 canvas->drawPath(outline, paint); | 332 canvas->drawPath(outline, flags); |
| 333 | 333 |
| 334 paint.setAntiAlias(true); | 334 flags.setAntiAlias(true); |
| 335 paint.setStyle(cc::PaintFlags::kStroke_Style); | 335 flags.setStyle(cc::PaintFlags::kStroke_Style); |
| 336 SkScalar thumbHSV[3]; | 336 SkScalar thumbHSV[3]; |
| 337 SkColorToHSV(thumb_inactive_color_, thumbHSV); | 337 SkColorToHSV(thumb_inactive_color_, thumbHSV); |
| 338 paint.setColor(OutlineColor(trackHSV, thumbHSV)); | 338 flags.setColor(OutlineColor(trackHSV, thumbHSV)); |
| 339 canvas->drawPath(outline, paint); | 339 canvas->drawPath(outline, flags); |
| 340 | 340 |
| 341 PaintArrow(canvas, rect, direction, GetArrowColor(state)); | 341 PaintArrow(canvas, rect, direction, GetArrowColor(state)); |
| 342 } | 342 } |
| 343 | 343 |
| 344 void NativeThemeBase::PaintArrow(cc::PaintCanvas* gc, | 344 void NativeThemeBase::PaintArrow(cc::PaintCanvas* gc, |
| 345 const gfx::Rect& rect, | 345 const gfx::Rect& rect, |
| 346 Part direction, | 346 Part direction, |
| 347 SkColor color) const { | 347 SkColor color) const { |
| 348 cc::PaintFlags paint; | 348 cc::PaintFlags flags; |
| 349 paint.setColor(color); | 349 flags.setColor(color); |
| 350 | 350 |
| 351 SkPath path = PathForArrow(rect, direction); | 351 SkPath path = PathForArrow(rect, direction); |
| 352 | 352 |
| 353 gc->drawPath(path, paint); | 353 gc->drawPath(path, flags); |
| 354 } | 354 } |
| 355 | 355 |
| 356 SkPath NativeThemeBase::PathForArrow(const gfx::Rect& rect, | 356 SkPath NativeThemeBase::PathForArrow(const gfx::Rect& rect, |
| 357 Part direction) const { | 357 Part direction) const { |
| 358 gfx::Rect bounding_rect = BoundingRectForArrow(rect); | 358 gfx::Rect bounding_rect = BoundingRectForArrow(rect); |
| 359 const gfx::PointF center = gfx::RectF(bounding_rect).CenterPoint(); | 359 const gfx::PointF center = gfx::RectF(bounding_rect).CenterPoint(); |
| 360 SkPath path; | 360 SkPath path; |
| 361 SkMatrix transform; | 361 SkMatrix transform; |
| 362 transform.setIdentity(); | 362 transform.setIdentity(); |
| 363 if (direction == kScrollbarUpArrow || direction == kScrollbarDownArrow) { | 363 if (direction == kScrollbarUpArrow || direction == kScrollbarDownArrow) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 rect.y() + (rect.height() - side_length + 1) / 2, | 397 rect.y() + (rect.height() - side_length + 1) / 2, |
| 398 side_length, side_length); | 398 side_length, side_length); |
| 399 } | 399 } |
| 400 | 400 |
| 401 void NativeThemeBase::PaintScrollbarTrack( | 401 void NativeThemeBase::PaintScrollbarTrack( |
| 402 cc::PaintCanvas* canvas, | 402 cc::PaintCanvas* canvas, |
| 403 Part part, | 403 Part part, |
| 404 State state, | 404 State state, |
| 405 const ScrollbarTrackExtraParams& extra_params, | 405 const ScrollbarTrackExtraParams& extra_params, |
| 406 const gfx::Rect& rect) const { | 406 const gfx::Rect& rect) const { |
| 407 cc::PaintFlags paint; | 407 cc::PaintFlags flags; |
| 408 SkIRect skrect; | 408 SkIRect skrect; |
| 409 | 409 |
| 410 skrect.set(rect.x(), rect.y(), rect.right(), rect.bottom()); | 410 skrect.set(rect.x(), rect.y(), rect.right(), rect.bottom()); |
| 411 SkScalar track_hsv[3]; | 411 SkScalar track_hsv[3]; |
| 412 SkColorToHSV(track_color_, track_hsv); | 412 SkColorToHSV(track_color_, track_hsv); |
| 413 paint.setColor(SaturateAndBrighten(track_hsv, 0, 0)); | 413 flags.setColor(SaturateAndBrighten(track_hsv, 0, 0)); |
| 414 canvas->drawIRect(skrect, paint); | 414 canvas->drawIRect(skrect, flags); |
| 415 | 415 |
| 416 SkScalar thumb_hsv[3]; | 416 SkScalar thumb_hsv[3]; |
| 417 SkColorToHSV(thumb_inactive_color_, thumb_hsv); | 417 SkColorToHSV(thumb_inactive_color_, thumb_hsv); |
| 418 | 418 |
| 419 paint.setColor(OutlineColor(track_hsv, thumb_hsv)); | 419 flags.setColor(OutlineColor(track_hsv, thumb_hsv)); |
| 420 DrawBox(canvas, rect, paint); | 420 DrawBox(canvas, rect, flags); |
| 421 } | 421 } |
| 422 | 422 |
| 423 void NativeThemeBase::PaintScrollbarThumb(cc::PaintCanvas* canvas, | 423 void NativeThemeBase::PaintScrollbarThumb(cc::PaintCanvas* canvas, |
| 424 Part part, | 424 Part part, |
| 425 State state, | 425 State state, |
| 426 const gfx::Rect& rect, | 426 const gfx::Rect& rect, |
| 427 ScrollbarOverlayColorTheme) const { | 427 ScrollbarOverlayColorTheme) const { |
| 428 const bool hovered = state == kHovered; | 428 const bool hovered = state == kHovered; |
| 429 const int midx = rect.x() + rect.width() / 2; | 429 const int midx = rect.x() + rect.width() / 2; |
| 430 const int midy = rect.y() + rect.height() / 2; | 430 const int midy = rect.y() + rect.height() / 2; |
| 431 const bool vertical = part == kScrollbarVerticalThumb; | 431 const bool vertical = part == kScrollbarVerticalThumb; |
| 432 | 432 |
| 433 SkScalar thumb[3]; | 433 SkScalar thumb[3]; |
| 434 SkColorToHSV(hovered ? thumb_active_color_ : thumb_inactive_color_, thumb); | 434 SkColorToHSV(hovered ? thumb_active_color_ : thumb_inactive_color_, thumb); |
| 435 | 435 |
| 436 cc::PaintFlags paint; | 436 cc::PaintFlags flags; |
| 437 paint.setColor(SaturateAndBrighten(thumb, 0, 0.02f)); | 437 flags.setColor(SaturateAndBrighten(thumb, 0, 0.02f)); |
| 438 | 438 |
| 439 SkIRect skrect; | 439 SkIRect skrect; |
| 440 if (vertical) | 440 if (vertical) |
| 441 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()); |
| 442 else | 442 else |
| 443 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); |
| 444 | 444 |
| 445 canvas->drawIRect(skrect, paint); | 445 canvas->drawIRect(skrect, flags); |
| 446 | 446 |
| 447 paint.setColor(SaturateAndBrighten(thumb, 0, -0.02f)); | 447 flags.setColor(SaturateAndBrighten(thumb, 0, -0.02f)); |
| 448 | 448 |
| 449 if (vertical) { | 449 if (vertical) { |
| 450 skrect.set( | 450 skrect.set( |
| 451 midx + 1, rect.y(), rect.x() + rect.width(), rect.y() + rect.height()); | 451 midx + 1, rect.y(), rect.x() + rect.width(), rect.y() + rect.height()); |
| 452 } else { | 452 } else { |
| 453 skrect.set( | 453 skrect.set( |
| 454 rect.x(), midy + 1, rect.x() + rect.width(), rect.y() + rect.height()); | 454 rect.x(), midy + 1, rect.x() + rect.width(), rect.y() + rect.height()); |
| 455 } | 455 } |
| 456 | 456 |
| 457 canvas->drawIRect(skrect, paint); | 457 canvas->drawIRect(skrect, flags); |
| 458 | 458 |
| 459 SkScalar track[3]; | 459 SkScalar track[3]; |
| 460 SkColorToHSV(track_color_, track); | 460 SkColorToHSV(track_color_, track); |
| 461 paint.setColor(OutlineColor(track, thumb)); | 461 flags.setColor(OutlineColor(track, thumb)); |
| 462 DrawBox(canvas, rect, paint); | 462 DrawBox(canvas, rect, flags); |
| 463 | 463 |
| 464 if (rect.height() > 10 && rect.width() > 10) { | 464 if (rect.height() > 10 && rect.width() > 10) { |
| 465 const int grippy_half_width = 2; | 465 const int grippy_half_width = 2; |
| 466 const int inter_grippy_offset = 3; | 466 const int inter_grippy_offset = 3; |
| 467 if (vertical) { | 467 if (vertical) { |
| 468 DrawHorizLine(canvas, | 468 DrawHorizLine(canvas, midx - grippy_half_width, midx + grippy_half_width, |
| 469 midx - grippy_half_width, | 469 midy - inter_grippy_offset, flags); |
| 470 midx + grippy_half_width, | 470 DrawHorizLine(canvas, midx - grippy_half_width, midx + grippy_half_width, |
| 471 midy - inter_grippy_offset, | 471 midy, flags); |
| 472 paint); | 472 DrawHorizLine(canvas, midx - grippy_half_width, midx + grippy_half_width, |
| 473 DrawHorizLine(canvas, | 473 midy + inter_grippy_offset, flags); |
| 474 midx - grippy_half_width, | |
| 475 midx + grippy_half_width, | |
| 476 midy, | |
| 477 paint); | |
| 478 DrawHorizLine(canvas, | |
| 479 midx - grippy_half_width, | |
| 480 midx + grippy_half_width, | |
| 481 midy + inter_grippy_offset, | |
| 482 paint); | |
| 483 } else { | 474 } else { |
| 484 DrawVertLine(canvas, | 475 DrawVertLine(canvas, midx - inter_grippy_offset, midy - grippy_half_width, |
| 485 midx - inter_grippy_offset, | 476 midy + grippy_half_width, flags); |
| 486 midy - grippy_half_width, | 477 DrawVertLine(canvas, midx, midy - grippy_half_width, |
| 487 midy + grippy_half_width, | 478 midy + grippy_half_width, flags); |
| 488 paint); | 479 DrawVertLine(canvas, midx + inter_grippy_offset, midy - grippy_half_width, |
| 489 DrawVertLine(canvas, | 480 midy + grippy_half_width, flags); |
| 490 midx, | |
| 491 midy - grippy_half_width, | |
| 492 midy + grippy_half_width, | |
| 493 paint); | |
| 494 DrawVertLine(canvas, | |
| 495 midx + inter_grippy_offset, | |
| 496 midy - grippy_half_width, | |
| 497 midy + grippy_half_width, | |
| 498 paint); | |
| 499 } | 481 } |
| 500 } | 482 } |
| 501 } | 483 } |
| 502 | 484 |
| 503 void NativeThemeBase::PaintScrollbarCorner(cc::PaintCanvas* canvas, | 485 void NativeThemeBase::PaintScrollbarCorner(cc::PaintCanvas* canvas, |
| 504 State state, | 486 State state, |
| 505 const gfx::Rect& rect) const {} | 487 const gfx::Rect& rect) const {} |
| 506 | 488 |
| 507 void NativeThemeBase::PaintCheckbox(cc::PaintCanvas* canvas, | 489 void NativeThemeBase::PaintCheckbox(cc::PaintCanvas* canvas, |
| 508 State state, | 490 State state, |
| 509 const gfx::Rect& rect, | 491 const gfx::Rect& rect, |
| 510 const ButtonExtraParams& button) const { | 492 const ButtonExtraParams& button) const { |
| 511 SkRect skrect = PaintCheckboxRadioCommon(canvas, state, rect, | 493 SkRect skrect = PaintCheckboxRadioCommon(canvas, state, rect, |
| 512 SkIntToScalar(2)); | 494 SkIntToScalar(2)); |
| 513 if (!skrect.isEmpty()) { | 495 if (!skrect.isEmpty()) { |
| 514 // Draw the checkmark / dash. | 496 // Draw the checkmark / dash. |
| 515 cc::PaintFlags paint; | 497 cc::PaintFlags flags; |
| 516 paint.setAntiAlias(true); | 498 flags.setAntiAlias(true); |
| 517 paint.setStyle(cc::PaintFlags::kStroke_Style); | 499 flags.setStyle(cc::PaintFlags::kStroke_Style); |
| 518 if (state == kDisabled) | 500 if (state == kDisabled) |
| 519 paint.setColor(kCheckboxStrokeDisabledColor); | 501 flags.setColor(kCheckboxStrokeDisabledColor); |
| 520 else | 502 else |
| 521 paint.setColor(kCheckboxStrokeColor); | 503 flags.setColor(kCheckboxStrokeColor); |
| 522 if (button.indeterminate) { | 504 if (button.indeterminate) { |
| 523 SkPath dash; | 505 SkPath dash; |
| 524 dash.moveTo(skrect.x() + skrect.width() * 0.16, | 506 dash.moveTo(skrect.x() + skrect.width() * 0.16, |
| 525 (skrect.y() + skrect.bottom()) / 2); | 507 (skrect.y() + skrect.bottom()) / 2); |
| 526 dash.rLineTo(skrect.width() * 0.68, 0); | 508 dash.rLineTo(skrect.width() * 0.68, 0); |
| 527 paint.setStrokeWidth(SkFloatToScalar(skrect.height() * 0.2)); | 509 flags.setStrokeWidth(SkFloatToScalar(skrect.height() * 0.2)); |
| 528 canvas->drawPath(dash, paint); | 510 canvas->drawPath(dash, flags); |
| 529 } else if (button.checked) { | 511 } else if (button.checked) { |
| 530 SkPath check; | 512 SkPath check; |
| 531 check.moveTo(skrect.x() + skrect.width() * 0.2, | 513 check.moveTo(skrect.x() + skrect.width() * 0.2, |
| 532 skrect.y() + skrect.height() * 0.5); | 514 skrect.y() + skrect.height() * 0.5); |
| 533 check.rLineTo(skrect.width() * 0.2, skrect.height() * 0.2); | 515 check.rLineTo(skrect.width() * 0.2, skrect.height() * 0.2); |
| 534 paint.setStrokeWidth(SkFloatToScalar(skrect.height() * 0.23)); | 516 flags.setStrokeWidth(SkFloatToScalar(skrect.height() * 0.23)); |
| 535 check.lineTo(skrect.right() - skrect.width() * 0.2, | 517 check.lineTo(skrect.right() - skrect.width() * 0.2, |
| 536 skrect.y() + skrect.height() * 0.2); | 518 skrect.y() + skrect.height() * 0.2); |
| 537 canvas->drawPath(check, paint); | 519 canvas->drawPath(check, flags); |
| 538 } | 520 } |
| 539 } | 521 } |
| 540 } | 522 } |
| 541 | 523 |
| 542 // Draws the common elements of checkboxes and radio buttons. | 524 // Draws the common elements of checkboxes and radio buttons. |
| 543 // Returns the rectangle within which any additional decorations should be | 525 // Returns the rectangle within which any additional decorations should be |
| 544 // drawn, or empty if none. | 526 // drawn, or empty if none. |
| 545 SkRect NativeThemeBase::PaintCheckboxRadioCommon( | 527 SkRect NativeThemeBase::PaintCheckboxRadioCommon( |
| 546 cc::PaintCanvas* canvas, | 528 cc::PaintCanvas* canvas, |
| 547 State state, | 529 State state, |
| 548 const gfx::Rect& rect, | 530 const gfx::Rect& rect, |
| 549 const SkScalar borderRadius) const { | 531 const SkScalar borderRadius) const { |
| 550 SkRect skrect = gfx::RectToSkRect(rect); | 532 SkRect skrect = gfx::RectToSkRect(rect); |
| 551 | 533 |
| 552 // Use the largest square that fits inside the provided rectangle. | 534 // Use the largest square that fits inside the provided rectangle. |
| 553 // No other browser seems to support non-square widget, so accidentally | 535 // No other browser seems to support non-square widget, so accidentally |
| 554 // having non-square sizes is common (eg. amazon and webkit dev tools). | 536 // having non-square sizes is common (eg. amazon and webkit dev tools). |
| 555 if (skrect.width() != skrect.height()) { | 537 if (skrect.width() != skrect.height()) { |
| 556 SkScalar size = SkMinScalar(skrect.width(), skrect.height()); | 538 SkScalar size = SkMinScalar(skrect.width(), skrect.height()); |
| 557 skrect.inset((skrect.width() - size) / 2, (skrect.height() - size) / 2); | 539 skrect.inset((skrect.width() - size) / 2, (skrect.height() - size) / 2); |
| 558 } | 540 } |
| 559 | 541 |
| 560 // If the rectangle is too small then paint only a rectangle. We don't want | 542 // If the rectangle is too small then paint only a rectangle. We don't want |
| 561 // to have to worry about '- 1' and '+ 1' calculations below having overflow | 543 // to have to worry about '- 1' and '+ 1' calculations below having overflow |
| 562 // or underflow. | 544 // or underflow. |
| 563 if (skrect.width() <= 2) { | 545 if (skrect.width() <= 2) { |
| 564 cc::PaintFlags paint; | 546 cc::PaintFlags flags; |
| 565 paint.setColor(kCheckboxTinyColor); | 547 flags.setColor(kCheckboxTinyColor); |
| 566 paint.setStyle(cc::PaintFlags::kFill_Style); | 548 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 567 canvas->drawRect(skrect, paint); | 549 canvas->drawRect(skrect, flags); |
| 568 // Too small to draw anything more. | 550 // Too small to draw anything more. |
| 569 return SkRect::MakeEmpty(); | 551 return SkRect::MakeEmpty(); |
| 570 } | 552 } |
| 571 | 553 |
| 572 // Make room for padding/drop shadow. | 554 // Make room for padding/drop shadow. |
| 573 AdjustCheckboxRadioRectForPadding(&skrect); | 555 AdjustCheckboxRadioRectForPadding(&skrect); |
| 574 | 556 |
| 575 // Draw the drop shadow below the widget. | 557 // Draw the drop shadow below the widget. |
| 576 if (state != kPressed) { | 558 if (state != kPressed) { |
| 577 cc::PaintFlags paint; | 559 cc::PaintFlags flags; |
| 578 paint.setAntiAlias(true); | 560 flags.setAntiAlias(true); |
| 579 SkRect shadowRect = skrect; | 561 SkRect shadowRect = skrect; |
| 580 shadowRect.offset(0, 1); | 562 shadowRect.offset(0, 1); |
| 581 if (state == kDisabled) | 563 if (state == kDisabled) |
| 582 paint.setColor(kCheckboxShadowDisabledColor); | 564 flags.setColor(kCheckboxShadowDisabledColor); |
| 583 else if (state == kHovered) | 565 else if (state == kHovered) |
| 584 paint.setColor(kCheckboxShadowHoveredColor); | 566 flags.setColor(kCheckboxShadowHoveredColor); |
| 585 else | 567 else |
| 586 paint.setColor(kCheckboxShadowColor); | 568 flags.setColor(kCheckboxShadowColor); |
| 587 paint.setStyle(cc::PaintFlags::kFill_Style); | 569 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 588 canvas->drawRoundRect(shadowRect, borderRadius, borderRadius, paint); | 570 canvas->drawRoundRect(shadowRect, borderRadius, borderRadius, flags); |
| 589 } | 571 } |
| 590 | 572 |
| 591 // Draw the gradient-filled rectangle | 573 // Draw the gradient-filled rectangle |
| 592 SkPoint gradient_bounds[3]; | 574 SkPoint gradient_bounds[3]; |
| 593 gradient_bounds[0].set(skrect.x(), skrect.y()); | 575 gradient_bounds[0].set(skrect.x(), skrect.y()); |
| 594 gradient_bounds[1].set(skrect.x(), skrect.y() + skrect.height() * 0.38); | 576 gradient_bounds[1].set(skrect.x(), skrect.y() + skrect.height() * 0.38); |
| 595 gradient_bounds[2].set(skrect.x(), skrect.bottom()); | 577 gradient_bounds[2].set(skrect.x(), skrect.bottom()); |
| 596 const SkColor* startEndColors; | 578 const SkColor* startEndColors; |
| 597 if (state == kPressed) | 579 if (state == kPressed) |
| 598 startEndColors = kCheckboxGradientPressedColors; | 580 startEndColors = kCheckboxGradientPressedColors; |
| 599 else if (state == kHovered) | 581 else if (state == kHovered) |
| 600 startEndColors = kCheckboxGradientHoveredColors; | 582 startEndColors = kCheckboxGradientHoveredColors; |
| 601 else if (state == kDisabled) | 583 else if (state == kDisabled) |
| 602 startEndColors = kCheckboxGradientDisabledColors; | 584 startEndColors = kCheckboxGradientDisabledColors; |
| 603 else /* kNormal */ | 585 else /* kNormal */ |
| 604 startEndColors = kCheckboxGradientColors; | 586 startEndColors = kCheckboxGradientColors; |
| 605 SkColor colors[3] = {startEndColors[0], startEndColors[0], startEndColors[1]}; | 587 SkColor colors[3] = {startEndColors[0], startEndColors[0], startEndColors[1]}; |
| 606 cc::PaintFlags paint; | 588 cc::PaintFlags flags; |
| 607 paint.setAntiAlias(true); | 589 flags.setAntiAlias(true); |
| 608 paint.setShader(cc::WrapSkShader(SkGradientShader::MakeLinear( | 590 flags.setShader(cc::WrapSkShader(SkGradientShader::MakeLinear( |
| 609 gradient_bounds, colors, NULL, 3, SkShader::kClamp_TileMode))); | 591 gradient_bounds, colors, NULL, 3, SkShader::kClamp_TileMode))); |
| 610 paint.setStyle(cc::PaintFlags::kFill_Style); | 592 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 611 canvas->drawRoundRect(skrect, borderRadius, borderRadius, paint); | 593 canvas->drawRoundRect(skrect, borderRadius, borderRadius, flags); |
| 612 paint.setShader(NULL); | 594 flags.setShader(NULL); |
| 613 | 595 |
| 614 // Draw the border. | 596 // Draw the border. |
| 615 if (state == kHovered) | 597 if (state == kHovered) |
| 616 paint.setColor(kCheckboxBorderHoveredColor); | 598 flags.setColor(kCheckboxBorderHoveredColor); |
| 617 else if (state == kDisabled) | 599 else if (state == kDisabled) |
| 618 paint.setColor(kCheckboxBorderDisabledColor); | 600 flags.setColor(kCheckboxBorderDisabledColor); |
| 619 else | 601 else |
| 620 paint.setColor(kCheckboxBorderColor); | 602 flags.setColor(kCheckboxBorderColor); |
| 621 paint.setStyle(cc::PaintFlags::kStroke_Style); | 603 flags.setStyle(cc::PaintFlags::kStroke_Style); |
| 622 paint.setStrokeWidth(SkIntToScalar(1)); | 604 flags.setStrokeWidth(SkIntToScalar(1)); |
| 623 skrect.inset(SkFloatToScalar(.5f), SkFloatToScalar(.5f)); | 605 skrect.inset(SkFloatToScalar(.5f), SkFloatToScalar(.5f)); |
| 624 canvas->drawRoundRect(skrect, borderRadius, borderRadius, paint); | 606 canvas->drawRoundRect(skrect, borderRadius, borderRadius, flags); |
| 625 | 607 |
| 626 // Return the rectangle excluding the drop shadow for drawing any additional | 608 // Return the rectangle excluding the drop shadow for drawing any additional |
| 627 // decorations. | 609 // decorations. |
| 628 return skrect; | 610 return skrect; |
| 629 } | 611 } |
| 630 | 612 |
| 631 void NativeThemeBase::PaintRadio(cc::PaintCanvas* canvas, | 613 void NativeThemeBase::PaintRadio(cc::PaintCanvas* canvas, |
| 632 State state, | 614 State state, |
| 633 const gfx::Rect& rect, | 615 const gfx::Rect& rect, |
| 634 const ButtonExtraParams& button) const { | 616 const ButtonExtraParams& button) const { |
| 635 // Most of a radio button is the same as a checkbox, except the the rounded | 617 // 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%). | 618 // square is a circle (i.e. border radius >= 100%). |
| 637 const SkScalar radius = SkFloatToScalar( | 619 const SkScalar radius = SkFloatToScalar( |
| 638 static_cast<float>(std::max(rect.width(), rect.height())) / 2); | 620 static_cast<float>(std::max(rect.width(), rect.height())) / 2); |
| 639 SkRect skrect = PaintCheckboxRadioCommon(canvas, state, rect, radius); | 621 SkRect skrect = PaintCheckboxRadioCommon(canvas, state, rect, radius); |
| 640 if (!skrect.isEmpty() && button.checked) { | 622 if (!skrect.isEmpty() && button.checked) { |
| 641 // Draw the dot. | 623 // Draw the dot. |
| 642 cc::PaintFlags paint; | 624 cc::PaintFlags flags; |
| 643 paint.setAntiAlias(true); | 625 flags.setAntiAlias(true); |
| 644 paint.setStyle(cc::PaintFlags::kFill_Style); | 626 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 645 if (state == kDisabled) | 627 if (state == kDisabled) |
| 646 paint.setColor(kRadioDotDisabledColor); | 628 flags.setColor(kRadioDotDisabledColor); |
| 647 else | 629 else |
| 648 paint.setColor(kRadioDotColor); | 630 flags.setColor(kRadioDotColor); |
| 649 skrect.inset(skrect.width() * 0.25, skrect.height() * 0.25); | 631 skrect.inset(skrect.width() * 0.25, skrect.height() * 0.25); |
| 650 // Use drawRoundedRect instead of drawOval to be completely consistent | 632 // Use drawRoundedRect instead of drawOval to be completely consistent |
| 651 // with the border in PaintCheckboxRadioNewCommon. | 633 // with the border in PaintCheckboxRadioNewCommon. |
| 652 canvas->drawRoundRect(skrect, radius, radius, paint); | 634 canvas->drawRoundRect(skrect, radius, radius, flags); |
| 653 } | 635 } |
| 654 } | 636 } |
| 655 | 637 |
| 656 void NativeThemeBase::PaintButton(cc::PaintCanvas* canvas, | 638 void NativeThemeBase::PaintButton(cc::PaintCanvas* canvas, |
| 657 State state, | 639 State state, |
| 658 const gfx::Rect& rect, | 640 const gfx::Rect& rect, |
| 659 const ButtonExtraParams& button) const { | 641 const ButtonExtraParams& button) const { |
| 660 cc::PaintFlags paint; | 642 cc::PaintFlags flags; |
| 661 SkRect skrect = gfx::RectToSkRect(rect); | 643 SkRect skrect = gfx::RectToSkRect(rect); |
| 662 SkColor base_color = button.background_color; | 644 SkColor base_color = button.background_color; |
| 663 | 645 |
| 664 color_utils::HSL base_hsl; | 646 color_utils::HSL base_hsl; |
| 665 color_utils::SkColorToHSL(base_color, &base_hsl); | 647 color_utils::SkColorToHSL(base_color, &base_hsl); |
| 666 | 648 |
| 667 // Our standard gradient is from 0xdd to 0xf8. This is the amount of | 649 // Our standard gradient is from 0xdd to 0xf8. This is the amount of |
| 668 // increased luminance between those values. | 650 // increased luminance between those values. |
| 669 SkColor light_color(BrightenColor(base_hsl, SkColorGetA(base_color), 0.105)); | 651 SkColor light_color(BrightenColor(base_hsl, SkColorGetA(base_color), 0.105)); |
| 670 | 652 |
| 671 // If the button is too small, fallback to drawing a single, solid color | 653 // If the button is too small, fallback to drawing a single, solid color |
| 672 if (rect.width() < 5 || rect.height() < 5) { | 654 if (rect.width() < 5 || rect.height() < 5) { |
| 673 paint.setColor(base_color); | 655 flags.setColor(base_color); |
| 674 canvas->drawRect(skrect, paint); | 656 canvas->drawRect(skrect, flags); |
| 675 return; | 657 return; |
| 676 } | 658 } |
| 677 | 659 |
| 678 paint.setColor(SK_ColorBLACK); | 660 flags.setColor(SK_ColorBLACK); |
| 679 SkPoint gradient_bounds[2] = { | 661 SkPoint gradient_bounds[2] = { |
| 680 gfx::PointToSkPoint(rect.origin()), | 662 gfx::PointToSkPoint(rect.origin()), |
| 681 gfx::PointToSkPoint(rect.bottom_left() - gfx::Vector2d(0, 1)) | 663 gfx::PointToSkPoint(rect.bottom_left() - gfx::Vector2d(0, 1)) |
| 682 }; | 664 }; |
| 683 if (state == kPressed) | 665 if (state == kPressed) |
| 684 std::swap(gradient_bounds[0], gradient_bounds[1]); | 666 std::swap(gradient_bounds[0], gradient_bounds[1]); |
| 685 SkColor colors[2] = { light_color, base_color }; | 667 SkColor colors[2] = { light_color, base_color }; |
| 686 | 668 |
| 687 paint.setStyle(cc::PaintFlags::kFill_Style); | 669 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 688 paint.setAntiAlias(true); | 670 flags.setAntiAlias(true); |
| 689 paint.setShader(cc::WrapSkShader(SkGradientShader::MakeLinear( | 671 flags.setShader(cc::WrapSkShader(SkGradientShader::MakeLinear( |
| 690 gradient_bounds, colors, NULL, 2, SkShader::kClamp_TileMode))); | 672 gradient_bounds, colors, NULL, 2, SkShader::kClamp_TileMode))); |
| 691 | 673 |
| 692 canvas->drawRoundRect(skrect, SkIntToScalar(1), SkIntToScalar(1), paint); | 674 canvas->drawRoundRect(skrect, SkIntToScalar(1), SkIntToScalar(1), flags); |
| 693 paint.setShader(NULL); | 675 flags.setShader(NULL); |
| 694 | 676 |
| 695 if (button.has_border) { | 677 if (button.has_border) { |
| 696 int border_alpha = state == kHovered ? 0x80 : 0x55; | 678 int border_alpha = state == kHovered ? 0x80 : 0x55; |
| 697 if (button.is_focused) { | 679 if (button.is_focused) { |
| 698 border_alpha = 0xff; | 680 border_alpha = 0xff; |
| 699 paint.setColor(GetSystemColor(kColorId_FocusedBorderColor)); | 681 flags.setColor(GetSystemColor(kColorId_FocusedBorderColor)); |
| 700 } | 682 } |
| 701 paint.setStyle(cc::PaintFlags::kStroke_Style); | 683 flags.setStyle(cc::PaintFlags::kStroke_Style); |
| 702 paint.setStrokeWidth(SkIntToScalar(1)); | 684 flags.setStrokeWidth(SkIntToScalar(1)); |
| 703 paint.setAlpha(border_alpha); | 685 flags.setAlpha(border_alpha); |
| 704 skrect.inset(SkFloatToScalar(.5f), SkFloatToScalar(.5f)); | 686 skrect.inset(SkFloatToScalar(.5f), SkFloatToScalar(.5f)); |
| 705 canvas->drawRoundRect(skrect, SkIntToScalar(1), SkIntToScalar(1), paint); | 687 canvas->drawRoundRect(skrect, SkIntToScalar(1), SkIntToScalar(1), flags); |
| 706 } | 688 } |
| 707 } | 689 } |
| 708 | 690 |
| 709 void NativeThemeBase::PaintTextField(cc::PaintCanvas* canvas, | 691 void NativeThemeBase::PaintTextField(cc::PaintCanvas* canvas, |
| 710 State state, | 692 State state, |
| 711 const gfx::Rect& rect, | 693 const gfx::Rect& rect, |
| 712 const TextFieldExtraParams& text) const { | 694 const TextFieldExtraParams& text) const { |
| 713 SkRect bounds; | 695 SkRect bounds; |
| 714 bounds.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1); | 696 bounds.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1); |
| 715 | 697 |
| 716 cc::PaintFlags fill_paint; | 698 cc::PaintFlags fill_flags; |
| 717 fill_paint.setStyle(cc::PaintFlags::kFill_Style); | 699 fill_flags.setStyle(cc::PaintFlags::kFill_Style); |
| 718 fill_paint.setColor(text.background_color); | 700 fill_flags.setColor(text.background_color); |
| 719 canvas->drawRect(bounds, fill_paint); | 701 canvas->drawRect(bounds, fill_flags); |
| 720 | 702 |
| 721 // Text INPUT, listbox SELECT, and TEXTAREA have consistent borders. | 703 // Text INPUT, listbox SELECT, and TEXTAREA have consistent borders. |
| 722 // border: 1px solid #a9a9a9 | 704 // border: 1px solid #a9a9a9 |
| 723 cc::PaintFlags stroke_paint; | 705 cc::PaintFlags stroke_flags; |
| 724 stroke_paint.setStyle(cc::PaintFlags::kStroke_Style); | 706 stroke_flags.setStyle(cc::PaintFlags::kStroke_Style); |
| 725 stroke_paint.setColor(kTextBorderColor); | 707 stroke_flags.setColor(kTextBorderColor); |
| 726 canvas->drawRect(bounds, stroke_paint); | 708 canvas->drawRect(bounds, stroke_flags); |
| 727 } | 709 } |
| 728 | 710 |
| 729 void NativeThemeBase::PaintMenuList( | 711 void NativeThemeBase::PaintMenuList( |
| 730 cc::PaintCanvas* canvas, | 712 cc::PaintCanvas* canvas, |
| 731 State state, | 713 State state, |
| 732 const gfx::Rect& rect, | 714 const gfx::Rect& rect, |
| 733 const MenuListExtraParams& menu_list) const { | 715 const MenuListExtraParams& menu_list) const { |
| 734 // If a border radius is specified, we let the WebCore paint the background | 716 // If a border radius is specified, we let the WebCore paint the background |
| 735 // and the border of the control. | 717 // and the border of the control. |
| 736 if (!menu_list.has_border_radius) { | 718 if (!menu_list.has_border_radius) { |
| 737 ButtonExtraParams button = { 0 }; | 719 ButtonExtraParams button = { 0 }; |
| 738 button.background_color = menu_list.background_color; | 720 button.background_color = menu_list.background_color; |
| 739 button.has_border = menu_list.has_border; | 721 button.has_border = menu_list.has_border; |
| 740 PaintButton(canvas, state, rect, button); | 722 PaintButton(canvas, state, rect, button); |
| 741 } | 723 } |
| 742 | 724 |
| 743 cc::PaintFlags paint; | 725 cc::PaintFlags flags; |
| 744 paint.setColor(menu_list.arrow_color); | 726 flags.setColor(menu_list.arrow_color); |
| 745 paint.setAntiAlias(true); | 727 flags.setAntiAlias(true); |
| 746 paint.setStyle(cc::PaintFlags::kFill_Style); | 728 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 747 | 729 |
| 748 int arrow_size = menu_list.arrow_size; | 730 int arrow_size = menu_list.arrow_size; |
| 749 gfx::Rect arrow( | 731 gfx::Rect arrow( |
| 750 menu_list.arrow_x, | 732 menu_list.arrow_x, |
| 751 menu_list.arrow_y - (arrow_size / 2), | 733 menu_list.arrow_y - (arrow_size / 2), |
| 752 arrow_size, | 734 arrow_size, |
| 753 arrow_size); | 735 arrow_size); |
| 754 | 736 |
| 755 // Constrain to the paint rect. | 737 // Constrain to the paint rect. |
| 756 arrow.Intersect(rect); | 738 arrow.Intersect(rect); |
| 757 | 739 |
| 758 SkPath path; | 740 SkPath path; |
| 759 path.moveTo(arrow.x(), arrow.y()); | 741 path.moveTo(arrow.x(), arrow.y()); |
| 760 path.lineTo(arrow.right(), arrow.y()); | 742 path.lineTo(arrow.right(), arrow.y()); |
| 761 path.lineTo(arrow.x() + arrow.width() / 2, arrow.bottom()); | 743 path.lineTo(arrow.x() + arrow.width() / 2, arrow.bottom()); |
| 762 path.close(); | 744 path.close(); |
| 763 canvas->drawPath(path, paint); | 745 canvas->drawPath(path, flags); |
| 764 } | 746 } |
| 765 | 747 |
| 766 void NativeThemeBase::PaintMenuPopupBackground( | 748 void NativeThemeBase::PaintMenuPopupBackground( |
| 767 cc::PaintCanvas* canvas, | 749 cc::PaintCanvas* canvas, |
| 768 const gfx::Size& size, | 750 const gfx::Size& size, |
| 769 const MenuBackgroundExtraParams& menu_background) const { | 751 const MenuBackgroundExtraParams& menu_background) const { |
| 770 canvas->drawColor(kMenuPopupBackgroundColor, SkBlendMode::kSrc); | 752 canvas->drawColor(kMenuPopupBackgroundColor, SkBlendMode::kSrc); |
| 771 } | 753 } |
| 772 | 754 |
| 773 void NativeThemeBase::PaintMenuItemBackground( | 755 void NativeThemeBase::PaintMenuItemBackground( |
| 774 cc::PaintCanvas* canvas, | 756 cc::PaintCanvas* canvas, |
| 775 State state, | 757 State state, |
| 776 const gfx::Rect& rect, | 758 const gfx::Rect& rect, |
| 777 const MenuItemExtraParams& menu_item) const { | 759 const MenuItemExtraParams& menu_item) const { |
| 778 // By default don't draw anything over the normal background. | 760 // By default don't draw anything over the normal background. |
| 779 } | 761 } |
| 780 | 762 |
| 781 void NativeThemeBase::PaintMenuSeparator( | 763 void NativeThemeBase::PaintMenuSeparator( |
| 782 cc::PaintCanvas* canvas, | 764 cc::PaintCanvas* canvas, |
| 783 State state, | 765 State state, |
| 784 const gfx::Rect& rect, | 766 const gfx::Rect& rect, |
| 785 const MenuSeparatorExtraParams& menu_separator) const { | 767 const MenuSeparatorExtraParams& menu_separator) const { |
| 786 cc::PaintFlags paint; | 768 cc::PaintFlags flags; |
| 787 paint.setColor(GetSystemColor(ui::NativeTheme::kColorId_MenuSeparatorColor)); | 769 flags.setColor(GetSystemColor(ui::NativeTheme::kColorId_MenuSeparatorColor)); |
| 788 canvas->drawRect(gfx::RectToSkRect(*menu_separator.paint_rect), paint); | 770 canvas->drawRect(gfx::RectToSkRect(*menu_separator.paint_rect), flags); |
| 789 } | 771 } |
| 790 | 772 |
| 791 void NativeThemeBase::PaintSliderTrack(cc::PaintCanvas* canvas, | 773 void NativeThemeBase::PaintSliderTrack(cc::PaintCanvas* canvas, |
| 792 State state, | 774 State state, |
| 793 const gfx::Rect& rect, | 775 const gfx::Rect& rect, |
| 794 const SliderExtraParams& slider) const { | 776 const SliderExtraParams& slider) const { |
| 795 const int kMidX = rect.x() + rect.width() / 2; | 777 const int kMidX = rect.x() + rect.width() / 2; |
| 796 const int kMidY = rect.y() + rect.height() / 2; | 778 const int kMidY = rect.y() + rect.height() / 2; |
| 797 | 779 |
| 798 cc::PaintFlags paint; | 780 cc::PaintFlags flags; |
| 799 paint.setColor(kSliderTrackBackgroundColor); | 781 flags.setColor(kSliderTrackBackgroundColor); |
| 800 | 782 |
| 801 SkRect skrect; | 783 SkRect skrect; |
| 802 if (slider.vertical) { | 784 if (slider.vertical) { |
| 803 skrect.set(std::max(rect.x(), kMidX - 2), | 785 skrect.set(std::max(rect.x(), kMidX - 2), |
| 804 rect.y(), | 786 rect.y(), |
| 805 std::min(rect.right(), kMidX + 2), | 787 std::min(rect.right(), kMidX + 2), |
| 806 rect.bottom()); | 788 rect.bottom()); |
| 807 } else { | 789 } else { |
| 808 skrect.set(rect.x(), | 790 skrect.set(rect.x(), |
| 809 std::max(rect.y(), kMidY - 2), | 791 std::max(rect.y(), kMidY - 2), |
| 810 rect.right(), | 792 rect.right(), |
| 811 std::min(rect.bottom(), kMidY + 2)); | 793 std::min(rect.bottom(), kMidY + 2)); |
| 812 } | 794 } |
| 813 canvas->drawRect(skrect, paint); | 795 canvas->drawRect(skrect, flags); |
| 814 } | 796 } |
| 815 | 797 |
| 816 void NativeThemeBase::PaintSliderThumb(cc::PaintCanvas* canvas, | 798 void NativeThemeBase::PaintSliderThumb(cc::PaintCanvas* canvas, |
| 817 State state, | 799 State state, |
| 818 const gfx::Rect& rect, | 800 const gfx::Rect& rect, |
| 819 const SliderExtraParams& slider) const { | 801 const SliderExtraParams& slider) const { |
| 820 const bool hovered = (state == kHovered) || slider.in_drag; | 802 const bool hovered = (state == kHovered) || slider.in_drag; |
| 821 const int kMidX = rect.x() + rect.width() / 2; | 803 const int kMidX = rect.x() + rect.width() / 2; |
| 822 const int kMidY = rect.y() + rect.height() / 2; | 804 const int kMidY = rect.y() + rect.height() / 2; |
| 823 | 805 |
| 824 cc::PaintFlags paint; | 806 cc::PaintFlags flags; |
| 825 paint.setColor(hovered ? SK_ColorWHITE : kSliderThumbLightGrey); | 807 flags.setColor(hovered ? SK_ColorWHITE : kSliderThumbLightGrey); |
| 826 | 808 |
| 827 SkIRect skrect; | 809 SkIRect skrect; |
| 828 if (slider.vertical) | 810 if (slider.vertical) |
| 829 skrect.set(rect.x(), rect.y(), kMidX + 1, rect.bottom()); | 811 skrect.set(rect.x(), rect.y(), kMidX + 1, rect.bottom()); |
| 830 else | 812 else |
| 831 skrect.set(rect.x(), rect.y(), rect.right(), kMidY + 1); | 813 skrect.set(rect.x(), rect.y(), rect.right(), kMidY + 1); |
| 832 | 814 |
| 833 canvas->drawIRect(skrect, paint); | 815 canvas->drawIRect(skrect, flags); |
| 834 | 816 |
| 835 paint.setColor(hovered ? kSliderThumbLightGrey : kSliderThumbDarkGrey); | 817 flags.setColor(hovered ? kSliderThumbLightGrey : kSliderThumbDarkGrey); |
| 836 | 818 |
| 837 if (slider.vertical) | 819 if (slider.vertical) |
| 838 skrect.set(kMidX + 1, rect.y(), rect.right(), rect.bottom()); | 820 skrect.set(kMidX + 1, rect.y(), rect.right(), rect.bottom()); |
| 839 else | 821 else |
| 840 skrect.set(rect.x(), kMidY + 1, rect.right(), rect.bottom()); | 822 skrect.set(rect.x(), kMidY + 1, rect.right(), rect.bottom()); |
| 841 | 823 |
| 842 canvas->drawIRect(skrect, paint); | 824 canvas->drawIRect(skrect, flags); |
| 843 | 825 |
| 844 paint.setColor(kSliderThumbBorderDarkGrey); | 826 flags.setColor(kSliderThumbBorderDarkGrey); |
| 845 DrawBox(canvas, rect, paint); | 827 DrawBox(canvas, rect, flags); |
| 846 | 828 |
| 847 if (rect.height() > 10 && rect.width() > 10) { | 829 if (rect.height() > 10 && rect.width() > 10) { |
| 848 DrawHorizLine(canvas, kMidX - 2, kMidX + 2, kMidY, paint); | 830 DrawHorizLine(canvas, kMidX - 2, kMidX + 2, kMidY, flags); |
| 849 DrawHorizLine(canvas, kMidX - 2, kMidX + 2, kMidY - 3, paint); | 831 DrawHorizLine(canvas, kMidX - 2, kMidX + 2, kMidY - 3, flags); |
| 850 DrawHorizLine(canvas, kMidX - 2, kMidX + 2, kMidY + 3, paint); | 832 DrawHorizLine(canvas, kMidX - 2, kMidX + 2, kMidY + 3, flags); |
| 851 } | 833 } |
| 852 } | 834 } |
| 853 | 835 |
| 854 void NativeThemeBase::PaintInnerSpinButton( | 836 void NativeThemeBase::PaintInnerSpinButton( |
| 855 cc::PaintCanvas* canvas, | 837 cc::PaintCanvas* canvas, |
| 856 State state, | 838 State state, |
| 857 const gfx::Rect& rect, | 839 const gfx::Rect& rect, |
| 858 const InnerSpinButtonExtraParams& spin_button) const { | 840 const InnerSpinButtonExtraParams& spin_button) const { |
| 859 if (spin_button.read_only) | 841 if (spin_button.read_only) |
| 860 state = kDisabled; | 842 state = kDisabled; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 887 // evenly divide into the width. | 869 // evenly divide into the width. |
| 888 SkPath path; | 870 SkPath path; |
| 889 int stroke_width = std::max(1, rect.height() / 18); | 871 int stroke_width = std::max(1, rect.height() / 18); |
| 890 int tick_width = 16 * stroke_width; | 872 int tick_width = 16 * stroke_width; |
| 891 int ticks = rect.width() / tick_width + (rect.width() % tick_width ? 1 : 0); | 873 int ticks = rect.width() / tick_width + (rect.width() % tick_width ? 1 : 0); |
| 892 SkScalar tick_spacing = SkIntToScalar(rect.width()) / ticks; | 874 SkScalar tick_spacing = SkIntToScalar(rect.width()) / ticks; |
| 893 for (int i = 1; i < ticks; ++i) { | 875 for (int i = 1; i < ticks; ++i) { |
| 894 path.moveTo(rect.x() + i * tick_spacing, rect.y()); | 876 path.moveTo(rect.x() + i * tick_spacing, rect.y()); |
| 895 path.rLineTo(0, rect.height()); | 877 path.rLineTo(0, rect.height()); |
| 896 } | 878 } |
| 897 cc::PaintFlags stroke_paint; | 879 cc::PaintFlags stroke_flags; |
| 898 stroke_paint.setColor(kProgressTickColor); | 880 stroke_flags.setColor(kProgressTickColor); |
| 899 stroke_paint.setStyle(cc::PaintFlags::kStroke_Style); | 881 stroke_flags.setStyle(cc::PaintFlags::kStroke_Style); |
| 900 stroke_paint.setStrokeWidth(stroke_width); | 882 stroke_flags.setStrokeWidth(stroke_width); |
| 901 canvas->drawPath(path, stroke_paint); | 883 canvas->drawPath(path, stroke_flags); |
| 902 | 884 |
| 903 // Draw progress. | 885 // Draw progress. |
| 904 gfx::Rect progress_rect(progress_bar.value_rect_x, progress_bar.value_rect_y, | 886 gfx::Rect progress_rect(progress_bar.value_rect_x, progress_bar.value_rect_y, |
| 905 progress_bar.value_rect_width, | 887 progress_bar.value_rect_width, |
| 906 progress_bar.value_rect_height); | 888 progress_bar.value_rect_height); |
| 907 cc::PaintFlags progress_paint; | 889 cc::PaintFlags progress_flags; |
| 908 progress_paint.setColor(kProgressValueColor); | 890 progress_flags.setColor(kProgressValueColor); |
| 909 progress_paint.setStyle(cc::PaintFlags::kFill_Style); | 891 progress_flags.setStyle(cc::PaintFlags::kFill_Style); |
| 910 canvas->drawRect(gfx::RectToSkRect(progress_rect), progress_paint); | 892 canvas->drawRect(gfx::RectToSkRect(progress_rect), progress_flags); |
| 911 | 893 |
| 912 // Draw the border. | 894 // Draw the border. |
| 913 gfx::RectF border_rect(rect); | 895 gfx::RectF border_rect(rect); |
| 914 border_rect.Inset(stroke_width / 2.0f, stroke_width / 2.0f); | 896 border_rect.Inset(stroke_width / 2.0f, stroke_width / 2.0f); |
| 915 stroke_paint.setColor(kProgressBorderColor); | 897 stroke_flags.setColor(kProgressBorderColor); |
| 916 canvas->drawRect(gfx::RectFToSkRect(border_rect), stroke_paint); | 898 canvas->drawRect(gfx::RectFToSkRect(border_rect), stroke_flags); |
| 917 } | 899 } |
| 918 | 900 |
| 919 void NativeThemeBase::PaintFrameTopArea( | 901 void NativeThemeBase::PaintFrameTopArea( |
| 920 SkCanvas* canvas, | 902 SkCanvas* canvas, |
| 921 State state, | 903 State state, |
| 922 const gfx::Rect& rect, | 904 const gfx::Rect& rect, |
| 923 const FrameTopAreaExtraParams& frame_top_area) const { | 905 const FrameTopAreaExtraParams& frame_top_area) const { |
| 924 SkPaint paint; | 906 SkPaint flags; |
| 925 paint.setColor(frame_top_area.default_background_color); | 907 flags.setColor(frame_top_area.default_background_color); |
| 926 canvas->drawRect(gfx::RectToSkRect(rect), paint); | 908 canvas->drawRect(gfx::RectToSkRect(rect), flags); |
| 927 } | 909 } |
| 928 | 910 |
| 929 void NativeThemeBase::AdjustCheckboxRadioRectForPadding(SkRect* rect) const { | 911 void NativeThemeBase::AdjustCheckboxRadioRectForPadding(SkRect* rect) const { |
| 930 // By default we only take 1px from right and bottom for the drop shadow. | 912 // By default we only take 1px from right and bottom for the drop shadow. |
| 931 rect->iset(rect->x(), rect->y(), rect->right() - 1, rect->bottom() - 1); | 913 rect->iset(rect->x(), rect->y(), rect->right() - 1, rect->bottom() - 1); |
| 932 } | 914 } |
| 933 | 915 |
| 934 SkColor NativeThemeBase::SaturateAndBrighten(SkScalar* hsv, | 916 SkColor NativeThemeBase::SaturateAndBrighten(SkScalar* hsv, |
| 935 SkScalar saturate_amount, | 917 SkScalar saturate_amount, |
| 936 SkScalar brighten_amount) const { | 918 SkScalar brighten_amount) const { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 949 SkColorToHSV(track_color_, track_hsv); | 931 SkColorToHSV(track_color_, track_hsv); |
| 950 SkScalar thumb_hsv[3]; | 932 SkScalar thumb_hsv[3]; |
| 951 SkColorToHSV(thumb_inactive_color_, thumb_hsv); | 933 SkColorToHSV(thumb_inactive_color_, thumb_hsv); |
| 952 return OutlineColor(track_hsv, thumb_hsv); | 934 return OutlineColor(track_hsv, thumb_hsv); |
| 953 } | 935 } |
| 954 | 936 |
| 955 void NativeThemeBase::DrawVertLine(cc::PaintCanvas* canvas, | 937 void NativeThemeBase::DrawVertLine(cc::PaintCanvas* canvas, |
| 956 int x, | 938 int x, |
| 957 int y1, | 939 int y1, |
| 958 int y2, | 940 int y2, |
| 959 const cc::PaintFlags& paint) const { | 941 const cc::PaintFlags& flags) const { |
| 960 SkIRect skrect; | 942 SkIRect skrect; |
| 961 skrect.set(x, y1, x + 1, y2 + 1); | 943 skrect.set(x, y1, x + 1, y2 + 1); |
| 962 canvas->drawIRect(skrect, paint); | 944 canvas->drawIRect(skrect, flags); |
| 963 } | 945 } |
| 964 | 946 |
| 965 void NativeThemeBase::DrawHorizLine(cc::PaintCanvas* canvas, | 947 void NativeThemeBase::DrawHorizLine(cc::PaintCanvas* canvas, |
| 966 int x1, | 948 int x1, |
| 967 int x2, | 949 int x2, |
| 968 int y, | 950 int y, |
| 969 const cc::PaintFlags& paint) const { | 951 const cc::PaintFlags& flags) const { |
| 970 SkIRect skrect; | 952 SkIRect skrect; |
| 971 skrect.set(x1, y, x2 + 1, y + 1); | 953 skrect.set(x1, y, x2 + 1, y + 1); |
| 972 canvas->drawIRect(skrect, paint); | 954 canvas->drawIRect(skrect, flags); |
| 973 } | 955 } |
| 974 | 956 |
| 975 void NativeThemeBase::DrawBox(cc::PaintCanvas* canvas, | 957 void NativeThemeBase::DrawBox(cc::PaintCanvas* canvas, |
| 976 const gfx::Rect& rect, | 958 const gfx::Rect& rect, |
| 977 const cc::PaintFlags& paint) const { | 959 const cc::PaintFlags& flags) const { |
| 978 const int right = rect.x() + rect.width() - 1; | 960 const int right = rect.x() + rect.width() - 1; |
| 979 const int bottom = rect.y() + rect.height() - 1; | 961 const int bottom = rect.y() + rect.height() - 1; |
| 980 DrawHorizLine(canvas, rect.x(), right, rect.y(), paint); | 962 DrawHorizLine(canvas, rect.x(), right, rect.y(), flags); |
| 981 DrawVertLine(canvas, right, rect.y(), bottom, paint); | 963 DrawVertLine(canvas, right, rect.y(), bottom, flags); |
| 982 DrawHorizLine(canvas, rect.x(), right, bottom, paint); | 964 DrawHorizLine(canvas, rect.x(), right, bottom, flags); |
| 983 DrawVertLine(canvas, rect.x(), rect.y(), bottom, paint); | 965 DrawVertLine(canvas, rect.x(), rect.y(), bottom, flags); |
| 984 } | 966 } |
| 985 | 967 |
| 986 SkScalar NativeThemeBase::Clamp(SkScalar value, | 968 SkScalar NativeThemeBase::Clamp(SkScalar value, |
| 987 SkScalar min, | 969 SkScalar min, |
| 988 SkScalar max) const { | 970 SkScalar max) const { |
| 989 return std::min(std::max(value, min), max); | 971 return std::min(std::max(value, min), max); |
| 990 } | 972 } |
| 991 | 973 |
| 992 SkColor NativeThemeBase::OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const { | 974 SkColor NativeThemeBase::OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const { |
| 993 // GTK Theme engines have way too much control over the layout of | 975 // GTK Theme engines have way too much control over the layout of |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1020 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); | 1002 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); | 1003 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); |
| 1022 | 1004 |
| 1023 if (hsv1[2] + hsv2[2] > 1.0) | 1005 if (hsv1[2] + hsv2[2] > 1.0) |
| 1024 diff = -diff; | 1006 diff = -diff; |
| 1025 | 1007 |
| 1026 return SaturateAndBrighten(hsv2, -0.2f, diff); | 1008 return SaturateAndBrighten(hsv2, -0.2f, diff); |
| 1027 } | 1009 } |
| 1028 | 1010 |
| 1029 } // namespace ui | 1011 } // namespace ui |
| OLD | NEW |