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" |
11 #include "base/stl_util-inl.h" | 11 #include "base/stl_util-inl.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/win/wrapped_window_proc.h" | 13 #include "base/win/wrapped_window_proc.h" |
14 #include "third_party/skia/include/core/SkBitmap.h" | 14 #include "third_party/skia/include/core/SkBitmap.h" |
15 #include "ui/base/keycodes/keyboard_codes.h" | 15 #include "ui/base/keycodes/keyboard_codes.h" |
16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/base/l10n/l10n_util_win.h" | 17 #include "ui/base/l10n/l10n_util_win.h" |
18 #include "ui/base/win/hwnd_util.h" | 18 #include "ui/base/win/hwnd_util.h" |
19 #include "ui/gfx/canvas_skia.h" | 19 #include "ui/gfx/canvas_skia.h" |
20 #include "ui/gfx/font.h" | 20 #include "ui/gfx/font.h" |
| 21 #include "ui/gfx/rect.h" |
21 #include "views/accelerator.h" | 22 #include "views/accelerator.h" |
22 #include "views/controls/menu/menu_2.h" | 23 #include "views/controls/menu/menu_2.h" |
23 | 24 |
24 namespace views { | 25 namespace views { |
25 | 26 |
26 // The width of an icon, including the pixels between the icon and | 27 // The width of an icon, including the pixels between the icon and |
27 // the item label. | 28 // the item label. |
28 static const int kIconWidth = 23; | 29 static const int kIconWidth = 23; |
29 // Margins between the top of the item and the label. | 30 // Margins between the top of the item and the label. |
30 static const int kItemTopMargin = 3; | 31 static const int kItemTopMargin = 3; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 if (!accel.empty()) | 231 if (!accel.empty()) |
231 DrawTextEx(dc, const_cast<wchar_t*>(accel.data()), | 232 DrawTextEx(dc, const_cast<wchar_t*>(accel.data()), |
232 static_cast<int>(accel.size()), &rect, | 233 static_cast<int>(accel.size()), &rect, |
233 format | DT_RIGHT, NULL); | 234 format | DT_RIGHT, NULL); |
234 SelectObject(dc, old_font); | 235 SelectObject(dc, old_font); |
235 | 236 |
236 // Draw the icon after the label, otherwise it would be covered | 237 // Draw the icon after the label, otherwise it would be covered |
237 // by the label. | 238 // by the label. |
238 SkBitmap icon; | 239 SkBitmap icon; |
239 if (data->native_menu_win->model_->GetIconAt(data->model_index, &icon)) { | 240 if (data->native_menu_win->model_->GetIconAt(data->model_index, &icon)) { |
240 gfx::CanvasSkia canvas(icon.width(), icon.height(), false); | 241 gfx::CanvasSkia canvas; |
241 canvas.drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); | 242 canvas.Init(icon.width(), icon.height(), false); |
| 243 |
| 244 canvas.skia_canvas()->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); |
242 canvas.DrawBitmapInt(icon, 0, 0); | 245 canvas.DrawBitmapInt(icon, 0, 0); |
243 canvas.getTopPlatformDevice().drawToHDC(dc, | 246 canvas.BlitToNativeContext( |
244 draw_item_struct->rcItem.left + kItemLeftMargin, | 247 gfx::Rect(icon.width(), icon.height()), |
245 draw_item_struct->rcItem.top + (draw_item_struct->rcItem.bottom - | 248 gfx::Point(draw_item_struct->rcItem.left + kItemLeftMargin, |
246 draw_item_struct->rcItem.top - icon.height()) / 2, NULL); | 249 draw_item_struct->rcItem.top + |
| 250 (draw_item_struct->rcItem.bottom - |
| 251 draw_item_struct->rcItem.top - icon.height()) / 2), |
| 252 dc); |
247 } | 253 } |
248 | |
249 } else { | 254 } else { |
250 // Draw the separator | 255 // Draw the separator |
251 draw_item_struct->rcItem.top += | 256 draw_item_struct->rcItem.top += |
252 (draw_item_struct->rcItem.bottom - draw_item_struct->rcItem.top) / 3; | 257 (draw_item_struct->rcItem.bottom - draw_item_struct->rcItem.top) / 3; |
253 DrawEdge(dc, &draw_item_struct->rcItem, EDGE_ETCHED, BF_TOP); | 258 DrawEdge(dc, &draw_item_struct->rcItem, EDGE_ETCHED, BF_TOP); |
254 } | 259 } |
255 | 260 |
256 SetBkColor(dc, prev_bg_color); | 261 SetBkColor(dc, prev_bg_color); |
257 SetTextColor(dc, prev_text_color); | 262 SetTextColor(dc, prev_text_color); |
258 } | 263 } |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 | 724 |
720 //////////////////////////////////////////////////////////////////////////////// | 725 //////////////////////////////////////////////////////////////////////////////// |
721 // MenuWrapper, public: | 726 // MenuWrapper, public: |
722 | 727 |
723 // static | 728 // static |
724 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) { | 729 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) { |
725 return new NativeMenuWin(menu->model(), NULL); | 730 return new NativeMenuWin(menu->model(), NULL); |
726 } | 731 } |
727 | 732 |
728 } // namespace views | 733 } // namespace views |
OLD | NEW |