Bug 577579. Add a nsIDOMWindowUtils method to send a mouse event to the window directly instead of via the toplevel window. r=roc

This commit is contained in:
Timothy Nikkel 2010-08-27 18:15:07 -05:00
parent 2419196a47
commit 95c637fe20
3 changed files with 77 additions and 4 deletions

View File

@ -66,6 +66,8 @@
#include "gfxImageSurface.h"
#include "nsLayoutUtils.h"
#include "nsComputedDOMStyle.h"
#include "nsIViewObserver.h"
#include "nsIPresShell.h"
#if defined(MOZ_X11) && defined(MOZ_WIDGET_GTK2)
#include <gdk/gdk.h>
@ -225,6 +227,33 @@ nsDOMWindowUtils::SendMouseEvent(const nsAString& aType,
PRInt32 aClickCount,
PRInt32 aModifiers,
PRBool aIgnoreRootScrollFrame)
{
return SendMouseEventCommon(aType, aX, aY, aButton, aClickCount, aModifiers,
aIgnoreRootScrollFrame, PR_FALSE);
}
NS_IMETHODIMP
nsDOMWindowUtils::SendMouseEventToWindow(const nsAString& aType,
float aX,
float aY,
PRInt32 aButton,
PRInt32 aClickCount,
PRInt32 aModifiers,
PRBool aIgnoreRootScrollFrame)
{
return SendMouseEventCommon(aType, aX, aY, aButton, aClickCount, aModifiers,
aIgnoreRootScrollFrame, PR_TRUE);
}
NS_IMETHODIMP
nsDOMWindowUtils::SendMouseEventCommon(const nsAString& aType,
float aX,
float aY,
PRInt32 aButton,
PRInt32 aClickCount,
PRInt32 aModifiers,
PRBool aIgnoreRootScrollFrame,
PRBool aToWindow)
{
if (!IsUniversalXPConnectCapable()) {
return NS_ERROR_DOM_SECURITY_ERR;
@ -281,8 +310,29 @@ nsDOMWindowUtils::SendMouseEvent(const nsAString& aType,
appPerDev);
event.ignoreRootScrollFrame = aIgnoreRootScrollFrame;
nsresult rv;
nsEventStatus status;
return widget->DispatchEvent(&event, status);
if (aToWindow) {
nsIPresShell* presShell = presContext->PresShell();
if (!presShell)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIViewObserver> vo = do_QueryInterface(presShell);
if (!vo)
return NS_ERROR_FAILURE;
nsIViewManager* viewManager = presShell->GetViewManager();
if (!viewManager)
return NS_ERROR_FAILURE;
nsIView* view = nsnull;
rv = viewManager->GetRootView(view);
if (NS_FAILED(rv) || !view)
return NS_ERROR_FAILURE;
status = nsEventStatus_eIgnore;
rv = vo->HandleEvent(view, &event, &status);
} else {
rv = widget->DispatchEvent(&event, status);
}
return rv;
}
NS_IMETHODIMP

View File

@ -62,4 +62,13 @@ protected:
nsIWidget* GetWidgetForElement(nsIDOMElement* aElement);
nsPresContext* GetPresContext();
NS_IMETHOD SendMouseEventCommon(const nsAString& aType,
float aX,
float aY,
PRInt32 aButton,
PRInt32 aClickCount,
PRInt32 aModifiers,
PRBool aIgnoreRootScrollFrame,
PRBool aToWindow);
};

View File

@ -53,7 +53,7 @@ interface nsIDOMEvent;
interface nsITransferable;
interface nsIQueryContentEventResult;
[scriptable, uuid(1e042706-0343-4cba-a549-6a83eefb1835)]
[scriptable, uuid(59e6f1be-ba0e-4102-9fe5-d5af8777742a)]
interface nsIDOMWindowUtils : nsISupports {
/**
@ -100,8 +100,7 @@ interface nsIDOMWindowUtils : nsISupports {
*/
unsigned long redraw([optional] in unsigned long aCount);
/** Synthesize a mouse event for a window. The event types supported
* are:
/** Synthesize a mouse event. The event types supported are:
* mousedown, mouseup, mousemove, mouseover, mouseout, contextmenu
*
* Events are sent in coordinates offset by aX and aY from the window.
@ -119,6 +118,10 @@ interface nsIDOMWindowUtils : nsISupports {
* Will throw a DOM security error if called without UniversalXPConnect
* privileges.
*
* The event is dispatched via the toplevel window, so it could go to any
* window under the toplevel window, in some cases it could never reach this
* window at all.
*
* @param aType event type
* @param aX x offset in CSS pixels
* @param aY y offset in CSS pixels
@ -136,6 +139,17 @@ interface nsIDOMWindowUtils : nsISupports {
in long aModifiers,
[optional] in boolean aIgnoreRootScrollFrame);
/** The same as sendMouseEvent but ensures that the event is dispatched to
* this DOM window or one of its children.
*/
void sendMouseEventToWindow(in AString aType,
in float aX,
in float aY,
in long aButton,
in long aClickCount,
in long aModifiers,
[optional] in boolean aIgnoreRootScrollFrame);
/** Synthesize a mouse scroll event for a window. The event types supported
* are:
* DOMMouseScroll