/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// If the bounds have changed, we need to do a layout flush. if (currentBounds.Size().ToUnknownSize() != aViewportSize) {
mViewer->SetBounds(LayoutDeviceIntRect(
LayoutDeviceIntPoint(),
LayoutDeviceIntSize::FromUnknownSize(aViewportSize)));
FlushLayout();
}
mIgnoreInvalidation = false;
}
void SVGDocumentWrapper::FlushImageTransformInvalidation() {
MOZ_ASSERT(!mIgnoreInvalidation, "shouldn't be reentrant");
SVGSVGElement* svgElem = GetRootSVGElem(); if (!svgElem) { return;
}
bool SVGDocumentWrapper::IsAnimated() { // Can be called for animated images during shutdown, after we've // already Observe()'d XPCOM shutdown and cleared out our mViewer pointer. if (!mViewer) { returnfalse;
}
Document* doc = mViewer->GetDocument(); if (!doc) { returnfalse;
} 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). returntrue;
} if (doc->HasAnimationController() &&
doc->GetAnimationController()->HasRegisteredAnimations()) { // SMIL animations returntrue;
} returnfalse;
}
void SVGDocumentWrapper::StartAnimation() { // Can be called for animated images during shutdown, after we've // already Observe()'d XPCOM shutdown and cleared out our mViewer pointer. if (!mViewer) { return;
}
Document* doc = mViewer->GetDocument(); if (doc) {
SMILAnimationController* controller = doc->GetAnimationController(); if (controller) {
controller->Resume(SMILTimeContainer::PAUSE_IMAGE);
}
doc->ImageTracker()->SetAnimatingState(true);
}
}
void SVGDocumentWrapper::StopAnimation() { // Can be called for animated images during shutdown, after we've // already Observe()'d XPCOM shutdown and cleared out our mViewer pointer. if (!mViewer) { return;
}
Document* doc = mViewer->GetDocument(); if (doc) {
SMILAnimationController* controller = doc->GetAnimationController(); if (controller) {
controller->Pause(SMILTimeContainer::PAUSE_IMAGE);
}
doc->ImageTracker()->SetAnimatingState(false);
}
}
/** nsIObserver Methods **/
NS_IMETHODIMP
SVGDocumentWrapper::Observe(nsISupports* aSubject, constchar* aTopic, const char16_t* aData) { if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) { // Sever ties from rendering observers to helper-doc's root SVG node
SVGSVGElement* svgElem = GetRootSVGElem(); if (svgElem) {
SVGObserverUtils::RemoveAllRenderingObservers(svgElem);
}
// Clean up at XPCOM shutdown time.
DestroyViewer(); if (mListener) {
mListener = nullptr;
} if (mLoadGroup) {
mLoadGroup = nullptr;
}
// Turn off "registered" flag, or else we'll try to unregister when we die. // (No need for that now, and the try would fail anyway -- it's too late.)
mRegisteredForXPCOMShutdown = false;
} else {
NS_ERROR("Unexpected observer topic.");
} return NS_OK;
}
/** Private helper methods **/
// This method is largely cribbed from // nsExternalResourceMap::PendingLoad::SetupViewer.
nsresult SVGDocumentWrapper::SetupViewer(nsIRequest* aRequest,
nsIDocumentViewer** aViewer,
nsILoadGroup** aLoadGroup) {
nsCOMPtr<nsIChannel> chan(do_QueryInterface(aRequest));
NS_ENSURE_TRUE(chan, NS_ERROR_UNEXPECTED);
// Check for HTTP error page
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aRequest)); if (httpChannel) { bool requestSucceeded; if (NS_FAILED(httpChannel->GetRequestSucceeded(&requestSucceeded)) ||
!requestSucceeded) { return NS_ERROR_FAILURE;
}
}
// Give this document its own loadgroup
nsCOMPtr<nsILoadGroup> loadGroup;
chan->GetLoadGroup(getter_AddRefs(loadGroup));
// 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(nullptr);
timing->NotifyNavigationStart(
nsDOMNavigationTiming::DocShellState::eInactive);
viewer->SetNavigationTiming(timing);
void SVGDocumentWrapper::RegisterForXPCOMShutdown() {
MOZ_ASSERT(!mRegisteredForXPCOMShutdown, "re-registering for XPCOM shutdown"); // Listen for xpcom-shutdown so that we can drop references to our // helper-document at that point. (Otherwise, we won't get cleaned up // until imgLoader::Shutdown, which can happen after the JAR service // and RDF service have been unregistered.)
nsresult rv;
nsCOMPtr<nsIObserverService> obsSvc = do_GetService(OBSERVER_SVC_CID, &rv); if (NS_FAILED(rv) || NS_FAILED(obsSvc->AddObserver( this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true))) {
NS_WARNING("Failed to register as observer of XPCOM shutdown");
} else {
mRegisteredForXPCOMShutdown = true;
}
}
void SVGDocumentWrapper::UnregisterForXPCOMShutdown() {
MOZ_ASSERT(mRegisteredForXPCOMShutdown, "unregistering for XPCOM shutdown w/out being registered");
nsresult rv;
nsCOMPtr<nsIObserverService> obsSvc = do_GetService(OBSERVER_SVC_CID, &rv); if (NS_FAILED(rv) ||
NS_FAILED(obsSvc->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID))) {
NS_WARNING("Failed to unregister as observer of XPCOM shutdown");
} else {
mRegisteredForXPCOMShutdown = false;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.