Bug 602787 part.1 Don't implement PresShell::Delayed*Event class in nsPresShell.h r=smaug

This commit is contained in:
Masayuki Nakano 2013-10-22 22:27:34 +09:00
parent 860e2fc11f
commit 072dd9b177
2 changed files with 67 additions and 51 deletions

View File

@ -6091,8 +6091,7 @@ PresShell::HandleEvent(nsIFrame* aFrame,
if (aEvent->message == NS_KEY_DOWN) { if (aEvent->message == NS_KEY_DOWN) {
mNoDelayedKeyEvents = true; mNoDelayedKeyEvents = true;
} else if (!mNoDelayedKeyEvents) { } else if (!mNoDelayedKeyEvents) {
nsDelayedEvent* event = DelayedEvent* event = new DelayedKeyEvent(aEvent->AsKeyboardEvent());
new nsDelayedKeyEvent(aEvent->AsKeyboardEvent());
if (!mDelayedEvents.AppendElement(event)) { if (!mDelayedEvents.AppendElement(event)) {
delete event; delete event;
} }
@ -6313,7 +6312,7 @@ PresShell::HandleEvent(nsIFrame* aFrame,
if (aEvent->message == NS_MOUSE_BUTTON_DOWN) { if (aEvent->message == NS_MOUSE_BUTTON_DOWN) {
mNoDelayedMouseEvents = true; mNoDelayedMouseEvents = true;
} else if (!mNoDelayedMouseEvents && aEvent->message == NS_MOUSE_BUTTON_UP) { } 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)) { if (!mDelayedEvents.AppendElement(event)) {
delete event; delete event;
} }
@ -7606,9 +7605,9 @@ PresShell::FireOrClearDelayedEvents(bool aFireEvents)
nsCOMPtr<nsIDocument> doc = mDocument; nsCOMPtr<nsIDocument> doc = mDocument;
while (!mIsDestroying && mDelayedEvents.Length() && while (!mIsDestroying && mDelayedEvents.Length() &&
!doc->EventHandlingSuppressed()) { !doc->EventHandlingSuppressed()) {
nsAutoPtr<nsDelayedEvent> ev(mDelayedEvents[0].forget()); nsAutoPtr<DelayedEvent> ev(mDelayedEvents[0].forget());
mDelayedEvents.RemoveElementAt(0); mDelayedEvents.RemoveElementAt(0);
ev->Dispatch(this); ev->Dispatch();
} }
if (!doc->EventHandlingSuppressed()) { if (!doc->EventHandlingSuppressed()) {
mDelayedEvents.Clear(); mDelayedEvents.Clear();
@ -8319,6 +8318,56 @@ nsIPresShell::RemovePostRefreshObserver(nsAPostRefreshObserver* aObserver)
// End of protected and private methods on the PresShell // 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<nsIWidget> 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 // Start of DEBUG only code
#ifdef DEBUG #ifdef DEBUG

View File

@ -34,9 +34,8 @@
#include "nsContentUtils.h" // For AddScriptBlocker(). #include "nsContentUtils.h" // For AddScriptBlocker().
#include "nsRefreshDriver.h" #include "nsRefreshDriver.h"
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#include "mozilla/EventForwards.h"
#include "mozilla/MemoryReporting.h" #include "mozilla/MemoryReporting.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/TextEvents.h"
class nsRange; class nsRange;
class nsIDragService; class nsIDragService;
@ -547,67 +546,35 @@ protected:
return rv; return rv;
} }
class nsDelayedEvent class DelayedEvent
{ {
public: public:
virtual ~nsDelayedEvent() {}; virtual ~DelayedEvent() { }
virtual void Dispatch(PresShell* aShell) {} virtual void Dispatch() { }
}; };
class nsDelayedInputEvent : public nsDelayedEvent class DelayedInputEvent : public DelayedEvent
{ {
public: public:
virtual void Dispatch(PresShell* aShell) virtual void Dispatch() MOZ_OVERRIDE;
{
if (mEvent && mEvent->widget) {
nsCOMPtr<nsIWidget> w = mEvent->widget;
nsEventStatus status;
w->DispatchEvent(mEvent, status);
}
}
protected: protected:
nsDelayedInputEvent() DelayedInputEvent();
: nsDelayedEvent(), mEvent(nullptr) {} virtual ~DelayedInputEvent();
virtual ~nsDelayedInputEvent()
{
delete mEvent;
}
mozilla::WidgetInputEvent* mEvent; mozilla::WidgetInputEvent* mEvent;
}; };
class nsDelayedMouseEvent : public nsDelayedInputEvent class DelayedMouseEvent : public DelayedInputEvent
{ {
public: public:
nsDelayedMouseEvent(mozilla::WidgetMouseEvent* aEvent) : DelayedMouseEvent(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;
}
}; };
class nsDelayedKeyEvent : public nsDelayedInputEvent class DelayedKeyEvent : public DelayedInputEvent
{ {
public: public:
nsDelayedKeyEvent(mozilla::WidgetKeyboardEvent* aEvent) : DelayedKeyEvent(mozilla::WidgetKeyboardEvent* aEvent);
nsDelayedInputEvent()
{
mozilla::WidgetKeyboardEvent* keyEvent =
new mozilla::WidgetKeyboardEvent(aEvent->mFlags.mIsTrusted,
aEvent->message,
aEvent->widget);
keyEvent->AssignKeyEventData(*aEvent, false);
mEvent = keyEvent;
}
}; };
// Check if aEvent is a mouse event and record the mouse location for later // 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. // Reflow roots that need to be reflowed.
nsTArray<nsIFrame*> mDirtyRoots; nsTArray<nsIFrame*> mDirtyRoots;
nsTArray<nsAutoPtr<nsDelayedEvent> > mDelayedEvents; nsTArray<nsAutoPtr<DelayedEvent> > mDelayedEvents;
nsRevocableEventPtr<nsRunnableMethod<PresShell> > mResizeEvent; nsRevocableEventPtr<nsRunnableMethod<PresShell> > mResizeEvent;
nsCOMPtr<nsITimer> mAsyncResizeEventTimer; nsCOMPtr<nsITimer> mAsyncResizeEventTimer;
private: private: