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

     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/. */
     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"
    14 using namespace mozilla::dom;
    16 namespace mozilla {
    17 namespace dom {
    19 //----------------------------------------------------------------------
    20 // Implementation
    22 //----------------------------------------------------------------------
    23 // nsISupports methods:
    25 void
    26 SVGDocument::GetDomain(nsAString& aDomain, ErrorResult& aRv)
    27 {
    28   SetDOMStringToNull(aDomain);
    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 }
    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 }
    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!");
    64   nsRefPtr<SVGDocument> clone = new SVGDocument();
    65   nsresult rv = CloneDocHelper(clone.get());
    66   NS_ENSURE_SUCCESS(rv, rv);
    68   return CallQueryInterface(clone.get(), aResult);
    69 }
    71 JSObject*
    72 SVGDocument::WrapNode(JSContext *aCx)
    73 {
    74   return SVGDocumentBinding::Wrap(aCx, this);
    75 }
    77 } // namespace dom
    78 } // namespace mozilla
    80 ////////////////////////////////////////////////////////////////////////
    81 // Exported creation functions
    83 nsresult
    84 NS_NewSVGDocument(nsIDocument** aInstancePtrResult)
    85 {
    86   nsRefPtr<SVGDocument> doc = new SVGDocument();
    88   nsresult rv = doc->Init();
    89   if (NS_FAILED(rv)) {
    90     return rv;
    91   }
    93   doc.forget(aInstancePtrResult);
    94   return rv;
    95 }

mercurial