| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/native_menu_win.h" | 5 #include "views/controls/menu/native_menu_win.h" |
| 6 | 6 |
| 7 #include <Windowsx.h> | 7 #include <Windowsx.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 ui::MenuModel::ItemType type = | 242 ui::MenuModel::ItemType type = |
| 243 data->native_menu_win->model_->GetTypeAt(data->model_index); | 243 data->native_menu_win->model_->GetTypeAt(data->model_index); |
| 244 | 244 |
| 245 // Draw the icon after the label, otherwise it would be covered | 245 // Draw the icon after the label, otherwise it would be covered |
| 246 // by the label. | 246 // by the label. |
| 247 SkBitmap icon; | 247 SkBitmap icon; |
| 248 if (data->native_menu_win->model_->GetIconAt(data->model_index, &icon)) { | 248 if (data->native_menu_win->model_->GetIconAt(data->model_index, &icon)) { |
| 249 // We currently don't support items with both icons and checkboxes. | 249 // We currently don't support items with both icons and checkboxes. |
| 250 DCHECK(type != ui::MenuModel::TYPE_CHECK); | 250 DCHECK(type != ui::MenuModel::TYPE_CHECK); |
| 251 gfx::CanvasSkia canvas(icon.width(), icon.height(), false); | 251 gfx::CanvasSkia canvas(icon.width(), icon.height(), false); |
| 252 canvas.drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); | 252 canvas.sk_canvas()->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); |
| 253 canvas.DrawBitmapInt(icon, 0, 0); | 253 canvas.DrawBitmapInt(icon, 0, 0); |
| 254 skia::DrawToNativeContext( | 254 skia::DrawToNativeContext( |
| 255 &canvas, dc, draw_item_struct->rcItem.left + kItemLeftMargin, | 255 canvas.sk_canvas(), dc, |
| 256 draw_item_struct->rcItem.left + kItemLeftMargin, |
| 256 draw_item_struct->rcItem.top + (draw_item_struct->rcItem.bottom - | 257 draw_item_struct->rcItem.top + (draw_item_struct->rcItem.bottom - |
| 257 draw_item_struct->rcItem.top - icon.height()) / 2, NULL); | 258 draw_item_struct->rcItem.top - icon.height()) / 2, NULL); |
| 258 } else if (type == ui::MenuModel::TYPE_CHECK && | 259 } else if (type == ui::MenuModel::TYPE_CHECK && |
| 259 data->native_menu_win->model_->IsItemCheckedAt( | 260 data->native_menu_win->model_->IsItemCheckedAt( |
| 260 data->model_index)) { | 261 data->model_index)) { |
| 261 // Manually render a checkbox. | 262 // Manually render a checkbox. |
| 262 const MenuConfig& config = MenuConfig::instance(); | 263 const MenuConfig& config = MenuConfig::instance(); |
| 263 NativeTheme::State state; | 264 NativeTheme::State state; |
| 264 if (draw_item_struct->itemState & ODS_DISABLED) { | 265 if (draw_item_struct->itemState & ODS_DISABLED) { |
| 265 state = NativeTheme::kDisabled; | 266 state = NativeTheme::kDisabled; |
| 266 } else { | 267 } else { |
| 267 state = draw_item_struct->itemState & ODS_SELECTED ? | 268 state = draw_item_struct->itemState & ODS_SELECTED ? |
| 268 NativeTheme::kHovered : NativeTheme::kNormal; | 269 NativeTheme::kHovered : NativeTheme::kNormal; |
| 269 } | 270 } |
| 270 int height = | 271 int height = |
| 271 draw_item_struct->rcItem.bottom - draw_item_struct->rcItem.top; | 272 draw_item_struct->rcItem.bottom - draw_item_struct->rcItem.top; |
| 272 int icon_y = kItemTopMargin + | 273 int icon_y = kItemTopMargin + |
| 273 (height - kItemTopMargin - kItemBottomMargin - | 274 (height - kItemTopMargin - kItemBottomMargin - |
| 274 config.check_height) / 2; | 275 config.check_height) / 2; |
| 275 gfx::CanvasSkia canvas(config.check_width, config.check_height, false); | 276 gfx::CanvasSkia canvas(config.check_width, config.check_height, false); |
| 276 NativeTheme::ExtraParams extra; | 277 NativeTheme::ExtraParams extra; |
| 277 extra.menu_check.is_radio = false; | 278 extra.menu_check.is_radio = false; |
| 278 gfx::Rect bounds(0, 0, config.check_width, config.check_height); | 279 gfx::Rect bounds(0, 0, config.check_width, config.check_height); |
| 279 | 280 |
| 280 // Draw the background and the check. | 281 // Draw the background and the check. |
| 281 NativeTheme::instance()->Paint( | 282 NativeTheme::instance()->Paint( |
| 282 &canvas, NativeTheme::kMenuCheckBackground, state, bounds, extra); | 283 canvas.sk_canvas(), NativeTheme::kMenuCheckBackground, |
| 284 state, bounds, extra); |
| 283 NativeTheme::instance()->Paint( | 285 NativeTheme::instance()->Paint( |
| 284 &canvas, NativeTheme::kMenuCheck, state, bounds, extra); | 286 canvas.sk_canvas(), NativeTheme::kMenuCheck, state, bounds, extra); |
| 285 | 287 |
| 286 // Draw checkbox to menu. | 288 // Draw checkbox to menu. |
| 287 skia::DrawToNativeContext(&canvas, dc, | 289 skia::DrawToNativeContext(canvas.sk_canvas(), dc, |
| 288 draw_item_struct->rcItem.left + kItemLeftMargin, | 290 draw_item_struct->rcItem.left + kItemLeftMargin, |
| 289 draw_item_struct->rcItem.top + (draw_item_struct->rcItem.bottom - | 291 draw_item_struct->rcItem.top + (draw_item_struct->rcItem.bottom - |
| 290 draw_item_struct->rcItem.top - config.check_height) / 2, NULL); | 292 draw_item_struct->rcItem.top - config.check_height) / 2, NULL); |
| 291 } | 293 } |
| 292 | 294 |
| 293 } else { | 295 } else { |
| 294 // Draw the separator | 296 // Draw the separator |
| 295 draw_item_struct->rcItem.top += | 297 draw_item_struct->rcItem.top += |
| 296 (draw_item_struct->rcItem.bottom - draw_item_struct->rcItem.top) / 3; | 298 (draw_item_struct->rcItem.bottom - draw_item_struct->rcItem.top) / 3; |
| 297 DrawEdge(dc, &draw_item_struct->rcItem, EDGE_ETCHED, BF_TOP); | 299 DrawEdge(dc, &draw_item_struct->rcItem, EDGE_ETCHED, BF_TOP); |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 | 757 |
| 756 //////////////////////////////////////////////////////////////////////////////// | 758 //////////////////////////////////////////////////////////////////////////////// |
| 757 // MenuWrapper, public: | 759 // MenuWrapper, public: |
| 758 | 760 |
| 759 // static | 761 // static |
| 760 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) { | 762 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) { |
| 761 return new NativeMenuWin(menu->model(), NULL); | 763 return new NativeMenuWin(menu->model(), NULL); |
| 762 } | 764 } |
| 763 | 765 |
| 764 } // namespace views | 766 } // namespace views |
| OLD | NEW |