OLD | NEW |
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/menu_controller.h" | 5 #include "views/controls/menu/menu_controller.h" |
6 | 6 |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "ui/base/dragdrop/os_exchange_data.h" | 10 #include "ui/base/dragdrop/os_exchange_data.h" |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 void MenuController::Cancel(ExitType type) { | 370 void MenuController::Cancel(ExitType type) { |
371 if (!showing_) { | 371 if (!showing_) { |
372 // This occurs if we're in the process of notifying the delegate for a drop | 372 // This occurs if we're in the process of notifying the delegate for a drop |
373 // and the delegate cancels us. | 373 // and the delegate cancels us. |
374 return; | 374 return; |
375 } | 375 } |
376 | 376 |
377 MenuItemView* selected = state_.item; | 377 MenuItemView* selected = state_.item; |
378 exit_type_ = type; | 378 exit_type_ = type; |
379 | 379 |
380 SendMouseReleaseToActiveView(); | 380 SendMouseCaptureLostToActiveView(); |
381 | 381 |
382 // Hide windows immediately. | 382 // Hide windows immediately. |
383 SetSelection(NULL, SELECTION_UPDATE_IMMEDIATELY | SELECTION_EXIT); | 383 SetSelection(NULL, SELECTION_UPDATE_IMMEDIATELY | SELECTION_EXIT); |
384 | 384 |
385 if (!blocking_run_) { | 385 if (!blocking_run_) { |
386 // If we didn't block the caller we need to notify the menu, which | 386 // If we didn't block the caller we need to notify the menu, which |
387 // triggers deleting us. | 387 // triggers deleting us. |
388 DCHECK(selected); | 388 DCHECK(selected); |
389 showing_ = false; | 389 showing_ = false; |
390 selected->GetRootMenuItem()->DropMenuClosed(true); | 390 selected->GetRootMenuItem()->DropMenuClosed(true); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 int selection_types = SELECTION_UPDATE_IMMEDIATELY; | 511 int selection_types = SELECTION_UPDATE_IMMEDIATELY; |
512 if (state_.item == pending_state_.item && state_.submenu_open) | 512 if (state_.item == pending_state_.item && state_.submenu_open) |
513 selection_types |= SELECTION_OPEN_SUBMENU; | 513 selection_types |= SELECTION_OPEN_SUBMENU; |
514 SetSelection(pending_state_.item, selection_types); | 514 SetSelection(pending_state_.item, selection_types); |
515 gfx::Point loc(event.location()); | 515 gfx::Point loc(event.location()); |
516 View::ConvertPointToScreen(source->GetScrollViewContainer(), &loc); | 516 View::ConvertPointToScreen(source->GetScrollViewContainer(), &loc); |
517 | 517 |
518 // If we open a context menu just return now | 518 // If we open a context menu just return now |
519 if (part.menu->GetDelegate()->ShowContextMenu( | 519 if (part.menu->GetDelegate()->ShowContextMenu( |
520 part.menu, part.menu->GetCommand(), loc, true)) { | 520 part.menu, part.menu->GetCommand(), loc, true)) { |
521 SendMouseReleaseToActiveView(source, event, true); | 521 SendMouseCaptureLostToActiveView(); |
522 return; | 522 return; |
523 } | 523 } |
524 } | 524 } |
525 | 525 |
526 // We can use Ctrl+click or the middle mouse button to recursively open urls | 526 // We can use Ctrl+click or the middle mouse button to recursively open urls |
527 // for selected folder menu items. If it's only a left click, show the | 527 // for selected folder menu items. If it's only a left click, show the |
528 // contents of the folder. | 528 // contents of the folder. |
529 if (!part.is_scroll() && part.menu && | 529 if (!part.is_scroll() && part.menu && |
530 !(part.menu->HasSubmenu() && | 530 !(part.menu->HasSubmenu() && |
531 (event.flags() == ui::EF_LEFT_BUTTON_DOWN))) { | 531 (event.flags() == ui::EF_LEFT_BUTTON_DOWN))) { |
532 if (active_mouse_view_) { | 532 if (active_mouse_view_) { |
533 SendMouseReleaseToActiveView(source, event, false); | 533 SendMouseReleaseToActiveView(source, event); |
534 return; | 534 return; |
535 } | 535 } |
536 if (part.menu->GetDelegate()->IsTriggerableEvent(event)) { | 536 if (part.menu->GetDelegate()->IsTriggerableEvent(event)) { |
537 Accept(part.menu, event.flags()); | 537 Accept(part.menu, event.flags()); |
538 return; | 538 return; |
539 } | 539 } |
540 } else if (part.type == MenuPart::MENU_ITEM) { | 540 } else if (part.type == MenuPart::MENU_ITEM) { |
541 // User either clicked on empty space, or a menu that has children. | 541 // User either clicked on empty space, or a menu that has children. |
542 SetSelection(part.menu ? part.menu : state_.item, | 542 SetSelection(part.menu ? part.menu : state_.item, |
543 SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY); | 543 SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY); |
544 } | 544 } |
545 SendMouseReleaseToActiveView(source, event, true); | 545 SendMouseCaptureLostToActiveView(); |
546 } | 546 } |
547 | 547 |
548 void MenuController::OnMouseMoved(SubmenuView* source, | 548 void MenuController::OnMouseMoved(SubmenuView* source, |
549 const MouseEvent& event) { | 549 const MouseEvent& event) { |
550 if (showing_submenu_) | 550 if (showing_submenu_) |
551 return; | 551 return; |
552 | 552 |
553 MenuPart part = GetMenuPartByScreenCoordinate(source, event.x(), event.y()); | 553 MenuPart part = GetMenuPartByScreenCoordinate(source, event.x(), event.y()); |
554 | 554 |
555 UpdateScrolling(part); | 555 UpdateScrolling(part); |
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1789 // is currently true for the cases we are embedding views, but if we embed | 1789 // is currently true for the cases we are embedding views, but if we embed |
1790 // more complex hierarchies it'll need to change. | 1790 // more complex hierarchies it'll need to change. |
1791 View::ConvertPointToScreen(event_source->GetScrollViewContainer(), | 1791 View::ConvertPointToScreen(event_source->GetScrollViewContainer(), |
1792 &target_menu_loc); | 1792 &target_menu_loc); |
1793 View::ConvertPointToView(NULL, target_menu, &target_menu_loc); | 1793 View::ConvertPointToView(NULL, target_menu, &target_menu_loc); |
1794 target = target_menu->GetEventHandlerForPoint(target_menu_loc); | 1794 target = target_menu->GetEventHandlerForPoint(target_menu_loc); |
1795 if (target == target_menu || !target->IsEnabled()) | 1795 if (target == target_menu || !target->IsEnabled()) |
1796 target = NULL; | 1796 target = NULL; |
1797 } | 1797 } |
1798 if (target != active_mouse_view_) { | 1798 if (target != active_mouse_view_) { |
1799 if (active_mouse_view_) { | 1799 SendMouseCaptureLostToActiveView(); |
1800 // TODO(msw): Revise api and uses with OnMouseCaptureLost (like ui/views). | |
1801 // Send a mouse release with cancel set to true. | |
1802 active_mouse_view_->OnMouseReleased(event, true); | |
1803 active_mouse_view_ = NULL; | |
1804 } | |
1805 active_mouse_view_ = target; | 1800 active_mouse_view_ = target; |
1806 if (active_mouse_view_) { | 1801 if (active_mouse_view_) { |
1807 gfx::Point target_point(target_menu_loc); | 1802 gfx::Point target_point(target_menu_loc); |
1808 View::ConvertPointToView(target_menu, active_mouse_view_, &target_point); | 1803 View::ConvertPointToView(target_menu, active_mouse_view_, &target_point); |
1809 MouseEvent mouse_entered_event(ui::ET_MOUSE_ENTERED, | 1804 MouseEvent mouse_entered_event(ui::ET_MOUSE_ENTERED, |
1810 target_point.x(), target_point.y(), 0); | 1805 target_point.x(), target_point.y(), 0); |
1811 active_mouse_view_->OnMouseEntered(mouse_entered_event); | 1806 active_mouse_view_->OnMouseEntered(mouse_entered_event); |
1812 | 1807 |
1813 MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, | 1808 MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, |
1814 target_point.x(), target_point.y(), | 1809 target_point.x(), target_point.y(), |
1815 event.flags()); | 1810 event.flags()); |
1816 active_mouse_view_->OnMousePressed(mouse_pressed_event); | 1811 active_mouse_view_->OnMousePressed(mouse_pressed_event); |
1817 } | 1812 } |
1818 } | 1813 } |
1819 | 1814 |
1820 if (active_mouse_view_) { | 1815 if (active_mouse_view_) { |
1821 gfx::Point target_point(target_menu_loc); | 1816 gfx::Point target_point(target_menu_loc); |
1822 View::ConvertPointToView(target_menu, active_mouse_view_, &target_point); | 1817 View::ConvertPointToView(target_menu, active_mouse_view_, &target_point); |
1823 MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, | 1818 MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, |
1824 target_point.x(), target_point.y(), | 1819 target_point.x(), target_point.y(), |
1825 event.flags()); | 1820 event.flags()); |
1826 active_mouse_view_->OnMouseDragged(mouse_dragged_event); | 1821 active_mouse_view_->OnMouseDragged(mouse_dragged_event); |
1827 } | 1822 } |
1828 } | 1823 } |
1829 | 1824 |
1830 void MenuController::SendMouseReleaseToActiveView(SubmenuView* event_source, | 1825 void MenuController::SendMouseReleaseToActiveView(SubmenuView* event_source, |
1831 const MouseEvent& event, | 1826 const MouseEvent& event) { |
1832 bool cancel) { | |
1833 if (!active_mouse_view_) | 1827 if (!active_mouse_view_) |
1834 return; | 1828 return; |
1835 | 1829 |
1836 gfx::Point target_loc(event.location()); | 1830 gfx::Point target_loc(event.location()); |
1837 View::ConvertPointToScreen(event_source->GetScrollViewContainer(), | 1831 View::ConvertPointToScreen(event_source->GetScrollViewContainer(), |
1838 &target_loc); | 1832 &target_loc); |
1839 View::ConvertPointToView(NULL, active_mouse_view_, &target_loc); | 1833 View::ConvertPointToView(NULL, active_mouse_view_, &target_loc); |
1840 MouseEvent release_event(ui::ET_MOUSE_RELEASED, target_loc.x(), | 1834 MouseEvent release_event(ui::ET_MOUSE_RELEASED, target_loc.x(), |
1841 target_loc.y(), event.flags()); | 1835 target_loc.y(), event.flags()); |
1842 // Reset the active_mouse_view_ before sending mouse released. That way if if | 1836 // Reset the active_mouse_view_ before sending mouse released. That way if it |
1843 // calls back to use we aren't in a weird state. | 1837 // calls back to us, we aren't in a weird state. |
1844 View* active_view = active_mouse_view_; | 1838 View* active_view = active_mouse_view_; |
1845 active_mouse_view_ = NULL; | 1839 active_mouse_view_ = NULL; |
1846 active_view->OnMouseReleased(release_event, cancel); | 1840 active_view->OnMouseReleased(release_event); |
1847 } | 1841 } |
1848 | 1842 |
1849 void MenuController::SendMouseReleaseToActiveView() { | 1843 void MenuController::SendMouseCaptureLostToActiveView() { |
1850 if (!active_mouse_view_) | 1844 if (!active_mouse_view_) |
1851 return; | 1845 return; |
1852 | 1846 |
1853 MouseEvent release_event(ui::ET_MOUSE_RELEASED, -1, -1, 0); | 1847 // Reset the active_mouse_view_ before sending mouse capture lost. That way if |
1854 // Reset the active_mouse_view_ before sending mouse released. That way if if | 1848 // it calls back to us, we aren't in a weird state. |
1855 // calls back to use we aren't in a weird state. | |
1856 View* active_view = active_mouse_view_; | 1849 View* active_view = active_mouse_view_; |
1857 active_mouse_view_ = NULL; | 1850 active_mouse_view_ = NULL; |
1858 active_view->OnMouseReleased(release_event, true); | 1851 active_view->OnMouseCaptureLost(); |
1859 } | 1852 } |
1860 | 1853 |
1861 } // namespace views | 1854 } // namespace views |
OLD | NEW |