From 9d5daf95e9b56df12e64cb513c768facd36d3b77 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sun, 17 Mar 2013 08:55:17 +0100 Subject: [PATCH] Bug 851134 - Part a: Implement the primitive getters in the WebIDL API for Event directly instead of calling the XPIDL implementations; r=smaug --- content/events/src/nsDOMEvent.cpp | 57 ++++++++++++++++--------------- content/events/src/nsDOMEvent.h | 45 ++++++++---------------- 2 files changed, 43 insertions(+), 59 deletions(-) diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp index 1d3c8d43c589..b3a623fcfe0d 100644 --- a/content/events/src/nsDOMEvent.cpp +++ b/content/events/src/nsDOMEvent.cpp @@ -376,43 +376,50 @@ nsDOMEvent::Constructor(const mozilla::dom::GlobalObject& aGlobal, return e.forget(); } -NS_IMETHODIMP -nsDOMEvent::GetEventPhase(uint16_t* aEventPhase) +uint16_t +nsDOMEvent::EventPhase() const { // Note, remember to check that this works also // if or when Bug 235441 is fixed. if ((mEvent->currentTarget && mEvent->currentTarget == mEvent->target) || mEvent->mFlags.InTargetPhase()) { - *aEventPhase = nsIDOMEvent::AT_TARGET; - } else if (mEvent->mFlags.mInCapturePhase) { - *aEventPhase = nsIDOMEvent::CAPTURING_PHASE; - } else if (mEvent->mFlags.mInBubblingPhase) { - *aEventPhase = nsIDOMEvent::BUBBLING_PHASE; - } else { - *aEventPhase = nsIDOMEvent::NONE; + return nsIDOMEvent::AT_TARGET; } + if (mEvent->mFlags.mInCapturePhase) { + return nsIDOMEvent::CAPTURING_PHASE; + } + if (mEvent->mFlags.mInBubblingPhase) { + return nsIDOMEvent::BUBBLING_PHASE; + } + return nsIDOMEvent::NONE; +} + +NS_IMETHODIMP +nsDOMEvent::GetEventPhase(uint16_t* aEventPhase) +{ + *aEventPhase = EventPhase(); return NS_OK; } NS_IMETHODIMP nsDOMEvent::GetBubbles(bool* aBubbles) { - *aBubbles = mEvent->mFlags.mBubbles; + *aBubbles = Bubbles(); return NS_OK; } NS_IMETHODIMP nsDOMEvent::GetCancelable(bool* aCancelable) { - *aCancelable = mEvent->mFlags.mCancelable; + *aCancelable = Cancelable(); return NS_OK; } NS_IMETHODIMP nsDOMEvent::GetTimeStamp(uint64_t* aTimeStamp) { - *aTimeStamp = mEvent->time; + *aTimeStamp = TimeStamp(); return NS_OK; } @@ -478,7 +485,7 @@ nsDOMEvent::PreventCapture() NS_IMETHODIMP nsDOMEvent::GetIsTrusted(bool *aIsTrusted) { - *aIsTrusted = mEvent->mFlags.mIsTrusted; + *aIsTrusted = IsTrusted(); return NS_OK; } @@ -489,7 +496,7 @@ nsDOMEvent::PreventDefault() mEvent->mFlags.mDefaultPrevented = true; // Need to set an extra flag for drag events. - if (mEvent->eventStructType == NS_DRAG_EVENT && mEvent->mFlags.mIsTrusted) { + if (mEvent->eventStructType == NS_DRAG_EVENT && IsTrusted()) { nsCOMPtr node = do_QueryInterface(mEvent->currentTarget); if (!node) { nsCOMPtr win = do_QueryInterface(mEvent->currentTarget); @@ -520,7 +527,7 @@ nsDOMEvent::InitEvent(const nsAString& aEventTypeArg, bool aCanBubbleArg, bool a // Make sure this event isn't already being dispatched. NS_ENSURE_TRUE(!mEvent->mFlags.mIsBeingDispatched, NS_OK); - if (mEvent->mFlags.mIsTrusted) { + if (IsTrusted()) { // Ensure the caller is permitted to dispatch trusted DOM events. if (!nsContentUtils::IsCallerChrome()) { SetTrusted(false); @@ -1207,14 +1214,16 @@ NS_IMETHODIMP nsDOMEvent::GetPreventDefault(bool* aReturn) { NS_ENSURE_ARG_POINTER(aReturn); - *aReturn = mEvent && mEvent->mFlags.mDefaultPrevented; + *aReturn = GetPreventDefault(); return NS_OK; } NS_IMETHODIMP nsDOMEvent::GetDefaultPrevented(bool* aReturn) { - return GetPreventDefault(aReturn); + NS_ENSURE_ARG_POINTER(aReturn); + *aReturn = DefaultPrevented(); + return NS_OK; } NS_IMETHODIMP_(void) @@ -1228,17 +1237,9 @@ nsDOMEvent::Serialize(IPC::Message* aMsg, bool aSerializeInterfaceType) GetType(type); IPC::WriteParam(aMsg, type); - bool bubbles = false; - GetBubbles(&bubbles); - IPC::WriteParam(aMsg, bubbles); - - bool cancelable = false; - GetCancelable(&cancelable); - IPC::WriteParam(aMsg, cancelable); - - bool trusted = false; - GetIsTrusted(&trusted); - IPC::WriteParam(aMsg, trusted); + IPC::WriteParam(aMsg, Bubbles()); + IPC::WriteParam(aMsg, Cancelable()); + IPC::WriteParam(aMsg, IsTrusted()); // No timestamp serialization for now! } diff --git a/content/events/src/nsDOMEvent.h b/content/events/src/nsDOMEvent.h index 8ccd2fee8433..445412c7fff1 100644 --- a/content/events/src/nsDOMEvent.h +++ b/content/events/src/nsDOMEvent.h @@ -142,12 +142,7 @@ public: return et.forget(); } - uint16_t EventPhase() - { - uint16_t p; - GetEventPhase(&p); - return p; - } + uint16_t EventPhase() const; // xpidl implementation // void StopPropagation(); @@ -155,47 +150,37 @@ public: // xpidl implementation // void StopImmediatePropagation(); - bool Bubbles() + bool Bubbles() const { - bool b; - GetBubbles(&b); - return b; + return mEvent->mFlags.mBubbles; } - bool Cancelable() + bool Cancelable() const { - bool c; - GetCancelable(&c); - return c; + return mEvent->mFlags.mCancelable; } // xpidl implementation // void PreventDefault(); - bool DefaultPrevented() + bool DefaultPrevented() const { - bool d; - GetDefaultPrevented(&d); - return d; + return mEvent && mEvent->mFlags.mDefaultPrevented; } - bool MultipleActionsPrevented() + bool MultipleActionsPrevented() const { return mEvent->mFlags.mMultipleActionsPrevented; } - bool IsTrusted() + bool IsTrusted() const { - bool i; - GetIsTrusted(&i); - return i; + return mEvent->mFlags.mIsTrusted; } - uint64_t TimeStamp() + uint64_t TimeStamp() const { - uint64_t t; - GetTimeStamp(&t); - return t; + return mEvent->time; } void InitEvent(const nsAString& aType, bool aBubbles, bool aCancelable, @@ -220,11 +205,9 @@ public: return et.forget(); } - bool GetPreventDefault() + bool GetPreventDefault() const { - bool d; - GetDefaultPrevented(&d); - return d; + return DefaultPrevented(); } protected: