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

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: Created 9 years, 9 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/win/wrapped_window_proc.h" 10 #include "base/win/wrapped_window_proc.h"
10 #include "third_party/skia/include/core/SkBitmap.h" 11 #include "third_party/skia/include/core/SkBitmap.h"
11 #include "ui/base/keycodes/keyboard_codes.h" 12 #include "ui/base/keycodes/keyboard_codes.h"
12 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/l10n/l10n_util_win.h" 14 #include "ui/base/l10n/l10n_util_win.h"
14 #include "ui/base/win/hwnd_util.h" 15 #include "ui/base/win/hwnd_util.h"
15 #include "ui/gfx/canvas_skia.h" 16 #include "ui/gfx/canvas_skia.h"
16 #include "ui/gfx/font.h" 17 #include "ui/gfx/font.h"
17 #include "views/accelerator.h" 18 #include "views/accelerator.h"
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 // NativeMenuWin, public: 304 // NativeMenuWin, public:
304 305
305 NativeMenuWin::NativeMenuWin(ui::MenuModel* model, HWND system_menu_for) 306 NativeMenuWin::NativeMenuWin(ui::MenuModel* model, HWND system_menu_for)
306 : model_(model), 307 : model_(model),
307 menu_(NULL), 308 menu_(NULL),
308 owner_draw_(l10n_util::NeedOverrideDefaultUIFont(NULL, NULL) && 309 owner_draw_(l10n_util::NeedOverrideDefaultUIFont(NULL, NULL) &&
309 !system_menu_for), 310 !system_menu_for),
310 system_menu_for_(system_menu_for), 311 system_menu_for_(system_menu_for),
311 first_item_index_(0), 312 first_item_index_(0),
312 menu_action_(MENU_ACTION_NONE) { 313 menu_action_(MENU_ACTION_NONE) {
314 model_->SetMenuModelDelegate(this);
sky 2011/03/24 22:39:29 I don't see you ever removing the delegate.
Avi (use Gerrit) 2011/03/25 00:19:35 Good point. Ditto for all implementations.
dill 2011/03/25 01:47:47 I should do model_->SetMenuModelDelegate(NULL); in
dill 2011/03/25 19:06:56 Ah, well that sounded good. But model_ outlives th
313 } 315 }
314 316
315 NativeMenuWin::~NativeMenuWin() { 317 NativeMenuWin::~NativeMenuWin() {
316 STLDeleteContainerPointers(items_.begin(), items_.end()); 318 STLDeleteContainerPointers(items_.begin(), items_.end());
317 DestroyMenu(menu_); 319 DestroyMenu(menu_);
318 } 320 }
319 321
320 //////////////////////////////////////////////////////////////////////////////// 322 ////////////////////////////////////////////////////////////////////////////////
321 // NativeMenuWin, MenuWrapper implementation: 323 // NativeMenuWin, MenuWrapper implementation:
322 324
323 void NativeMenuWin::RunMenuAt(const gfx::Point& point, int alignment) { 325 void NativeMenuWin::RunMenuAt(const gfx::Point& point, int alignment) {
324 CreateHostWindow(); 326 CreateHostWindow();
325 UpdateStates(); 327 UpdateStates();
326 UINT flags = TPM_LEFTBUTTON | TPM_RECURSE; 328 UINT flags = TPM_LEFTBUTTON | TPM_RECURSE;
327 flags |= GetAlignmentFlags(alignment); 329 flags |= GetAlignmentFlags(alignment);
328 menu_action_ = MENU_ACTION_NONE; 330 menu_action_ = MENU_ACTION_NONE;
329 331
330 // Set a hook function so we can listen for keyboard events while the 332 // Set a hook function so we can listen for keyboard events while the
331 // menu is open, and store a pointer to this object in a static 333 // menu is open, and store a pointer to this object in a static
332 // 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
333 // only way). 335 // only way).
334 open_native_menu_win_ = this; 336 open_native_menu_win_ = this;
335 HHOOK hhook = SetWindowsHookEx(WH_MSGFILTER, MenuMessageHook, 337 HHOOK hhook = SetWindowsHookEx(WH_MSGFILTER, MenuMessageHook,
336 GetModuleHandle(NULL), ::GetCurrentThreadId()); 338 GetModuleHandle(NULL), ::GetCurrentThreadId());
337 339
338 // 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
339 // opening of the menu. 341 // opening of the menu.
340 listeners_called_ = false; 342 listeners_called_ = false;
341 343
344 // Retrieving favicons from history requires nestable tasks.
345 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
346
342 // Command dispatch is done through WM_MENUCOMMAND, handled by the host 347 // Command dispatch is done through WM_MENUCOMMAND, handled by the host
343 // window. 348 // window.
344 HWND hwnd = host_window_->hwnd(); 349 HWND hwnd = host_window_->hwnd();
345 TrackPopupMenuEx(menu_, flags, point.x(), point.y(), host_window_->hwnd(), 350 TrackPopupMenuEx(menu_, flags, point.x(), point.y(), host_window_->hwnd(),
346 NULL); 351 NULL);
347 352
348 UnhookWindowsHookEx(hhook); 353 UnhookWindowsHookEx(hhook);
349 open_native_menu_win_ = NULL; 354 open_native_menu_win_ = NULL;
350 } 355 }
351 356
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 listeners_.erase(iter); 413 listeners_.erase(iter);
409 return; 414 return;
410 } 415 }
411 } 416 }
412 } 417 }
413 418
414 void NativeMenuWin::SetMinimumWidth(int width) { 419 void NativeMenuWin::SetMinimumWidth(int width) {
415 NOTIMPLEMENTED(); 420 NOTIMPLEMENTED();
416 } 421 }
417 422
423 void NativeMenuWin::OnIconChanged(int model_index) {
424 // Translate the model_index to the menu_index.
425 int first_item_index_ = model_->GetFirstItemIndex(GetNativeMenu());
426 int menu_index = model_index + first_item_index_;
427 // Unfortunately this repaints the entire menu.
428 SetMenuItemState(menu_index, model_->IsEnabledAt(model_index),
429 model_->IsItemCheckedAt(model_index), false);
430 }
431
418 //////////////////////////////////////////////////////////////////////////////// 432 ////////////////////////////////////////////////////////////////////////////////
419 // NativeMenuWin, private: 433 // NativeMenuWin, private:
420 434
421 // static 435 // static
422 NativeMenuWin* NativeMenuWin::open_native_menu_win_ = NULL; 436 NativeMenuWin* NativeMenuWin::open_native_menu_win_ = NULL;
423 437
424 // static 438 // static
425 bool NativeMenuWin::GetHighlightedMenuItemInfo( 439 bool NativeMenuWin::GetHighlightedMenuItemInfo(
426 HMENU menu, bool* has_parent, bool* has_submenu) { 440 HMENU menu, bool* has_parent, bool* has_submenu) {
427 for (int i = 0; i < ::GetMenuItemCount(menu); i++) { 441 for (int i = 0; i < ::GetMenuItemCount(menu); i++) {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 645
632 //////////////////////////////////////////////////////////////////////////////// 646 ////////////////////////////////////////////////////////////////////////////////
633 // MenuWrapper, public: 647 // MenuWrapper, public:
634 648
635 // static 649 // static
636 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) { 650 MenuWrapper* MenuWrapper::CreateWrapper(Menu2* menu) {
637 return new NativeMenuWin(menu->model(), NULL); 651 return new NativeMenuWin(menu->model(), NULL);
638 } 652 }
639 653
640 } // namespace views 654 } // namespace views
OLDNEW
« views/controls/menu/native_menu_win.h ('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