Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: ui/views/controls/menu/native_menu_win.cc

Issue 24175004: Remove dependency on ui::ScaleFactor from ui/gfx (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/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/layout.h"
Ben Goodger (Google) 2013/09/16 23:10:31 etc
19 #include "ui/base/models/menu_model.h" 20 #include "ui/base/models/menu_model.h"
20 #include "ui/gfx/canvas.h" 21 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/font.h" 22 #include "ui/gfx/font.h"
22 #include "ui/gfx/image/image.h" 23 #include "ui/gfx/image/image.h"
23 #include "ui/gfx/image/image_skia.h" 24 #include "ui/gfx/image/image_skia.h"
24 #include "ui/gfx/rect.h" 25 #include "ui/gfx/rect.h"
25 #include "ui/gfx/win/hwnd_util.h" 26 #include "ui/gfx/win/hwnd_util.h"
26 #include "ui/native_theme/native_theme.h" 27 #include "ui/native_theme/native_theme.h"
27 #include "ui/native_theme/native_theme_win.h" 28 #include "ui/native_theme/native_theme_win.h"
28 #include "ui/views/controls/menu/menu_2.h" 29 #include "ui/views/controls/menu/menu_2.h"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 data->native_menu_win->model_->GetTypeAt(data->model_index); 255 data->native_menu_win->model_->GetTypeAt(data->model_index);
255 256
256 // Draw the icon after the label, otherwise it would be covered 257 // Draw the icon after the label, otherwise it would be covered
257 // by the label. 258 // by the label.
258 gfx::Image icon; 259 gfx::Image icon;
259 if (data->native_menu_win->model_->GetIconAt(data->model_index, &icon)) { 260 if (data->native_menu_win->model_->GetIconAt(data->model_index, &icon)) {
260 // We currently don't support items with both icons and checkboxes. 261 // We currently don't support items with both icons and checkboxes.
261 const gfx::ImageSkia* skia_icon = icon.ToImageSkia(); 262 const gfx::ImageSkia* skia_icon = icon.ToImageSkia();
262 DCHECK(type != ui::MenuModel::TYPE_CHECK); 263 DCHECK(type != ui::MenuModel::TYPE_CHECK);
263 gfx::Canvas canvas( 264 gfx::Canvas canvas(
264 skia_icon->GetRepresentation(ui::SCALE_FACTOR_100P), 265 skia_icon->GetRepresentation(1.0f),
265 false); 266 false);
266 skia::DrawToNativeContext( 267 skia::DrawToNativeContext(
267 canvas.sk_canvas(), dc, 268 canvas.sk_canvas(), dc,
268 draw_item_struct->rcItem.left + kItemLeftMargin, 269 draw_item_struct->rcItem.left + kItemLeftMargin,
269 draw_item_struct->rcItem.top + (draw_item_struct->rcItem.bottom - 270 draw_item_struct->rcItem.top + (draw_item_struct->rcItem.bottom -
270 draw_item_struct->rcItem.top - skia_icon->height()) / 2, NULL); 271 draw_item_struct->rcItem.top - skia_icon->height()) / 2, NULL);
271 } else if (type == ui::MenuModel::TYPE_CHECK && 272 } else if (type == ui::MenuModel::TYPE_CHECK &&
272 data->native_menu_win->model_->IsItemCheckedAt( 273 data->native_menu_win->model_->IsItemCheckedAt(
273 data->model_index)) { 274 data->model_index)) {
274 // Manually render a checkbox. 275 // Manually render a checkbox.
275 ui::NativeThemeWin* native_theme = ui::NativeThemeWin::instance(); 276 ui::NativeThemeWin* native_theme = ui::NativeThemeWin::instance();
276 const MenuConfig& config = MenuConfig::instance(native_theme); 277 const MenuConfig& config = MenuConfig::instance(native_theme);
277 NativeTheme::State state; 278 NativeTheme::State state;
278 if (draw_item_struct->itemState & ODS_DISABLED) { 279 if (draw_item_struct->itemState & ODS_DISABLED) {
279 state = NativeTheme::kDisabled; 280 state = NativeTheme::kDisabled;
280 } else { 281 } else {
281 state = draw_item_struct->itemState & ODS_SELECTED ? 282 state = draw_item_struct->itemState & ODS_SELECTED ?
282 NativeTheme::kHovered : NativeTheme::kNormal; 283 NativeTheme::kHovered : NativeTheme::kNormal;
283 } 284 }
284 int height = 285 int height =
285 draw_item_struct->rcItem.bottom - draw_item_struct->rcItem.top; 286 draw_item_struct->rcItem.bottom - draw_item_struct->rcItem.top;
286 int icon_y = kItemTopMargin + 287 int icon_y = kItemTopMargin +
287 (height - kItemTopMargin - kItemBottomMargin - 288 (height - kItemTopMargin - kItemBottomMargin -
288 config.check_height) / 2; 289 config.check_height) / 2;
289 gfx::Canvas canvas(gfx::Size(config.check_width, config.check_height), 290 gfx::Canvas canvas(gfx::Size(config.check_width, config.check_height),
290 ui::SCALE_FACTOR_100P, 291 1.0f,
291 false); 292 false);
292 NativeTheme::ExtraParams extra; 293 NativeTheme::ExtraParams extra;
293 extra.menu_check.is_radio = false; 294 extra.menu_check.is_radio = false;
294 gfx::Rect bounds(0, 0, config.check_width, config.check_height); 295 gfx::Rect bounds(0, 0, config.check_width, config.check_height);
295 296
296 // Draw the background and the check. 297 // Draw the background and the check.
297 native_theme->Paint( 298 native_theme->Paint(
298 canvas.sk_canvas(), NativeTheme::kMenuCheckBackground, 299 canvas.sk_canvas(), NativeTheme::kMenuCheckBackground,
299 state, bounds, extra); 300 state, bounds, extra);
300 native_theme->Paint( 301 native_theme->Paint(
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 757
757 //////////////////////////////////////////////////////////////////////////////// 758 ////////////////////////////////////////////////////////////////////////////////
758 // MenuWrapper, public: 759 // MenuWrapper, public:
759 760
760 // static 761 // static
761 MenuWrapper* MenuWrapper::CreateWrapper(ui::MenuModel* model) { 762 MenuWrapper* MenuWrapper::CreateWrapper(ui::MenuModel* model) {
762 return new NativeMenuWin(model, NULL); 763 return new NativeMenuWin(model, NULL);
763 } 764 }
764 765
765 } // namespace views 766 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698