OLD | NEW |
---|---|
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/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 if (event.IsRightMouseButton() && part.type == MenuPart::MENU_ITEM) { | 483 if (event.IsRightMouseButton() && part.type == MenuPart::MENU_ITEM) { |
484 MenuItemView* menu = part.menu; | 484 MenuItemView* menu = part.menu; |
485 // |menu| is NULL means this event is from an empty menu or a separator. | 485 // |menu| is NULL means this event is from an empty menu or a separator. |
486 // If it is from an empty menu, use parent context menu instead of that. | 486 // If it is from an empty menu, use parent context menu instead of that. |
487 if (menu == NULL && | 487 if (menu == NULL && |
488 part.submenu->child_count() == 1 && | 488 part.submenu->child_count() == 1 && |
489 part.submenu->child_at(0)->id() | 489 part.submenu->child_at(0)->id() |
490 == views::MenuItemView::kEmptyMenuItemViewID) | 490 == views::MenuItemView::kEmptyMenuItemViewID) |
491 menu = part.parent; | 491 menu = part.parent; |
492 | 492 |
493 if (menu != NULL && ShowContextMenu(menu, source, event)) | 493 if (menu != NULL && ShowContextMenu(menu, source, event, |
494 ui::MENU_SOURCE_MOUSE)) | |
494 return; | 495 return; |
495 } | 496 } |
496 | 497 |
497 // We can use Ctrl+click or the middle mouse button to recursively open urls | 498 // We can use Ctrl+click or the middle mouse button to recursively open urls |
498 // for selected folder menu items. If it's only a left click, show the | 499 // for selected folder menu items. If it's only a left click, show the |
499 // contents of the folder. | 500 // contents of the folder. |
500 if (!part.is_scroll() && part.menu && | 501 if (!part.is_scroll() && part.menu && |
501 !(part.menu->HasSubmenu() && | 502 !(part.menu->HasSubmenu() && |
502 (event.flags() & ui::EF_LEFT_MOUSE_BUTTON))) { | 503 (event.flags() & ui::EF_LEFT_MOUSE_BUTTON))) { |
503 if (active_mouse_view_) { | 504 if (active_mouse_view_) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
547 #endif | 548 #endif |
548 | 549 |
549 void MenuController::OnGestureEvent(SubmenuView* source, | 550 void MenuController::OnGestureEvent(SubmenuView* source, |
550 ui::GestureEvent* event) { | 551 ui::GestureEvent* event) { |
551 MenuPart part = GetMenuPart(source, event->location()); | 552 MenuPart part = GetMenuPart(source, event->location()); |
552 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | 553 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
553 SetSelectionOnPointerDown(source, *event); | 554 SetSelectionOnPointerDown(source, *event); |
554 event->StopPropagation(); | 555 event->StopPropagation(); |
555 } else if (event->type() == ui::ET_GESTURE_LONG_PRESS) { | 556 } else if (event->type() == ui::ET_GESTURE_LONG_PRESS) { |
556 if (part.type == MenuPart::MENU_ITEM && part.menu) { | 557 if (part.type == MenuPart::MENU_ITEM && part.menu) { |
557 if (ShowContextMenu(part.menu, source, *event)) | 558 if (ShowContextMenu(part.menu, source, *event, ui::MENU_SOURCE_TOUCH)) |
558 event->StopPropagation(); | 559 event->StopPropagation(); |
559 } | 560 } |
560 } else if (event->type() == ui::ET_GESTURE_TAP) { | 561 } else if (event->type() == ui::ET_GESTURE_TAP) { |
561 if (!part.is_scroll() && part.menu && | 562 if (!part.is_scroll() && part.menu && |
562 !(part.menu->HasSubmenu())) { | 563 !(part.menu->HasSubmenu())) { |
563 if (part.menu->GetDelegate()->IsTriggerableEvent( | 564 if (part.menu->GetDelegate()->IsTriggerableEvent( |
564 part.menu, *event)) { | 565 part.menu, *event)) { |
565 Accept(part.menu, event->flags()); | 566 Accept(part.menu, event->flags()); |
566 } | 567 } |
567 event->StopPropagation(); | 568 event->StopPropagation(); |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
951 } | 952 } |
952 | 953 |
953 // NOTE: we don't get WM_ACTIVATE or anything else interesting in here. | 954 // NOTE: we don't get WM_ACTIVATE or anything else interesting in here. |
954 switch (msg.message) { | 955 switch (msg.message) { |
955 case WM_CONTEXTMENU: { | 956 case WM_CONTEXTMENU: { |
956 MenuItemView* item = pending_state_.item; | 957 MenuItemView* item = pending_state_.item; |
957 if (item && item->GetRootMenuItem() != item) { | 958 if (item && item->GetRootMenuItem() != item) { |
958 gfx::Point screen_loc(0, item->height()); | 959 gfx::Point screen_loc(0, item->height()); |
959 View::ConvertPointToScreen(item, &screen_loc); | 960 View::ConvertPointToScreen(item, &screen_loc); |
960 item->GetDelegate()->ShowContextMenu(item, item->GetCommand(), | 961 item->GetDelegate()->ShowContextMenu(item, item->GetCommand(), |
961 screen_loc, false); | 962 screen_loc, ui::MENU_SOURCE_MOUSE); |
sky
2013/06/17 16:08:19
I think this can be keyboard too. See description
varunjain
2013/06/17 20:13:55
Done.
| |
962 } | 963 } |
963 return true; | 964 return true; |
964 } | 965 } |
965 | 966 |
966 // NOTE: focus wasn't changed when the menu was shown. As such, don't | 967 // NOTE: focus wasn't changed when the menu was shown. As such, don't |
967 // dispatch key events otherwise the focused window will get the events. | 968 // dispatch key events otherwise the focused window will get the events. |
968 case WM_KEYDOWN: { | 969 case WM_KEYDOWN: { |
969 bool result = OnKeyDown(ui::KeyboardCodeFromNative(msg)); | 970 bool result = OnKeyDown(ui::KeyboardCodeFromNative(msg)); |
970 TranslateMessage(&msg); | 971 TranslateMessage(&msg); |
971 return result; | 972 return result; |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1263 alt_menu->PrepareForRun( | 1264 alt_menu->PrepareForRun( |
1264 false, has_mnemonics, | 1265 false, has_mnemonics, |
1265 source->GetMenuItem()->GetRootMenuItem()->show_mnemonics_); | 1266 source->GetMenuItem()->GetRootMenuItem()->show_mnemonics_); |
1266 alt_menu->controller_ = this; | 1267 alt_menu->controller_ = this; |
1267 SetSelection(alt_menu, SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY); | 1268 SetSelection(alt_menu, SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY); |
1268 return true; | 1269 return true; |
1269 } | 1270 } |
1270 | 1271 |
1271 bool MenuController::ShowContextMenu(MenuItemView* menu_item, | 1272 bool MenuController::ShowContextMenu(MenuItemView* menu_item, |
1272 SubmenuView* source, | 1273 SubmenuView* source, |
1273 const ui::LocatedEvent& event) { | 1274 const ui::LocatedEvent& event, |
1275 ui::MenuSourceType source_type) { | |
1274 // Set the selection immediately, making sure the submenu is only open | 1276 // Set the selection immediately, making sure the submenu is only open |
1275 // if it already was. | 1277 // if it already was. |
1276 int selection_types = SELECTION_UPDATE_IMMEDIATELY; | 1278 int selection_types = SELECTION_UPDATE_IMMEDIATELY; |
1277 if (state_.item == pending_state_.item && state_.submenu_open) | 1279 if (state_.item == pending_state_.item && state_.submenu_open) |
1278 selection_types |= SELECTION_OPEN_SUBMENU; | 1280 selection_types |= SELECTION_OPEN_SUBMENU; |
1279 SetSelection(pending_state_.item, selection_types); | 1281 SetSelection(pending_state_.item, selection_types); |
1280 gfx::Point loc(event.location()); | 1282 gfx::Point loc(event.location()); |
1281 View::ConvertPointToScreen(source->GetScrollViewContainer(), &loc); | 1283 View::ConvertPointToScreen(source->GetScrollViewContainer(), &loc); |
1282 | 1284 |
1283 if (menu_item->GetDelegate()->ShowContextMenu( | 1285 if (menu_item->GetDelegate()->ShowContextMenu( |
1284 menu_item, menu_item->GetCommand(), loc, true)) { | 1286 menu_item, menu_item->GetCommand(), loc, source_type)) { |
1285 SendMouseCaptureLostToActiveView(); | 1287 SendMouseCaptureLostToActiveView(); |
1286 return true; | 1288 return true; |
1287 } | 1289 } |
1288 return false; | 1290 return false; |
1289 } | 1291 } |
1290 | 1292 |
1291 void MenuController::CloseAllNestedMenus() { | 1293 void MenuController::CloseAllNestedMenus() { |
1292 for (std::list<State>::iterator i = menu_stack_.begin(); | 1294 for (std::list<State>::iterator i = menu_stack_.begin(); |
1293 i != menu_stack_.end(); ++i) { | 1295 i != menu_stack_.end(); ++i) { |
1294 MenuItemView* last_item = i->item; | 1296 MenuItemView* last_item = i->item; |
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2285 (!pending_state_.item->HasSubmenu() || | 2287 (!pending_state_.item->HasSubmenu() || |
2286 !pending_state_.item->GetSubmenu()->IsShowing())) { | 2288 !pending_state_.item->GetSubmenu()->IsShowing())) { |
2287 // On exit if the user hasn't selected an item with a submenu, move the | 2289 // On exit if the user hasn't selected an item with a submenu, move the |
2288 // selection back to the parent menu item. | 2290 // selection back to the parent menu item. |
2289 SetSelection(pending_state_.item->GetParentMenuItem(), | 2291 SetSelection(pending_state_.item->GetParentMenuItem(), |
2290 SELECTION_OPEN_SUBMENU); | 2292 SELECTION_OPEN_SUBMENU); |
2291 } | 2293 } |
2292 } | 2294 } |
2293 | 2295 |
2294 } // namespace views | 2296 } // namespace views |
OLD | NEW |