Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: ui/native_theme/native_theme_base.cc

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

Powered by Google App Engine
This is Rietveld 408576698