Index: Source/core/html/CustomContextMenuProvider.cpp |
diff --git a/Source/core/html/CustomContextMenuProvider.cpp b/Source/core/html/CustomContextMenuProvider.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b6d44b336446f6cb0d416ee474f554378fa4c325 |
--- /dev/null |
+++ b/Source/core/html/CustomContextMenuProvider.cpp |
@@ -0,0 +1,34 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "config.h" |
+ |
+#include "core/html/CustomContextMenuProvider.h" |
+ |
+#include "core/events/EventDispatcher.h" |
+#include "core/events/MouseEvent.h" |
+#include "core/html/HTMLMenuElement.h" |
+#include "platform/ContextMenu.h" |
+ |
+namespace WebCore { |
+ |
+void CustomContextMenuProvider::populateContextMenu(ContextMenu* menu) |
+{ |
+ for (size_t i = 0; i < m_items.size(); ++i) |
+ menu->appendItem(m_items[i]); |
+} |
+ |
+void CustomContextMenuProvider::contextMenuItemSelected(const ContextMenuItem* item) |
+{ |
+ if (!m_menu) |
+ return; |
+ |
+ if (HTMLElement* element = m_menu->menuItemAt(item->action())) { |
+ RefPtrWillBeRawPtr<SimulatedMouseEvent> click = SimulatedMouseEvent::create(EventTypeNames::click, m_menu->document().domWindow(), Event::create()); |
+ click->setRelatedTarget(m_menu->subjectElement()); |
+ EventDispatcher::dispatchEvent(element, EventDispatchMediator::create(click.release())); |
+ } |
+} |
+ |
+} // namespace |