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 "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" | 5 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" |
6 #include "content/public/browser/web_contents.h" | |
7 #include "ui/base/models/menu_model.h" | |
8 | |
9 using ui::MenuModel; | |
6 | 10 |
7 TestRenderViewContextMenu::TestRenderViewContextMenu( | 11 TestRenderViewContextMenu::TestRenderViewContextMenu( |
8 content::RenderFrameHost* render_frame_host, | 12 content::RenderFrameHost* render_frame_host, |
9 content::ContextMenuParams params) | 13 content::ContextMenuParams params) |
10 : RenderViewContextMenu(render_frame_host, params) {} | 14 : RenderViewContextMenu(render_frame_host, params) {} |
11 | 15 |
12 TestRenderViewContextMenu::~TestRenderViewContextMenu() {} | 16 TestRenderViewContextMenu::~TestRenderViewContextMenu() {} |
13 | 17 |
18 // static. | |
Yoyo Zhou
2014/03/07 23:03:21
nit: no .
lazyboy
2014/03/08 00:16:45
Done.
| |
19 TestRenderViewContextMenu* TestRenderViewContextMenu::Create( | |
20 content::WebContents* web_contents, | |
21 const GURL& page_url, | |
22 const GURL& link_url, | |
23 const GURL& frame_url) { | |
24 content::ContextMenuParams params; | |
25 params.page_url = page_url; | |
26 params.link_url = link_url; | |
27 params.frame_url = frame_url; | |
28 TestRenderViewContextMenu* menu = | |
29 new TestRenderViewContextMenu(web_contents->GetMainFrame(), params); | |
30 menu->Init(); | |
31 return menu; | |
32 } | |
33 | |
14 void TestRenderViewContextMenu::PlatformInit() {} | 34 void TestRenderViewContextMenu::PlatformInit() {} |
15 | 35 |
16 void TestRenderViewContextMenu::PlatformCancel() {} | 36 void TestRenderViewContextMenu::PlatformCancel() {} |
17 | 37 |
18 bool TestRenderViewContextMenu::GetAcceleratorForCommandId( | 38 bool TestRenderViewContextMenu::GetAcceleratorForCommandId( |
19 int command_id, | 39 int command_id, |
20 ui::Accelerator* accelerator) { | 40 ui::Accelerator* accelerator) { |
41 // None of our commands have accelerators, so always return false. | |
21 return false; | 42 return false; |
22 } | 43 } |
23 | 44 |
24 bool TestRenderViewContextMenu::IsItemPresent(int command_id) { | 45 bool TestRenderViewContextMenu::IsItemPresent(int command_id) { |
25 return menu_model_.GetIndexOfCommandId(command_id) != -1; | 46 return menu_model_.GetIndexOfCommandId(command_id) != -1; |
26 } | 47 } |
48 | |
49 bool TestRenderViewContextMenu::GetMenuModelAndItemIndex( | |
50 int command_id, | |
51 MenuModel** found_model, | |
52 int* found_index) { | |
53 std::vector<MenuModel*> models_to_search; | |
54 models_to_search.push_back(&menu_model_); | |
55 | |
56 while (!models_to_search.empty()) { | |
57 MenuModel* model = models_to_search.back(); | |
58 models_to_search.pop_back(); | |
59 for (int i = 0; i < model->GetItemCount(); i++) { | |
60 if (model->GetCommandIdAt(i) == command_id) { | |
61 *found_model = model; | |
62 *found_index = i; | |
63 return true; | |
64 } else if (model->GetTypeAt(i) == MenuModel::TYPE_SUBMENU) { | |
65 models_to_search.push_back(model->GetSubmenuModelAt(i)); | |
66 } | |
67 } | |
68 } | |
69 | |
70 return false; | |
71 } | |
OLD | NEW |