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

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

Issue 139983009: ui::LocatedEvent location() returns gfx::PointF (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Undo accidental change. Created 6 years, 7 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 | Annotate | Revision Log
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 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windowsx.h> 8 #include <windowsx.h>
9 #endif 9 #endif
10 10
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 // If we are shown on mouse press, we will eat the subsequent mouse down and 380 // If we are shown on mouse press, we will eat the subsequent mouse down and
381 // the parent widget will not be able to reset its state (it might have mouse 381 // the parent widget will not be able to reset its state (it might have mouse
382 // capture from the mouse down). So we clear its state here. 382 // capture from the mouse down). So we clear its state here.
383 if (parent) { 383 if (parent) {
384 View* root_view = parent->GetRootView(); 384 View* root_view = parent->GetRootView();
385 if (root_view) { 385 if (root_view) {
386 root_view->SetMouseHandler(NULL); 386 root_view->SetMouseHandler(NULL);
387 const ui::Event* event = 387 const ui::Event* event =
388 static_cast<internal::RootView*>(root_view)->current_event(); 388 static_cast<internal::RootView*>(root_view)->current_event();
389 if (event && event->type() == ui::ET_MOUSE_PRESSED) { 389 if (event && event->type() == ui::ET_MOUSE_PRESSED) {
390 gfx::Point screen_loc( 390 gfx::Point screen_loc(gfx::ToFlooredPoint(
391 static_cast<const ui::MouseEvent*>(event)->location()); 391 static_cast<const ui::MouseEvent*>(event)->location()));
392 View::ConvertPointToScreen( 392 View::ConvertPointToScreen(
393 static_cast<View*>(event->target()), &screen_loc); 393 static_cast<View*>(event->target()), &screen_loc);
394 menu_start_mouse_press_loc_ = screen_loc; 394 menu_start_mouse_press_loc_ = screen_loc;
395 } 395 }
396 } 396 }
397 } 397 }
398 398
399 bool nested_menu = showing_; 399 bool nested_menu = showing_;
400 if (showing_) { 400 if (showing_) {
401 // Only support nesting of blocking_run menus, nesting of 401 // Only support nesting of blocking_run menus, nesting of
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 } 553 }
554 } 554 }
555 555
556 void MenuController::OnMousePressed(SubmenuView* source, 556 void MenuController::OnMousePressed(SubmenuView* source,
557 const ui::MouseEvent& event) { 557 const ui::MouseEvent& event) {
558 SetSelectionOnPointerDown(source, event); 558 SetSelectionOnPointerDown(source, event);
559 } 559 }
560 560
561 void MenuController::OnMouseDragged(SubmenuView* source, 561 void MenuController::OnMouseDragged(SubmenuView* source,
562 const ui::MouseEvent& event) { 562 const ui::MouseEvent& event) {
563 MenuPart part = GetMenuPart(source, event.location()); 563 MenuPart part = GetMenuPart(source, gfx::ToFlooredPoint(event.location()));
564 UpdateScrolling(part); 564 UpdateScrolling(part);
565 565
566 if (!blocking_run_) 566 if (!blocking_run_)
567 return; 567 return;
568 568
569 if (possible_drag_) { 569 if (possible_drag_) {
570 if (View::ExceededDragThreshold(event.location() - press_pt_)) 570 if (View::ExceededDragThreshold(gfx::ToFlooredPoint(event.location()) -
571 press_pt_))
571 StartDrag(source, press_pt_); 572 StartDrag(source, press_pt_);
572 return; 573 return;
573 } 574 }
574 MenuItemView* mouse_menu = NULL; 575 MenuItemView* mouse_menu = NULL;
575 if (part.type == MenuPart::MENU_ITEM) { 576 if (part.type == MenuPart::MENU_ITEM) {
576 if (!part.menu) 577 if (!part.menu)
577 part.menu = source->GetMenuItem(); 578 part.menu = source->GetMenuItem();
578 else 579 else
579 mouse_menu = part.menu; 580 mouse_menu = part.menu;
580 SetSelection(part.menu ? part.menu : state_.item, SELECTION_OPEN_SUBMENU); 581 SetSelection(part.menu ? part.menu : state_.item, SELECTION_OPEN_SUBMENU);
581 } else if (part.type == MenuPart::NONE) { 582 } else if (part.type == MenuPart::NONE) {
582 ShowSiblingMenu(source, event.location()); 583 ShowSiblingMenu(source, gfx::ToFlooredPoint(event.location()));
583 } 584 }
584 UpdateActiveMouseView(source, event, mouse_menu); 585 UpdateActiveMouseView(source, event, mouse_menu);
585 } 586 }
586 587
587 void MenuController::OnMouseReleased(SubmenuView* source, 588 void MenuController::OnMouseReleased(SubmenuView* source,
588 const ui::MouseEvent& event) { 589 const ui::MouseEvent& event) {
589 if (!blocking_run_) 590 if (!blocking_run_)
590 return; 591 return;
591 592
592 DCHECK(state_.item); 593 DCHECK(state_.item);
593 possible_drag_ = false; 594 possible_drag_ = false;
594 DCHECK(blocking_run_); 595 DCHECK(blocking_run_);
595 MenuPart part = GetMenuPart(source, event.location()); 596 MenuPart part = GetMenuPart(source, gfx::ToFlooredPoint(event.location()));
596 if (event.IsRightMouseButton() && part.type == MenuPart::MENU_ITEM) { 597 if (event.IsRightMouseButton() && part.type == MenuPart::MENU_ITEM) {
597 MenuItemView* menu = part.menu; 598 MenuItemView* menu = part.menu;
598 // |menu| is NULL means this event is from an empty menu or a separator. 599 // |menu| is NULL means this event is from an empty menu or a separator.
599 // If it is from an empty menu, use parent context menu instead of that. 600 // If it is from an empty menu, use parent context menu instead of that.
600 if (menu == NULL && 601 if (menu == NULL &&
601 part.submenu->child_count() == 1 && 602 part.submenu->child_count() == 1 &&
602 part.submenu->child_at(0)->id() == MenuItemView::kEmptyMenuItemViewID) { 603 part.submenu->child_at(0)->id() == MenuItemView::kEmptyMenuItemViewID) {
603 menu = part.parent; 604 menu = part.parent;
604 } 605 }
605 606
606 if (menu != NULL && ShowContextMenu(menu, source, event, 607 if (menu != NULL && ShowContextMenu(menu, source, event,
607 ui::MENU_SOURCE_MOUSE)) 608 ui::MENU_SOURCE_MOUSE))
608 return; 609 return;
609 } 610 }
610 611
611 // We can use Ctrl+click or the middle mouse button to recursively open urls 612 // We can use Ctrl+click or the middle mouse button to recursively open urls
612 // for selected folder menu items. If it's only a left click, show the 613 // for selected folder menu items. If it's only a left click, show the
613 // contents of the folder. 614 // contents of the folder.
614 if (!part.is_scroll() && part.menu && 615 if (!part.is_scroll() && part.menu &&
615 !(part.menu->HasSubmenu() && 616 !(part.menu->HasSubmenu() &&
616 (event.flags() & ui::EF_LEFT_MOUSE_BUTTON))) { 617 (event.flags() & ui::EF_LEFT_MOUSE_BUTTON))) {
617 if (GetActiveMouseView()) { 618 if (GetActiveMouseView()) {
618 SendMouseReleaseToActiveView(source, event); 619 SendMouseReleaseToActiveView(source, event);
619 return; 620 return;
620 } 621 }
621 // If a mouse release was received quickly after showing. 622 // If a mouse release was received quickly after showing.
622 base::TimeDelta time_shown = base::TimeTicks::Now() - menu_start_time_; 623 base::TimeDelta time_shown = base::TimeTicks::Now() - menu_start_time_;
623 if (time_shown.InMilliseconds() < menu_selection_hold_time_ms) { 624 if (time_shown.InMilliseconds() < menu_selection_hold_time_ms) {
624 // And it wasn't far from the mouse press location. 625 // And it wasn't far from the mouse press location.
625 gfx::Point screen_loc(event.location()); 626 gfx::Point screen_loc(gfx::ToFlooredPoint(event.location()));
626 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc); 627 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc);
627 gfx::Vector2d moved = screen_loc - menu_start_mouse_press_loc_; 628 gfx::Vector2d moved = screen_loc - menu_start_mouse_press_loc_;
628 if (moved.Length() < kMaximumLengthMovedToActivate) { 629 if (moved.Length() < kMaximumLengthMovedToActivate) {
629 // Ignore the mouse release as it was likely this menu was shown under 630 // Ignore the mouse release as it was likely this menu was shown under
630 // the mouse and the action was just a normal click. 631 // the mouse and the action was just a normal click.
631 return; 632 return;
632 } 633 }
633 } 634 }
634 if (part.menu->GetDelegate()->ShouldExecuteCommandWithoutClosingMenu( 635 if (part.menu->GetDelegate()->ShouldExecuteCommandWithoutClosingMenu(
635 part.menu->GetCommand(), event)) { 636 part.menu->GetCommand(), event)) {
(...skipping 13 matching lines...) Expand all
649 } else if (part.type == MenuPart::MENU_ITEM) { 650 } else if (part.type == MenuPart::MENU_ITEM) {
650 // User either clicked on empty space, or a menu that has children. 651 // User either clicked on empty space, or a menu that has children.
651 SetSelection(part.menu ? part.menu : state_.item, 652 SetSelection(part.menu ? part.menu : state_.item,
652 SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY); 653 SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY);
653 } 654 }
654 SendMouseCaptureLostToActiveView(); 655 SendMouseCaptureLostToActiveView();
655 } 656 }
656 657
657 void MenuController::OnMouseMoved(SubmenuView* source, 658 void MenuController::OnMouseMoved(SubmenuView* source,
658 const ui::MouseEvent& event) { 659 const ui::MouseEvent& event) {
659 HandleMouseLocation(source, event.location()); 660 HandleMouseLocation(source, gfx::ToFlooredPoint(event.location()));
660 } 661 }
661 662
662 void MenuController::OnMouseEntered(SubmenuView* source, 663 void MenuController::OnMouseEntered(SubmenuView* source,
663 const ui::MouseEvent& event) { 664 const ui::MouseEvent& event) {
664 // MouseEntered is always followed by a mouse moved, so don't need to 665 // MouseEntered is always followed by a mouse moved, so don't need to
665 // do anything here. 666 // do anything here.
666 } 667 }
667 668
668 bool MenuController::OnMouseWheel(SubmenuView* source, 669 bool MenuController::OnMouseWheel(SubmenuView* source,
669 const ui::MouseWheelEvent& event) { 670 const ui::MouseWheelEvent& event) {
670 MenuPart part = GetMenuPart(source, event.location()); 671 MenuPart part = GetMenuPart(source, gfx::ToFlooredPoint(event.location()));
671 return part.submenu && part.submenu->OnMouseWheel(event); 672 return part.submenu && part.submenu->OnMouseWheel(event);
672 } 673 }
673 674
674 void MenuController::OnGestureEvent(SubmenuView* source, 675 void MenuController::OnGestureEvent(SubmenuView* source,
675 ui::GestureEvent* event) { 676 ui::GestureEvent* event) {
676 MenuPart part = GetMenuPart(source, event->location()); 677 MenuPart part = GetMenuPart(source, gfx::ToFlooredPoint(event->location()));
677 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { 678 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
678 SetSelectionOnPointerDown(source, *event); 679 SetSelectionOnPointerDown(source, *event);
679 event->StopPropagation(); 680 event->StopPropagation();
680 } else if (event->type() == ui::ET_GESTURE_LONG_PRESS) { 681 } else if (event->type() == ui::ET_GESTURE_LONG_PRESS) {
681 if (part.type == MenuPart::MENU_ITEM && part.menu) { 682 if (part.type == MenuPart::MENU_ITEM && part.menu) {
682 if (ShowContextMenu(part.menu, source, *event, ui::MENU_SOURCE_TOUCH)) 683 if (ShowContextMenu(part.menu, source, *event, ui::MENU_SOURCE_TOUCH))
683 event->StopPropagation(); 684 event->StopPropagation();
684 } 685 }
685 } else if (event->type() == ui::ET_GESTURE_TAP) { 686 } else if (event->type() == ui::ET_GESTURE_TAP) {
686 if (!part.is_scroll() && part.menu && 687 if (!part.is_scroll() && part.menu &&
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 737
737 void MenuController::OnDragEntered(SubmenuView* source, 738 void MenuController::OnDragEntered(SubmenuView* source,
738 const ui::DropTargetEvent& event) { 739 const ui::DropTargetEvent& event) {
739 valid_drop_coordinates_ = false; 740 valid_drop_coordinates_ = false;
740 } 741 }
741 742
742 int MenuController::OnDragUpdated(SubmenuView* source, 743 int MenuController::OnDragUpdated(SubmenuView* source,
743 const ui::DropTargetEvent& event) { 744 const ui::DropTargetEvent& event) {
744 StopCancelAllTimer(); 745 StopCancelAllTimer();
745 746
746 gfx::Point screen_loc(event.location()); 747 gfx::Point screen_loc(gfx::ToFlooredPoint(event.location()));
747 View::ConvertPointToScreen(source, &screen_loc); 748 View::ConvertPointToScreen(source, &screen_loc);
748 if (valid_drop_coordinates_ && screen_loc == drop_pt_) 749 if (valid_drop_coordinates_ && screen_loc == drop_pt_)
749 return last_drop_operation_; 750 return last_drop_operation_;
750 drop_pt_ = screen_loc; 751 drop_pt_ = screen_loc;
751 valid_drop_coordinates_ = true; 752 valid_drop_coordinates_ = true;
752 753
753 MenuItemView* menu_item = GetMenuItemAt(source, event.x(), event.y()); 754 MenuItemView* menu_item = GetMenuItemAt(source, event.x(), event.y());
754 bool over_empty_menu = false; 755 bool over_empty_menu = false;
755 if (!menu_item) { 756 if (!menu_item) {
756 // See if we're over an empty menu. 757 // See if we're over an empty menu.
757 menu_item = GetEmptyMenuItemAt(source, event.x(), event.y()); 758 menu_item = GetEmptyMenuItemAt(source, event.x(), event.y());
758 if (menu_item) 759 if (menu_item)
759 over_empty_menu = true; 760 over_empty_menu = true;
760 } 761 }
761 MenuDelegate::DropPosition drop_position = MenuDelegate::DROP_NONE; 762 MenuDelegate::DropPosition drop_position = MenuDelegate::DROP_NONE;
762 int drop_operation = ui::DragDropTypes::DRAG_NONE; 763 int drop_operation = ui::DragDropTypes::DRAG_NONE;
763 if (menu_item) { 764 if (menu_item) {
764 gfx::Point menu_item_loc(event.location()); 765 gfx::Point menu_item_loc(gfx::ToFlooredPoint(event.location()));
765 View::ConvertPointToTarget(source, menu_item, &menu_item_loc); 766 View::ConvertPointToTarget(source, menu_item, &menu_item_loc);
766 MenuItemView* query_menu_item; 767 MenuItemView* query_menu_item;
767 if (!over_empty_menu) { 768 if (!over_empty_menu) {
768 int menu_item_height = menu_item->height(); 769 int menu_item_height = menu_item->height();
769 if (menu_item->HasSubmenu() && 770 if (menu_item->HasSubmenu() &&
770 (menu_item_loc.y() > kDropBetweenPixels && 771 (menu_item_loc.y() > kDropBetweenPixels &&
771 menu_item_loc.y() < (menu_item_height - kDropBetweenPixels))) { 772 menu_item_loc.y() < (menu_item_height - kDropBetweenPixels))) {
772 drop_position = MenuDelegate::DROP_ON; 773 drop_position = MenuDelegate::DROP_ON;
773 } else { 774 } else {
774 drop_position = (menu_item_loc.y() < menu_item_height / 2) ? 775 drop_position = (menu_item_loc.y() < menu_item_height / 2) ?
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 } 947 }
947 } 948 }
948 949
949 void MenuController::SetSelectionOnPointerDown(SubmenuView* source, 950 void MenuController::SetSelectionOnPointerDown(SubmenuView* source,
950 const ui::LocatedEvent& event) { 951 const ui::LocatedEvent& event) {
951 if (!blocking_run_) 952 if (!blocking_run_)
952 return; 953 return;
953 954
954 DCHECK(!GetActiveMouseView()); 955 DCHECK(!GetActiveMouseView());
955 956
956 MenuPart part = GetMenuPart(source, event.location()); 957 MenuPart part = GetMenuPart(source, gfx::ToFlooredPoint(event.location()));
957 if (part.is_scroll()) 958 if (part.is_scroll())
958 return; // Ignore presses on scroll buttons. 959 return; // Ignore presses on scroll buttons.
959 960
960 // When this menu is opened through a touch event, a simulated right-click 961 // When this menu is opened through a touch event, a simulated right-click
961 // is sent before the menu appears. Ignore it. 962 // is sent before the menu appears. Ignore it.
962 if ((event.flags() & ui::EF_RIGHT_MOUSE_BUTTON) && 963 if ((event.flags() & ui::EF_RIGHT_MOUSE_BUTTON) &&
963 (event.flags() & ui::EF_FROM_TOUCH)) 964 (event.flags() & ui::EF_FROM_TOUCH))
964 return; 965 return;
965 966
966 if (part.type == MenuPart::NONE || 967 if (part.type == MenuPart::NONE ||
(...skipping 13 matching lines...) Expand all
980 // We're going to close and we own the mouse capture. We need to repost the 981 // We're going to close and we own the mouse capture. We need to repost the
981 // mouse down, otherwise the window the user clicked on won't get the event. 982 // mouse down, otherwise the window the user clicked on won't get the event.
982 RepostEvent(source, event); 983 RepostEvent(source, event);
983 #endif 984 #endif
984 985
985 // And close. 986 // And close.
986 ExitType exit_type = EXIT_ALL; 987 ExitType exit_type = EXIT_ALL;
987 if (!menu_stack_.empty()) { 988 if (!menu_stack_.empty()) {
988 // We're running nested menus. Only exit all if the mouse wasn't over one 989 // We're running nested menus. Only exit all if the mouse wasn't over one
989 // of the menus from the last run. 990 // of the menus from the last run.
990 gfx::Point screen_loc(event.location()); 991 gfx::Point screen_loc(gfx::ToFlooredPoint(event.location()));
991 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc); 992 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc);
992 MenuPart last_part = GetMenuPartByScreenCoordinateUsingMenu( 993 MenuPart last_part = GetMenuPartByScreenCoordinateUsingMenu(
993 menu_stack_.back().item, screen_loc); 994 menu_stack_.back().item, screen_loc);
994 if (last_part.type != MenuPart::NONE) 995 if (last_part.type != MenuPart::NONE)
995 exit_type = EXIT_OUTERMOST; 996 exit_type = EXIT_OUTERMOST;
996 } 997 }
997 Cancel(exit_type); 998 Cancel(exit_type);
998 999
999 #if defined(OS_CHROMEOS) 1000 #if defined(OS_CHROMEOS)
1000 // We're going to exit the menu and want to repost the event so that is 1001 // We're going to exit the menu and want to repost the event so that is
1001 // is handled normally after the context menu has exited. We call 1002 // is handled normally after the context menu has exited. We call
1002 // RepostEvent after Cancel so that mouse capture has been released so 1003 // RepostEvent after Cancel so that mouse capture has been released so
1003 // that finding the event target is unaffected by the current capture. 1004 // that finding the event target is unaffected by the current capture.
1004 RepostEvent(source, event); 1005 RepostEvent(source, event);
1005 #endif 1006 #endif
1006 // Do not repost events for Linux Aura because this behavior is more 1007 // Do not repost events for Linux Aura because this behavior is more
1007 // consistent with the behavior of other Linux apps. 1008 // consistent with the behavior of other Linux apps.
1008 return; 1009 return;
1009 } 1010 }
1010 1011
1011 // On a press we immediately commit the selection, that way a submenu 1012 // On a press we immediately commit the selection, that way a submenu
1012 // pops up immediately rather than after a delay. 1013 // pops up immediately rather than after a delay.
1013 int selection_types = SELECTION_UPDATE_IMMEDIATELY; 1014 int selection_types = SELECTION_UPDATE_IMMEDIATELY;
1014 if (!part.menu) { 1015 if (!part.menu) {
1015 part.menu = part.parent; 1016 part.menu = part.parent;
1016 selection_types |= SELECTION_OPEN_SUBMENU; 1017 selection_types |= SELECTION_OPEN_SUBMENU;
1017 } else { 1018 } else {
1018 if (part.menu->GetDelegate()->CanDrag(part.menu)) { 1019 if (part.menu->GetDelegate()->CanDrag(part.menu)) {
1019 possible_drag_ = true; 1020 possible_drag_ = true;
1020 press_pt_ = event.location(); 1021 press_pt_ = gfx::ToFlooredPoint(event.location());
1021 } 1022 }
1022 if (part.menu->HasSubmenu()) 1023 if (part.menu->HasSubmenu())
1023 selection_types |= SELECTION_OPEN_SUBMENU; 1024 selection_types |= SELECTION_OPEN_SUBMENU;
1024 } 1025 }
1025 SetSelection(part.menu, selection_types); 1026 SetSelection(part.menu, selection_types);
1026 } 1027 }
1027 1028
1028 void MenuController::StartDrag(SubmenuView* source, 1029 void MenuController::StartDrag(SubmenuView* source,
1029 const gfx::Point& location) { 1030 const gfx::Point& location) {
1030 MenuItemView* item = state_.item; 1031 MenuItemView* item = state_.item;
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 bool MenuController::ShowContextMenu(MenuItemView* menu_item, 1355 bool MenuController::ShowContextMenu(MenuItemView* menu_item,
1355 SubmenuView* source, 1356 SubmenuView* source,
1356 const ui::LocatedEvent& event, 1357 const ui::LocatedEvent& event,
1357 ui::MenuSourceType source_type) { 1358 ui::MenuSourceType source_type) {
1358 // Set the selection immediately, making sure the submenu is only open 1359 // Set the selection immediately, making sure the submenu is only open
1359 // if it already was. 1360 // if it already was.
1360 int selection_types = SELECTION_UPDATE_IMMEDIATELY; 1361 int selection_types = SELECTION_UPDATE_IMMEDIATELY;
1361 if (state_.item == pending_state_.item && state_.submenu_open) 1362 if (state_.item == pending_state_.item && state_.submenu_open)
1362 selection_types |= SELECTION_OPEN_SUBMENU; 1363 selection_types |= SELECTION_OPEN_SUBMENU;
1363 SetSelection(pending_state_.item, selection_types); 1364 SetSelection(pending_state_.item, selection_types);
1364 gfx::Point loc(event.location()); 1365 gfx::Point loc(gfx::ToFlooredPoint(event.location()));
1365 View::ConvertPointToScreen(source->GetScrollViewContainer(), &loc); 1366 View::ConvertPointToScreen(source->GetScrollViewContainer(), &loc);
1366 1367
1367 if (menu_item->GetDelegate()->ShowContextMenu( 1368 if (menu_item->GetDelegate()->ShowContextMenu(
1368 menu_item, menu_item->GetCommand(), loc, source_type)) { 1369 menu_item, menu_item->GetCommand(), loc, source_type)) {
1369 SendMouseCaptureLostToActiveView(); 1370 SendMouseCaptureLostToActiveView();
1370 return true; 1371 return true;
1371 } 1372 }
1372 return false; 1373 return false;
1373 } 1374 }
1374 1375
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
2155 // We some times get an event after closing all the menus. Ignore it. Make 2156 // We some times get an event after closing all the menus. Ignore it. Make
2156 // sure the menu is in fact not visible. If the menu is visible, then 2157 // sure the menu is in fact not visible. If the menu is visible, then
2157 // we're in a bad state where we think the menu isn't visibile but it is. 2158 // we're in a bad state where we think the menu isn't visibile but it is.
2158 DCHECK(!source->GetWidget()->IsVisible()); 2159 DCHECK(!source->GetWidget()->IsVisible());
2159 return; 2160 return;
2160 } 2161 }
2161 2162
2162 state_.item->GetRootMenuItem()->GetSubmenu()->ReleaseCapture(); 2163 state_.item->GetRootMenuItem()->GetSubmenu()->ReleaseCapture();
2163 #endif 2164 #endif
2164 2165
2165 gfx::Point screen_loc(event.location()); 2166 gfx::Point screen_loc(gfx::ToFlooredPoint(event.location()));
2166 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc); 2167 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc);
2167 gfx::NativeView native_view = source->GetWidget()->GetNativeView(); 2168 gfx::NativeView native_view = source->GetWidget()->GetNativeView();
2168 if (!native_view) 2169 if (!native_view)
2169 return; 2170 return;
2170 2171
2171 gfx::Screen* screen = gfx::Screen::GetScreenFor(native_view); 2172 gfx::Screen* screen = gfx::Screen::GetScreenFor(native_view);
2172 gfx::NativeWindow window = screen->GetWindowAtScreenPoint(screen_loc); 2173 gfx::NativeWindow window = screen->GetWindowAtScreenPoint(screen_loc);
2173 2174
2174 #if defined(OS_WIN) 2175 #if defined(OS_WIN)
2175 // PostMessage() to metro windows isn't allowed (access will be denied). Don't 2176 // PostMessage() to metro windows isn't allowed (access will be denied). Don't
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
2272 } 2273 }
2273 2274
2274 void MenuController::StopScrolling() { 2275 void MenuController::StopScrolling() {
2275 scroll_task_.reset(NULL); 2276 scroll_task_.reset(NULL);
2276 } 2277 }
2277 2278
2278 void MenuController::UpdateActiveMouseView(SubmenuView* event_source, 2279 void MenuController::UpdateActiveMouseView(SubmenuView* event_source,
2279 const ui::MouseEvent& event, 2280 const ui::MouseEvent& event,
2280 View* target_menu) { 2281 View* target_menu) {
2281 View* target = NULL; 2282 View* target = NULL;
2282 gfx::Point target_menu_loc(event.location()); 2283 gfx::Point target_menu_loc(gfx::ToFlooredPoint(event.location()));
2283 if (target_menu && target_menu->has_children()) { 2284 if (target_menu && target_menu->has_children()) {
2284 // Locate the deepest child view to send events to. This code assumes we 2285 // Locate the deepest child view to send events to. This code assumes we
2285 // don't have to walk up the tree to find a view interested in events. This 2286 // don't have to walk up the tree to find a view interested in events. This
2286 // is currently true for the cases we are embedding views, but if we embed 2287 // is currently true for the cases we are embedding views, but if we embed
2287 // more complex hierarchies it'll need to change. 2288 // more complex hierarchies it'll need to change.
2288 View::ConvertPointToScreen(event_source->GetScrollViewContainer(), 2289 View::ConvertPointToScreen(event_source->GetScrollViewContainer(),
2289 &target_menu_loc); 2290 &target_menu_loc);
2290 View::ConvertPointFromScreen(target_menu, &target_menu_loc); 2291 View::ConvertPointFromScreen(target_menu, &target_menu_loc);
2291 target = target_menu->GetEventHandlerForPoint(target_menu_loc); 2292 target = target_menu->GetEventHandlerForPoint(target_menu_loc);
2292 if (target == target_menu || !target->enabled()) 2293 if (target == target_menu || !target->enabled())
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2324 active_mouse_view->OnMouseDragged(mouse_dragged_event); 2325 active_mouse_view->OnMouseDragged(mouse_dragged_event);
2325 } 2326 }
2326 } 2327 }
2327 2328
2328 void MenuController::SendMouseReleaseToActiveView(SubmenuView* event_source, 2329 void MenuController::SendMouseReleaseToActiveView(SubmenuView* event_source,
2329 const ui::MouseEvent& event) { 2330 const ui::MouseEvent& event) {
2330 View* active_mouse_view = GetActiveMouseView(); 2331 View* active_mouse_view = GetActiveMouseView();
2331 if (!active_mouse_view) 2332 if (!active_mouse_view)
2332 return; 2333 return;
2333 2334
2334 gfx::Point target_loc(event.location()); 2335 gfx::Point target_loc(gfx::ToFlooredPoint(event.location()));
2335 View::ConvertPointToScreen(event_source->GetScrollViewContainer(), 2336 View::ConvertPointToScreen(event_source->GetScrollViewContainer(),
2336 &target_loc); 2337 &target_loc);
2337 View::ConvertPointFromScreen(active_mouse_view, &target_loc); 2338 View::ConvertPointFromScreen(active_mouse_view, &target_loc);
2338 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, target_loc, target_loc, 2339 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, target_loc, target_loc,
2339 event.flags(), event.changed_button_flags()); 2340 event.flags(), event.changed_button_flags());
2340 // Reset active mouse view before sending mouse released. That way if it calls 2341 // Reset active mouse view before sending mouse released. That way if it calls
2341 // back to us, we aren't in a weird state. 2342 // back to us, we aren't in a weird state.
2342 SetActiveMouseView(NULL); 2343 SetActiveMouseView(NULL);
2343 active_mouse_view->OnMouseReleased(release_event); 2344 active_mouse_view->OnMouseReleased(release_event);
2344 } 2345 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
2429 } 2430 }
2430 } 2431 }
2431 2432
2432 gfx::Screen* MenuController::GetScreen() { 2433 gfx::Screen* MenuController::GetScreen() {
2433 aura::Window* root = GetOwnerRootWindow(owner_); 2434 aura::Window* root = GetOwnerRootWindow(owner_);
2434 return root ? gfx::Screen::GetScreenFor(root) 2435 return root ? gfx::Screen::GetScreenFor(root)
2435 : gfx::Screen::GetNativeScreen(); 2436 : gfx::Screen::GetNativeScreen();
2436 } 2437 }
2437 2438
2438 } // namespace views 2439 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698