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

Unified Diff: ui/views/controls/menu/menu_runner_impl.cc

Issue 2779373002: Remove Nested Message Loop from MenuController (Closed)
Patch Set: unneeded runloop Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/menu/menu_runner_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/menu/menu_runner_impl.cc
diff --git a/ui/views/controls/menu/menu_runner_impl.cc b/ui/views/controls/menu/menu_runner_impl.cc
index a247d5129bba444b463610ba9855590974ef70ae..7dd87fe7c322c30d2c89e9bf45fb82b828c34833 100644
--- a/ui/views/controls/menu/menu_runner_impl.cc
+++ b/ui/views/controls/menu/menu_runner_impl.cc
@@ -33,7 +33,6 @@ MenuRunnerImpl::MenuRunnerImpl(MenuItemView* menu)
: menu_(menu),
running_(false),
delete_after_run_(false),
- async_(false),
for_drop_(false),
controller_(NULL),
owns_controller_(false),
@@ -114,7 +113,6 @@ MenuRunner::RunResult MenuRunnerImpl::RunMenuAt(Widget* parent,
}
running_ = true;
- async_ = (run_types & MenuRunner::ASYNC) != 0;
for_drop_ = (run_types & MenuRunner::FOR_DROP) != 0;
bool has_mnemonics = (run_types & MenuRunner::HAS_MNEMONICS) != 0;
owns_controller_ = false;
@@ -123,7 +121,6 @@ MenuRunner::RunResult MenuRunnerImpl::RunMenuAt(Widget* parent,
controller = new MenuController(!for_drop_, this);
owns_controller_ = true;
}
- controller->SetAsyncRun(async_);
controller->set_is_combobox((run_types & MenuRunner::COMBOBOX) != 0);
controller_ = controller->AsWeakPtr();
menu_->set_controller(controller_.get());
@@ -131,25 +128,13 @@ MenuRunner::RunResult MenuRunnerImpl::RunMenuAt(Widget* parent,
has_mnemonics,
!for_drop_ && ShouldShowMnemonics(button));
- // Run the loop.
int mouse_event_flags = 0;
- MenuItemView* result =
- controller->Run(parent,
- button,
- menu_,
- bounds,
- anchor,
- (run_types & MenuRunner::CONTEXT_MENU) != 0,
- (run_types & MenuRunner::NESTED_DRAG) != 0,
- &mouse_event_flags);
- // Get the time of the event which closed this menu.
- closing_event_time_ = controller->closing_event_time();
- if (for_drop_ || async_) {
- // Drop and asynchronous menus return immediately. We finish processing in
- // OnMenuClosed.
- return MenuRunner::NORMAL_EXIT;
- }
- return MenuDone(NOTIFY_DELEGATE, result, mouse_event_flags);
+ controller->Run(parent, button, menu_, bounds, anchor,
+ (run_types & MenuRunner::CONTEXT_MENU) != 0,
+ (run_types & MenuRunner::NESTED_DRAG) != 0,
+ &mouse_event_flags);
+ // We finish processing results in OnMenuClosed.
+ return MenuRunner::NORMAL_EXIT;
}
void MenuRunnerImpl::Cancel() {
@@ -164,25 +149,8 @@ base::TimeTicks MenuRunnerImpl::GetClosingEventTime() const {
void MenuRunnerImpl::OnMenuClosed(NotifyType type,
MenuItemView* menu,
int mouse_event_flags) {
- MenuDone(type, menu, mouse_event_flags);
-}
-
-void MenuRunnerImpl::SiblingMenuCreated(MenuItemView* menu) {
- if (menu != menu_ && sibling_menus_.count(menu) == 0)
- sibling_menus_.insert(menu);
-}
-
-MenuRunnerImpl::~MenuRunnerImpl() {
- delete menu_;
- for (std::set<MenuItemView*>::iterator i = sibling_menus_.begin();
- i != sibling_menus_.end();
- ++i)
- delete *i;
-}
-
-MenuRunner::RunResult MenuRunnerImpl::MenuDone(NotifyType type,
- MenuItemView* result,
- int mouse_event_flags) {
+ if (controller_)
+ closing_event_time_ = controller_->closing_event_time();
menu_->RemoveEmptyMenus();
menu_->set_controller(nullptr);
@@ -197,24 +165,35 @@ MenuRunner::RunResult MenuRunnerImpl::MenuDone(NotifyType type,
menu_->DestroyAllMenuHosts();
if (delete_after_run_) {
delete this;
- return MenuRunner::MENU_DELETED;
+ return;
}
running_ = false;
if (menu_->GetDelegate()) {
// Executing the command may also delete this.
base::WeakPtr<MenuRunnerImpl> ref(weak_factory_.GetWeakPtr());
- if (result && !for_drop_) {
+ if (menu && !for_drop_) {
// Do not execute the menu that was dragged/dropped.
- menu_->GetDelegate()->ExecuteCommand(result->GetCommand(),
+ menu_->GetDelegate()->ExecuteCommand(menu->GetCommand(),
mouse_event_flags);
}
// Only notify the delegate if it did not delete this.
if (!ref)
- return MenuRunner::MENU_DELETED;
+ return;
else if (type == NOTIFY_DELEGATE)
- menu_->GetDelegate()->OnMenuClosed(result, MenuRunner::NORMAL_EXIT);
+ menu_->GetDelegate()->OnMenuClosed(menu, MenuRunner::NORMAL_EXIT);
}
- return MenuRunner::NORMAL_EXIT;
+}
+
+void MenuRunnerImpl::SiblingMenuCreated(MenuItemView* menu) {
+ if (menu != menu_ && sibling_menus_.count(menu) == 0)
+ sibling_menus_.insert(menu);
+}
+
+MenuRunnerImpl::~MenuRunnerImpl() {
+ delete menu_;
+ for (std::set<MenuItemView*>::iterator i = sibling_menus_.begin();
+ i != sibling_menus_.end(); ++i)
+ delete *i;
}
bool MenuRunnerImpl::ShouldShowMnemonics(MenuButton* button) {
« no previous file with comments | « ui/views/controls/menu/menu_runner_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698