From aeba4210a7151a3f3a2c96b490be0d53099dba76 Mon Sep 17 00:00:00 2001 From: "Olli.Pettay@helsinki.fi" Date: Mon, 12 Nov 2007 04:53:06 -0800 Subject: [PATCH] Bug 402089, nsDOMUIEvent should cache coordinates when DuplicatePrivateData is called, r+sr=jst, a=mtschrep --- content/events/src/nsDOMUIEvent.cpp | 34 +++++++++---- content/events/src/nsDOMUIEvent.h | 6 +++ content/events/test/Makefile.in | 1 + content/events/test/test_bug402089.html | 65 +++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 10 deletions(-) create mode 100644 content/events/test/test_bug402089.html diff --git a/content/events/src/nsDOMUIEvent.cpp b/content/events/src/nsDOMUIEvent.cpp index 1c9284d2cf5..b280257b7e2 100644 --- a/content/events/src/nsDOMUIEvent.cpp +++ b/content/events/src/nsDOMUIEvent.cpp @@ -55,7 +55,7 @@ nsDOMUIEvent::nsDOMUIEvent(nsPresContext* aPresContext, nsGUIEvent* aEvent) : nsDOMEvent(aPresContext, aEvent ? static_cast(aEvent) : static_cast(new nsUIEvent(PR_FALSE, 0, 0))) - , mClientPoint(0,0) + , mClientPoint(0, 0), mLayerPoint(0, 0), mPagePoint(0, 0) { if (aEvent) { mEventIsInternal = PR_FALSE; @@ -148,12 +148,10 @@ nsPoint nsDOMUIEvent::GetClientPoint() { mEvent->eventStructType != NS_POPUP_EVENT && mEvent->eventStructType != NS_MOUSE_SCROLL_EVENT && !NS_IS_DRAG_EVENT(mEvent)) || - !mPresContext) { - return nsPoint(0, 0); - } - - if (!((nsGUIEvent*)mEvent)->widget) + !mPresContext || + !((nsGUIEvent*)mEvent)->widget) { return mClientPoint; + } nsPoint pt(0, 0); nsIFrame* rootFrame = mPresContext->PresShell()->GetRootFrame(); @@ -209,7 +207,7 @@ nsDOMUIEvent::GetPagePoint() nsPresContext::AppUnitsToIntCSSPixels(pt.y)); } - return GetClientPoint(); + return mPagePoint; } @@ -307,14 +305,15 @@ nsPoint nsDOMUIEvent::GetLayerPoint() { if (!mEvent || (mEvent->eventStructType != NS_MOUSE_EVENT && mEvent->eventStructType != NS_MOUSE_SCROLL_EVENT) || - !mPresContext) { - return nsPoint(0,0); + !mPresContext || + mEventIsInternal) { + return mLayerPoint; } // XXX I'm not really sure this is correct; it's my best shot, though nsIFrame* targetFrame; mPresContext->EventStateManager()->GetEventTarget(&targetFrame); if (!targetFrame) - return nsPoint(0,0); + return mLayerPoint; nsIFrame* layer = nsLayoutUtils::GetClosestLayer(targetFrame); nsPoint pt(nsLayoutUtils::GetEventCoordinatesRelativeTo(mEvent, layer)); pt.x = nsPresContext::AppUnitsToIntCSSPixels(pt.x); @@ -401,6 +400,21 @@ nsDOMUIEvent::GetQueryCaretRectReply(nsQueryCaretRectEventReply** aReply) return NS_ERROR_FAILURE; } +NS_METHOD +nsDOMUIEvent::DuplicatePrivateData() +{ + mClientPoint = GetClientPoint(); + mLayerPoint = GetLayerPoint(); + mPagePoint = GetPagePoint(); + // GetScreenPoint converts mEvent->refPoint to right coordinates. + nsPoint screenPoint = GetScreenPoint(); + nsresult rv = nsDOMEvent::DuplicatePrivateData(); + if (NS_SUCCEEDED(rv)) { + mEvent->refPoint = screenPoint; + } + return rv; +} + nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, nsGUIEvent *aEvent) diff --git a/content/events/src/nsDOMUIEvent.h b/content/events/src/nsDOMUIEvent.h index 88f13b50adf..1e9a24779d7 100644 --- a/content/events/src/nsDOMUIEvent.h +++ b/content/events/src/nsDOMUIEvent.h @@ -61,6 +61,9 @@ public: // nsIDOMNSUIEvent Interface NS_DECL_NSIDOMNSUIEVENT + + // nsIPrivateDOMEvent interface + NS_IMETHOD DuplicatePrivateData(); // nsIPrivateCompositionEvent interface NS_IMETHOD GetCompositionReply(nsTextEventReply** aReply); @@ -82,6 +85,9 @@ protected: nsCOMPtr mView; PRInt32 mDetail; nsPoint mClientPoint; + // Screenpoint is mEvent->refPoint. + nsPoint mLayerPoint; + nsPoint mPagePoint; }; #define NS_FORWARD_TO_NSDOMUIEVENT \ diff --git a/content/events/test/Makefile.in b/content/events/test/Makefile.in index 2121d259a60..fcc3faf1741 100644 --- a/content/events/test/Makefile.in +++ b/content/events/test/Makefile.in @@ -53,6 +53,7 @@ _TEST_FILES = \ test_bug367781.html \ test_bug379120.html \ test_bug391568.xhtml \ + test_bug402089.html \ $(NULL) libs:: $(_TEST_FILES) diff --git a/content/events/test/test_bug402089.html b/content/events/test/test_bug402089.html new file mode 100644 index 00000000000..5404f8c1b5e --- /dev/null +++ b/content/events/test/test_bug402089.html @@ -0,0 +1,65 @@ + + + + + Test for Bug 402089 + + + + + + +Mozilla Bug 402089 +

+ +
+
+
+ + +