From 6dd2534950d7309337be3e4c61b1406b3fc66096 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Tue, 22 Oct 2013 22:27:34 +0900 Subject: [PATCH] Bug 602787 part.1 Don't implement PresShell::Delayed*Event class in nsPresShell.h r=smaug --- layout/base/nsPresShell.cpp | 59 +++++++++++++++++++++++++++++++++---- layout/base/nsPresShell.h | 59 ++++++++----------------------------- 2 files changed, 67 insertions(+), 51 deletions(-) diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 2f9b2cc475b0..269a1b29bf72 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -6106,8 +6106,7 @@ PresShell::HandleEvent(nsIFrame* aFrame, if (aEvent->message == NS_KEY_DOWN) { mNoDelayedKeyEvents = true; } else if (!mNoDelayedKeyEvents) { - nsDelayedEvent* event = - new nsDelayedKeyEvent(aEvent->AsKeyboardEvent()); + DelayedEvent* event = new DelayedKeyEvent(aEvent->AsKeyboardEvent()); if (!mDelayedEvents.AppendElement(event)) { delete event; } @@ -6335,7 +6334,7 @@ PresShell::HandleEvent(nsIFrame* aFrame, if (aEvent->message == NS_MOUSE_BUTTON_DOWN) { mNoDelayedMouseEvents = true; } else if (!mNoDelayedMouseEvents && aEvent->message == NS_MOUSE_BUTTON_UP) { - nsDelayedEvent* event = new nsDelayedMouseEvent(aEvent->AsMouseEvent()); + DelayedEvent* event = new DelayedMouseEvent(aEvent->AsMouseEvent()); if (!mDelayedEvents.AppendElement(event)) { delete event; } @@ -7628,9 +7627,9 @@ PresShell::FireOrClearDelayedEvents(bool aFireEvents) nsCOMPtr doc = mDocument; while (!mIsDestroying && mDelayedEvents.Length() && !doc->EventHandlingSuppressed()) { - nsAutoPtr ev(mDelayedEvents[0].forget()); + nsAutoPtr ev(mDelayedEvents[0].forget()); mDelayedEvents.RemoveElementAt(0); - ev->Dispatch(this); + ev->Dispatch(); } if (!doc->EventHandlingSuppressed()) { mDelayedEvents.Clear(); @@ -8341,6 +8340,56 @@ nsIPresShell::RemovePostRefreshObserver(nsAPostRefreshObserver* aObserver) // End of protected and private methods on the PresShell //------------------------------------------------------ +//------------------------------------------------------------------ +//-- Delayed event Classes Impls +//------------------------------------------------------------------ + +PresShell::DelayedInputEvent::DelayedInputEvent() : + DelayedEvent(), + mEvent(nullptr) +{ +} + +PresShell::DelayedInputEvent::~DelayedInputEvent() +{ + delete mEvent; +} + +void +PresShell::DelayedInputEvent::Dispatch() +{ + if (!mEvent || !mEvent->widget) { + return; + } + nsCOMPtr widget = mEvent->widget; + nsEventStatus status; + widget->DispatchEvent(mEvent, status); +} + +PresShell::DelayedMouseEvent::DelayedMouseEvent(WidgetMouseEvent* aEvent) : + DelayedInputEvent() +{ + WidgetMouseEvent* mouseEvent = + new WidgetMouseEvent(aEvent->mFlags.mIsTrusted, + aEvent->message, + aEvent->widget, + aEvent->reason, + aEvent->context); + mouseEvent->AssignMouseEventData(*aEvent, false); + mEvent = mouseEvent; +} + +PresShell::DelayedKeyEvent::DelayedKeyEvent(WidgetKeyboardEvent* aEvent) : + DelayedInputEvent() +{ + WidgetKeyboardEvent* keyEvent = + new WidgetKeyboardEvent(aEvent->mFlags.mIsTrusted, + aEvent->message, + aEvent->widget); + keyEvent->AssignKeyEventData(*aEvent, false); + mEvent = keyEvent; +} + // Start of DEBUG only code #ifdef DEBUG diff --git a/layout/base/nsPresShell.h b/layout/base/nsPresShell.h index dcb2af38cbc1..47e901a34e60 100644 --- a/layout/base/nsPresShell.h +++ b/layout/base/nsPresShell.h @@ -34,9 +34,8 @@ #include "nsContentUtils.h" // For AddScriptBlocker(). #include "nsRefreshDriver.h" #include "mozilla/Attributes.h" +#include "mozilla/EventForwards.h" #include "mozilla/MemoryReporting.h" -#include "mozilla/MouseEvents.h" -#include "mozilla/TextEvents.h" class nsRange; class nsIDragService; @@ -547,67 +546,35 @@ protected: return rv; } - class nsDelayedEvent + class DelayedEvent { public: - virtual ~nsDelayedEvent() {}; - virtual void Dispatch(PresShell* aShell) {} + virtual ~DelayedEvent() { } + virtual void Dispatch() { } }; - class nsDelayedInputEvent : public nsDelayedEvent + class DelayedInputEvent : public DelayedEvent { public: - virtual void Dispatch(PresShell* aShell) - { - if (mEvent && mEvent->widget) { - nsCOMPtr w = mEvent->widget; - nsEventStatus status; - w->DispatchEvent(mEvent, status); - } - } + virtual void Dispatch() MOZ_OVERRIDE; protected: - nsDelayedInputEvent() - : nsDelayedEvent(), mEvent(nullptr) {} - - virtual ~nsDelayedInputEvent() - { - delete mEvent; - } + DelayedInputEvent(); + virtual ~DelayedInputEvent(); mozilla::WidgetInputEvent* mEvent; }; - class nsDelayedMouseEvent : public nsDelayedInputEvent + class DelayedMouseEvent : public DelayedInputEvent { public: - nsDelayedMouseEvent(mozilla::WidgetMouseEvent* aEvent) : - nsDelayedInputEvent() - { - mozilla::WidgetMouseEvent* mouseEvent = - new mozilla::WidgetMouseEvent(aEvent->mFlags.mIsTrusted, - aEvent->message, - aEvent->widget, - aEvent->reason, - aEvent->context); - mouseEvent->AssignMouseEventData(*aEvent, false); - mEvent = mouseEvent; - } + DelayedMouseEvent(mozilla::WidgetMouseEvent* aEvent); }; - class nsDelayedKeyEvent : public nsDelayedInputEvent + class DelayedKeyEvent : public DelayedInputEvent { public: - nsDelayedKeyEvent(mozilla::WidgetKeyboardEvent* aEvent) : - nsDelayedInputEvent() - { - mozilla::WidgetKeyboardEvent* keyEvent = - new mozilla::WidgetKeyboardEvent(aEvent->mFlags.mIsTrusted, - aEvent->message, - aEvent->widget); - keyEvent->AssignKeyEventData(*aEvent, false); - mEvent = keyEvent; - } + DelayedKeyEvent(mozilla::WidgetKeyboardEvent* aEvent); }; // Check if aEvent is a mouse event and record the mouse location for later @@ -759,7 +726,7 @@ protected: // Reflow roots that need to be reflowed. nsTArray mDirtyRoots; - nsTArray > mDelayedEvents; + nsTArray > mDelayedEvents; nsRevocableEventPtr > mResizeEvent; nsCOMPtr mAsyncResizeEventTimer; private: