| OLD | NEW | 
|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "views/controls/menu/menu_item_view.h" | 5 #include "views/controls/menu/menu_item_view.h" | 
| 6 | 6 | 
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" | 
| 8 #include "gfx/canvas.h" | 8 #include "gfx/canvas_skia.h" | 
| 9 #include "gfx/favicon_size.h" | 9 #include "gfx/favicon_size.h" | 
| 10 #include "grit/app_resources.h" | 10 #include "grit/app_resources.h" | 
| 11 #include "third_party/skia/include/effects/SkGradientShader.h" | 11 #include "third_party/skia/include/effects/SkGradientShader.h" | 
| 12 #include "views/controls/button/text_button.h" | 12 #include "views/controls/button/text_button.h" | 
| 13 #include "views/controls/menu/menu_config.h" | 13 #include "views/controls/menu/menu_config.h" | 
| 14 #include "views/controls/menu/submenu_view.h" | 14 #include "views/controls/menu/submenu_view.h" | 
| 15 | 15 | 
| 16 namespace views { | 16 namespace views { | 
| 17 | 17 | 
| 18 // Background color when the menu item is selected. | 18 // Background color when the menu item is selected. | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 63   int bottom_margin = GetBottomMargin(); | 63   int bottom_margin = GetBottomMargin(); | 
| 64   int icon_y = top_margin + (height() - config.item_top_margin - | 64   int icon_y = top_margin + (height() - config.item_top_margin - | 
| 65                              bottom_margin - config.check_height) / 2; | 65                              bottom_margin - config.check_height) / 2; | 
| 66   int icon_height = config.check_height; | 66   int icon_height = config.check_height; | 
| 67   int available_height = height() - top_margin - bottom_margin; | 67   int available_height = height() - top_margin - bottom_margin; | 
| 68 | 68 | 
| 69   // Render the background. As MenuScrollViewContainer draws the background, we | 69   // Render the background. As MenuScrollViewContainer draws the background, we | 
| 70   // only need the background when we want it to look different, as when we're | 70   // only need the background when we want it to look different, as when we're | 
| 71   // selected. | 71   // selected. | 
| 72   if (render_selection) | 72   if (render_selection) | 
| 73     canvas->drawColor(kSelectedBackgroundColor, SkXfermode::kSrc_Mode); | 73     canvas->AsCanvasSkia()->drawColor(kSelectedBackgroundColor, | 
|  | 74                                       SkXfermode::kSrc_Mode); | 
| 74 | 75 | 
| 75   // Render the check. | 76   // Render the check. | 
| 76   if (type_ == CHECKBOX && GetDelegate()->IsItemChecked(GetCommand())) { | 77   if (type_ == CHECKBOX && GetDelegate()->IsItemChecked(GetCommand())) { | 
| 77     ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 78     ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 
| 78     SkBitmap* check = rb.GetBitmapNamed(IDR_MENU_CHECK); | 79     SkBitmap* check = rb.GetBitmapNamed(IDR_MENU_CHECK); | 
| 79     // Don't use config.check_width here as it's padded to force more padding. | 80     // Don't use config.check_width here as it's padded to force more padding. | 
| 80     gfx::Rect check_bounds(icon_x, icon_y, check->width(), icon_height); | 81     gfx::Rect check_bounds(icon_x, icon_y, check->width(), icon_height); | 
| 81     AdjustBoundsForRTLUI(&check_bounds); | 82     AdjustBoundsForRTLUI(&check_bounds); | 
| 82     canvas->DrawBitmapInt(*check, check_bounds.x(), check_bounds.y()); | 83     canvas->DrawBitmapInt(*check, check_bounds.x(), check_bounds.y()); | 
| 83   } else if (type_ == RADIO) { | 84   } else if (type_ == RADIO) { | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 96     SkColor gradient_colors[3] = { kGradient0, kGradient1, kGradient2 }; | 97     SkColor gradient_colors[3] = { kGradient0, kGradient1, kGradient2 }; | 
| 97     SkShader* shader = SkGradientShader::CreateLinear( | 98     SkShader* shader = SkGradientShader::CreateLinear( | 
| 98         gradient_points, gradient_colors, NULL, arraysize(gradient_points), | 99         gradient_points, gradient_colors, NULL, arraysize(gradient_points), | 
| 99         SkShader::kClamp_TileMode, NULL); | 100         SkShader::kClamp_TileMode, NULL); | 
| 100     SkPaint paint; | 101     SkPaint paint; | 
| 101     paint.setStyle(SkPaint::kFill_Style); | 102     paint.setStyle(SkPaint::kFill_Style); | 
| 102     paint.setAntiAlias(true); | 103     paint.setAntiAlias(true); | 
| 103     paint.setShader(shader); | 104     paint.setShader(shader); | 
| 104     shader->unref(); | 105     shader->unref(); | 
| 105     int radius = kIndicatorSize / 2; | 106     int radius = kIndicatorSize / 2; | 
| 106     canvas->drawCircle(radius, radius, radius, paint); | 107     canvas->AsCanvasSkia()->drawCircle(radius, radius, radius, paint); | 
| 107 | 108 | 
| 108     paint.setStrokeWidth(SkIntToScalar(0)); | 109     paint.setStrokeWidth(SkIntToScalar(0)); | 
| 109     paint.setShader(NULL); | 110     paint.setShader(NULL); | 
| 110     paint.setStyle(SkPaint::kStroke_Style); | 111     paint.setStyle(SkPaint::kStroke_Style); | 
| 111     paint.setColor(kBaseStroke); | 112     paint.setColor(kBaseStroke); | 
| 112     canvas->drawCircle(radius, radius, radius, paint); | 113     canvas->AsCanvasSkia()->drawCircle(radius, radius, radius, paint); | 
| 113 | 114 | 
| 114     if (GetDelegate()->IsItemChecked(GetCommand())) { | 115     if (GetDelegate()->IsItemChecked(GetCommand())) { | 
| 115       SkPoint selected_gradient_points[2]; | 116       SkPoint selected_gradient_points[2]; | 
| 116       selected_gradient_points[0].set(SkIntToScalar(0), SkIntToScalar(0)); | 117       selected_gradient_points[0].set(SkIntToScalar(0), SkIntToScalar(0)); | 
| 117       selected_gradient_points[1].set( | 118       selected_gradient_points[1].set( | 
| 118           SkIntToScalar(0), | 119           SkIntToScalar(0), | 
| 119           SkIntToScalar(kSelectedIndicatorSize)); | 120           SkIntToScalar(kSelectedIndicatorSize)); | 
| 120       SkColor selected_gradient_colors[2] = { kRadioButtonIndicatorGradient0, | 121       SkColor selected_gradient_colors[2] = { kRadioButtonIndicatorGradient0, | 
| 121                                               kRadioButtonIndicatorGradient1 }; | 122                                               kRadioButtonIndicatorGradient1 }; | 
| 122       shader = SkGradientShader::CreateLinear( | 123       shader = SkGradientShader::CreateLinear( | 
| 123           selected_gradient_points, selected_gradient_colors, NULL, | 124           selected_gradient_points, selected_gradient_colors, NULL, | 
| 124           arraysize(selected_gradient_points), SkShader::kClamp_TileMode, NULL); | 125           arraysize(selected_gradient_points), SkShader::kClamp_TileMode, NULL); | 
| 125       paint.setShader(shader); | 126       paint.setShader(shader); | 
| 126       shader->unref(); | 127       shader->unref(); | 
| 127       paint.setStyle(SkPaint::kFill_Style); | 128       paint.setStyle(SkPaint::kFill_Style); | 
| 128       canvas->drawCircle(radius, radius, kSelectedIndicatorSize / 2, paint); | 129       canvas->AsCanvasSkia()->drawCircle(radius, radius, | 
|  | 130                                          kSelectedIndicatorSize / 2, paint); | 
| 129 | 131 | 
| 130       paint.setStrokeWidth(SkIntToScalar(0)); | 132       paint.setStrokeWidth(SkIntToScalar(0)); | 
| 131       paint.setShader(NULL); | 133       paint.setShader(NULL); | 
| 132       paint.setStyle(SkPaint::kStroke_Style); | 134       paint.setStyle(SkPaint::kStroke_Style); | 
| 133       paint.setColor(kIndicatorStroke); | 135       paint.setColor(kIndicatorStroke); | 
| 134       canvas->drawCircle(radius, radius, kSelectedIndicatorSize / 2, paint); | 136       canvas->AsCanvasSkia()->drawCircle(radius, radius, | 
|  | 137                                          kSelectedIndicatorSize / 2, paint); | 
| 135     } | 138     } | 
| 136 | 139 | 
| 137     canvas->TranslateInt( | 140     canvas->TranslateInt( | 
| 138         -icon_x, | 141         -icon_x, | 
| 139         -(top_margin + (height() - top_margin - bottom_margin - | 142         -(top_margin + (height() - top_margin - bottom_margin - | 
| 140                         kIndicatorSize) / 2)); | 143                         kIndicatorSize) / 2)); | 
| 141   } | 144   } | 
| 142 | 145 | 
| 143   // Render the foreground. | 146   // Render the foreground. | 
| 144 #if defined(OS_CHROMEOS) | 147 #if defined(OS_CHROMEOS) | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 181                                          config.arrow_width) / 2, | 184                                          config.arrow_width) / 2, | 
| 182                            config.arrow_width, height()); | 185                            config.arrow_width, height()); | 
| 183     AdjustBoundsForRTLUI(&arrow_bounds); | 186     AdjustBoundsForRTLUI(&arrow_bounds); | 
| 184     ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 187     ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 
| 185     canvas->DrawBitmapInt(*rb.GetBitmapNamed(IDR_MENU_ARROW), | 188     canvas->DrawBitmapInt(*rb.GetBitmapNamed(IDR_MENU_ARROW), | 
| 186                           arrow_bounds.x(), arrow_bounds.y()); | 189                           arrow_bounds.x(), arrow_bounds.y()); | 
| 187   } | 190   } | 
| 188 } | 191 } | 
| 189 | 192 | 
| 190 }  // namespace views | 193 }  // namespace views | 
| OLD | NEW | 
|---|