Bug 1446711 part 1. Get rid of nsIDOMMouseEvent::GetScreenX/Y. r=qdot

MozReview-Commit-ID: 9Y61WHTDVvF
This commit is contained in:
Boris Zbarsky
2018-03-20 00:16:05 -04:00
parent 29226b0510
commit 7d175e191e
9 changed files with 58 additions and 53 deletions

View File

@@ -30,9 +30,9 @@
#include "nsIDOMElement.h" #include "nsIDOMElement.h"
#include "Link.h" #include "Link.h"
#include "mozilla/dom/Element.h" #include "mozilla/dom/Element.h"
#include "mozilla/dom/MouseEvent.h"
#include "mozilla/dom/SVGTitleElement.h" #include "mozilla/dom/SVGTitleElement.h"
#include "nsIDOMEvent.h" #include "nsIDOMEvent.h"
#include "nsIDOMMouseEvent.h"
#include "nsIFormControl.h" #include "nsIFormControl.h"
#include "nsIImageLoadingContent.h" #include "nsIImageLoadingContent.h"
#include "nsIWebNavigation.h" #include "nsIWebNavigation.h"
@@ -1187,7 +1187,7 @@ ChromeTooltipListener::HandleEvent(nsIDOMEvent* aEvent)
nsresult nsresult
ChromeTooltipListener::MouseMove(nsIDOMEvent* aMouseEvent) ChromeTooltipListener::MouseMove(nsIDOMEvent* aMouseEvent)
{ {
nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aMouseEvent)); MouseEvent* mouseEvent = aMouseEvent->InternalDOMEvent()->AsMouseEvent();
if (!mouseEvent) { if (!mouseEvent) {
return NS_OK; return NS_OK;
} }
@@ -1212,8 +1212,8 @@ ChromeTooltipListener::MouseMove(nsIDOMEvent* aMouseEvent)
mMouseClientX = newMouseX; mMouseClientX = newMouseX;
mMouseClientY = newMouseY; mMouseClientY = newMouseY;
mouseEvent->GetScreenX(&mMouseScreenX); mMouseScreenX = mouseEvent->ScreenX(CallerType::System);
mouseEvent->GetScreenY(&mMouseScreenY); mMouseScreenY = mouseEvent->ScreenY(CallerType::System);
if (mTooltipTimer) { if (mTooltipTimer) {
mTooltipTimer->Cancel(); mTooltipTimer->Cancel();

View File

@@ -37,6 +37,7 @@ class EventMessageAutoOverride;
// autogenerated since it has some extra methods. // autogenerated since it has some extra methods.
class ExtendableEvent; class ExtendableEvent;
class KeyboardEvent; class KeyboardEvent;
class MouseEvent;
class TimeEvent; class TimeEvent;
class WantsPopupControlCheck; class WantsPopupControlCheck;
class XULCommandEvent; class XULCommandEvent;
@@ -139,6 +140,13 @@ public:
return nullptr; return nullptr;
} }
// MouseEvent has a non-autogeneratable initMouseEvent and other
// non-autogeneratable methods.
virtual MouseEvent* AsMouseEvent()
{
return nullptr;
}
// nsIDOMEvent Interface // nsIDOMEvent Interface
NS_DECL_NSIDOMEVENT NS_DECL_NSIDOMEVENT
@@ -401,11 +409,14 @@ private:
#define NS_FORWARD_TO_EVENT \ #define NS_FORWARD_TO_EVENT \
NS_FORWARD_NSIDOMEVENT(Event::) \ NS_FORWARD_NSIDOMEVENT(Event::) \
using Event::GetTarget; /* Because forwarding shadows. */ \
using Event::GetOriginalTarget; /* Because forwarding shadows. */ \
virtual void PreventDefault(JSContext* aCx, CallerType aCallerType) override { Event::PreventDefault(aCx, aCallerType); } virtual void PreventDefault(JSContext* aCx, CallerType aCallerType) override { Event::PreventDefault(aCx, aCallerType); }
#define NS_FORWARD_NSIDOMEVENT_NO_SERIALIZATION_NO_DUPLICATION(_to) \ #define NS_FORWARD_NSIDOMEVENT_NO_SERIALIZATION_NO_DUPLICATION(_to) \
NS_IMETHOD GetType(nsAString& aType) override { return _to GetType(aType); } \ NS_IMETHOD GetType(nsAString& aType) override { return _to GetType(aType); } \
NS_IMETHOD GetTarget(nsIDOMEventTarget** aTarget) override { return _to GetTarget(aTarget); } \ NS_IMETHOD GetTarget(nsIDOMEventTarget** aTarget) override { return _to GetTarget(aTarget); } \
using Event::GetTarget; /* Because forwarding shadows. */ \
NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget) override { return _to GetCurrentTarget(aCurrentTarget); } \ NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget) override { return _to GetCurrentTarget(aCurrentTarget); } \
NS_IMETHOD GetEventPhase(uint16_t* aEventPhase) override { return _to GetEventPhase(aEventPhase); } \ NS_IMETHOD GetEventPhase(uint16_t* aEventPhase) override { return _to GetEventPhase(aEventPhase); } \
NS_IMETHOD GetBubbles(bool* aBubbles) override { return _to GetBubbles(aBubbles); } \ NS_IMETHOD GetBubbles(bool* aBubbles) override { return _to GetBubbles(aBubbles); } \
@@ -418,6 +429,7 @@ private:
NS_IMETHOD GetDefaultPrevented(bool* aDefaultPrevented) override { return _to GetDefaultPrevented(aDefaultPrevented); } \ NS_IMETHOD GetDefaultPrevented(bool* aDefaultPrevented) override { return _to GetDefaultPrevented(aDefaultPrevented); } \
NS_IMETHOD StopImmediatePropagation(void) override { return _to StopImmediatePropagation(); } \ NS_IMETHOD StopImmediatePropagation(void) override { return _to StopImmediatePropagation(); } \
NS_IMETHOD GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget) override { return _to GetOriginalTarget(aOriginalTarget); } \ NS_IMETHOD GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget) override { return _to GetOriginalTarget(aOriginalTarget); } \
using Event::GetOriginalTarget; /* Because forwarding shadows. */ \
NS_IMETHOD GetExplicitOriginalTarget(nsIDOMEventTarget** aExplicitOriginalTarget) override { return _to GetExplicitOriginalTarget(aExplicitOriginalTarget); } \ NS_IMETHOD GetExplicitOriginalTarget(nsIDOMEventTarget** aExplicitOriginalTarget) override { return _to GetExplicitOriginalTarget(aExplicitOriginalTarget); } \
NS_IMETHOD GetIsTrusted(bool* aIsTrusted) override { return _to GetIsTrusted(aIsTrusted); } \ NS_IMETHOD GetIsTrusted(bool* aIsTrusted) override { return _to GetIsTrusted(aIsTrusted); } \
NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget) override { return _to SetTarget(aTarget); } \ NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget) override { return _to SetTarget(aTarget); } \

View File

@@ -332,14 +332,6 @@ MouseEvent::GetMozMovementY(int32_t* aMovementY)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
MouseEvent::GetScreenX(int32_t* aScreenX)
{
NS_ENSURE_ARG_POINTER(aScreenX);
*aScreenX = ScreenX(CallerType::System);
return NS_OK;
}
int32_t int32_t
MouseEvent::ScreenX(CallerType aCallerType) MouseEvent::ScreenX(CallerType aCallerType)
{ {
@@ -357,14 +349,6 @@ MouseEvent::ScreenX(CallerType aCallerType)
return Event::GetScreenCoords(mPresContext, mEvent, mEvent->mRefPoint).x; return Event::GetScreenCoords(mPresContext, mEvent, mEvent->mRefPoint).x;
} }
NS_IMETHODIMP
MouseEvent::GetScreenY(int32_t* aScreenY)
{
NS_ENSURE_ARG_POINTER(aScreenY);
*aScreenY = ScreenY(CallerType::System);
return NS_OK;
}
int32_t int32_t
MouseEvent::ScreenY(CallerType aCallerType) MouseEvent::ScreenY(CallerType aCallerType)
{ {

View File

@@ -37,6 +37,11 @@ public:
return MouseEventBinding::Wrap(aCx, this, aGivenProto); return MouseEventBinding::Wrap(aCx, this, aGivenProto);
} }
virtual MouseEvent* AsMouseEvent() override
{
return this;
}
// Web IDL binding methods // Web IDL binding methods
virtual uint32_t Which(CallerType aCallerType) override virtual uint32_t Which(CallerType aCallerType) override
{ {

View File

@@ -16,9 +16,6 @@
[builtinclass, uuid(5bdab8d8-7933-4c5c-b6d1-ab34481237f7)] [builtinclass, uuid(5bdab8d8-7933-4c5c-b6d1-ab34481237f7)]
interface nsIDOMMouseEvent : nsIDOMUIEvent interface nsIDOMMouseEvent : nsIDOMUIEvent
{ {
readonly attribute long screenX;
readonly attribute long screenY;
readonly attribute long mozMovementX; readonly attribute long mozMovementX;
readonly attribute long mozMovementY; readonly attribute long mozMovementY;

View File

@@ -29,6 +29,7 @@
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent() #include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
#include "mozilla/dom/EventTarget.h" #include "mozilla/dom/EventTarget.h"
#include "mozilla/dom/FragmentOrElement.h" #include "mozilla/dom/FragmentOrElement.h"
#include "mozilla/dom/MouseEvent.h"
// for event firing in context menus // for event firing in context menus
#include "nsPresContext.h" #include "nsPresContext.h"
@@ -100,16 +101,14 @@ nsXULPopupListener::HandleEvent(nsIDOMEvent* aEvent)
(eventType.EqualsLiteral("contextmenu") && mIsContext))) (eventType.EqualsLiteral("contextmenu") && mIsContext)))
return NS_OK; return NS_OK;
int16_t button; MouseEvent* mouseEvent = aEvent->InternalDOMEvent()->AsMouseEvent();
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aEvent);
if (!mouseEvent) { if (!mouseEvent) {
//non-ui event passed in. bad things. //non-ui event passed in. bad things.
return NS_OK; return NS_OK;
} }
// Get the node that was clicked on. // Get the node that was clicked on.
EventTarget* target = mouseEvent->AsEvent()->InternalDOMEvent()->GetTarget(); EventTarget* target = mouseEvent->GetTarget();
nsCOMPtr<nsIDOMNode> targetNode = do_QueryInterface(target); nsCOMPtr<nsIDOMNode> targetNode = do_QueryInterface(target);
if (!targetNode && mIsContext) { if (!targetNode && mIsContext) {
@@ -134,15 +133,14 @@ nsXULPopupListener::HandleEvent(nsIDOMEvent* aEvent)
} }
{ {
EventTarget* originalTarget = mouseEvent->AsEvent()->InternalDOMEvent()->GetOriginalTarget(); EventTarget* originalTarget = mouseEvent->GetOriginalTarget();
nsCOMPtr<nsIContent> content = do_QueryInterface(originalTarget); nsCOMPtr<nsIContent> content = do_QueryInterface(originalTarget);
if (content && EventStateManager::IsRemoteTarget(content)) { if (content && EventStateManager::IsRemoteTarget(content)) {
return NS_OK; return NS_OK;
} }
} }
bool preventDefault; bool preventDefault = mouseEvent->DefaultPrevented();
mouseEvent->AsEvent()->GetDefaultPrevented(&preventDefault);
if (preventDefault && targetNode && mIsContext) { if (preventDefault && targetNode && mIsContext) {
// Someone called preventDefault on a context menu. // Someone called preventDefault on a context menu.
// Let's make sure they are allowed to do so. // Let's make sure they are allowed to do so.
@@ -203,14 +201,14 @@ nsXULPopupListener::HandleEvent(nsIDOMEvent* aEvent)
} }
else { else {
// Only open popups when the left mouse button is down. // Only open popups when the left mouse button is down.
mouseEvent->GetButton(&button); if (mouseEvent->Button() != 0) {
if (button != 0)
return NS_OK; return NS_OK;
} }
}
// Open the popup. LaunchPopup will call StopPropagation and PreventDefault // Open the popup. LaunchPopup will call StopPropagation and PreventDefault
// in the right situations. // in the right situations.
LaunchPopup(aEvent, targetContent); LaunchPopup(mouseEvent, targetContent);
return NS_OK; return NS_OK;
} }
@@ -328,7 +326,7 @@ GetImmediateChild(nsIContent* aContent, nsAtom *aTag)
// the popup content in the document. // the popup content in the document.
// //
nsresult nsresult
nsXULPopupListener::LaunchPopup(nsIDOMEvent* aEvent, nsIContent* aTargetContent) nsXULPopupListener::LaunchPopup(MouseEvent* aEvent, nsIContent* aTargetContent)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
@@ -416,10 +414,8 @@ nsXULPopupListener::LaunchPopup(nsIDOMEvent* aEvent, nsIContent* aTargetContent)
false, true, false, aEvent); false, true, false, aEvent);
} }
else { else {
int32_t xPos = 0, yPos = 0; int32_t xPos = aEvent->ScreenX(CallerType::System);
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aEvent); int32_t yPos = aEvent->ScreenY(CallerType::System);
mouseEvent->GetScreenX(&xPos);
mouseEvent->GetScreenY(&yPos);
pm->ShowPopupAtScreen(mPopupContent, xPos, yPos, mIsContext, aEvent); pm->ShowPopupAtScreen(mPopupContent, xPos, yPos, mIsContext, aEvent);
} }

View File

@@ -18,6 +18,12 @@
#include "nsIDOMEventListener.h" #include "nsIDOMEventListener.h"
#include "nsCycleCollectionParticipant.h" #include "nsCycleCollectionParticipant.h"
namespace mozilla {
namespace dom {
class MouseEvent;
} // namespace dom
} // namespace mozilla
class nsXULPopupListener : public nsIDOMEventListener class nsXULPopupListener : public nsIDOMEventListener
{ {
public: public:
@@ -37,7 +43,8 @@ protected:
// open the popup. aEvent is the event that triggered the popup such as // open the popup. aEvent is the event that triggered the popup such as
// a mouse click and aTargetContent is the target of this event. // a mouse click and aTargetContent is the target of this event.
virtual nsresult LaunchPopup(nsIDOMEvent* aEvent, nsIContent* aTargetContent); virtual nsresult LaunchPopup(mozilla::dom::MouseEvent* aEvent,
nsIContent* aTargetContent);
// close the popup when the listener goes away // close the popup when the listener goes away
virtual void ClosePopup(); virtual void ClosePopup();

View File

@@ -6,7 +6,6 @@
#include "nsXULTooltipListener.h" #include "nsXULTooltipListener.h"
#include "nsIDOMMouseEvent.h"
#include "nsXULElement.h" #include "nsXULElement.h"
#include "nsIDocument.h" #include "nsIDocument.h"
#include "nsGkAtoms.h" #include "nsGkAtoms.h"
@@ -30,6 +29,7 @@
#include "mozilla/dom/Element.h" #include "mozilla/dom/Element.h"
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent() #include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
#include "mozilla/dom/BoxObject.h" #include "mozilla/dom/BoxObject.h"
#include "mozilla/dom/MouseEvent.h"
#include "mozilla/TextEvents.h" #include "mozilla/TextEvents.h"
using namespace mozilla; using namespace mozilla;
@@ -132,12 +132,12 @@ nsXULTooltipListener::MouseMove(nsIDOMEvent* aEvent)
// timer callback. On win32, we'll get a MouseMove event even when a popup goes away -- // timer callback. On win32, we'll get a MouseMove event even when a popup goes away --
// even when the mouse doesn't change position! To get around this, we make sure the // even when the mouse doesn't change position! To get around this, we make sure the
// mouse has really moved before proceeding. // mouse has really moved before proceeding.
nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aEvent)); MouseEvent* mouseEvent = aEvent->InternalDOMEvent()->AsMouseEvent();
if (!mouseEvent) if (!mouseEvent) {
return; return;
int32_t newMouseX, newMouseY; }
mouseEvent->GetScreenX(&newMouseX); int32_t newMouseX = mouseEvent->ScreenX(CallerType::System);
mouseEvent->GetScreenY(&newMouseY); int32_t newMouseY = mouseEvent->ScreenY(CallerType::System);
// filter out false win32 MouseMove event // filter out false win32 MouseMove event
if (mMouseScreenX == newMouseX && mMouseScreenY == newMouseY) if (mMouseScreenX == newMouseX && mMouseScreenY == newMouseY)
@@ -330,7 +330,7 @@ nsXULTooltipListener::RemoveTooltipSupport(nsIContent* aNode)
#ifdef MOZ_XUL #ifdef MOZ_XUL
void void
nsXULTooltipListener::CheckTreeBodyMove(nsIDOMMouseEvent* aMouseEvent) nsXULTooltipListener::CheckTreeBodyMove(MouseEvent* aMouseEvent)
{ {
nsCOMPtr<nsIContent> sourceNode = do_QueryReferent(mSourceNode); nsCOMPtr<nsIContent> sourceNode = do_QueryReferent(mSourceNode);
if (!sourceNode) if (!sourceNode)
@@ -347,9 +347,8 @@ nsXULTooltipListener::CheckTreeBodyMove(nsIDOMMouseEvent* aMouseEvent)
nsCOMPtr<nsITreeBoxObject> obx; nsCOMPtr<nsITreeBoxObject> obx;
GetSourceTreeBoxObject(getter_AddRefs(obx)); GetSourceTreeBoxObject(getter_AddRefs(obx));
if (bx && obx) { if (bx && obx) {
int32_t x, y; int32_t x = aMouseEvent->ScreenX(CallerType::System);
aMouseEvent->GetScreenX(&x); int32_t y = aMouseEvent->ScreenY(CallerType::System);
aMouseEvent->GetScreenY(&y);
int32_t row; int32_t row;
nsCOMPtr<nsITreeColumn> col; nsCOMPtr<nsITreeColumn> col;

View File

@@ -8,7 +8,6 @@
#define nsXULTooltipListener_h__ #define nsXULTooltipListener_h__
#include "nsIDOMEventListener.h" #include "nsIDOMEventListener.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMElement.h" #include "nsIDOMElement.h"
#include "nsITimer.h" #include "nsITimer.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
@@ -22,6 +21,12 @@
class nsIContent; class nsIContent;
namespace mozilla {
namespace dom {
class MouseEvent;
} // namespace dom
} // namespace mozilla
class nsXULTooltipListener final : public nsIDOMEventListener class nsXULTooltipListener final : public nsIDOMEventListener
{ {
public: public:
@@ -50,7 +55,7 @@ protected:
void KillTooltipTimer(); void KillTooltipTimer();
#ifdef MOZ_XUL #ifdef MOZ_XUL
void CheckTreeBodyMove(nsIDOMMouseEvent* aMouseEvent); void CheckTreeBodyMove(mozilla::dom::MouseEvent* aMouseEvent);
nsresult GetSourceTreeBoxObject(nsITreeBoxObject** aBoxObject); nsresult GetSourceTreeBoxObject(nsITreeBoxObject** aBoxObject);
#endif #endif