Bug 976963 - Resolve issues with tests on B2G system. r=smaug

This commit is contained in:
Lebedev Maksim 2014-07-09 01:03:00 -04:00
parent eee9073572
commit c7ee285c63
4 changed files with 174 additions and 54 deletions

View File

@ -688,6 +688,23 @@ GetButtonsFlagForButton(int32_t aButton)
}
}
nsView*
nsDOMWindowUtils::GetViewToDispatchEvent(nsPresContext* presContext, nsIPresShell** presShell)
{
if (presContext && presShell) {
*presShell = presContext->PresShell();
if (*presShell) {
NS_ADDREF(*presShell);
if (nsViewManager* viewManager = (*presShell)->GetViewManager()) {
if (nsView* view = viewManager->GetRootView()) {
return view;
}
}
}
}
return nullptr;
}
NS_IMETHODIMP
nsDOMWindowUtils::SendMouseEventCommon(const nsAString& aType,
float aX,
@ -756,44 +773,42 @@ nsDOMWindowUtils::SendMouseEventCommon(const nsAString& aType,
nsEventStatus status;
if (aToWindow) {
nsCOMPtr<nsIPresShell> presShell = presContext->PresShell();
if (!presShell)
nsCOMPtr<nsIPresShell> presShell;
nsView* view = GetViewToDispatchEvent(presContext, getter_AddRefs(presShell));
if (!presShell || !view) {
return NS_ERROR_FAILURE;
nsViewManager* viewManager = presShell->GetViewManager();
if (!viewManager)
return NS_ERROR_FAILURE;
nsView* view = viewManager->GetRootView();
if (!view)
return NS_ERROR_FAILURE;
}
status = nsEventStatus_eIgnore;
return presShell->HandleEvent(view->GetFrame(), &event, false, &status);
}
nsresult rv = widget->DispatchEvent(&event, status);
*aPreventDefault = (status == nsEventStatus_eConsumeNoDefault);
if (aPreventDefault) {
*aPreventDefault = (status == nsEventStatus_eConsumeNoDefault);
}
return rv;
}
NS_IMETHODIMP
nsDOMWindowUtils::SendPointerEvent(const nsAString& aType,
float aX,
float aY,
int32_t aButton,
int32_t aClickCount,
int32_t aModifiers,
bool aIgnoreRootScrollFrame,
float aPressure,
unsigned short aInputSourceArg,
int32_t aPointerId,
int32_t aWidth,
int32_t aHeight,
int32_t tiltX,
int32_t tiltY,
bool aIsPrimary,
bool aIsSynthesized,
uint8_t aOptionalArgCount,
bool* aPreventDefault)
nsDOMWindowUtils::SendPointerEventCommon(const nsAString& aType,
float aX,
float aY,
int32_t aButton,
int32_t aClickCount,
int32_t aModifiers,
bool aIgnoreRootScrollFrame,
float aPressure,
unsigned short aInputSourceArg,
int32_t aPointerId,
int32_t aWidth,
int32_t aHeight,
int32_t aTiltX,
int32_t aTiltY,
bool aIsPrimary,
bool aIsSynthesized,
uint8_t aOptionalArgCount,
bool aToWindow,
bool* aPreventDefault)
{
MOZ_RELEASE_ASSERT(nsContentUtils::IsCallerChrome());
@ -833,8 +848,8 @@ nsDOMWindowUtils::SendPointerEvent(const nsAString& aType,
event.pointerId = aPointerId;
event.width = aWidth;
event.height = aHeight;
event.tiltX = tiltX;
event.tiltY = tiltY;
event.tiltX = aTiltX;
event.tiltY = aTiltY;
event.isPrimary = aIsPrimary;
event.clickCount = aClickCount;
event.time = PR_IntervalNow();
@ -849,12 +864,84 @@ nsDOMWindowUtils::SendPointerEvent(const nsAString& aType,
event.ignoreRootScrollFrame = aIgnoreRootScrollFrame;
nsEventStatus status;
if (aToWindow) {
nsCOMPtr<nsIPresShell> presShell;
nsView* view = GetViewToDispatchEvent(presContext, getter_AddRefs(presShell));
if (!presShell || !view) {
return NS_ERROR_FAILURE;
}
status = nsEventStatus_eIgnore;
return presShell->HandleEvent(view->GetFrame(), &event, false, &status);
}
nsresult rv = widget->DispatchEvent(&event, status);
*aPreventDefault = (status == nsEventStatus_eConsumeNoDefault);
if (aPreventDefault) {
*aPreventDefault = (status == nsEventStatus_eConsumeNoDefault);
}
return rv;
}
NS_IMETHODIMP
nsDOMWindowUtils::SendPointerEvent(const nsAString& aType,
float aX,
float aY,
int32_t aButton,
int32_t aClickCount,
int32_t aModifiers,
bool aIgnoreRootScrollFrame,
float aPressure,
unsigned short aInputSourceArg,
int32_t aPointerId,
int32_t aWidth,
int32_t aHeight,
int32_t aTiltX,
int32_t aTiltY,
bool aIsPrimary,
bool aIsSynthesized,
uint8_t aOptionalArgCount,
bool* aPreventDefault)
{
PROFILER_LABEL("nsDOMWindowUtils", "SendPointerEvent",
js::ProfileEntry::Category::EVENTS);
return SendPointerEventCommon(aType, aX, aY, aButton, aClickCount,
aModifiers, aIgnoreRootScrollFrame,
aPressure, aInputSourceArg, aPointerId,
aWidth, aHeight, aTiltX, aTiltY,
aIsPrimary, aIsSynthesized,
aOptionalArgCount, false, aPreventDefault);
}
NS_IMETHODIMP
nsDOMWindowUtils::SendPointerEventToWindow(const nsAString& aType,
float aX,
float aY,
int32_t aButton,
int32_t aClickCount,
int32_t aModifiers,
bool aIgnoreRootScrollFrame,
float aPressure,
unsigned short aInputSourceArg,
int32_t aPointerId,
int32_t aWidth,
int32_t aHeight,
int32_t aTiltX,
int32_t aTiltY,
bool aIsPrimary,
bool aIsSynthesized,
uint8_t aOptionalArgCount)
{
PROFILER_LABEL("nsDOMWindowUtils", "SendPointerEventToWindow",
js::ProfileEntry::Category::EVENTS);
return SendPointerEventCommon(aType, aX, aY, aButton, aClickCount,
aModifiers, aIgnoreRootScrollFrame,
aPressure, aInputSourceArg, aPointerId,
aWidth, aHeight, aTiltX, aTiltY,
aIsPrimary, aIsSynthesized,
aOptionalArgCount, true, nullptr);
}
NS_IMETHODIMP
nsDOMWindowUtils::SendWheelEvent(float aX,
float aY,
@ -1042,21 +1129,11 @@ nsDOMWindowUtils::SendTouchEventCommon(const nsAString& aType,
nsEventStatus status;
if (aToWindow) {
nsCOMPtr<nsIPresShell> presShell = presContext->PresShell();
if (!presShell) {
nsCOMPtr<nsIPresShell> presShell;
nsView* view = GetViewToDispatchEvent(presContext, getter_AddRefs(presShell));
if (!presShell || !view) {
return NS_ERROR_FAILURE;
}
nsViewManager* viewManager = presShell->GetViewManager();
if (!viewManager) {
return NS_ERROR_FAILURE;
}
nsView* view = viewManager->GetRootView();
if (!view) {
return NS_ERROR_FAILURE;
}
status = nsEventStatus_eIgnore;
*aPreventDefault = (status == nsEventStatus_eConsumeNoDefault);
return presShell->HandleEvent(view->GetFrame(), &event, false, &status);

View File

@ -17,6 +17,7 @@ class nsIPresShell;
class nsIWidget;
class nsPresContext;
class nsIDocument;
class nsView;
struct nsPoint;
namespace mozilla {
@ -78,6 +79,8 @@ protected:
nsIDocument* GetDocument();
mozilla::layers::LayerTransactionChild* GetLayerTransaction();
nsView* GetViewToDispatchEvent(nsPresContext* presContext, nsIPresShell** presShell);
NS_IMETHOD SendMouseEventCommon(const nsAString& aType,
float aX,
float aY,
@ -91,6 +94,26 @@ protected:
bool *aPreventDefault,
bool aIsSynthesized);
NS_IMETHOD SendPointerEventCommon(const nsAString& aType,
float aX,
float aY,
int32_t aButton,
int32_t aClickCount,
int32_t aModifiers,
bool aIgnoreRootScrollFrame,
float aPressure,
unsigned short aInputSourceArg,
int32_t aPointerId,
int32_t aWidth,
int32_t aHeight,
int32_t aTiltX,
int32_t aTiltY,
bool aIsPrimary,
bool aIsSynthesized,
uint8_t aOptionalArgCount,
bool aToWindow,
bool* aPreventDefault);
NS_IMETHOD SendTouchEventCommon(const nsAString& aType,
uint32_t* aIdentifiers,
int32_t* aXs,
@ -105,7 +128,6 @@ protected:
bool aToWindow,
bool* aPreventDefault);
static mozilla::Modifiers GetWidgetModifiers(int32_t aModifiers);
};

View File

@ -51,7 +51,7 @@ interface nsITranslationNodeList;
interface nsIJSRAIIHelper;
interface nsIContentPermissionRequest;
[scriptable, uuid(0ef9e8bb-b934-4f6b-ae05-e98774d8d3d3)]
[scriptable, uuid(11911980-607c-4efd-aacc-de3b9005c058)]
interface nsIDOMWindowUtils : nsISupports {
/**
@ -371,8 +371,8 @@ interface nsIDOMWindowUtils : nsISupports {
[optional] in long aPointerId,
[optional] in long aWidth,
[optional] in long aHeight,
[optional] in long tiltX,
[optional] in long tiltY,
[optional] in long aTiltX,
[optional] in long aTiltY,
[optional] in boolean aIsPrimary,
[optional] in boolean aIsSynthesized);
@ -429,6 +429,27 @@ interface nsIDOMWindowUtils : nsISupports {
[optional] in unsigned short aInputSourceArg,
[optional] in boolean aIsSynthesized);
/** The same as sendPointerEvent but ensures that the event
* is dispatched to this DOM window or one of its children.
*/
[optional_argc]
void sendPointerEventToWindow(in AString aType,
in float aX,
in float aY,
in long aButton,
in long aClickCount,
in long aModifiers,
[optional] in boolean aIgnoreRootScrollFrame,
[optional] in float aPressure,
[optional] in unsigned short aInputSourceArg,
[optional] in long aPointerId,
[optional] in long aWidth,
[optional] in long aHeight,
[optional] in long aTiltX,
[optional] in long aTiltY,
[optional] in boolean aIsPrimary,
[optional] in boolean aIsSynthesized);
/** The same as sendTouchEvent but ensures that the event is dispatched to
* this DOM window or one of its children.
*/

View File

@ -307,14 +307,14 @@ function synthesizePointerAtPoint(left, top, aEvent, aWindow)
var synthesized = ("isSynthesized" in aEvent) ? aEvent.isSynthesized : true;
if (("type" in aEvent) && aEvent.type) {
defaultPrevented = utils.sendPointerEvent(aEvent.type, left, top, button,
clickCount, modifiers, false,
pressure, inputSource,
synthesized);
defaultPrevented = utils.sendPointerEventToWindow(aEvent.type, left, top, button,
clickCount, modifiers, false,
pressure, inputSource,
synthesized);
}
else {
utils.sendPointerEvent("pointerdown", left, top, button, clickCount, modifiers, false, pressure, inputSource);
utils.sendPointerEvent("pointerup", left, top, button, clickCount, modifiers, false, pressure, inputSource);
utils.sendPointerEventToWindow("pointerdown", left, top, button, clickCount, modifiers, false, pressure, inputSource);
utils.sendPointerEventToWindow("pointerup", left, top, button, clickCount, modifiers, false, pressure, inputSource);
}
}