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

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

Issue 10832282: Replace views::MouseEvent with ui::MouseEvent (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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
« no previous file with comments | « ui/views/controls/menu/menu_controller.h ('k') | ui/views/controls/menu/menu_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 showing_ = false; 429 showing_ = false;
430 delegate_->DropMenuClosed( 430 delegate_->DropMenuClosed(
431 internal::MenuControllerDelegate::NOTIFY_DELEGATE, 431 internal::MenuControllerDelegate::NOTIFY_DELEGATE,
432 selected->GetRootMenuItem()); 432 selected->GetRootMenuItem());
433 // WARNING: the call to MenuClosed deletes us. 433 // WARNING: the call to MenuClosed deletes us.
434 return; 434 return;
435 } 435 }
436 } 436 }
437 437
438 void MenuController::OnMousePressed(SubmenuView* source, 438 void MenuController::OnMousePressed(SubmenuView* source,
439 const MouseEvent& event) { 439 const ui::MouseEvent& event) {
440 SetSelectionOnPointerDown(source, event); 440 SetSelectionOnPointerDown(source, event);
441 } 441 }
442 442
443 void MenuController::OnMouseDragged(SubmenuView* source, 443 void MenuController::OnMouseDragged(SubmenuView* source,
444 const MouseEvent& event) { 444 const ui::MouseEvent& event) {
445 MenuPart part = GetMenuPart(source, event.location()); 445 MenuPart part = GetMenuPart(source, event.location());
446 UpdateScrolling(part); 446 UpdateScrolling(part);
447 447
448 if (!blocking_run_) 448 if (!blocking_run_)
449 return; 449 return;
450 450
451 if (possible_drag_) { 451 if (possible_drag_) {
452 if (View::ExceededDragThreshold(event.x() - press_pt_.x(), 452 if (View::ExceededDragThreshold(event.x() - press_pt_.x(),
453 event.y() - press_pt_.y())) { 453 event.y() - press_pt_.y())) {
454 StartDrag(source, press_pt_); 454 StartDrag(source, press_pt_);
455 } 455 }
456 return; 456 return;
457 } 457 }
458 MenuItemView* mouse_menu = NULL; 458 MenuItemView* mouse_menu = NULL;
459 if (part.type == MenuPart::MENU_ITEM) { 459 if (part.type == MenuPart::MENU_ITEM) {
460 if (!part.menu) 460 if (!part.menu)
461 part.menu = source->GetMenuItem(); 461 part.menu = source->GetMenuItem();
462 else 462 else
463 mouse_menu = part.menu; 463 mouse_menu = part.menu;
464 SetSelection(part.menu ? part.menu : state_.item, SELECTION_OPEN_SUBMENU); 464 SetSelection(part.menu ? part.menu : state_.item, SELECTION_OPEN_SUBMENU);
465 } else if (part.type == MenuPart::NONE) { 465 } else if (part.type == MenuPart::NONE) {
466 ShowSiblingMenu(source, event.location()); 466 ShowSiblingMenu(source, event.location());
467 } 467 }
468 UpdateActiveMouseView(source, event, mouse_menu); 468 UpdateActiveMouseView(source, event, mouse_menu);
469 } 469 }
470 470
471 void MenuController::OnMouseReleased(SubmenuView* source, 471 void MenuController::OnMouseReleased(SubmenuView* source,
472 const MouseEvent& event) { 472 const ui::MouseEvent& event) {
473 if (!blocking_run_) 473 if (!blocking_run_)
474 return; 474 return;
475 475
476 // We must ignore the first release event when it occured within the original 476 // We must ignore the first release event when it occured within the original
477 // bounds. 477 // bounds.
478 if (drop_first_release_event_ && (event.flags() & ui::EF_LEFT_MOUSE_BUTTON)) { 478 if (drop_first_release_event_ && (event.flags() & ui::EF_LEFT_MOUSE_BUTTON)) {
479 drop_first_release_event_ = false; 479 drop_first_release_event_ = false;
480 gfx::Point loc(event.location()); 480 gfx::Point loc(event.location());
481 View::ConvertPointToScreen(source->GetScrollViewContainer(), &loc); 481 View::ConvertPointToScreen(source->GetScrollViewContainer(), &loc);
482 DCHECK(!state_.initial_bounds.IsEmpty()); 482 DCHECK(!state_.initial_bounds.IsEmpty());
(...skipping 28 matching lines...) Expand all
511 } 511 }
512 } else if (part.type == MenuPart::MENU_ITEM) { 512 } else if (part.type == MenuPart::MENU_ITEM) {
513 // User either clicked on empty space, or a menu that has children. 513 // User either clicked on empty space, or a menu that has children.
514 SetSelection(part.menu ? part.menu : state_.item, 514 SetSelection(part.menu ? part.menu : state_.item,
515 SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY); 515 SELECTION_OPEN_SUBMENU | SELECTION_UPDATE_IMMEDIATELY);
516 } 516 }
517 SendMouseCaptureLostToActiveView(); 517 SendMouseCaptureLostToActiveView();
518 } 518 }
519 519
520 void MenuController::OnMouseMoved(SubmenuView* source, 520 void MenuController::OnMouseMoved(SubmenuView* source,
521 const MouseEvent& event) { 521 const ui::MouseEvent& event) {
522 HandleMouseLocation(source, event.location()); 522 HandleMouseLocation(source, event.location());
523 } 523 }
524 524
525 void MenuController::OnMouseEntered(SubmenuView* source, 525 void MenuController::OnMouseEntered(SubmenuView* source,
526 const MouseEvent& event) { 526 const ui::MouseEvent& event) {
527 // MouseEntered is always followed by a mouse moved, so don't need to 527 // MouseEntered is always followed by a mouse moved, so don't need to
528 // do anything here. 528 // do anything here.
529 } 529 }
530 530
531 #if defined(OS_LINUX) 531 #if defined(OS_LINUX)
532 bool MenuController::OnMouseWheel(SubmenuView* source, 532 bool MenuController::OnMouseWheel(SubmenuView* source,
533 const MouseWheelEvent& event) { 533 const MouseWheelEvent& event) {
534 MenuPart part = GetMenuPart(source, event.location()); 534 MenuPart part = GetMenuPart(source, event.location());
535 return part.submenu && part.submenu->OnMouseWheel(event); 535 return part.submenu && part.submenu->OnMouseWheel(event);
536 } 536 }
(...skipping 1467 matching lines...) Expand 10 before | Expand all | Expand 10 after
2004 if (!scroll_task_.get()) 2004 if (!scroll_task_.get())
2005 scroll_task_.reset(new MenuScrollTask()); 2005 scroll_task_.reset(new MenuScrollTask());
2006 scroll_task_->Update(part); 2006 scroll_task_->Update(part);
2007 } 2007 }
2008 2008
2009 void MenuController::StopScrolling() { 2009 void MenuController::StopScrolling() {
2010 scroll_task_.reset(NULL); 2010 scroll_task_.reset(NULL);
2011 } 2011 }
2012 2012
2013 void MenuController::UpdateActiveMouseView(SubmenuView* event_source, 2013 void MenuController::UpdateActiveMouseView(SubmenuView* event_source,
2014 const MouseEvent& event, 2014 const ui::MouseEvent& event,
2015 View* target_menu) { 2015 View* target_menu) {
2016 View* target = NULL; 2016 View* target = NULL;
2017 gfx::Point target_menu_loc(event.location()); 2017 gfx::Point target_menu_loc(event.location());
2018 if (target_menu && target_menu->has_children()) { 2018 if (target_menu && target_menu->has_children()) {
2019 // Locate the deepest child view to send events to. This code assumes we 2019 // Locate the deepest child view to send events to. This code assumes we
2020 // don't have to walk up the tree to find a view interested in events. This 2020 // don't have to walk up the tree to find a view interested in events. This
2021 // is currently true for the cases we are embedding views, but if we embed 2021 // is currently true for the cases we are embedding views, but if we embed
2022 // more complex hierarchies it'll need to change. 2022 // more complex hierarchies it'll need to change.
2023 View::ConvertPointToScreen(event_source->GetScrollViewContainer(), 2023 View::ConvertPointToScreen(event_source->GetScrollViewContainer(),
2024 &target_menu_loc); 2024 &target_menu_loc);
2025 View::ConvertPointToTarget(NULL, target_menu, &target_menu_loc); 2025 View::ConvertPointToTarget(NULL, target_menu, &target_menu_loc);
2026 target = target_menu->GetEventHandlerForPoint(target_menu_loc); 2026 target = target_menu->GetEventHandlerForPoint(target_menu_loc);
2027 if (target == target_menu || !target->enabled()) 2027 if (target == target_menu || !target->enabled())
2028 target = NULL; 2028 target = NULL;
2029 } 2029 }
2030 if (target != active_mouse_view_) { 2030 if (target != active_mouse_view_) {
2031 SendMouseCaptureLostToActiveView(); 2031 SendMouseCaptureLostToActiveView();
2032 active_mouse_view_ = target; 2032 active_mouse_view_ = target;
2033 if (active_mouse_view_) { 2033 if (active_mouse_view_) {
2034 gfx::Point target_point(target_menu_loc); 2034 gfx::Point target_point(target_menu_loc);
2035 View::ConvertPointToTarget( 2035 View::ConvertPointToTarget(
2036 target_menu, active_mouse_view_, &target_point); 2036 target_menu, active_mouse_view_, &target_point);
2037 MouseEvent mouse_entered_event(ui::ET_MOUSE_ENTERED, 2037 ui::MouseEvent mouse_entered_event(ui::ET_MOUSE_ENTERED,
2038 target_point.x(), target_point.y(), 0); 2038 target_point, target_point,
2039 0);
2039 active_mouse_view_->OnMouseEntered(mouse_entered_event); 2040 active_mouse_view_->OnMouseEntered(mouse_entered_event);
2040 2041
2041 MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, 2042 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED,
2042 target_point.x(), target_point.y(), 2043 target_point, target_point,
2043 event.flags()); 2044 event.flags());
2044 active_mouse_view_->OnMousePressed(mouse_pressed_event); 2045 active_mouse_view_->OnMousePressed(mouse_pressed_event);
2045 } 2046 }
2046 } 2047 }
2047 2048
2048 if (active_mouse_view_) { 2049 if (active_mouse_view_) {
2049 gfx::Point target_point(target_menu_loc); 2050 gfx::Point target_point(target_menu_loc);
2050 View::ConvertPointToTarget(target_menu, active_mouse_view_, &target_point); 2051 View::ConvertPointToTarget(target_menu, active_mouse_view_, &target_point);
2051 MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, 2052 ui::MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED,
2052 target_point.x(), target_point.y(), 2053 target_point, target_point,
2053 event.flags()); 2054 event.flags());
2054 active_mouse_view_->OnMouseDragged(mouse_dragged_event); 2055 active_mouse_view_->OnMouseDragged(mouse_dragged_event);
2055 } 2056 }
2056 } 2057 }
2057 2058
2058 void MenuController::SendMouseReleaseToActiveView(SubmenuView* event_source, 2059 void MenuController::SendMouseReleaseToActiveView(SubmenuView* event_source,
2059 const MouseEvent& event) { 2060 const ui::MouseEvent& event) {
2060 if (!active_mouse_view_) 2061 if (!active_mouse_view_)
2061 return; 2062 return;
2062 2063
2063 gfx::Point target_loc(event.location()); 2064 gfx::Point target_loc(event.location());
2064 View::ConvertPointToScreen(event_source->GetScrollViewContainer(), 2065 View::ConvertPointToScreen(event_source->GetScrollViewContainer(),
2065 &target_loc); 2066 &target_loc);
2066 View::ConvertPointToTarget(NULL, active_mouse_view_, &target_loc); 2067 View::ConvertPointToTarget(NULL, active_mouse_view_, &target_loc);
2067 MouseEvent release_event(ui::ET_MOUSE_RELEASED, target_loc.x(), 2068 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED,
2068 target_loc.y(), event.flags()); 2069 target_loc, target_loc,
2070 event.flags());
2069 // Reset the active_mouse_view_ before sending mouse released. That way if it 2071 // Reset the active_mouse_view_ before sending mouse released. That way if it
2070 // calls back to us, we aren't in a weird state. 2072 // calls back to us, we aren't in a weird state.
2071 View* active_view = active_mouse_view_; 2073 View* active_view = active_mouse_view_;
2072 active_mouse_view_ = NULL; 2074 active_mouse_view_ = NULL;
2073 active_view->OnMouseReleased(release_event); 2075 active_view->OnMouseReleased(release_event);
2074 } 2076 }
2075 2077
2076 void MenuController::SendMouseCaptureLostToActiveView() { 2078 void MenuController::SendMouseCaptureLostToActiveView() {
2077 if (!active_mouse_view_) 2079 if (!active_mouse_view_)
2078 return; 2080 return;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2141 2143
2142 #if defined(USE_AURA) 2144 #if defined(USE_AURA)
2143 void MenuController::OnWindowActivated(aura::Window* active, 2145 void MenuController::OnWindowActivated(aura::Window* active,
2144 aura::Window* old_active) { 2146 aura::Window* old_active) {
2145 if (!drag_in_progress_) 2147 if (!drag_in_progress_)
2146 Cancel(EXIT_ALL); 2148 Cancel(EXIT_ALL);
2147 } 2149 }
2148 #endif 2150 #endif
2149 2151
2150 } // namespace views 2152 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_controller.h ('k') | ui/views/controls/menu/menu_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698