Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(665)

Unified Diff: Source/core/html/CustomContextMenuProvider.cpp

Issue 243403006: Implement contextmenu attribute with basic support of <menu> (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Move to oilpan Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..3b07b22f2edbded1b5aa9a907dc1a16d8af070b2
--- /dev/null
+++ b/Source/core/html/CustomContextMenuProvider.cpp
@@ -0,0 +1,45 @@
+// 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/dom/Document.h"
+#include "core/events/EventDispatcher.h"
+#include "core/events/MouseEvent.h"
+#include "core/html/HTMLMenuElement.h"
+#include "core/html/HTMLMenuItemElement.h"
+#include "platform/ContextMenu.h"
+
+namespace blink {
+
+CustomContextMenuProvider::CustomContextMenuProvider(HTMLMenuElement* menu, const Vector<ContextMenuItem>& items)
+ : m_menu(menu)
+ , 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 (!m_menu)
tkent 2014/07/25 04:42:37 This check is unnecessary. m_menu is always non-nu
pals 2014/07/30 09:47:43 This can happen if user has been shown context men
+ return;
+
+ if (HTMLMenuItemElement* element = m_menu->menuItemAt(item->action())) {
+ RefPtrWillBeRawPtr<SimulatedMouseEvent> click = SimulatedMouseEvent::create(EventTypeNames::click, m_menu->document().domWindow(), Event::create());
tkent 2014/07/25 04:42:37 Why do you dispatch 'click' event even though the
pals 2014/07/30 09:47:43 Selection is done on menu shown by platform contex
tkent 2014/07/31 06:10:47 I'm asking why 'click'. We should not dispatch 'c
+ click->setRelatedTarget(m_menu->subjectElement());
+ EventDispatcher::dispatchEvent(element, EventDispatchMediator::create(click.release()));
tkent 2014/07/25 04:42:37 Why don't you use element->dispatchEvent(click.rel
pals 2014/07/30 09:47:43 Done.
+ }
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698