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

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

Issue 6732007: Native menu implementation for bug 5679. Followup to http://codereview.chromium.org/2928005/ Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: More code review updates. Created 9 years, 8 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) 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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h"
8 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
9 #include "base/string_util.h" 10 #include "base/string_util.h"
10 #include "base/win/wrapped_window_proc.h" 11 #include "base/win/wrapped_window_proc.h"
11 #include "third_party/skia/include/core/SkBitmap.h" 12 #include "third_party/skia/include/core/SkBitmap.h"
12 #include "ui/base/keycodes/keyboard_codes.h" 13 #include "ui/base/keycodes/keyboard_codes.h"
13 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/l10n/l10n_util_win.h" 15 #include "ui/base/l10n/l10n_util_win.h"
15 #include "ui/base/win/hwnd_util.h" 16 #include "ui/base/win/hwnd_util.h"
16 #include "ui/gfx/canvas_skia.h" 17 #include "ui/gfx/canvas_skia.h"
17 #include "ui/gfx/font.h" 18 #include "ui/gfx/font.h"
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // variable so the hook has access to it (ugly, but it's the 334 // variable so the hook has access to it (ugly, but it's the
334 // only way). 335 // only way).
335 open_native_menu_win_ = this; 336 open_native_menu_win_ = this;
336 HHOOK hhook = SetWindowsHookEx(WH_MSGFILTER, MenuMessageHook, 337 HHOOK hhook = SetWindowsHookEx(WH_MSGFILTER, MenuMessageHook,
337 GetModuleHandle(NULL), ::GetCurrentThreadId()); 338 GetModuleHandle(NULL), ::GetCurrentThreadId());
338 339
339 // Mark that any registered listeners have not been called for this particular 340 // Mark that any registered listeners have not been called for this particular
340 // opening of the menu. 341 // opening of the menu.
341 listeners_called_ = false; 342 listeners_called_ = false;
342 343
344 // Retrieving favicons from history requires nestable tasks.
345 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
346
347 model_->SetMenuModelDelegate(this);
348
343 // Command dispatch is done through WM_MENUCOMMAND, handled by the host 349 // Command dispatch is done through WM_MENUCOMMAND, handled by the host
344 // window. 350 // window.
345 HWND hwnd = host_window_->hwnd(); 351 HWND hwnd = host_window_->hwnd();
346 TrackPopupMenuEx(menu_, flags, point.x(), point.y(), host_window_->hwnd(), 352 TrackPopupMenuEx(menu_, flags, point.x(), point.y(), host_window_->hwnd(),
347 NULL); 353 NULL);
348 354
355 model_->SetMenuModelDelegate(NULL);
349 UnhookWindowsHookEx(hhook); 356 UnhookWindowsHookEx(hhook);
350 open_native_menu_win_ = NULL; 357 open_native_menu_win_ = NULL;
351 } 358 }
352 359
353 void NativeMenuWin::CancelMenu() { 360 void NativeMenuWin::CancelMenu() {
354 EndMenu(); 361 EndMenu();
355 } 362 }
356 363
357 void NativeMenuWin::Rebuild() { 364 void NativeMenuWin::Rebuild() {
358 ResetNativeMenu(); 365 ResetNativeMenu();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 listeners_.erase(iter); 416 listeners_.erase(iter);
410 return; 417 return;
411 } 418 }
412 } 419 }
413 } 420 }
414 421
415 void NativeMenuWin::SetMinimumWidth(int width) { 422 void NativeMenuWin::SetMinimumWidth(int width) {
416 NOTIMPLEMENTED(); 423 NOTIMPLEMENTED();
417 } 424 }
418 425
426 void NativeMenuWin::OnIconChanged(int model_index) {
427 // Translate the model_index to the menu_index.
428 int first_item_index_ = model_->GetFirstItemIndex(GetNativeMenu());
429 int menu_index = model_index + first_item_index_;
430 // Unfortunately this repaints the entire menu.
431 SetMenuItemState(menu_index, model_->IsEnabledAt(model_index),
432 model_->IsItemCheckedAt(model_index), false);
433 }
434
419 //////////////////////////////////////////////////////////////////////////////// 435 ////////////////////////////////////////////////////////////////////////////////
420 // NativeMenuWin, private: 436 // NativeMenuWin, private:
421 437
422 // static 438 // static
423 NativeMenuWin* NativeMenuWin::open_native_menu_win_ = NULL; 439 NativeMenuWin* NativeMenuWin::open_native_menu_win_ = NULL;
424 440
425 // static 441 // static
426 bool NativeMenuWin::GetHighlightedMenuItemInfo( 442 bool NativeMenuWin::GetHighlightedMenuItemInfo(
427 HMENU menu, bool* has_parent, bool* has_submenu) { 443 HMENU menu, bool* has_parent, bool* has_submenu) {
428 for (int i = 0; i < ::GetMenuItemCount(menu); i++) { 444 for (int i = 0; i < ::GetMenuItemCount(menu); i++) {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 651
636 //////////////////////////////////////////////////////////////////////////////// 652 ////////////////////////////////////////////////////////////////////////////////
637 // MenuWrapper, public: 653 // MenuWrapper, public:
638 654
639 // static 655 // static
640 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) { 656 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) {
641 return new NativeMenuWin(menu->model(), NULL); 657 return new NativeMenuWin(menu->model(), NULL);
642 } 658 }
643 659
644 } // namespace views 660 } // namespace views
OLDNEW
« chrome/browser/ui/gtk/menu_gtk.cc ('K') | « views/controls/menu/native_menu_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698