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

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

Issue 2155243007: Turn Bookmark Menus Async (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge the pretarget handlers Created 4 years, 4 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
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/menu_controller.h" 5 #include "ui/views/controls/menu/menu_controller.h"
6 6
7 #include "base/i18n/case_conversion.h" 7 #include "base/i18n/case_conversion.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 28 matching lines...) Expand all
39 #include "ui/views/widget/widget.h" 39 #include "ui/views/widget/widget.h"
40 40
41 #if defined(OS_WIN) 41 #if defined(OS_WIN)
42 #include "ui/aura/window_tree_host.h" 42 #include "ui/aura/window_tree_host.h"
43 #include "ui/base/win/internal_constants.h" 43 #include "ui/base/win/internal_constants.h"
44 #include "ui/display/win/screen_win.h" 44 #include "ui/display/win/screen_win.h"
45 #include "ui/views/win/hwnd_util.h" 45 #include "ui/views/win/hwnd_util.h"
46 #endif 46 #endif
47 47
48 #if defined(USE_AURA) 48 #if defined(USE_AURA)
49 #include "ui/views/controls/menu/menu_key_event_handler.h" 49 #include "ui/views/controls/menu/menu_pre_target_handler.h"
50 #endif 50 #endif
51 51
52 using base::Time; 52 using base::Time;
53 using base::TimeDelta; 53 using base::TimeDelta;
54 using ui::OSExchangeData; 54 using ui::OSExchangeData;
55 55
56 namespace views { 56 namespace views {
57 57
58 namespace { 58 namespace {
59 59
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 if (event && event->type() == ui::ET_MOUSE_PRESSED) { 413 if (event && event->type() == ui::ET_MOUSE_PRESSED) {
414 gfx::Point screen_loc( 414 gfx::Point screen_loc(
415 static_cast<const ui::MouseEvent*>(event)->location()); 415 static_cast<const ui::MouseEvent*>(event)->location());
416 View::ConvertPointToScreen( 416 View::ConvertPointToScreen(
417 static_cast<View*>(event->target()), &screen_loc); 417 static_cast<View*>(event->target()), &screen_loc);
418 menu_start_mouse_press_loc_ = screen_loc; 418 menu_start_mouse_press_loc_ = screen_loc;
419 } 419 }
420 } 420 }
421 } 421 }
422 422
423 bool nested_menu = showing_; 423 // If we are already showing, this new menu is being nested. Such as context
424 // menus on top of normal menus.
424 if (showing_) { 425 if (showing_) {
425 // Only support nesting of blocking_run menus, nesting of 426 // Only support nesting of blocking_run menus, nesting of
426 // blocking/non-blocking shouldn't be needed. 427 // blocking/non-blocking shouldn't be needed.
427 DCHECK(blocking_run_); 428 DCHECK(blocking_run_);
428 429
429 state_.hot_button = hot_button_; 430 state_.hot_button = hot_button_;
430 hot_button_ = nullptr; 431 hot_button_ = nullptr;
431 // We're already showing, push the current state. 432 // We're already showing, push the current state.
432 menu_stack_.push_back( 433 menu_stack_.push_back(
433 std::make_pair(state_, make_linked_ptr(pressed_lock_.release()))); 434 std::make_pair(state_, make_linked_ptr(pressed_lock_.release())));
434 435
435 // The context menu should be owned by the same parent. 436 // The context menu should be owned by the same parent.
436 DCHECK_EQ(owner_, parent); 437 DCHECK_EQ(owner_, parent);
437 } else { 438 } else {
438 showing_ = true; 439 showing_ = true;
439 440
441 if (owner_)
442 owner_->RemoveObserver(this);
443 owner_ = parent;
444 if (owner_)
445 owner_->AddObserver(this);
446
440 #if defined(USE_AURA) 447 #if defined(USE_AURA)
441 // Only create a MenuKeyEventHandler for non-nested menus. Nested menus will 448 // Only create a MenuPreTargetHandler for non-nested menus. Nested menus
442 // use the existing one. 449 // will use the existing one.
443 key_event_handler_.reset(new MenuKeyEventHandler); 450 menu_pre_target_handler_.reset(new MenuPreTargetHandler(this, owner_));
444 #endif 451 #endif
445 } 452 }
446 453
447 // Reset current state. 454 // Reset current state.
448 pending_state_ = State(); 455 pending_state_ = State();
449 state_ = State(); 456 state_ = State();
450 UpdateInitialLocation(bounds, position, context_menu); 457 UpdateInitialLocation(bounds, position, context_menu);
451 458
452 if (owner_)
453 owner_->RemoveObserver(this);
454 owner_ = parent;
455 if (owner_)
456 owner_->AddObserver(this);
457
458 // Set the selection, which opens the initial menu. 459 // Set the selection, which opens the initial menu.
459 SetSelection(root, SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY); 460 SetSelection(root, SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY);
460 461
461 if (!blocking_run_) { 462 if (!blocking_run_) {
462 if (!is_nested_drag) { 463 if (!is_nested_drag) {
463 // Start the timer to hide the menu. This is needed as we get no 464 // Start the timer to hide the menu. This is needed as we get no
464 // notification when the drag has finished. 465 // notification when the drag has finished.
465 StartCancelAllTimer(); 466 StartCancelAllTimer();
466 } 467 }
467 return NULL; 468 return NULL;
468 } 469 }
469 470
470 if (button) 471 if (button)
471 pressed_lock_.reset(new MenuButton::PressedLock(button)); 472 pressed_lock_.reset(new MenuButton::PressedLock(button));
472 473
473 // Make sure Chrome doesn't attempt to shut down while the menu is showing. 474 // Make sure Chrome doesn't attempt to shut down while the menu is showing.
474 if (ViewsDelegate::GetInstance()) 475 if (ViewsDelegate::GetInstance())
475 ViewsDelegate::GetInstance()->AddRef(); 476 ViewsDelegate::GetInstance()->AddRef();
476 477
477 if (async_run_) 478 if (async_run_)
478 return nullptr; 479 return nullptr;
479 480
480 // We need to turn on nestable tasks as in some situations (pressing alt-f for 481 // We need to turn on nestable tasks as in some situations (pressing alt-f for
481 // one) the menus are run from a task. If we don't do this and are invoked 482 // one) the menus are run from a task. If we don't do this and are invoked
482 // from a task none of the tasks we schedule are processed and the menu 483 // from a task none of the tasks we schedule are processed and the menu
483 // appears totally broken. 484 // appears totally broken.
484 message_loop_depth_++; 485 message_loop_depth_++;
485 DCHECK_LE(message_loop_depth_, 2); 486 DCHECK_LE(message_loop_depth_, 2);
486 RunMessageLoop(nested_menu); 487 RunMessageLoop();
487 message_loop_depth_--; 488 message_loop_depth_--;
488 489
489 if (ViewsDelegate::GetInstance()) 490 if (ViewsDelegate::GetInstance())
490 ViewsDelegate::GetInstance()->ReleaseRef(); 491 ViewsDelegate::GetInstance()->ReleaseRef();
491 492
492 if (result_event_flags) 493 if (result_event_flags)
493 *result_event_flags = accept_event_flags_; 494 *result_event_flags = accept_event_flags_;
494 495
495 // The nested message loop could have been killed externally. Check to see if 496 // The nested message loop could have been killed externally. Check to see if
496 // there are nested asynchronous menus to shutdown. 497 // there are nested asynchronous menus to shutdown.
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 View::ConvertPointFromScreen( 1080 View::ConvertPointFromScreen(
1080 root_submenu->GetWidget()->GetRootView(), &point); 1081 root_submenu->GetWidget()->GetRootView(), &point);
1081 HandleMouseLocation(submenu, point); 1082 HandleMouseLocation(submenu, point);
1082 } 1083 }
1083 } 1084 }
1084 1085
1085 void MenuController::OnWidgetDestroying(Widget* widget) { 1086 void MenuController::OnWidgetDestroying(Widget* widget) {
1086 DCHECK_EQ(owner_, widget); 1087 DCHECK_EQ(owner_, widget);
1087 owner_->RemoveObserver(this); 1088 owner_->RemoveObserver(this);
1088 owner_ = NULL; 1089 owner_ = NULL;
1089 message_loop_->ClearOwner();
1090 } 1090 }
1091 1091
1092 bool MenuController::IsCancelAllTimerRunningForTest() { 1092 bool MenuController::IsCancelAllTimerRunningForTest() {
1093 return cancel_all_timer_.IsRunning(); 1093 return cancel_all_timer_.IsRunning();
1094 } 1094 }
1095 1095
1096 // static 1096 // static
1097 void MenuController::TurnOffMenuSelectionHoldForTest() { 1097 void MenuController::TurnOffMenuSelectionHoldForTest() {
1098 menu_selection_hold_time_ms = -1; 1098 menu_selection_hold_time_ms = -1;
1099 } 1099 }
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1380 MenuController::~MenuController() { 1380 MenuController::~MenuController() {
1381 DCHECK(!showing_); 1381 DCHECK(!showing_);
1382 if (owner_) 1382 if (owner_)
1383 owner_->RemoveObserver(this); 1383 owner_->RemoveObserver(this);
1384 if (active_instance_ == this) 1384 if (active_instance_ == this)
1385 active_instance_ = NULL; 1385 active_instance_ = NULL;
1386 StopShowTimer(); 1386 StopShowTimer();
1387 StopCancelAllTimer(); 1387 StopCancelAllTimer();
1388 } 1388 }
1389 1389
1390 void MenuController::RunMessageLoop(bool nested_menu) { 1390 void MenuController::RunMessageLoop() {
1391 message_loop_->Run(this, owner_, nested_menu); 1391 message_loop_->Run();
1392 } 1392 }
1393 1393
1394 bool MenuController::SendAcceleratorToHotTrackedView() { 1394 bool MenuController::SendAcceleratorToHotTrackedView() {
1395 CustomButton* hot_view = GetFirstHotTrackedView(pending_state_.item); 1395 CustomButton* hot_view = GetFirstHotTrackedView(pending_state_.item);
1396 if (!hot_view) 1396 if (!hot_view)
1397 return false; 1397 return false;
1398 1398
1399 ui::Accelerator accelerator(ui::VKEY_RETURN, ui::EF_NONE); 1399 ui::Accelerator accelerator(ui::VKEY_RETURN, ui::EF_NONE);
1400 hot_view->AcceleratorPressed(accelerator); 1400 hot_view->AcceleratorPressed(accelerator);
1401 CustomButton* button = static_cast<CustomButton*>(hot_view); 1401 CustomButton* button = static_cast<CustomButton*>(hot_view);
(...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after
2603 nested_pressed_lock = menu_stack_.back().second; 2603 nested_pressed_lock = menu_stack_.back().second;
2604 menu_stack_.pop_back(); 2604 menu_stack_.pop_back();
2605 // Even though the menus are nested, there may not be nested delegates. 2605 // Even though the menus are nested, there may not be nested delegates.
2606 if (delegate_stack_.size() > 1) { 2606 if (delegate_stack_.size() > 1) {
2607 delegate_stack_.pop_back(); 2607 delegate_stack_.pop_back();
2608 delegate_ = delegate_stack_.back().first; 2608 delegate_ = delegate_stack_.back().first;
2609 async_run_ = delegate_stack_.back().second; 2609 async_run_ = delegate_stack_.back().second;
2610 } 2610 }
2611 } else { 2611 } else {
2612 #if defined(USE_AURA) 2612 #if defined(USE_AURA)
2613 key_event_handler_.reset(); 2613 menu_pre_target_handler_.reset();
2614 #endif 2614 #endif
2615 2615
2616 showing_ = false; 2616 showing_ = false;
2617 did_capture_ = false; 2617 did_capture_ = false;
2618 } 2618 }
2619 2619
2620 MenuItemView* result = result_; 2620 MenuItemView* result = result_;
2621 // In case we're nested, reset |result_|. 2621 // In case we're nested, reset |result_|.
2622 result_ = nullptr; 2622 result_ = nullptr;
2623 2623
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
2703 if (hot_button_) 2703 if (hot_button_)
2704 hot_button_->SetHotTracked(false); 2704 hot_button_->SetHotTracked(false);
2705 hot_button_ = hot_button; 2705 hot_button_ = hot_button;
2706 if (hot_button) { 2706 if (hot_button) {
2707 hot_button->SetHotTracked(true); 2707 hot_button->SetHotTracked(true);
2708 hot_button->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true); 2708 hot_button->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true);
2709 } 2709 }
2710 } 2710 }
2711 2711
2712 } // namespace views 2712 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_controller.h ('k') | ui/views/controls/menu/menu_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698