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

Unified Diff: Source/core/page/ContextMenuController.cpp

Issue 243403006: Implement contextmenu attribute with basic support of <menu> (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Reflect HTMLMenuElement as per spec Created 6 years, 4 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
« no previous file with comments | « Source/core/page/ContextMenuController.h ('k') | Source/core/page/ContextMenuControllerTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/page/ContextMenuController.cpp
diff --git a/Source/core/page/ContextMenuController.cpp b/Source/core/page/ContextMenuController.cpp
index 13680a5486f29ff9378e8ae7b4d748ff8590b81c..6b888f13afb3dc07a9e6ee5cbac8588c537c6ee3 100644
--- a/Source/core/page/ContextMenuController.cpp
+++ b/Source/core/page/ContextMenuController.cpp
@@ -28,18 +28,25 @@
#include "core/page/ContextMenuController.h"
#include "core/dom/Document.h"
+#include "core/dom/Node.h"
#include "core/events/Event.h"
+#include "core/events/EventDispatchMediator.h"
+#include "core/events/EventDispatcher.h"
#include "core/events/MouseEvent.h"
-#include "core/dom/Node.h"
+#include "core/events/RelatedEvent.h"
#include "core/frame/LocalFrame.h"
+#include "core/html/HTMLMenuElement.h"
#include "core/page/ContextMenuClient.h"
#include "core/page/ContextMenuProvider.h"
+#include "core/page/CustomContextMenuProvider.h"
#include "core/page/EventHandler.h"
#include "platform/ContextMenu.h"
#include "platform/ContextMenuItem.h"
namespace blink {
+using namespace HTMLNames;
+
ContextMenuController::ContextMenuController(Page*, ContextMenuClient* client)
: m_client(client)
{
@@ -79,12 +86,31 @@ void ContextMenuController::documentDetached(Document* document)
}
}
+void ContextMenuController::populateCustomContextMenu(Event* event)
+{
+ if (!RuntimeEnabledFeatures::contextMenuEnabled())
+ return;
+
+ Node* node = event->target()->toNode();
+ if (node && node->isHTMLElement()) {
+ HTMLElement& element = toHTMLElement(*node);
+ RefPtrWillBeRawPtr<HTMLMenuElement> menuElement = element.contextMenu();
+ RefPtrWillBeRawPtr<RelatedEvent> relatedEvent = RelatedEvent::create(EventTypeNames::show, true, true, node);
+ if (!menuElement->dispatchEvent(relatedEvent.release()))
+ return;
+ if (menuElement != element.contextMenu())
+ return;
+ m_menuProvider = CustomContextMenuProvider::create(*menuElement, element);
+ m_menuProvider->populateContextMenu(m_contextMenu.get());
+ }
+}
+
void ContextMenuController::handleContextMenuEvent(Event* event)
{
m_contextMenu = createContextMenu(event);
if (!m_contextMenu)
return;
-
+ populateCustomContextMenu(event);
showContextMenu(event);
}
« no previous file with comments | « Source/core/page/ContextMenuController.h ('k') | Source/core/page/ContextMenuControllerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698