Bug 848386 part 5. Convert SVGDocument to WebIDL. r=peterv

This commit is contained in:
Boris Zbarsky 2013-03-20 12:22:26 -04:00
parent 2b660bfe74
commit c29c55e65d
5 changed files with 72 additions and 7 deletions

View File

@ -37,6 +37,7 @@ INCLUDES += \
-I$(srcdir)/../../../base/src \
-I$(srcdir)/../../../events/src \
-I$(topsrcdir)/xpcom/ds \
-I$(topsrcdir)/content/svg/content/src \
$(NULL)
DEFINES += -D_IMPL_NS_LAYOUT

View File

@ -8,6 +8,8 @@
#include "nsLiteralString.h"
#include "nsIDOMSVGElement.h"
#include "mozilla/dom/Element.h"
#include "nsSVGElement.h"
#include "mozilla/dom/SVGDocumentBinding.h"
using namespace mozilla::dom;
@ -21,6 +23,7 @@ namespace dom {
SVGDocument::SVGDocument()
{
SetIsDOMBinding();
}
SVGDocument::~SVGDocument()
@ -46,28 +49,53 @@ NS_IMPL_RELEASE_INHERITED(SVGDocument, XMLDocument)
/* readonly attribute DOMString domain; */
NS_IMETHODIMP
SVGDocument::GetDomain(nsAString& aDomain)
{
ErrorResult rv;
GetDomain(aDomain, rv);
return rv.ErrorCode();
}
void
SVGDocument::GetDomain(nsAString& aDomain, ErrorResult& aRv)
{
SetDOMStringToNull(aDomain);
if (mDocumentURI) {
nsAutoCString domain;
nsresult rv = mDocumentURI->GetHost(domain);
if (domain.IsEmpty() || NS_FAILED(rv))
return rv;
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return;
}
if (domain.IsEmpty()) {
return;
}
CopyUTF8toUTF16(domain, aDomain);
}
return NS_OK;
}
/* readonly attribute SVGSVGElement rootElement; */
NS_IMETHODIMP
SVGDocument::GetRootElement(nsIDOMSVGElement** aRootElement)
{
*aRootElement = nullptr;
Element* root = nsDocument::GetRootElement();
ErrorResult rv;
nsCOMPtr<nsIDOMSVGElement> retval = do_QueryInterface(GetRootElement(rv));
retval.forget(aRootElement);
return rv.ErrorCode();
}
return root ? CallQueryInterface(root, aRootElement) : NS_OK;
nsSVGElement*
SVGDocument::GetRootElement(ErrorResult& aRv)
{
Element* root = nsDocument::GetRootElement();
if (!root) {
return nullptr;
}
if (!root->IsSVG()) {
aRv.Throw(NS_NOINTERFACE);
return nullptr;
}
return static_cast<nsSVGElement*>(root);
}
nsresult
@ -84,6 +112,16 @@ SVGDocument::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
return CallQueryInterface(clone.get(), aResult);
}
JSObject*
SVGDocument::WrapNode(JSContext *aCx, JSObject *aScope)
{
JSObject* obj = SVGDocumentBinding::Wrap(aCx, aScope, this);
if (obj && !PostCreateWrapper(aCx, obj)) {
return nullptr;
}
return obj;
}
} // namespace dom
} // namespace mozilla

View File

@ -9,6 +9,8 @@
#include "mozilla/dom/XMLDocument.h"
#include "nsIDOMSVGDocument.h"
class nsSVGElement;
namespace mozilla {
namespace dom {
@ -30,11 +32,19 @@ public:
using nsDocument::GetLastStyleSheetSet;
using nsDocument::MozSetImageElement;
using nsDocument::GetMozFullScreenElement;
using nsIDocument::GetLocation;
NS_FORWARD_NSIDOMNODE_TO_NSINODE
NS_DECL_ISUPPORTS_INHERITED
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
virtual nsXPCClassInfo* GetClassInfo();
// WebIDL API
void GetDomain(nsAString& aDomain, ErrorResult& aRv);
nsSVGElement* GetRootElement(ErrorResult& aRv);
protected:
virtual JSObject* WrapNode(JSContext *aCx, JSObject *aScope) MOZ_OVERRIDE;
};
} // namespace dom

View File

@ -0,0 +1,15 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The origin of this IDL file is:
* dom/interfaces/svg/nsIDOMSVGDocument.idl
*/
interface SVGDocument : Document {
[Throws]
readonly attribute DOMString domain;
[Throws]
readonly attribute SVGElement? rootElement;
};

View File

@ -180,6 +180,7 @@ webidl_files = \
SVGComponentTransferFunctionElement.webidl \
SVGDefsElement.webidl \
SVGDescElement.webidl \
SVGDocument.webidl \
SVGElement.webidl \
SVGEllipseElement.webidl \
SVGFilterElement.webidl \