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

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

Issue 547303003: Keep reference view pressed while extension actions have a popup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: MenuButton::PressedLock Created 6 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
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/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 349
350 if (!blocking_run_) { 350 if (!blocking_run_) {
351 if (!is_nested_drag) { 351 if (!is_nested_drag) {
352 // Start the timer to hide the menu. This is needed as we get no 352 // Start the timer to hide the menu. This is needed as we get no
353 // notification when the drag has finished. 353 // notification when the drag has finished.
354 StartCancelAllTimer(); 354 StartCancelAllTimer();
355 } 355 }
356 return NULL; 356 return NULL;
357 } 357 }
358 358
359 if (button) 359 scoped_ptr<MenuButton::PressedLock>& pressed_lock =
360 nested_menu ? nested_pressed_lock_ : pressed_lock_;
361 if (button) {
360 menu_button_ = button; 362 menu_button_ = button;
363 pressed_lock.reset(new MenuButton::PressedLock(menu_button_));
364 }
361 365
362 // Make sure Chrome doesn't attempt to shut down while the menu is showing. 366 // Make sure Chrome doesn't attempt to shut down while the menu is showing.
363 if (ViewsDelegate::views_delegate) 367 if (ViewsDelegate::views_delegate)
364 ViewsDelegate::views_delegate->AddRef(); 368 ViewsDelegate::views_delegate->AddRef();
365 369
366 // We need to turn on nestable tasks as in some situations (pressing alt-f for 370 // We need to turn on nestable tasks as in some situations (pressing alt-f for
367 // one) the menus are run from a task. If we don't do this and are invoked 371 // one) the menus are run from a task. If we don't do this and are invoked
368 // from a task none of the tasks we schedule are processed and the menu 372 // from a task none of the tasks we schedule are processed and the menu
369 // appears totally broken. 373 // appears totally broken.
370 message_loop_depth_++; 374 message_loop_depth_++;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 // before that happens otherwise the menus will stay on screen. 431 // before that happens otherwise the menus will stay on screen.
428 CloseAllNestedMenus(); 432 CloseAllNestedMenus();
429 SetSelection(NULL, SELECTION_UPDATE_IMMEDIATELY | SELECTION_EXIT); 433 SetSelection(NULL, SELECTION_UPDATE_IMMEDIATELY | SELECTION_EXIT);
430 434
431 // Set exit_all_, which makes sure all nested loops exit immediately. 435 // Set exit_all_, which makes sure all nested loops exit immediately.
432 if (exit_type_ != EXIT_DESTROYED) 436 if (exit_type_ != EXIT_DESTROYED)
433 SetExitType(EXIT_ALL); 437 SetExitType(EXIT_ALL);
434 } 438 }
435 } 439 }
436 440
437 // If we stopped running because one of the menus was destroyed chances are 441 // Reset our pressed lock. The lock handles the case if the button was
438 // the button was also destroyed. 442 // destroyed.
439 if (exit_type_ != EXIT_DESTROYED && menu_button_) { 443 pressed_lock.reset();
440 menu_button_->SetState(CustomButton::STATE_NORMAL); 444
441 menu_button_->SchedulePaint();
442 }
443 return result; 445 return result;
444 } 446 }
445 447
446 void MenuController::Cancel(ExitType type) { 448 void MenuController::Cancel(ExitType type) {
447 // If the menu has already been destroyed, no further cancellation is 449 // If the menu has already been destroyed, no further cancellation is
448 // needed. We especially don't want to set the |exit_type_| to a lesser 450 // needed. We especially don't want to set the |exit_type_| to a lesser
449 // value. 451 // value.
450 if (exit_type_ == EXIT_DESTROYED || exit_type_ == type) 452 if (exit_type_ == EXIT_DESTROYED || exit_type_ == type)
451 return; 453 return;
452 454
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 delegate_->SiblingMenuCreated(alt_menu); 1218 delegate_->SiblingMenuCreated(alt_menu);
1217 1219
1218 if (!button) { 1220 if (!button) {
1219 // If the delegate returns a menu, they must also return a button. 1221 // If the delegate returns a menu, they must also return a button.
1220 NOTREACHED(); 1222 NOTREACHED();
1221 return false; 1223 return false;
1222 } 1224 }
1223 1225
1224 // There is a sibling menu, update the button state, hide the current menu 1226 // There is a sibling menu, update the button state, hide the current menu
1225 // and show the new one. 1227 // and show the new one.
1226 menu_button_->SetState(CustomButton::STATE_NORMAL);
1227 menu_button_->SchedulePaint();
1228 menu_button_ = button; 1228 menu_button_ = button;
1229 menu_button_->SetState(CustomButton::STATE_PRESSED); 1229 // We know that we need to reset the nested lock if it exists because we only
1230 menu_button_->SchedulePaint(); 1230 // support nesting menus that block runs (so we can't both have a nested menu
1231 // *and* be updating the original).
1232 scoped_ptr<MenuButton::PressedLock>& pressed_lock =
1233 nested_pressed_lock_.get() ? nested_pressed_lock_ : pressed_lock_;
1234 pressed_lock.reset(new MenuButton::PressedLock(menu_button_));
1231 1235
1232 // Need to reset capture when we show the menu again, otherwise we aren't 1236 // Need to reset capture when we show the menu again, otherwise we aren't
1233 // going to get any events. 1237 // going to get any events.
1234 did_capture_ = false; 1238 did_capture_ = false;
1235 gfx::Point screen_menu_loc; 1239 gfx::Point screen_menu_loc;
1236 View::ConvertPointToScreen(button, &screen_menu_loc); 1240 View::ConvertPointToScreen(button, &screen_menu_loc);
1237 1241
1238 // It is currently not possible to show a submenu recursively in a bubble. 1242 // It is currently not possible to show a submenu recursively in a bubble.
1239 DCHECK(!MenuItemView::IsBubble(anchor)); 1243 DCHECK(!MenuItemView::IsBubble(anchor));
1240 // Subtract 1 from the height to make the popup flush with the button border. 1244 // Subtract 1 from the height to make the popup flush with the button border.
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
2309 } 2313 }
2310 } 2314 }
2311 2315
2312 gfx::Screen* MenuController::GetScreen() { 2316 gfx::Screen* MenuController::GetScreen() {
2313 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL; 2317 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL;
2314 return root ? gfx::Screen::GetScreenFor(root->GetNativeView()) 2318 return root ? gfx::Screen::GetScreenFor(root->GetNativeView())
2315 : gfx::Screen::GetNativeScreen(); 2319 : gfx::Screen::GetNativeScreen();
2316 } 2320 }
2317 2321
2318 } // namespace views 2322 } // namespace views
OLDNEW
« ui/views/controls/menu/menu_controller.h ('K') | « ui/views/controls/menu/menu_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698