2010-09-09 00:40:39 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2010-09-09 00:40:39 +04:00
|
|
|
|
|
|
|
#include "SVGDocumentWrapper.h"
|
2011-10-15 11:33:26 +04:00
|
|
|
|
2010-09-09 00:40:39 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "nsICategoryManager.h"
|
|
|
|
#include "nsIChannel.h"
|
2011-10-15 11:33:26 +04:00
|
|
|
#include "nsIContentViewer.h"
|
2010-09-09 00:40:39 +04:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDocumentLoaderFactory.h"
|
|
|
|
#include "nsIDOMSVGLength.h"
|
|
|
|
#include "nsIHttpChannel.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIParser.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIRequest.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIXMLContentSink.h"
|
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
2012-08-06 16:02:08 +04:00
|
|
|
#include "nsSMILAnimationController.h"
|
2010-09-09 00:40:39 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2013-01-10 03:02:45 +04:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
2010-11-16 21:35:59 +03:00
|
|
|
#include "nsSVGEffects.h"
|
2013-02-08 23:55:07 +04:00
|
|
|
#include "mozilla/dom/SVGAnimatedLength.h"
|
2013-09-07 17:01:08 +04:00
|
|
|
#include "nsMimeTypes.h"
|
2014-04-12 01:26:29 +04:00
|
|
|
#include "DOMSVGLength.h"
|
2010-09-09 00:40:39 +04:00
|
|
|
|
2013-11-19 10:03:36 +04:00
|
|
|
// undef the GetCurrentTime macro defined in WinBase.h from the MS Platform SDK
|
|
|
|
#undef GetCurrentTime
|
|
|
|
|
2010-09-09 00:40:39 +04:00
|
|
|
namespace mozilla {
|
2015-07-23 08:39:48 +03:00
|
|
|
|
|
|
|
using namespace dom;
|
|
|
|
using namespace gfx;
|
|
|
|
|
2012-01-06 20:02:27 +04:00
|
|
|
namespace image {
|
2010-09-09 00:40:39 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(SVGDocumentWrapper,
|
|
|
|
nsIStreamListener,
|
|
|
|
nsIRequestObserver,
|
|
|
|
nsIObserver,
|
|
|
|
nsISupportsWeakReference)
|
2010-09-09 00:40:39 +04:00
|
|
|
|
|
|
|
SVGDocumentWrapper::SVGDocumentWrapper()
|
2011-10-17 18:59:28 +04:00
|
|
|
: mIgnoreInvalidation(false),
|
|
|
|
mRegisteredForXPCOMShutdown(false)
|
2015-03-04 15:18:00 +03:00
|
|
|
{ }
|
2010-09-09 00:40:39 +04:00
|
|
|
|
|
|
|
SVGDocumentWrapper::~SVGDocumentWrapper()
|
|
|
|
{
|
|
|
|
DestroyViewer();
|
2010-11-08 20:45:18 +03:00
|
|
|
if (mRegisteredForXPCOMShutdown) {
|
|
|
|
UnregisterForXPCOMShutdown();
|
|
|
|
}
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGDocumentWrapper::DestroyViewer()
|
|
|
|
{
|
|
|
|
if (mViewer) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mViewer->GetDocument()->OnPageHide(false, nullptr);
|
|
|
|
mViewer->Close(nullptr);
|
2010-09-09 00:40:39 +04:00
|
|
|
mViewer->Destroy();
|
2012-07-30 18:20:58 +04:00
|
|
|
mViewer = nullptr;
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
SVGDocumentWrapper::GetRootLayoutFrame()
|
|
|
|
{
|
|
|
|
Element* rootElem = GetRootSVGElem();
|
2012-07-30 18:20:58 +04:00
|
|
|
return rootElem ? rootElem->GetPrimaryFrame() : nullptr;
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGDocumentWrapper::UpdateViewportBounds(const nsIntSize& aViewportSize)
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mIgnoreInvalidation, "shouldn't be reentrant");
|
2011-10-17 18:59:28 +04:00
|
|
|
mIgnoreInvalidation = true;
|
2012-11-08 23:54:47 +04:00
|
|
|
|
|
|
|
nsIntRect currentBounds;
|
|
|
|
mViewer->GetBounds(currentBounds);
|
2013-03-30 00:14:19 +04:00
|
|
|
|
2012-11-08 23:54:47 +04:00
|
|
|
// If the bounds have changed, we need to do a layout flush.
|
|
|
|
if (currentBounds.Size() != aViewportSize) {
|
2015-04-21 18:04:57 +03:00
|
|
|
mViewer->SetBounds(IntRect(IntPoint(0, 0), aViewportSize));
|
2012-11-08 23:54:47 +04:00
|
|
|
FlushLayout();
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mIgnoreInvalidation = false;
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
2010-12-20 03:45:29 +03:00
|
|
|
void
|
2011-02-09 23:13:18 +03:00
|
|
|
SVGDocumentWrapper::FlushImageTransformInvalidation()
|
2010-12-20 03:45:29 +03:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mIgnoreInvalidation, "shouldn't be reentrant");
|
2010-12-20 03:45:29 +03:00
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement* svgElem = GetRootSVGElem();
|
2015-03-04 15:18:00 +03:00
|
|
|
if (!svgElem) {
|
2010-12-20 03:45:29 +03:00
|
|
|
return;
|
2015-03-04 15:18:00 +03:00
|
|
|
}
|
2010-12-20 03:45:29 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mIgnoreInvalidation = true;
|
2011-02-09 23:13:18 +03:00
|
|
|
svgElem->FlushImageTransformInvalidation();
|
2010-12-20 03:45:29 +03:00
|
|
|
FlushLayout();
|
2011-10-17 18:59:28 +04:00
|
|
|
mIgnoreInvalidation = false;
|
2010-12-20 03:45:29 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-09-09 00:40:39 +04:00
|
|
|
SVGDocumentWrapper::IsAnimated()
|
|
|
|
{
|
|
|
|
nsIDocument* doc = mViewer->GetDocument();
|
|
|
|
return doc && doc->HasAnimationController() &&
|
|
|
|
doc->GetAnimationController()->HasRegisteredAnimations();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGDocumentWrapper::StartAnimation()
|
|
|
|
{
|
2010-12-20 21:44:05 +03:00
|
|
|
// Can be called for animated images during shutdown, after we've
|
|
|
|
// already Observe()'d XPCOM shutdown and cleared out our mViewer pointer.
|
2015-03-04 15:18:00 +03:00
|
|
|
if (!mViewer) {
|
2010-12-20 21:44:05 +03:00
|
|
|
return;
|
2015-03-04 15:18:00 +03:00
|
|
|
}
|
2010-12-20 21:44:05 +03:00
|
|
|
|
2010-11-06 22:13:01 +03:00
|
|
|
nsIDocument* doc = mViewer->GetDocument();
|
|
|
|
if (doc) {
|
2011-01-11 08:58:00 +03:00
|
|
|
nsSMILAnimationController* controller = doc->GetAnimationController();
|
|
|
|
if (controller) {
|
|
|
|
controller->Resume(nsSMILTimeContainer::PAUSE_IMAGE);
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
doc->SetImagesNeedAnimating(true);
|
2010-11-06 22:13:01 +03:00
|
|
|
}
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGDocumentWrapper::StopAnimation()
|
|
|
|
{
|
2010-12-20 21:44:05 +03:00
|
|
|
// Can be called for animated images during shutdown, after we've
|
2010-09-09 00:40:39 +04:00
|
|
|
// already Observe()'d XPCOM shutdown and cleared out our mViewer pointer.
|
2015-03-04 15:18:00 +03:00
|
|
|
if (!mViewer) {
|
2010-09-09 00:40:39 +04:00
|
|
|
return;
|
2015-03-04 15:18:00 +03:00
|
|
|
}
|
2010-09-09 00:40:39 +04:00
|
|
|
|
2010-11-06 22:13:01 +03:00
|
|
|
nsIDocument* doc = mViewer->GetDocument();
|
|
|
|
if (doc) {
|
2011-01-11 08:58:00 +03:00
|
|
|
nsSMILAnimationController* controller = doc->GetAnimationController();
|
|
|
|
if (controller) {
|
|
|
|
controller->Pause(nsSMILTimeContainer::PAUSE_IMAGE);
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
doc->SetImagesNeedAnimating(false);
|
2010-11-06 22:13:01 +03:00
|
|
|
}
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGDocumentWrapper::ResetAnimation()
|
|
|
|
{
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement* svgElem = GetRootSVGElem();
|
2015-03-04 15:18:00 +03:00
|
|
|
if (!svgElem) {
|
2010-09-09 00:40:39 +04:00
|
|
|
return;
|
2015-03-04 15:18:00 +03:00
|
|
|
}
|
2010-09-09 00:40:39 +04:00
|
|
|
|
2013-02-08 23:55:07 +04:00
|
|
|
svgElem->SetCurrentTime(0.0f);
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-11 05:43:37 +04:00
|
|
|
float
|
|
|
|
SVGDocumentWrapper::GetCurrentTime()
|
|
|
|
{
|
|
|
|
SVGSVGElement* svgElem = GetRootSVGElem();
|
|
|
|
return svgElem ? svgElem->GetCurrentTime()
|
|
|
|
: 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGDocumentWrapper::SetCurrentTime(float aTime)
|
|
|
|
{
|
|
|
|
SVGSVGElement* svgElem = GetRootSVGElem();
|
|
|
|
if (svgElem && svgElem->GetCurrentTime() != aTime) {
|
|
|
|
svgElem->SetCurrentTime(aTime);
|
|
|
|
}
|
|
|
|
}
|
2010-09-09 00:40:39 +04:00
|
|
|
|
2014-05-01 20:31:54 +04:00
|
|
|
void
|
|
|
|
SVGDocumentWrapper::TickRefreshDriver()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
mViewer->GetPresShell(getter_AddRefs(presShell));
|
|
|
|
if (presShell) {
|
|
|
|
nsPresContext* presContext = presShell->GetPresContext();
|
|
|
|
if (presContext) {
|
|
|
|
presContext->RefreshDriver()->DoTick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-09 00:40:39 +04:00
|
|
|
/** nsIStreamListener methods **/
|
|
|
|
|
|
|
|
/* void onDataAvailable (in nsIRequest request, in nsISupports ctxt,
|
|
|
|
in nsIInputStream inStr, in unsigned long sourceOffset,
|
|
|
|
in unsigned long count); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
SVGDocumentWrapper::OnDataAvailable(nsIRequest* aRequest, nsISupports* ctxt,
|
|
|
|
nsIInputStream* inStr,
|
2012-09-06 06:41:02 +04:00
|
|
|
uint64_t sourceOffset,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count)
|
2010-09-09 00:40:39 +04:00
|
|
|
{
|
|
|
|
return mListener->OnDataAvailable(aRequest, ctxt, inStr,
|
|
|
|
sourceOffset, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** nsIRequestObserver methods **/
|
|
|
|
|
|
|
|
/* void onStartRequest (in nsIRequest request, in nsISupports ctxt); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
SVGDocumentWrapper::OnStartRequest(nsIRequest* aRequest, nsISupports* ctxt)
|
|
|
|
{
|
|
|
|
nsresult rv = SetupViewer(aRequest,
|
|
|
|
getter_AddRefs(mViewer),
|
|
|
|
getter_AddRefs(mLoadGroup));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) &&
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_SUCCEEDED(mListener->OnStartRequest(aRequest, nullptr))) {
|
2010-09-09 00:40:39 +04:00
|
|
|
mViewer->GetDocument()->SetIsBeingUsedAsImage();
|
2010-11-16 21:35:59 +03:00
|
|
|
StopAnimation(); // otherwise animations start automatically in helper doc
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = mViewer->Init(nullptr, nsIntRect(0, 0, 0, 0));
|
2010-09-09 00:40:39 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = mViewer->Open(nullptr, nullptr);
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* void onStopRequest (in nsIRequest request, in nsISupports ctxt,
|
|
|
|
in nsresult status); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
SVGDocumentWrapper::OnStopRequest(nsIRequest* aRequest, nsISupports* ctxt,
|
|
|
|
nsresult status)
|
|
|
|
{
|
|
|
|
if (mListener) {
|
2010-09-25 21:51:37 +04:00
|
|
|
mListener->OnStopRequest(aRequest, ctxt, status);
|
2012-07-30 18:20:58 +04:00
|
|
|
mListener = nullptr;
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** nsIObserver Methods **/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
SVGDocumentWrapper::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
2015-03-04 15:18:00 +03:00
|
|
|
const char16_t* aData)
|
2010-09-09 00:40:39 +04:00
|
|
|
{
|
|
|
|
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
2010-11-16 21:35:59 +03:00
|
|
|
// Sever ties from rendering observers to helper-doc's root SVG node
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement* svgElem = GetRootSVGElem();
|
2010-11-16 21:35:59 +03:00
|
|
|
if (svgElem) {
|
|
|
|
nsSVGEffects::RemoveAllRenderingObservers(svgElem);
|
|
|
|
}
|
|
|
|
|
2010-09-09 00:40:39 +04:00
|
|
|
// Clean up at XPCOM shutdown time.
|
|
|
|
DestroyViewer();
|
2015-03-04 15:18:00 +03:00
|
|
|
if (mListener) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mListener = nullptr;
|
2015-03-04 15:18:00 +03:00
|
|
|
}
|
|
|
|
if (mLoadGroup) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mLoadGroup = nullptr;
|
2015-03-04 15:18:00 +03:00
|
|
|
}
|
2010-11-10 08:50:29 +03:00
|
|
|
|
|
|
|
// 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.)
|
2011-10-17 18:59:28 +04:00
|
|
|
mRegisteredForXPCOMShutdown = false;
|
2010-09-09 00:40:39 +04:00
|
|
|
} 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,
|
2011-10-15 11:33:26 +04:00
|
|
|
nsIContentViewer** aViewer,
|
2010-09-09 00:40:39 +04:00
|
|
|
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) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool requestSucceeded;
|
2010-09-09 00:40:39 +04:00
|
|
|
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));
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> newLoadGroup =
|
|
|
|
do_CreateInstance(NS_LOADGROUP_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(newLoadGroup, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
newLoadGroup->SetLoadGroup(loadGroup);
|
|
|
|
|
|
|
|
nsCOMPtr<nsICategoryManager> catMan =
|
|
|
|
do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(catMan, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
nsXPIDLCString contractId;
|
2013-01-09 01:40:47 +04:00
|
|
|
nsresult rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", IMAGE_SVG_XML,
|
2010-09-09 00:40:39 +04:00
|
|
|
getter_Copies(contractId));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory =
|
|
|
|
do_GetService(contractId);
|
|
|
|
NS_ENSURE_TRUE(docLoaderFactory, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewer> viewer;
|
|
|
|
nsCOMPtr<nsIStreamListener> listener;
|
|
|
|
rv = docLoaderFactory->CreateInstance("external-resource", chan,
|
|
|
|
newLoadGroup,
|
2015-02-25 18:26:51 +03:00
|
|
|
NS_LITERAL_CSTRING(IMAGE_SVG_XML),
|
|
|
|
nullptr, nullptr,
|
2010-09-09 00:40:39 +04:00
|
|
|
getter_AddRefs(listener),
|
|
|
|
getter_AddRefs(viewer));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-10-15 11:33:26 +04:00
|
|
|
NS_ENSURE_TRUE(viewer, NS_ERROR_UNEXPECTED);
|
2010-09-09 00:40:39 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIParser> parser = do_QueryInterface(listener);
|
|
|
|
NS_ENSURE_TRUE(parser, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
// XML-only, because this is for SVG content
|
|
|
|
nsIContentSink* sink = parser->GetContentSink();
|
|
|
|
nsCOMPtr<nsIXMLContentSink> xmlSink = do_QueryInterface(sink);
|
|
|
|
NS_ENSURE_TRUE(sink, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
listener.swap(mListener);
|
2011-10-15 11:33:26 +04:00
|
|
|
viewer.forget(aViewer);
|
|
|
|
newLoadGroup.forget(aLoadGroup);
|
2010-09-09 00:40:39 +04:00
|
|
|
|
|
|
|
RegisterForXPCOMShutdown();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGDocumentWrapper::RegisterForXPCOMShutdown()
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mRegisteredForXPCOMShutdown,
|
|
|
|
"re-registering for XPCOM shutdown");
|
2010-09-09 00:40:39 +04:00
|
|
|
// 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,
|
2011-10-17 18:59:28 +04:00
|
|
|
true))) {
|
2010-09-09 00:40:39 +04:00
|
|
|
NS_WARNING("Failed to register as observer of XPCOM shutdown");
|
2010-11-08 20:45:18 +03:00
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
mRegisteredForXPCOMShutdown = true;
|
2010-11-08 20:45:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGDocumentWrapper::UnregisterForXPCOMShutdown()
|
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mRegisteredForXPCOMShutdown,
|
|
|
|
"unregistering for XPCOM shutdown w/out being registered");
|
2010-11-08 20:45:18 +03:00
|
|
|
|
|
|
|
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 {
|
2011-10-17 18:59:28 +04:00
|
|
|
mRegisteredForXPCOMShutdown = false;
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGDocumentWrapper::FlushLayout()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
mViewer->GetPresShell(getter_AddRefs(presShell));
|
|
|
|
if (presShell) {
|
|
|
|
presShell->FlushPendingNotifications(Flush_Layout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 06:04:08 +04:00
|
|
|
nsIDocument*
|
|
|
|
SVGDocumentWrapper::GetDocument()
|
|
|
|
{
|
2015-03-04 15:18:00 +03:00
|
|
|
if (!mViewer) {
|
2013-02-14 06:04:08 +04:00
|
|
|
return nullptr;
|
2015-03-04 15:18:00 +03:00
|
|
|
}
|
2013-02-14 06:04:08 +04:00
|
|
|
|
|
|
|
return mViewer->GetDocument(); // May be nullptr.
|
|
|
|
}
|
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement*
|
2010-09-09 00:40:39 +04:00
|
|
|
SVGDocumentWrapper::GetRootSVGElem()
|
|
|
|
{
|
2015-03-04 15:18:00 +03:00
|
|
|
if (!mViewer) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr; // Can happen during destruction
|
2015-03-04 15:18:00 +03:00
|
|
|
}
|
2010-09-09 00:40:40 +04:00
|
|
|
|
|
|
|
nsIDocument* doc = mViewer->GetDocument();
|
2015-03-04 15:18:00 +03:00
|
|
|
if (!doc) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr; // Can happen during destruction
|
2015-03-04 15:18:00 +03:00
|
|
|
}
|
2010-09-09 00:40:40 +04:00
|
|
|
|
2010-09-09 00:40:39 +04:00
|
|
|
Element* rootElem = mViewer->GetDocument()->GetRootElement();
|
2015-03-03 14:08:59 +03:00
|
|
|
if (!rootElem || !rootElem->IsSVGElement(nsGkAtoms::svg)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 03:02:45 +04:00
|
|
|
return static_cast<SVGSVGElement*>(rootElem);
|
2010-09-09 00:40:39 +04:00
|
|
|
}
|
|
|
|
|
2012-01-06 20:02:27 +04:00
|
|
|
} // namespace image
|
2010-09-09 00:40:39 +04:00
|
|
|
} // namespace mozilla
|