| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/test/menu_test_utils.h" | 5 #include "ui/views/test/menu_test_utils.h" |
| 6 | 6 |
| 7 #include "ui/views/controls/menu/menu_controller.h" | 7 #include "ui/views/controls/menu/menu_controller.h" |
| 8 | 8 |
| 9 namespace views { | 9 namespace views { |
| 10 namespace test { | 10 namespace test { |
| 11 | 11 |
| 12 // TestMenuDelegate ----------------------------------------------------------- | 12 // TestMenuDelegate ----------------------------------------------------------- |
| 13 | 13 |
| 14 TestMenuDelegate::TestMenuDelegate() | 14 TestMenuDelegate::TestMenuDelegate() |
| 15 : execute_command_id_(0), | 15 : execute_command_id_(0), |
| 16 on_menu_closed_called_count_(0), | 16 on_menu_closed_called_count_(0), |
| 17 on_menu_closed_menu_(nullptr), | 17 on_menu_closed_menu_(nullptr), |
| 18 on_menu_closed_run_result_(MenuRunner::MENU_DELETED), | 18 on_menu_closed_run_result_(MenuRunner::MENU_DELETED), |
| 19 on_perform_drop_called_(false) {} | 19 on_perform_drop_called_(false) {} |
| 20 | 20 |
| 21 TestMenuDelegate::~TestMenuDelegate() {} | 21 TestMenuDelegate::~TestMenuDelegate() {} |
| 22 | 22 |
| 23 bool TestMenuDelegate::ShowContextMenu(MenuItemView* source, |
| 24 int id, |
| 25 const gfx::Point& p, |
| 26 ui::MenuSourceType source_type) { |
| 27 show_context_menu_count_++; |
| 28 show_context_menu_source_ = source; |
| 29 return true; |
| 30 } |
| 31 |
| 23 void TestMenuDelegate::ExecuteCommand(int id) { | 32 void TestMenuDelegate::ExecuteCommand(int id) { |
| 24 execute_command_id_ = id; | 33 execute_command_id_ = id; |
| 25 } | 34 } |
| 26 | 35 |
| 27 void TestMenuDelegate::OnMenuClosed(MenuItemView* menu, | 36 void TestMenuDelegate::OnMenuClosed(MenuItemView* menu, |
| 28 MenuRunner::RunResult result) { | 37 MenuRunner::RunResult result) { |
| 29 on_menu_closed_called_count_++; | 38 on_menu_closed_called_count_++; |
| 30 on_menu_closed_menu_ = menu; | 39 on_menu_closed_menu_ = menu; |
| 31 on_menu_closed_run_result_ = result; | 40 on_menu_closed_run_result_ = result; |
| 32 } | 41 } |
| 33 | 42 |
| 34 int TestMenuDelegate::OnPerformDrop(MenuItemView* menu, | 43 int TestMenuDelegate::OnPerformDrop(MenuItemView* menu, |
| 35 DropPosition position, | 44 DropPosition position, |
| 36 const ui::DropTargetEvent& event) { | 45 const ui::DropTargetEvent& event) { |
| 37 on_perform_drop_called_ = true; | 46 on_perform_drop_called_ = true; |
| 38 return ui::DragDropTypes::DRAG_COPY; | 47 return ui::DragDropTypes::DRAG_COPY; |
| 39 } | 48 } |
| 40 | 49 |
| 41 int TestMenuDelegate::GetDragOperations(MenuItemView* sender) { | 50 int TestMenuDelegate::GetDragOperations(MenuItemView* sender) { |
| 42 return ui::DragDropTypes::DRAG_COPY; | 51 return ui::DragDropTypes::DRAG_COPY; |
| 43 } | 52 } |
| 44 | 53 |
| 45 void TestMenuDelegate::WriteDragData(MenuItemView* sender, | 54 void TestMenuDelegate::WriteDragData(MenuItemView* sender, |
| 46 OSExchangeData* data) {} | 55 OSExchangeData* data) {} |
| 47 | 56 |
| 57 void TestMenuDelegate::WillHideMenu(MenuItemView* menu) { |
| 58 will_hide_menu_count_++; |
| 59 will_hide_menu_ = menu; |
| 60 } |
| 61 |
| 48 // MenuControllerTestApi ------------------------------------------------------ | 62 // MenuControllerTestApi ------------------------------------------------------ |
| 49 | 63 |
| 50 MenuControllerTestApi::MenuControllerTestApi() | 64 MenuControllerTestApi::MenuControllerTestApi() |
| 51 : controller_(MenuController::GetActiveInstance()->AsWeakPtr()) {} | 65 : controller_(MenuController::GetActiveInstance()->AsWeakPtr()) {} |
| 52 | 66 |
| 53 MenuControllerTestApi::~MenuControllerTestApi() {} | 67 MenuControllerTestApi::~MenuControllerTestApi() {} |
| 54 | 68 |
| 55 void MenuControllerTestApi::ClearState() { | 69 void MenuControllerTestApi::ClearState() { |
| 56 if (!controller_) | 70 if (!controller_) |
| 57 return; | 71 return; |
| 58 controller_->ClearStateForTest(); | 72 controller_->ClearStateForTest(); |
| 59 } | 73 } |
| 60 | 74 |
| 61 void MenuControllerTestApi::SetShowing(bool showing) { | 75 void MenuControllerTestApi::SetShowing(bool showing) { |
| 62 if (!controller_) | 76 if (!controller_) |
| 63 return; | 77 return; |
| 64 controller_->showing_ = showing; | 78 controller_->showing_ = showing; |
| 65 } | 79 } |
| 66 | 80 |
| 67 } // namespace test | 81 } // namespace test |
| 68 } // namespace views | 82 } // namespace views |
| OLD | NEW |