Index: Source/core/page/ContextMenuController.cpp |
diff --git a/Source/core/page/ContextMenuController.cpp b/Source/core/page/ContextMenuController.cpp |
index 13680a5486f29ff9378e8ae7b4d748ff8590b81c..b1b28ee509a3efabcb68cc366de53528eb6ab1ff 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" |
tkent
2014/08/25 23:07:42
Looks unnecessary.
pals
2014/08/26 07:13:23
Done.
|
+#include "core/events/EventDispatcher.h" |
tkent
2014/08/25 23:07:42
Looks unnecessary.
pals
2014/08/26 07:13:23
Done.
|
#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,34 @@ void ContextMenuController::documentDetached(Document* document) |
} |
} |
+void ContextMenuController::populateCustomContextMenu(const Event& event) |
+{ |
+ if (!RuntimeEnabledFeatures::contextMenuEnabled()) |
+ return; |
+ |
+ Node* node = event.target()->toNode(); |
+ if (!node || !node->isHTMLElement()) |
+ return; |
+ |
+ HTMLElement& element = toHTMLElement(*node); |
+ RefPtrWillBeRawPtr<HTMLMenuElement> menuElement = element.contextMenu(); |
+ if (!menuElement || !equalIgnoringCase(menuElement->fastGetAttribute(typeAttr), "popup")) |
+ return; |
+ 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); |
} |