diff --git a/content/events/public/nsIPrivateDOMEvent.h b/content/events/public/nsIPrivateDOMEvent.h index 1cd82b81f9cd..f5c37828e4ce 100644 --- a/content/events/public/nsIPrivateDOMEvent.h +++ b/content/events/public/nsIPrivateDOMEvent.h @@ -53,6 +53,7 @@ class nsIDOMEventTarget; class nsIDOMEvent; class nsEvent; class nsCommandEvent; +class nsRegion; class nsIPrivateDOMEvent : public nsISupports { @@ -110,7 +111,11 @@ NS_NewDOMMessageEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresCont nsresult NS_NewDOMProgressEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, class nsEvent* aEvent); nsresult -NS_NewDOMNotifyPaintEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, class nsNotifyPaintEvent* aEvent); +NS_NewDOMNotifyPaintEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, + nsEvent* aEvent, + PRUint32 aEventType = 0, + const nsRegion* aSameOriginRegion = nsnull, + const nsRegion* aCrossDocRegion = nsnull); nsresult NS_NewDOMSimpleGestureEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, class nsSimpleGestureEvent* aEvent); #endif // nsIPrivateDOMEvent_h__ diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp index 06b788c659b5..5445d4090339 100644 --- a/content/events/src/nsDOMEvent.cpp +++ b/content/events/src/nsDOMEvent.cpp @@ -532,6 +532,8 @@ nsDOMEvent::SetEventType(const nsAString& aEventTypeArg) else if (atom == nsGkAtoms::oncompositionend) mEvent->message = NS_COMPOSITION_END; } else if (mEvent->eventStructType == NS_EVENT) { + if (atom == nsGkAtoms::onMozAfterPaint) + mEvent->message = NS_AFTERPAINT; if (atom == nsGkAtoms::onfocus) mEvent->message = NS_FOCUS_CONTENT; else if (atom == nsGkAtoms::onblur) @@ -665,10 +667,6 @@ nsDOMEvent::SetEventType(const nsAString& aEventTypeArg) mEvent->message = NS_MEDIA_ERROR; } #endif // MOZ_MEDIA - else if (mEvent->eventStructType == NS_NOTIFYPAINT_EVENT) { - if (atom == nsGkAtoms::onMozAfterPaint) - mEvent->message = NS_AFTERPAINT; - } else if (mEvent->eventStructType == NS_SIMPLE_GESTURE_EVENT) { if (atom == nsGkAtoms::onMozSwipeGesture) mEvent->message = NS_SIMPLE_GESTURE_SWIPE; @@ -990,14 +988,6 @@ NS_METHOD nsDOMEvent::DuplicatePrivateData() static_cast(mEvent)->sourceEvent; break; } - case NS_NOTIFYPAINT_EVENT: - { - nsNotifyPaintEvent* event = static_cast(mEvent); - newEvent = - new nsNotifyPaintEvent(PR_FALSE, msg, - event->sameDocRegion, event->crossDocRegion); - break; - } case NS_SIMPLE_GESTURE_EVENT: { nsSimpleGestureEvent* oldSimpleGestureEvent = static_cast(mEvent); diff --git a/content/events/src/nsDOMNotifyPaintEvent.cpp b/content/events/src/nsDOMNotifyPaintEvent.cpp index 907a6b9c77c4..cfa30af8d3dc 100644 --- a/content/events/src/nsDOMNotifyPaintEvent.cpp +++ b/content/events/src/nsDOMNotifyPaintEvent.cpp @@ -41,27 +41,20 @@ #include "nsClientRect.h" nsDOMNotifyPaintEvent::nsDOMNotifyPaintEvent(nsPresContext* aPresContext, - nsNotifyPaintEvent* aEvent) - : nsDOMEvent(aPresContext, aEvent ? aEvent : - new nsNotifyPaintEvent(PR_FALSE, 0, nsRegion(), nsRegion())) -{ - if (aEvent) { - mEventIsInternal = PR_FALSE; - } - else - { - mEventIsInternal = PR_TRUE; - mEvent->time = PR_Now(); - } -} - -nsDOMNotifyPaintEvent::~nsDOMNotifyPaintEvent() + nsEvent* aEvent, + PRUint32 aEventType, + const nsRegion* aSameDocRegion, + const nsRegion* aCrossDocRegion) +: nsDOMEvent(aPresContext, aEvent) { - if (mEventIsInternal) { - if (mEvent->eventStructType == NS_NOTIFYPAINT_EVENT) { - delete static_cast(mEvent); - mEvent = nsnull; - } + if (mEvent) { + mEvent->message = aEventType; + } + if (aSameDocRegion) { + mSameDocRegion = *aSameDocRegion; + } + if (aCrossDocRegion) { + mCrossDocRegion = *aCrossDocRegion; } } @@ -76,13 +69,11 @@ NS_IMPL_RELEASE_INHERITED(nsDOMNotifyPaintEvent, nsDOMEvent) nsRegion nsDOMNotifyPaintEvent::GetRegion() { - nsNotifyPaintEvent* event = static_cast(mEvent); - nsRegion r; if (nsContentUtils::IsCallerTrustedForRead()) { - r.Or(event->sameDocRegion, event->crossDocRegion); + r.Or(mSameDocRegion, mCrossDocRegion); } else { - r = event->sameDocRegion; + r = mSameDocRegion; } return r; } @@ -127,10 +118,14 @@ nsDOMNotifyPaintEvent::GetClientRects(nsIDOMClientRectList** aResult) nsresult NS_NewDOMNotifyPaintEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, - nsNotifyPaintEvent *aEvent) + nsEvent *aEvent, + PRUint32 aEventType, + const nsRegion* aSameOriginRegion, + const nsRegion* aCrossDocRegion) { nsDOMNotifyPaintEvent* it = - new nsDOMNotifyPaintEvent(aPresContext, aEvent); + new nsDOMNotifyPaintEvent(aPresContext, aEvent, aEventType, + aSameOriginRegion, aCrossDocRegion); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } diff --git a/content/events/src/nsDOMNotifyPaintEvent.h b/content/events/src/nsDOMNotifyPaintEvent.h index 6d7bc7973395..44b5bf34790a 100644 --- a/content/events/src/nsDOMNotifyPaintEvent.h +++ b/content/events/src/nsDOMNotifyPaintEvent.h @@ -46,9 +46,11 @@ class nsDOMNotifyPaintEvent : public nsIDOMNotifyPaintEvent, public nsDOMEvent { public: - nsDOMNotifyPaintEvent(nsPresContext* aPresContext, - nsNotifyPaintEvent* aEvent); - virtual ~nsDOMNotifyPaintEvent(); + nsDOMNotifyPaintEvent(nsPresContext* aPresContext, + nsEvent* aEvent, + PRUint32 aEventType, + const nsRegion* aSameOriginRegion, + const nsRegion* aCrossDocRegion); NS_DECL_ISUPPORTS_INHERITED @@ -59,6 +61,9 @@ public: private: nsRegion GetRegion(); + + nsRegion mSameDocRegion; + nsRegion mCrossDocRegion; }; #endif // nsDOMNotifyPaintEvent_h_ diff --git a/content/events/src/nsEventDispatcher.cpp b/content/events/src/nsEventDispatcher.cpp index 813865320fe3..ab8a71bd5e55 100644 --- a/content/events/src/nsEventDispatcher.cpp +++ b/content/events/src/nsEventDispatcher.cpp @@ -668,10 +668,6 @@ nsEventDispatcher::CreateEvent(nsPresContext* aPresContext, case NS_COMMAND_EVENT: return NS_NewDOMCommandEvent(aDOMEvent, aPresContext, static_cast(aEvent)); - case NS_NOTIFYPAINT_EVENT: - return NS_NewDOMNotifyPaintEvent(aDOMEvent, aPresContext, - static_cast - (aEvent)); case NS_SIMPLE_GESTURE_EVENT: return NS_NewDOMSimpleGestureEvent(aDOMEvent, aPresContext, static_cast(aEvent)); diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 537306346bf8..2814c97913ee 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -91,6 +91,8 @@ #include "nsStyleStructInlines.h" #include "nsIAppShell.h" #include "prenv.h" +#include "nsIPrivateDOMEvent.h" +#include "nsIDOMEventTarget.h" #ifdef MOZ_SMIL #include "nsSMILAnimationController.h" @@ -1932,26 +1934,31 @@ nsPresContext::UserFontSetUpdated() void nsPresContext::FireDOMPaintEvent() { - nsCOMPtr ourWindow = mDocument->GetWindow(); + nsPIDOMWindow* ourWindow = mDocument->GetWindow(); if (!ourWindow) return; - nsISupports* eventTarget = ourWindow; + nsCOMPtr dispatchTarget = do_QueryInterface(ourWindow); + nsCOMPtr eventTarget = dispatchTarget; if (mSameDocDirtyRegion.IsEmpty() && !IsChrome()) { // Don't tell the window about this event, it should not know that // something happened in a subdocument. Tell only the chrome event handler. // (Events sent to the window get propagated to the chrome event handler // automatically.) - eventTarget = ourWindow->GetChromeEventHandler(); - if (!eventTarget) { + dispatchTarget = do_QueryInterface(ourWindow->GetChromeEventHandler()); + if (!dispatchTarget) { return; } } // Events sent to the window get propagated to the chrome event handler // automatically. + nsCOMPtr event; + NS_NewDOMNotifyPaintEvent(getter_AddRefs(event), this, nsnull, + NS_AFTERPAINT, + &mSameDocDirtyRegion, &mCrossDocDirtyRegion); + nsCOMPtr pEvent = do_QueryInterface(event); + if (!pEvent) return; - nsNotifyPaintEvent event(PR_TRUE, NS_AFTERPAINT, mSameDocDirtyRegion, - mCrossDocDirtyRegion); // Empty our regions now in case dispatching the event causes more damage // (hopefully it won't, or we're likely to get an infinite loop! At least // it won't be blocking app execution though). @@ -1960,8 +1967,9 @@ nsPresContext::FireDOMPaintEvent() // Even if we're not telling the window about the event (so eventTarget is // the chrome event handler, not the window), the window is still // logically the event target. - event.target = do_QueryInterface(ourWindow); - nsEventDispatcher::Dispatch(eventTarget, this, &event); + pEvent->SetTarget(eventTarget); + pEvent->SetTrusted(PR_TRUE); + nsEventDispatcher::DispatchDOMEvent(dispatchTarget, nsnull, event, this, nsnull); } static PRBool MayHavePaintEventListener(nsPIDOMWindow* aInnerWindow) diff --git a/widget/public/nsGUIEvent.h b/widget/public/nsGUIEvent.h index 4123baa07a59..f1c7d5906b6b 100644 --- a/widget/public/nsGUIEvent.h +++ b/widget/public/nsGUIEvent.h @@ -1220,23 +1220,6 @@ public: PRInt32 detail; }; -/** - * NotifyPaint event - */ -class nsNotifyPaintEvent : public nsEvent -{ -public: - nsNotifyPaintEvent(PRBool isTrusted, PRUint32 msg, - const nsRegion& aSameDocRegion, const nsRegion& aCrossDocRegion) - : nsEvent(isTrusted, msg, NS_NOTIFYPAINT_EVENT), - sameDocRegion(aSameDocRegion), crossDocRegion(aCrossDocRegion) - { - } - - nsRegion sameDocRegion; - nsRegion crossDocRegion; -}; - /** * PageTransition event */