| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "ui/aura/scoped_window_targeter.h" | 11 #include "ui/aura/scoped_window_targeter.h" |
| 12 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
| 13 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
| 14 #include "ui/events/event_constants.h" | 14 #include "ui/events/event_constants.h" |
| 15 #include "ui/events/event_handler.h" | 15 #include "ui/events/event_handler.h" |
| 16 #include "ui/events/event_utils.h" | 16 #include "ui/events/event_utils.h" |
| 17 #include "ui/events/null_event_targeter.h" | 17 #include "ui/events/null_event_targeter.h" |
| 18 #include "ui/events/test/event_generator.h" | 18 #include "ui/events/test/event_generator.h" |
| 19 #include "ui/gfx/geometry/point.h" | 19 #include "ui/gfx/geometry/point.h" |
| 20 #include "ui/gfx/geometry/rect.h" | 20 #include "ui/gfx/geometry/rect.h" |
| 21 #include "ui/views/controls/menu/menu_controller_delegate.h" | 21 #include "ui/views/controls/menu/menu_controller_delegate.h" |
| 22 #include "ui/views/controls/menu/menu_delegate.h" | 22 #include "ui/views/controls/menu/menu_delegate.h" |
| 23 #include "ui/views/controls/menu/menu_item_view.h" | 23 #include "ui/views/controls/menu/menu_item_view.h" |
| 24 #include "ui/views/controls/menu/menu_message_loop.h" | 24 #include "ui/views/controls/menu/menu_message_loop.h" |
| 25 #include "ui/views/controls/menu/menu_scroll_view_container.h" |
| 25 #include "ui/views/controls/menu/submenu_view.h" | 26 #include "ui/views/controls/menu/submenu_view.h" |
| 26 #include "ui/views/test/views_test_base.h" | 27 #include "ui/views/test/views_test_base.h" |
| 27 | 28 |
| 28 #if defined(USE_AURA) | 29 #if defined(USE_AURA) |
| 29 #include "ui/aura/scoped_window_targeter.h" | 30 #include "ui/aura/scoped_window_targeter.h" |
| 30 #include "ui/aura/window.h" | 31 #include "ui/aura/window.h" |
| 31 #include "ui/views/controls/menu/menu_key_event_handler.h" | 32 #include "ui/views/controls/menu/menu_key_event_handler.h" |
| 32 #endif | 33 #endif |
| 33 | 34 |
| 34 #if defined(USE_X11) | 35 #if defined(USE_X11) |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 | 401 |
| 401 void SetIsCombobox(bool is_combobox) { | 402 void SetIsCombobox(bool is_combobox) { |
| 402 menu_controller_->set_is_combobox(is_combobox); | 403 menu_controller_->set_is_combobox(is_combobox); |
| 403 } | 404 } |
| 404 | 405 |
| 405 void SetSelectionOnPointerDown(SubmenuView* source, | 406 void SetSelectionOnPointerDown(SubmenuView* source, |
| 406 const ui::LocatedEvent* event) { | 407 const ui::LocatedEvent* event) { |
| 407 menu_controller_->SetSelectionOnPointerDown(source, event); | 408 menu_controller_->SetSelectionOnPointerDown(source, event); |
| 408 } | 409 } |
| 409 | 410 |
| 410 void ProcessMouseMoved(SubmenuView* source, | 411 // Note that coordinates of events passed to MenuController must be in that of |
| 411 const ui::MouseEvent& event) { | 412 // the MenuScrollViewContainer. |
| 413 void ProcessMouseMoved(SubmenuView* source, const ui::MouseEvent& event) { |
| 412 menu_controller_->OnMouseMoved(source, event); | 414 menu_controller_->OnMouseMoved(source, event); |
| 413 } | 415 } |
| 414 | 416 |
| 415 void RunMenu() { | 417 void RunMenu() { |
| 416 #if defined(USE_AURA) | 418 #if defined(USE_AURA) |
| 417 scoped_ptr<MenuKeyEventHandler> key_event_handler(new MenuKeyEventHandler); | 419 scoped_ptr<MenuKeyEventHandler> key_event_handler(new MenuKeyEventHandler); |
| 418 #endif | 420 #endif |
| 419 | 421 |
| 420 menu_controller_->message_loop_depth_++; | 422 menu_controller_->message_loop_depth_++; |
| 421 menu_controller_->RunMessageLoop(false); | 423 menu_controller_->RunMessageLoop(false); |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 EXPECT_FALSE(button3->IsHotTracked()); | 759 EXPECT_FALSE(button3->IsHotTracked()); |
| 758 | 760 |
| 759 // Move selection to |button3|. | 761 // Move selection to |button3|. |
| 760 IncrementSelection(); | 762 IncrementSelection(); |
| 761 EXPECT_EQ(5, pending_state_item()->GetCommand()); | 763 EXPECT_EQ(5, pending_state_item()->GetCommand()); |
| 762 EXPECT_FALSE(button1->IsHotTracked()); | 764 EXPECT_FALSE(button1->IsHotTracked()); |
| 763 EXPECT_FALSE(button2->IsHotTracked()); | 765 EXPECT_FALSE(button2->IsHotTracked()); |
| 764 EXPECT_TRUE(button3->IsHotTracked()); | 766 EXPECT_TRUE(button3->IsHotTracked()); |
| 765 | 767 |
| 766 // Move a mouse to hot track the |button1|. | 768 // Move a mouse to hot track the |button1|. |
| 769 SubmenuView* sub_menu = menu_item()->GetSubmenu(); |
| 767 gfx::Point location(button1->GetBoundsInScreen().CenterPoint()); | 770 gfx::Point location(button1->GetBoundsInScreen().CenterPoint()); |
| 771 View::ConvertPointFromScreen(sub_menu->GetScrollViewContainer(), &location); |
| 768 ui::MouseEvent event(ui::ET_MOUSE_MOVED, location, location, | 772 ui::MouseEvent event(ui::ET_MOUSE_MOVED, location, location, |
| 769 ui::EventTimeForNow(), 0, 0); | 773 ui::EventTimeForNow(), 0, 0); |
| 770 SubmenuView* sub_menu = menu_item()->GetSubmenu(); | |
| 771 ProcessMouseMoved(sub_menu, event); | 774 ProcessMouseMoved(sub_menu, event); |
| 772 | 775 |
| 773 // Incrementing selection should move hot tracking to the second button (next | 776 // Incrementing selection should move hot tracking to the second button (next |
| 774 // after the first button). | 777 // after the first button). |
| 775 IncrementSelection(); | 778 IncrementSelection(); |
| 776 EXPECT_EQ(5, pending_state_item()->GetCommand()); | 779 EXPECT_EQ(5, pending_state_item()->GetCommand()); |
| 777 EXPECT_FALSE(button1->IsHotTracked()); | 780 EXPECT_FALSE(button1->IsHotTracked()); |
| 778 EXPECT_TRUE(button2->IsHotTracked()); | 781 EXPECT_TRUE(button2->IsHotTracked()); |
| 779 EXPECT_FALSE(button3->IsHotTracked()); | 782 EXPECT_FALSE(button3->IsHotTracked()); |
| 780 | 783 |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 // shutdown. This should not crash while attempting to repost the event. | 1122 // shutdown. This should not crash while attempting to repost the event. |
| 1120 SetSelectionOnPointerDown(sub_menu, &event); | 1123 SetSelectionOnPointerDown(sub_menu, &event); |
| 1121 | 1124 |
| 1122 // Close to remove observers before test TearDown | 1125 // Close to remove observers before test TearDown |
| 1123 sub_menu->Close(); | 1126 sub_menu->Close(); |
| 1124 EXPECT_EQ(1, nested_delegate->on_menu_closed_called()); | 1127 EXPECT_EQ(1, nested_delegate->on_menu_closed_called()); |
| 1125 } | 1128 } |
| 1126 | 1129 |
| 1127 } // namespace test | 1130 } // namespace test |
| 1128 } // namespace views | 1131 } // namespace views |
| OLD | NEW |