| 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/views/controls/menu/native_menu_win.h" | 5 #include "ui/views/controls/menu/native_menu_win.h" |
| 6 | 6 |
| 7 #include <Windowsx.h> | 7 #include <Windowsx.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/win/wrapped_window_proc.h" | 14 #include "base/win/wrapped_window_proc.h" |
| 15 #include "ui/base/accelerators/accelerator.h" | 15 #include "ui/base/accelerators/accelerator.h" |
| 16 #include "ui/base/keycodes/keyboard_codes.h" | 16 #include "ui/base/keycodes/keyboard_codes.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/l10n/l10n_util_win.h" | 18 #include "ui/base/l10n/l10n_util_win.h" |
| 19 #include "ui/base/models/menu_model.h" | 19 #include "ui/base/models/menu_model.h" |
| 20 #include "ui/base/native_theme/native_theme.h" | 20 #include "ui/base/native_theme/native_theme.h" |
| 21 #include "ui/base/win/hwnd_util.h" | 21 #include "ui/base/win/hwnd_util.h" |
| 22 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
| 23 #include "ui/gfx/font.h" | 23 #include "ui/gfx/font.h" |
| 24 #include "ui/gfx/image/image.h" |
| 24 #include "ui/gfx/image/image_skia.h" | 25 #include "ui/gfx/image/image_skia.h" |
| 25 #include "ui/gfx/rect.h" | 26 #include "ui/gfx/rect.h" |
| 26 #include "ui/views/controls/menu/menu_2.h" | 27 #include "ui/views/controls/menu/menu_2.h" |
| 27 #include "ui/views/controls/menu/menu_config.h" | 28 #include "ui/views/controls/menu/menu_config.h" |
| 28 #include "ui/views/controls/menu/menu_listener.h" | 29 #include "ui/views/controls/menu/menu_listener.h" |
| 29 | 30 |
| 30 using ui::NativeTheme; | 31 using ui::NativeTheme; |
| 31 | 32 |
| 32 namespace views { | 33 namespace views { |
| 33 | 34 |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 DrawTextEx(dc, const_cast<wchar_t*>(accel.data()), | 246 DrawTextEx(dc, const_cast<wchar_t*>(accel.data()), |
| 246 static_cast<int>(accel.size()), &rect, | 247 static_cast<int>(accel.size()), &rect, |
| 247 format | DT_RIGHT, NULL); | 248 format | DT_RIGHT, NULL); |
| 248 SelectObject(dc, old_font); | 249 SelectObject(dc, old_font); |
| 249 | 250 |
| 250 ui::MenuModel::ItemType type = | 251 ui::MenuModel::ItemType type = |
| 251 data->native_menu_win->model_->GetTypeAt(data->model_index); | 252 data->native_menu_win->model_->GetTypeAt(data->model_index); |
| 252 | 253 |
| 253 // Draw the icon after the label, otherwise it would be covered | 254 // Draw the icon after the label, otherwise it would be covered |
| 254 // by the label. | 255 // by the label. |
| 255 gfx::ImageSkia icon; | 256 gfx::Image icon; |
| 256 if (data->native_menu_win->model_->GetIconAt(data->model_index, &icon)) { | 257 if (data->native_menu_win->model_->GetIconAt(data->model_index, &icon)) { |
| 257 // We currently don't support items with both icons and checkboxes. | 258 // We currently don't support items with both icons and checkboxes. |
| 259 const gfx::ImageSkia* skia_icon = icon.ToImageSkia(); |
| 258 DCHECK(type != ui::MenuModel::TYPE_CHECK); | 260 DCHECK(type != ui::MenuModel::TYPE_CHECK); |
| 259 gfx::Canvas canvas(icon.GetRepresentation(ui::SCALE_FACTOR_100P), | 261 gfx::Canvas canvas( |
| 260 false); | 262 skia_icon->GetRepresentation(ui::SCALE_FACTOR_100P), |
| 263 false); |
| 261 skia::DrawToNativeContext( | 264 skia::DrawToNativeContext( |
| 262 canvas.sk_canvas(), dc, | 265 canvas.sk_canvas(), dc, |
| 263 draw_item_struct->rcItem.left + kItemLeftMargin, | 266 draw_item_struct->rcItem.left + kItemLeftMargin, |
| 264 draw_item_struct->rcItem.top + (draw_item_struct->rcItem.bottom - | 267 draw_item_struct->rcItem.top + (draw_item_struct->rcItem.bottom - |
| 265 draw_item_struct->rcItem.top - icon.height()) / 2, NULL); | 268 draw_item_struct->rcItem.top - skia_icon->height()) / 2, NULL); |
| 266 } else if (type == ui::MenuModel::TYPE_CHECK && | 269 } else if (type == ui::MenuModel::TYPE_CHECK && |
| 267 data->native_menu_win->model_->IsItemCheckedAt( | 270 data->native_menu_win->model_->IsItemCheckedAt( |
| 268 data->model_index)) { | 271 data->model_index)) { |
| 269 // Manually render a checkbox. | 272 // Manually render a checkbox. |
| 270 const MenuConfig& config = MenuConfig::instance(); | 273 const MenuConfig& config = MenuConfig::instance(); |
| 271 NativeTheme::State state; | 274 NativeTheme::State state; |
| 272 if (draw_item_struct->itemState & ODS_DISABLED) { | 275 if (draw_item_struct->itemState & ODS_DISABLED) { |
| 273 state = NativeTheme::kDisabled; | 276 state = NativeTheme::kDisabled; |
| 274 } else { | 277 } else { |
| 275 state = draw_item_struct->itemState & ODS_SELECTED ? | 278 state = draw_item_struct->itemState & ODS_SELECTED ? |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 | 753 |
| 751 //////////////////////////////////////////////////////////////////////////////// | 754 //////////////////////////////////////////////////////////////////////////////// |
| 752 // MenuWrapper, public: | 755 // MenuWrapper, public: |
| 753 | 756 |
| 754 // static | 757 // static |
| 755 MenuWrapper* MenuWrapper::CreateWrapper(ui::MenuModel* model) { | 758 MenuWrapper* MenuWrapper::CreateWrapper(ui::MenuModel* model) { |
| 756 return new NativeMenuWin(model, NULL); | 759 return new NativeMenuWin(model, NULL); |
| 757 } | 760 } |
| 758 | 761 |
| 759 } // namespace views | 762 } // namespace views |
| OLD | NEW |