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/common_theme.h" | 5 #include "ui/native_theme/common_theme.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "third_party/skia/include/core/SkCanvas.h" | 8 #include "third_party/skia/include/core/SkCanvas.h" |
9 #include "ui/base/material_design/material_design_controller.h" | 9 #include "ui/base/material_design/material_design_controller.h" |
10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 canvas->drawLine(position_x, rect.y(), position_x, rect.bottom(), paint); | 453 canvas->drawLine(position_x, rect.y(), position_x, rect.bottom(), paint); |
454 } | 454 } |
455 | 455 |
456 void CommonThemePaintMenuBackground(SkCanvas* canvas, const gfx::Rect& rect) { | 456 void CommonThemePaintMenuBackground(SkCanvas* canvas, const gfx::Rect& rect) { |
457 SkPaint paint; | 457 SkPaint paint; |
458 paint.setColor( | 458 paint.setColor( |
459 GetAuraColor(NativeTheme::kColorId_MenuBackgroundColor, nullptr)); | 459 GetAuraColor(NativeTheme::kColorId_MenuBackgroundColor, nullptr)); |
460 canvas->drawRect(gfx::RectToSkRect(rect), paint); | 460 canvas->drawRect(gfx::RectToSkRect(rect), paint); |
461 } | 461 } |
462 | 462 |
463 void CommonThemePaintMenuItemBackground(SkCanvas* canvas, | 463 void CommonThemePaintMenuItemBackground( |
464 NativeTheme::State state, | 464 SkCanvas* canvas, |
465 const gfx::Rect& rect) { | 465 NativeTheme::State state, |
| 466 const gfx::Rect& rect, |
| 467 const NativeTheme::MenuItemExtraParams& menu_item) { |
466 SkPaint paint; | 468 SkPaint paint; |
467 switch (state) { | 469 switch (state) { |
468 case NativeTheme::kNormal: | 470 case NativeTheme::kNormal: |
469 case NativeTheme::kDisabled: | 471 case NativeTheme::kDisabled: |
470 paint.setColor( | 472 paint.setColor( |
471 GetAuraColor(NativeTheme::kColorId_MenuBackgroundColor, nullptr)); | 473 GetAuraColor(NativeTheme::kColorId_MenuBackgroundColor, nullptr)); |
472 break; | 474 break; |
473 case NativeTheme::kHovered: | 475 case NativeTheme::kHovered: |
474 paint.setColor(GetAuraColor( | 476 paint.setColor(GetAuraColor( |
475 NativeTheme::kColorId_FocusedMenuItemBackgroundColor, nullptr)); | 477 NativeTheme::kColorId_FocusedMenuItemBackgroundColor, nullptr)); |
476 break; | 478 break; |
477 default: | 479 default: |
478 NOTREACHED() << "Invalid state " << state; | 480 NOTREACHED() << "Invalid state " << state; |
479 break; | 481 break; |
480 } | 482 } |
| 483 if (menu_item.corner_radius > 0) { |
| 484 const SkScalar radius = SkIntToScalar(menu_item.corner_radius); |
| 485 canvas->drawRoundRect(gfx::RectToSkRect(rect), radius, radius, paint); |
| 486 return; |
| 487 } |
481 canvas->drawRect(gfx::RectToSkRect(rect), paint); | 488 canvas->drawRect(gfx::RectToSkRect(rect), paint); |
482 } | 489 } |
483 | 490 |
484 // static | 491 // static |
485 scoped_ptr<gfx::Canvas> CommonThemeCreateCanvas(SkCanvas* sk_canvas) { | 492 scoped_ptr<gfx::Canvas> CommonThemeCreateCanvas(SkCanvas* sk_canvas) { |
486 // TODO(pkotwicz): Do something better and don't infer device | 493 // TODO(pkotwicz): Do something better and don't infer device |
487 // scale factor from canvas scale. | 494 // scale factor from canvas scale. |
488 SkMatrix m = sk_canvas->getTotalMatrix(); | 495 SkMatrix m = sk_canvas->getTotalMatrix(); |
489 float device_scale = static_cast<float>(SkScalarAbs(m.getScaleX())); | 496 float device_scale = static_cast<float>(SkScalarAbs(m.getScaleX())); |
490 return make_scoped_ptr(new gfx::Canvas(skia::SharePtr(sk_canvas), | 497 return make_scoped_ptr(new gfx::Canvas(skia::SharePtr(sk_canvas), |
491 device_scale)); | 498 device_scale)); |
492 } | 499 } |
493 | 500 |
494 } // namespace ui | 501 } // namespace ui |
OLD | NEW |