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