closes #374: asynchronous SVG through <img>

This commit is contained in:
Cameron Kaiser 2017-12-12 18:52:34 -08:00
parent 2e269c0fdb
commit cb70bd9e50
4 changed files with 50 additions and 7 deletions

View File

@ -94,6 +94,17 @@ public:
*/
virtual void NotifyAnimationUpdated(Animation& aAnimation);
/**
* Returns true if any CSS animations, CSS transitions or Web animations are
* currently associated with this timeline. As soon as an animation is
* applied to an element it is associated with the timeline even if it has a
* delayed start, so this includes animations that may not be active for some
* time.
*/
bool HasAnimations() const {
return !mAnimations.IsEmpty();
}
void RemoveAnimation(Animation* aAnimation);
protected:

View File

@ -5,7 +5,9 @@
#include "SVGDocumentWrapper.h"
#include "mozilla/dom/DocumentTimeline.h"
#include "mozilla/dom/Element.h"
#include "nsDOMNavigationTiming.h"
#include "nsICategoryManager.h"
#include "nsIChannel.h"
#include "nsIContentViewer.h"
@ -115,8 +117,21 @@ bool
SVGDocumentWrapper::IsAnimated()
{
nsIDocument* doc = mViewer->GetDocument();
return doc && doc->HasAnimationController() &&
doc->GetAnimationController()->HasRegisteredAnimations();
if (!doc) {
return false;
}
if (doc->Timeline()->HasAnimations()) {
// CSS animations (technically HasAnimations() also checks for CSS
// transitions and Web animations but since SVG-as-an-image doesn't run
// script they will never run in the document that we wrap).
return true;
}
if (doc->HasAnimationController() &&
doc->GetAnimationController()->HasRegisteredAnimations()) {
// SMIL animations
return true;
}
return false;
}
void
@ -330,6 +345,20 @@ SVGDocumentWrapper::SetupViewer(nsIRequest* aRequest,
NS_ENSURE_TRUE(viewer, NS_ERROR_UNEXPECTED);
// Create a navigation time object and pass it to the SVG document through
// the viewer.
// The timeline(DocumentTimeline, used in CSS animation) of this SVG
// document needs this navigation timing object for time computation, such
// as to calculate current time stamp based on the start time of navigation
// time object.
//
// For a root document, DocShell would do these sort of things
// automatically. Since there is no DocShell for this wrapped SVG document,
// we must set it up manually.
RefPtr<nsDOMNavigationTiming> timing = new nsDOMNavigationTiming();
timing->NotifyNavigationStart();
viewer->SetNavigationTiming(timing);
nsCOMPtr<nsIParser> parser = do_QueryInterface(listener);
NS_ENSURE_TRUE(parser, NS_ERROR_UNEXPECTED);

View File

@ -524,6 +524,12 @@ VectorImage::RequestRefresh(const TimeStamp& aTime)
return;
}
PendingAnimationTracker* tracker =
mSVGDocumentWrapper->GetDocument()->GetPendingAnimationTracker();
if (tracker && ShouldAnimate()) {
tracker->TriggerPendingAnimationsOnNextTick(aTime);
}
EvaluateAnimation();
mSVGDocumentWrapper->TickRefreshDriver();

View File

@ -1619,7 +1619,7 @@ already_AddRefed<LayerManager> nsDisplayList::PaintRoot(nsDisplayListBuilder* aB
nsIFrame* frame = aBuilder->RootReferenceFrame();
nsPresContext* presContext = frame->PresContext();
nsIPresShell* presShell = presContext->GetPresShell();
nsIPresShell* presShell = presContext->PresShell();
nsRootPresContext* rootPresContext = presContext->GetRootPresContext();
NotifySubDocInvalidationFunc computeInvalidFunc =
@ -1646,10 +1646,7 @@ already_AddRefed<LayerManager> nsDisplayList::PaintRoot(nsDisplayListBuilder* aB
BuildContainerLayerFor(aBuilder, layerManager, frame, nullptr, this,
containerParameters, nullptr);
nsIDocument* document = nullptr;
if (presShell) {
document = presShell->GetDocument();
}
nsIDocument* document = presShell->GetDocument();
if (!root) {
layerManager->SetUserData(&gLayerManagerLayerBuilder, oldBuilder);