| OLD | NEW |
| 1 // Copyright (c) 2011 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/views/controls/menu/menu_image_util.h" | 5 #include "ui/views/controls/menu/menu_image_util.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
| 9 #include "third_party/skia/include/effects/SkGradientShader.h" | 9 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/gfx/canvas_skia.h" | 11 #include "ui/gfx/canvas_skia.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 28 const SkColor kRadioButtonIndicatorGradient1 = SkColorSetRGB(0x83, 0x83, 0x83); | 28 const SkColor kRadioButtonIndicatorGradient1 = SkColorSetRGB(0x83, 0x83, 0x83); |
| 29 const SkColor kIndicatorStroke = SkColorSetRGB(0, 0, 0); | 29 const SkColor kIndicatorStroke = SkColorSetRGB(0, 0, 0); |
| 30 | 30 |
| 31 SkBitmap* CreateRadioButtonImage(bool selected) { | 31 SkBitmap* CreateRadioButtonImage(bool selected) { |
| 32 // + 2 (1px on each side) to cover rounding error. | 32 // + 2 (1px on each side) to cover rounding error. |
| 33 gfx::CanvasSkia canvas(gfx::Size(kIndicatorSize + 2, kIndicatorSize + 2), | 33 gfx::CanvasSkia canvas(gfx::Size(kIndicatorSize + 2, kIndicatorSize + 2), |
| 34 false); | 34 false); |
| 35 canvas.Translate(gfx::Point(1, 1)); | 35 canvas.Translate(gfx::Point(1, 1)); |
| 36 | 36 |
| 37 SkPoint gradient_points[3]; | 37 SkPoint gradient_points[3]; |
| 38 gradient_points[0].set(SkIntToScalar(0), SkIntToScalar(0)); | 38 gradient_points[0].iset(0, 0); |
| 39 gradient_points[1].set( | 39 gradient_points[1].iset(0, static_cast<int>(kIndicatorSize * kGradientStop)); |
| 40 SkIntToScalar(0), | 40 gradient_points[2].iset(0, kIndicatorSize); |
| 41 SkIntToScalar(static_cast<int>(kIndicatorSize * kGradientStop))); | |
| 42 gradient_points[2].set(SkIntToScalar(0), SkIntToScalar(kIndicatorSize)); | |
| 43 SkColor gradient_colors[3] = { kGradient0, kGradient1, kGradient2 }; | 41 SkColor gradient_colors[3] = { kGradient0, kGradient1, kGradient2 }; |
| 44 SkShader* shader = SkGradientShader::CreateLinear( | 42 SkShader* shader = SkGradientShader::CreateLinear( |
| 45 gradient_points, gradient_colors, NULL, arraysize(gradient_points), | 43 gradient_points, gradient_colors, NULL, arraysize(gradient_points), |
| 46 SkShader::kClamp_TileMode, NULL); | 44 SkShader::kClamp_TileMode, NULL); |
| 47 SkPaint paint; | 45 SkPaint paint; |
| 48 paint.setStyle(SkPaint::kFill_Style); | 46 paint.setStyle(SkPaint::kFill_Style); |
| 49 paint.setAntiAlias(true); | 47 paint.setAntiAlias(true); |
| 50 paint.setShader(shader); | 48 paint.setShader(shader); |
| 51 shader->unref(); | 49 shader->unref(); |
| 52 int radius = kIndicatorSize / 2; | 50 int radius = kIndicatorSize / 2; |
| 53 canvas.sk_canvas()->drawCircle(radius, radius, radius, paint); | 51 canvas.sk_canvas()->drawCircle(radius, radius, radius, paint); |
| 54 | 52 |
| 55 paint.setStrokeWidth(SkIntToScalar(0)); | 53 paint.setStrokeWidth(SkIntToScalar(0)); |
| 56 paint.setShader(NULL); | 54 paint.setShader(NULL); |
| 57 paint.setStyle(SkPaint::kStroke_Style); | 55 paint.setStyle(SkPaint::kStroke_Style); |
| 58 paint.setColor(kBaseStroke); | 56 paint.setColor(kBaseStroke); |
| 59 canvas.sk_canvas()->drawCircle(radius, radius, radius, paint); | 57 canvas.sk_canvas()->drawCircle(radius, radius, radius, paint); |
| 60 | 58 |
| 61 if (selected) { | 59 if (selected) { |
| 62 SkPoint selected_gradient_points[2]; | 60 SkPoint selected_gradient_points[2]; |
| 63 selected_gradient_points[0].set(SkIntToScalar(0), SkIntToScalar(0)); | 61 selected_gradient_points[0].iset(0, 0); |
| 64 selected_gradient_points[1].set( | 62 selected_gradient_points[1].iset(0, kSelectedIndicatorSize); |
| 65 SkIntToScalar(0), | |
| 66 SkIntToScalar(kSelectedIndicatorSize)); | |
| 67 SkColor selected_gradient_colors[2] = { kRadioButtonIndicatorGradient0, | 63 SkColor selected_gradient_colors[2] = { kRadioButtonIndicatorGradient0, |
| 68 kRadioButtonIndicatorGradient1 }; | 64 kRadioButtonIndicatorGradient1 }; |
| 69 shader = SkGradientShader::CreateLinear( | 65 shader = SkGradientShader::CreateLinear( |
| 70 selected_gradient_points, selected_gradient_colors, NULL, | 66 selected_gradient_points, selected_gradient_colors, NULL, |
| 71 arraysize(selected_gradient_points), SkShader::kClamp_TileMode, NULL); | 67 arraysize(selected_gradient_points), SkShader::kClamp_TileMode, NULL); |
| 72 paint.setShader(shader); | 68 paint.setShader(shader); |
| 73 shader->unref(); | 69 shader->unref(); |
| 74 paint.setStyle(SkPaint::kFill_Style); | 70 paint.setStyle(SkPaint::kFill_Style); |
| 75 canvas.sk_canvas()->drawCircle(radius, radius, | 71 canvas.sk_canvas()->drawCircle(radius, radius, |
| 76 kSelectedIndicatorSize / 2, paint); | 72 kSelectedIndicatorSize / 2, paint); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 return selected ? kRadioOn : kRadioOff; | 105 return selected ? kRadioOn : kRadioOff; |
| 110 } | 106 } |
| 111 | 107 |
| 112 const SkBitmap* GetSubmenuArrowImage() { | 108 const SkBitmap* GetSubmenuArrowImage() { |
| 113 return base::i18n::IsRTL() ? | 109 return base::i18n::IsRTL() ? |
| 114 GetRtlSubmenuArrowImage() : | 110 GetRtlSubmenuArrowImage() : |
| 115 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_MENU_ARROW); | 111 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_MENU_ARROW); |
| 116 } | 112 } |
| 117 | 113 |
| 118 } // namespace views; | 114 } // namespace views; |
| OLD | NEW |