michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/dom/SVGDocument.h" michael@0: #include "nsString.h" michael@0: #include "nsLiteralString.h" michael@0: #include "nsIDOMSVGElement.h" michael@0: #include "mozilla/dom/Element.h" michael@0: #include "nsSVGElement.h" michael@0: #include "mozilla/dom/SVGDocumentBinding.h" michael@0: michael@0: using namespace mozilla::dom; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // Implementation michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // nsISupports methods: michael@0: michael@0: void michael@0: SVGDocument::GetDomain(nsAString& aDomain, ErrorResult& aRv) michael@0: { michael@0: SetDOMStringToNull(aDomain); michael@0: michael@0: if (mDocumentURI) { michael@0: nsAutoCString domain; michael@0: nsresult rv = mDocumentURI->GetHost(domain); michael@0: if (NS_FAILED(rv)) { michael@0: aRv.Throw(rv); michael@0: return; michael@0: } michael@0: if (domain.IsEmpty()) { michael@0: return; michael@0: } michael@0: CopyUTF8toUTF16(domain, aDomain); michael@0: } michael@0: } michael@0: michael@0: nsSVGElement* michael@0: SVGDocument::GetRootElement(ErrorResult& aRv) michael@0: { michael@0: Element* root = nsDocument::GetRootElement(); michael@0: if (!root) { michael@0: return nullptr; michael@0: } michael@0: if (!root->IsSVG()) { michael@0: aRv.Throw(NS_NOINTERFACE); michael@0: return nullptr; michael@0: } michael@0: return static_cast(root); michael@0: } michael@0: michael@0: nsresult michael@0: SVGDocument::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const michael@0: { michael@0: NS_ASSERTION(aNodeInfo->NodeInfoManager() == mNodeInfoManager, michael@0: "Can't import this document into another document!"); michael@0: michael@0: nsRefPtr clone = new SVGDocument(); michael@0: nsresult rv = CloneDocHelper(clone.get()); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: return CallQueryInterface(clone.get(), aResult); michael@0: } michael@0: michael@0: JSObject* michael@0: SVGDocument::WrapNode(JSContext *aCx) michael@0: { michael@0: return SVGDocumentBinding::Wrap(aCx, this); michael@0: } michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: //////////////////////////////////////////////////////////////////////// michael@0: // Exported creation functions michael@0: michael@0: nsresult michael@0: NS_NewSVGDocument(nsIDocument** aInstancePtrResult) michael@0: { michael@0: nsRefPtr doc = new SVGDocument(); michael@0: michael@0: nsresult rv = doc->Init(); michael@0: if (NS_FAILED(rv)) { michael@0: return rv; michael@0: } michael@0: michael@0: doc.forget(aInstancePtrResult); michael@0: return rv; michael@0: }