Bug 1180125 part 8 - Dispatch transition events from refresh driver; r=dbaron

This patch causes transition events to be dispatched as a separate step after
sampling the transitions. Eventually this will allow us to sample transitions
from their timeline (independently of where they came from and in potentially
any order) by separating the concepts of sampling and event dispatch.
This commit is contained in:
Brian Birtles 2015-07-29 10:57:40 +09:00
parent d23c414f8c
commit ad94152680
3 changed files with 36 additions and 7 deletions

View File

@ -1490,25 +1490,44 @@ nsRefreshDriver::DispatchPendingEvents()
}
}
namespace {
enum class AnimationEventType {
CSSAnimations,
CSSTransitions
};
struct DispatchAnimationEventParams {
AnimationEventType mEventType;
nsRefreshDriver* mRefreshDriver;
};
}
static bool
DispatchAnimationEventsOnSubDocuments(nsIDocument* aDocument,
void* aRefreshDriver)
void* aParams)
{
MOZ_ASSERT(aParams, "Animation event parameters should be set");
auto params = static_cast<DispatchAnimationEventParams*>(aParams);
nsIPresShell* shell = aDocument->GetShell();
if (!shell) {
return true;
}
nsPresContext* context = shell->GetPresContext();
if (!context || context->RefreshDriver() != aRefreshDriver) {
if (!context || context->RefreshDriver() != params->mRefreshDriver) {
return true;
}
nsCOMPtr<nsIDocument> kungFuDeathGrip(aDocument);
context->AnimationManager()->DispatchEvents();
if (params->mEventType == AnimationEventType::CSSAnimations) {
context->AnimationManager()->DispatchEvents();
} else {
context->TransitionManager()->DispatchEvents();
}
aDocument->EnumerateSubDocuments(DispatchAnimationEventsOnSubDocuments,
nullptr);
aParams);
return true;
}
@ -1521,7 +1540,18 @@ nsRefreshDriver::DispatchAnimationEvents()
}
nsIDocument* doc = mPresContext->Document();
DispatchAnimationEventsOnSubDocuments(doc, this);
// Dispatch transition events first since transitions conceptually sit
// below animations in terms of compositing order.
DispatchAnimationEventParams params { AnimationEventType::CSSTransitions,
this };
DispatchAnimationEventsOnSubDocuments(doc, &params);
if (!mPresContext) {
return;
}
params.mEventType = AnimationEventType::CSSAnimations;
DispatchAnimationEventsOnSubDocuments(doc, &params);
}
void

View File

@ -1003,6 +1003,4 @@ nsTransitionManager::FlushTransitions(FlushFlags aFlags)
}
MaybeStartOrStopObservingRefreshDriver();
mEventDispatcher.DispatchEvents(mPresContext);
}

View File

@ -285,6 +285,7 @@ public:
mozilla::Forward<mozilla::TransitionEventInfo>(aEventInfo));
}
void DispatchEvents() { mEventDispatcher.DispatchEvents(mPresContext); }
void ClearEventQueue() { mEventDispatcher.ClearEventQueue(); }
protected: