1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/svg/document/src/SVGDocument.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,95 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "mozilla/dom/SVGDocument.h" 1.10 +#include "nsString.h" 1.11 +#include "nsLiteralString.h" 1.12 +#include "nsIDOMSVGElement.h" 1.13 +#include "mozilla/dom/Element.h" 1.14 +#include "nsSVGElement.h" 1.15 +#include "mozilla/dom/SVGDocumentBinding.h" 1.16 + 1.17 +using namespace mozilla::dom; 1.18 + 1.19 +namespace mozilla { 1.20 +namespace dom { 1.21 + 1.22 +//---------------------------------------------------------------------- 1.23 +// Implementation 1.24 + 1.25 +//---------------------------------------------------------------------- 1.26 +// nsISupports methods: 1.27 + 1.28 +void 1.29 +SVGDocument::GetDomain(nsAString& aDomain, ErrorResult& aRv) 1.30 +{ 1.31 + SetDOMStringToNull(aDomain); 1.32 + 1.33 + if (mDocumentURI) { 1.34 + nsAutoCString domain; 1.35 + nsresult rv = mDocumentURI->GetHost(domain); 1.36 + if (NS_FAILED(rv)) { 1.37 + aRv.Throw(rv); 1.38 + return; 1.39 + } 1.40 + if (domain.IsEmpty()) { 1.41 + return; 1.42 + } 1.43 + CopyUTF8toUTF16(domain, aDomain); 1.44 + } 1.45 +} 1.46 + 1.47 +nsSVGElement* 1.48 +SVGDocument::GetRootElement(ErrorResult& aRv) 1.49 +{ 1.50 + Element* root = nsDocument::GetRootElement(); 1.51 + if (!root) { 1.52 + return nullptr; 1.53 + } 1.54 + if (!root->IsSVG()) { 1.55 + aRv.Throw(NS_NOINTERFACE); 1.56 + return nullptr; 1.57 + } 1.58 + return static_cast<nsSVGElement*>(root); 1.59 +} 1.60 + 1.61 +nsresult 1.62 +SVGDocument::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const 1.63 +{ 1.64 + NS_ASSERTION(aNodeInfo->NodeInfoManager() == mNodeInfoManager, 1.65 + "Can't import this document into another document!"); 1.66 + 1.67 + nsRefPtr<SVGDocument> clone = new SVGDocument(); 1.68 + nsresult rv = CloneDocHelper(clone.get()); 1.69 + NS_ENSURE_SUCCESS(rv, rv); 1.70 + 1.71 + return CallQueryInterface(clone.get(), aResult); 1.72 +} 1.73 + 1.74 +JSObject* 1.75 +SVGDocument::WrapNode(JSContext *aCx) 1.76 +{ 1.77 + return SVGDocumentBinding::Wrap(aCx, this); 1.78 +} 1.79 + 1.80 +} // namespace dom 1.81 +} // namespace mozilla 1.82 + 1.83 +//////////////////////////////////////////////////////////////////////// 1.84 +// Exported creation functions 1.85 + 1.86 +nsresult 1.87 +NS_NewSVGDocument(nsIDocument** aInstancePtrResult) 1.88 +{ 1.89 + nsRefPtr<SVGDocument> doc = new SVGDocument(); 1.90 + 1.91 + nsresult rv = doc->Init(); 1.92 + if (NS_FAILED(rv)) { 1.93 + return rv; 1.94 + } 1.95 + 1.96 + doc.forget(aInstancePtrResult); 1.97 + return rv; 1.98 +}