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
Родитель 3986c21083
Коммит 6dd2534950
2 изменённых файлов: 67 добавлений и 51 удалений

Просмотреть файл

@ -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<nsIDocument> doc = mDocument;
while (!mIsDestroying && mDelayedEvents.Length() &&
!doc->EventHandlingSuppressed()) {
nsAutoPtr<nsDelayedEvent> ev(mDelayedEvents[0].forget());
nsAutoPtr<DelayedEvent> 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<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
#ifdef DEBUG

Просмотреть файл

@ -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<nsIWidget> 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<nsIFrame*> mDirtyRoots;
nsTArray<nsAutoPtr<nsDelayedEvent> > mDelayedEvents;
nsTArray<nsAutoPtr<DelayedEvent> > mDelayedEvents;
nsRevocableEventPtr<nsRunnableMethod<PresShell> > mResizeEvent;
nsCOMPtr<nsITimer> mAsyncResizeEventTimer;
private: