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_skia.h" | 8 #include "gfx/canvas.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->AsCanvasSkia()->drawColor(kSelectedBackgroundColor, | 73 canvas->drawColor(kSelectedBackgroundColor, SkXfermode::kSrc_Mode); |
74 SkXfermode::kSrc_Mode); | |
75 | 74 |
76 // Render the check. | 75 // Render the check. |
77 if (type_ == CHECKBOX && GetDelegate()->IsItemChecked(GetCommand())) { | 76 if (type_ == CHECKBOX && GetDelegate()->IsItemChecked(GetCommand())) { |
78 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 77 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
79 SkBitmap* check = rb.GetBitmapNamed(IDR_MENU_CHECK); | 78 SkBitmap* check = rb.GetBitmapNamed(IDR_MENU_CHECK); |
80 // Don't use config.check_width here as it's padded to force more padding. | 79 // Don't use config.check_width here as it's padded to force more padding. |
81 gfx::Rect check_bounds(icon_x, icon_y, check->width(), icon_height); | 80 gfx::Rect check_bounds(icon_x, icon_y, check->width(), icon_height); |
82 AdjustBoundsForRTLUI(&check_bounds); | 81 AdjustBoundsForRTLUI(&check_bounds); |
83 canvas->DrawBitmapInt(*check, check_bounds.x(), check_bounds.y()); | 82 canvas->DrawBitmapInt(*check, check_bounds.x(), check_bounds.y()); |
84 } else if (type_ == RADIO) { | 83 } else if (type_ == RADIO) { |
(...skipping 12 matching lines...) Expand all Loading... |
97 SkColor gradient_colors[3] = { kGradient0, kGradient1, kGradient2 }; | 96 SkColor gradient_colors[3] = { kGradient0, kGradient1, kGradient2 }; |
98 SkShader* shader = SkGradientShader::CreateLinear( | 97 SkShader* shader = SkGradientShader::CreateLinear( |
99 gradient_points, gradient_colors, NULL, arraysize(gradient_points), | 98 gradient_points, gradient_colors, NULL, arraysize(gradient_points), |
100 SkShader::kClamp_TileMode, NULL); | 99 SkShader::kClamp_TileMode, NULL); |
101 SkPaint paint; | 100 SkPaint paint; |
102 paint.setStyle(SkPaint::kFill_Style); | 101 paint.setStyle(SkPaint::kFill_Style); |
103 paint.setAntiAlias(true); | 102 paint.setAntiAlias(true); |
104 paint.setShader(shader); | 103 paint.setShader(shader); |
105 shader->unref(); | 104 shader->unref(); |
106 int radius = kIndicatorSize / 2; | 105 int radius = kIndicatorSize / 2; |
107 canvas->AsCanvasSkia()->drawCircle(radius, radius, radius, paint); | 106 canvas->drawCircle(radius, radius, radius, paint); |
108 | 107 |
109 paint.setStrokeWidth(SkIntToScalar(0)); | 108 paint.setStrokeWidth(SkIntToScalar(0)); |
110 paint.setShader(NULL); | 109 paint.setShader(NULL); |
111 paint.setStyle(SkPaint::kStroke_Style); | 110 paint.setStyle(SkPaint::kStroke_Style); |
112 paint.setColor(kBaseStroke); | 111 paint.setColor(kBaseStroke); |
113 canvas->AsCanvasSkia()->drawCircle(radius, radius, radius, paint); | 112 canvas->drawCircle(radius, radius, radius, paint); |
114 | 113 |
115 if (GetDelegate()->IsItemChecked(GetCommand())) { | 114 if (GetDelegate()->IsItemChecked(GetCommand())) { |
116 SkPoint selected_gradient_points[2]; | 115 SkPoint selected_gradient_points[2]; |
117 selected_gradient_points[0].set(SkIntToScalar(0), SkIntToScalar(0)); | 116 selected_gradient_points[0].set(SkIntToScalar(0), SkIntToScalar(0)); |
118 selected_gradient_points[1].set( | 117 selected_gradient_points[1].set( |
119 SkIntToScalar(0), | 118 SkIntToScalar(0), |
120 SkIntToScalar(kSelectedIndicatorSize)); | 119 SkIntToScalar(kSelectedIndicatorSize)); |
121 SkColor selected_gradient_colors[2] = { kRadioButtonIndicatorGradient0, | 120 SkColor selected_gradient_colors[2] = { kRadioButtonIndicatorGradient0, |
122 kRadioButtonIndicatorGradient1 }; | 121 kRadioButtonIndicatorGradient1 }; |
123 shader = SkGradientShader::CreateLinear( | 122 shader = SkGradientShader::CreateLinear( |
124 selected_gradient_points, selected_gradient_colors, NULL, | 123 selected_gradient_points, selected_gradient_colors, NULL, |
125 arraysize(selected_gradient_points), SkShader::kClamp_TileMode, NULL); | 124 arraysize(selected_gradient_points), SkShader::kClamp_TileMode, NULL); |
126 paint.setShader(shader); | 125 paint.setShader(shader); |
127 shader->unref(); | 126 shader->unref(); |
128 paint.setStyle(SkPaint::kFill_Style); | 127 paint.setStyle(SkPaint::kFill_Style); |
129 canvas->AsCanvasSkia()->drawCircle(radius, radius, | 128 canvas->drawCircle(radius, radius, kSelectedIndicatorSize / 2, paint); |
130 kSelectedIndicatorSize / 2, paint); | |
131 | 129 |
132 paint.setStrokeWidth(SkIntToScalar(0)); | 130 paint.setStrokeWidth(SkIntToScalar(0)); |
133 paint.setShader(NULL); | 131 paint.setShader(NULL); |
134 paint.setStyle(SkPaint::kStroke_Style); | 132 paint.setStyle(SkPaint::kStroke_Style); |
135 paint.setColor(kIndicatorStroke); | 133 paint.setColor(kIndicatorStroke); |
136 canvas->AsCanvasSkia()->drawCircle(radius, radius, | 134 canvas->drawCircle(radius, radius, kSelectedIndicatorSize / 2, paint); |
137 kSelectedIndicatorSize / 2, paint); | |
138 } | 135 } |
139 | 136 |
140 canvas->TranslateInt( | 137 canvas->TranslateInt( |
141 -icon_x, | 138 -icon_x, |
142 -(top_margin + (height() - top_margin - bottom_margin - | 139 -(top_margin + (height() - top_margin - bottom_margin - |
143 kIndicatorSize) / 2)); | 140 kIndicatorSize) / 2)); |
144 } | 141 } |
145 | 142 |
146 // Render the foreground. | 143 // Render the foreground. |
147 #if defined(OS_CHROMEOS) | 144 #if defined(OS_CHROMEOS) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 config.arrow_width) / 2, | 181 config.arrow_width) / 2, |
185 config.arrow_width, height()); | 182 config.arrow_width, height()); |
186 AdjustBoundsForRTLUI(&arrow_bounds); | 183 AdjustBoundsForRTLUI(&arrow_bounds); |
187 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 184 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
188 canvas->DrawBitmapInt(*rb.GetBitmapNamed(IDR_MENU_ARROW), | 185 canvas->DrawBitmapInt(*rb.GetBitmapNamed(IDR_MENU_ARROW), |
189 arrow_bounds.x(), arrow_bounds.y()); | 186 arrow_bounds.x(), arrow_bounds.y()); |
190 } | 187 } |
191 } | 188 } |
192 | 189 |
193 } // namespace views | 190 } // namespace views |
OLD | NEW |