content/svg/document/src/SVGDocument.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "mozilla/dom/SVGDocument.h"
michael@0 7 #include "nsString.h"
michael@0 8 #include "nsLiteralString.h"
michael@0 9 #include "nsIDOMSVGElement.h"
michael@0 10 #include "mozilla/dom/Element.h"
michael@0 11 #include "nsSVGElement.h"
michael@0 12 #include "mozilla/dom/SVGDocumentBinding.h"
michael@0 13
michael@0 14 using namespace mozilla::dom;
michael@0 15
michael@0 16 namespace mozilla {
michael@0 17 namespace dom {
michael@0 18
michael@0 19 //----------------------------------------------------------------------
michael@0 20 // Implementation
michael@0 21
michael@0 22 //----------------------------------------------------------------------
michael@0 23 // nsISupports methods:
michael@0 24
michael@0 25 void
michael@0 26 SVGDocument::GetDomain(nsAString& aDomain, ErrorResult& aRv)
michael@0 27 {
michael@0 28 SetDOMStringToNull(aDomain);
michael@0 29
michael@0 30 if (mDocumentURI) {
michael@0 31 nsAutoCString domain;
michael@0 32 nsresult rv = mDocumentURI->GetHost(domain);
michael@0 33 if (NS_FAILED(rv)) {
michael@0 34 aRv.Throw(rv);
michael@0 35 return;
michael@0 36 }
michael@0 37 if (domain.IsEmpty()) {
michael@0 38 return;
michael@0 39 }
michael@0 40 CopyUTF8toUTF16(domain, aDomain);
michael@0 41 }
michael@0 42 }
michael@0 43
michael@0 44 nsSVGElement*
michael@0 45 SVGDocument::GetRootElement(ErrorResult& aRv)
michael@0 46 {
michael@0 47 Element* root = nsDocument::GetRootElement();
michael@0 48 if (!root) {
michael@0 49 return nullptr;
michael@0 50 }
michael@0 51 if (!root->IsSVG()) {
michael@0 52 aRv.Throw(NS_NOINTERFACE);
michael@0 53 return nullptr;
michael@0 54 }
michael@0 55 return static_cast<nsSVGElement*>(root);
michael@0 56 }
michael@0 57
michael@0 58 nsresult
michael@0 59 SVGDocument::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
michael@0 60 {
michael@0 61 NS_ASSERTION(aNodeInfo->NodeInfoManager() == mNodeInfoManager,
michael@0 62 "Can't import this document into another document!");
michael@0 63
michael@0 64 nsRefPtr<SVGDocument> clone = new SVGDocument();
michael@0 65 nsresult rv = CloneDocHelper(clone.get());
michael@0 66 NS_ENSURE_SUCCESS(rv, rv);
michael@0 67
michael@0 68 return CallQueryInterface(clone.get(), aResult);
michael@0 69 }
michael@0 70
michael@0 71 JSObject*
michael@0 72 SVGDocument::WrapNode(JSContext *aCx)
michael@0 73 {
michael@0 74 return SVGDocumentBinding::Wrap(aCx, this);
michael@0 75 }
michael@0 76
michael@0 77 } // namespace dom
michael@0 78 } // namespace mozilla
michael@0 79
michael@0 80 ////////////////////////////////////////////////////////////////////////
michael@0 81 // Exported creation functions
michael@0 82
michael@0 83 nsresult
michael@0 84 NS_NewSVGDocument(nsIDocument** aInstancePtrResult)
michael@0 85 {
michael@0 86 nsRefPtr<SVGDocument> doc = new SVGDocument();
michael@0 87
michael@0 88 nsresult rv = doc->Init();
michael@0 89 if (NS_FAILED(rv)) {
michael@0 90 return rv;
michael@0 91 }
michael@0 92
michael@0 93 doc.forget(aInstancePtrResult);
michael@0 94 return rv;
michael@0 95 }

mercurial