Index: Source/core/page/CustomContextMenuProvider.cpp |
diff --git a/Source/core/page/CustomContextMenuProvider.cpp b/Source/core/page/CustomContextMenuProvider.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d07db2ffd165eb702be4982765257a9dcf6a56e1 |
--- /dev/null |
+++ b/Source/core/page/CustomContextMenuProvider.cpp |
@@ -0,0 +1,44 @@ |
+// 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/page/CustomContextMenuProvider.h" |
+ |
+#include "core/dom/Document.h" |
+#include "core/events/EventDispatcher.h" |
+#include "core/events/MouseEvent.h" |
+#include "core/html/HTMLMenuElement.h" |
+#include "core/html/HTMLMenuItemElement.h" |
+#include "core/page/ContextMenuController.h" |
+#include "core/page/Page.h" |
+#include "platform/ContextMenu.h" |
+ |
+namespace blink { |
+ |
+CustomContextMenuProvider::CustomContextMenuProvider(PassRefPtr<Document> document, const Vector<ContextMenuItem>& items) |
+ : m_document(document) |
+ , m_items(items) |
+{ |
+} |
+ |
+CustomContextMenuProvider::~CustomContextMenuProvider() |
+{ |
+} |
+ |
+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 (HTMLElement* element = m_document->page()->contextMenuController().menuItemAt(item->action())) { |
+ RefPtrWillBeRawPtr<SimulatedMouseEvent> click = SimulatedMouseEvent::create(EventTypeNames::click, m_document->domWindow(), Event::create()); |
+ click->setRelatedTarget(m_document->page()->contextMenuController().subjectElement()); |
+ element->dispatchEvent(click.release()); |
+ } |
+} |
+ |
+} // namespace blink |