| 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 canvas->drawRoundRect(gfx::RectToSkRect(rect), |
| 485 SkIntToScalar(menu_item.corner_radius), |
| 486 SkIntToScalar(menu_item.corner_radius), paint); |
| 487 return; |
| 488 } |
| 481 canvas->drawRect(gfx::RectToSkRect(rect), paint); | 489 canvas->drawRect(gfx::RectToSkRect(rect), paint); |
| 482 } | 490 } |
| 483 | 491 |
| 484 // static | 492 // static |
| 485 scoped_ptr<gfx::Canvas> CommonThemeCreateCanvas(SkCanvas* sk_canvas) { | 493 scoped_ptr<gfx::Canvas> CommonThemeCreateCanvas(SkCanvas* sk_canvas) { |
| 486 // TODO(pkotwicz): Do something better and don't infer device | 494 // TODO(pkotwicz): Do something better and don't infer device |
| 487 // scale factor from canvas scale. | 495 // scale factor from canvas scale. |
| 488 SkMatrix m = sk_canvas->getTotalMatrix(); | 496 SkMatrix m = sk_canvas->getTotalMatrix(); |
| 489 float device_scale = static_cast<float>(SkScalarAbs(m.getScaleX())); | 497 float device_scale = static_cast<float>(SkScalarAbs(m.getScaleX())); |
| 490 return make_scoped_ptr(new gfx::Canvas(sk_canvas, device_scale)); | 498 return make_scoped_ptr(new gfx::Canvas(sk_canvas, device_scale)); |
| 491 } | 499 } |
| 492 | 500 |
| 493 } // namespace ui | 501 } // namespace ui |
| OLD | NEW |