- Revision
- 159780
- Author
- grao...@apple.com
- Date
- 2013-11-26 00:29:11 -0800 (Tue, 26 Nov 2013)
Log Message
Web Inspector: Allow showing a context menu on all mouse events.
https://bugs.webkit.org/show_bug.cgi?id=124747
Reviewed by Joseph Pecoraro.
Source/WebCore:
Add a new InspectorFrontendHost::dispatchEventAsContextMenuEvent(Event*) method
to let the inspector front-end dispatch a native contextmenu event that will allow
for a context menu to be shown from within a non-contextmenu event handler.
* inspector/InspectorFrontendHost.cpp:
(WebCore::InspectorFrontendHost::dispatchEventAsContextMenuEvent):
Check that we're dealing with a mouse event, get the frame for the event target
and the event's location to call ContextMenuController::showContextMenuAt()
which will handle the new contextmenu event dispatch to the original event target.
* inspector/InspectorFrontendHost.h:
* inspector/InspectorFrontendHost.idl:
Source/WebInspectorUI:
Automatically dispatch a contextmenu event in case WebInspector.ContextMenu.prototype.show()
is called outside of a contextmenu event handler and would therefore not show the expected
context menu (except in the Remote Web Inspector where this already works).
* UserInterface/ContextMenu.js:
(WebInspector.ContextMenu.prototype.show):
Check whether the event is a contextmenu event, and if not, add an event listener for a manually
dispatched contextmenu event such that we may then call InspectorFrontendHost.showContextMenu()
in a contextmenu event handler.
(WebInspector.ContextMenu.prototype.handleEvent):
Call InspectorFrontendHost.showContextMenu() now that we received the manually dispatched
contextmenu event.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (159779 => 159780)
--- trunk/Source/WebCore/ChangeLog 2013-11-26 05:54:30 UTC (rev 159779)
+++ trunk/Source/WebCore/ChangeLog 2013-11-26 08:29:11 UTC (rev 159780)
@@ -1,3 +1,23 @@
+2013-11-26 Antoine Quint <grao...@apple.com>
+
+ Web Inspector: Allow showing a context menu on all mouse events.
+ https://bugs.webkit.org/show_bug.cgi?id=124747
+
+ Reviewed by Joseph Pecoraro.
+
+ Add a new InspectorFrontendHost::dispatchEventAsContextMenuEvent(Event*) method
+ to let the inspector front-end dispatch a native contextmenu event that will allow
+ for a context menu to be shown from within a non-contextmenu event handler.
+
+ * inspector/InspectorFrontendHost.cpp:
+ (WebCore::InspectorFrontendHost::dispatchEventAsContextMenuEvent):
+ Check that we're dealing with a mouse event, get the frame for the event target
+ and the event's location to call ContextMenuController::showContextMenuAt()
+ which will handle the new contextmenu event dispatch to the original event target.
+
+ * inspector/InspectorFrontendHost.h:
+ * inspector/InspectorFrontendHost.idl:
+
2013-11-25 Sam Weinig <s...@webkit.org>
Convert some Shape code to use references
Modified: trunk/Source/WebCore/inspector/InspectorFrontendHost.cpp (159779 => 159780)
--- trunk/Source/WebCore/inspector/InspectorFrontendHost.cpp 2013-11-26 05:54:30 UTC (rev 159779)
+++ trunk/Source/WebCore/inspector/InspectorFrontendHost.cpp 2013-11-26 08:29:11 UTC (rev 159780)
@@ -39,6 +39,7 @@
#include "ContextMenuProvider.h"
#include "DOMWrapperWorld.h"
#include "Element.h"
+#include "Event.h"
#include "FrameLoader.h"
#include "HitTestResult.h"
#include "HTMLFrameOwnerElement.h"
@@ -46,6 +47,7 @@
#include "InspectorController.h"
#include "InspectorFrontendClient.h"
#include "MainFrame.h"
+#include "MouseEvent.h"
#include "Page.h"
#include "Pasteboard.h"
#include "ResourceError.h"
@@ -279,7 +281,23 @@
m_frontendPage->contextMenuController().showContextMenu(event, menuProvider);
m_menuProvider = menuProvider.get();
}
+
+void InspectorFrontendHost::dispatchEventAsContextMenuEvent(Event* event)
+{
+#if USE(ACCESSIBILITY_CONTEXT_MENUS)
+ if (!event || !event->isMouseEvent())
+ return;
+
+ Frame* frame = event->target()->toNode()->document().frame();
+ MouseEvent* mouseEvent = toMouseEvent(event);
+ IntPoint mousePoint = IntPoint(mouseEvent->clientX(), mouseEvent->clientY());
+
+ m_frontendPage->contextMenuController().showContextMenuAt(frame, mousePoint);
+#else
+ UNUSED_PARAM(event);
#endif
+}
+#endif
String InspectorFrontendHost::loadResourceSynchronously(const String& url)
{
Modified: trunk/Source/WebCore/inspector/InspectorFrontendHost.h (159779 => 159780)
--- trunk/Source/WebCore/inspector/InspectorFrontendHost.h 2013-11-26 05:54:30 UTC (rev 159779)
+++ trunk/Source/WebCore/inspector/InspectorFrontendHost.h 2013-11-26 08:29:11 UTC (rev 159780)
@@ -80,6 +80,7 @@
// Called from [Custom] implementations.
void showContextMenu(Event*, const Vector<ContextMenuItem>& items);
void sendMessageToBackend(const String& message);
+ void dispatchEventAsContextMenuEvent(Event*);
String loadResourceSynchronously(const String& url);
Modified: trunk/Source/WebCore/inspector/InspectorFrontendHost.idl (159779 => 159780)
--- trunk/Source/WebCore/inspector/InspectorFrontendHost.idl 2013-11-26 05:54:30 UTC (rev 159779)
+++ trunk/Source/WebCore/inspector/InspectorFrontendHost.idl 2013-11-26 08:29:11 UTC (rev 159780)
@@ -62,6 +62,7 @@
[Custom] DOMString platform();
[Custom] DOMString port();
[Custom] void showContextMenu(MouseEvent event, any items);
+ void dispatchEventAsContextMenuEvent(Event event);
void sendMessageToBackend(DOMString message);
[Custom] void recordActionTaken(unsigned long actionCode);
Modified: trunk/Source/WebInspectorUI/ChangeLog (159779 => 159780)
--- trunk/Source/WebInspectorUI/ChangeLog 2013-11-26 05:54:30 UTC (rev 159779)
+++ trunk/Source/WebInspectorUI/ChangeLog 2013-11-26 08:29:11 UTC (rev 159780)
@@ -1,3 +1,24 @@
+2013-11-26 Antoine Quint <grao...@apple.com>
+
+ Web Inspector: Allow showing a context menu on all mouse events.
+ https://bugs.webkit.org/show_bug.cgi?id=124747
+
+ Reviewed by Joseph Pecoraro.
+
+ Automatically dispatch a contextmenu event in case WebInspector.ContextMenu.prototype.show()
+ is called outside of a contextmenu event handler and would therefore not show the expected
+ context menu (except in the Remote Web Inspector where this already works).
+
+ * UserInterface/ContextMenu.js:
+ (WebInspector.ContextMenu.prototype.show):
+ Check whether the event is a contextmenu event, and if not, add an event listener for a manually
+ dispatched contextmenu event such that we may then call InspectorFrontendHost.showContextMenu()
+ in a contextmenu event handler.
+
+ (WebInspector.ContextMenu.prototype.handleEvent):
+ Call InspectorFrontendHost.showContextMenu() now that we received the manually dispatched
+ contextmenu event.
+
2013-11-25 Alexandru Chiculita <ach...@adobe.com>
Web Inspector: [CSS Regions] A page with many flows should collapse the resources tree
Modified: trunk/Source/WebInspectorUI/UserInterface/ContextMenu.js (159779 => 159780)
--- trunk/Source/WebInspectorUI/UserInterface/ContextMenu.js 2013-11-26 05:54:30 UTC (rev 159779)
+++ trunk/Source/WebInspectorUI/UserInterface/ContextMenu.js 2013-11-26 08:29:11 UTC (rev 159780)
@@ -185,6 +185,9 @@
}
WebInspector.ContextMenu.prototype = {
+
+ // Public
+
nextId: function()
{
return this._id++;
@@ -192,16 +195,36 @@
show: function()
{
+ console.assert(this._event instanceof MouseEvent);
+
var menuObject = this._buildDescriptor();
if (menuObject.length) {
WebInspector._contextMenu = this;
- InspectorFrontendHost.showContextMenu(this._event, menuObject);
+ if (this._event.type !== "contextmenu" && typeof InspectorFrontendHost.dispatchEventAsContextMenuEvent === "function") {
+ this._menuObject = menuObject;
+ this._event.target.addEventListener("contextmenu", this, true);
+ InspectorFrontendHost.dispatchEventAsContextMenuEvent(this._event);
+ } else
+ InspectorFrontendHost.showContextMenu(this._event, menuObject);
}
if (this._event)
this._event.stopImmediatePropagation();
},
+ // Protected
+
+ handleEvent: function(event)
+ {
+ this._event.target.removeEventListener("contextmenu", this, true);
+ InspectorFrontendHost.showContextMenu(event, this._menuObject);
+ delete this._menuObject;
+
+ event.stopImmediatePropagation();
+ },
+
+ // Private
+
_setHandler: function(id, handler)
{
if (handler)