Bug 819239. Add the WebIDL API for HTMLDocument. r=peterv

This commit is contained in:
Boris Zbarsky 2012-12-25 18:00:47 -08:00
parent 8c0d5d6a31
commit 69df260c60
4 changed files with 695 additions and 251 deletions

File diff suppressed because it is too large Load Diff

View File

@ -109,14 +109,6 @@ public:
nsWrapperCache **aCache,
nsresult *aResult);
Element *GetBody();
Element *GetHead() { return GetHeadElement(); }
already_AddRefed<nsContentList> GetElementsByName(const nsAString & aName)
{
return NS_GetFuncStringNodeList(this, MatchNameAttribute, nullptr,
UseExistingNameString, aName);
}
virtual nsresult ResolveName(const nsAString& aName,
nsIContent *aForm,
nsISupports **aResult,
@ -181,6 +173,76 @@ public:
virtual void DocSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const;
// DocSizeOfIncludingThis is inherited from nsIDocument.
// WebIDL API
void GetDomain(nsAString& aDomain, mozilla::ErrorResult& rv);
void SetDomain(const nsAString& aDomain, mozilla::ErrorResult& rv);
void GetCookie(nsAString& aCookie, mozilla::ErrorResult& rv);
void SetCookie(const nsAString& aCookie, mozilla::ErrorResult& rv);
nsGenericHTMLElement *GetBody();
void SetBody(nsGenericHTMLElement* aBody, mozilla::ErrorResult& rv);
Element *GetHead() { return GetHeadElement(); }
nsIHTMLCollection* Images();
nsIHTMLCollection* Embeds();
nsIHTMLCollection* Plugins();
nsIHTMLCollection* Links();
nsIHTMLCollection* Forms()
{
return nsHTMLDocument::GetForms();
}
nsIHTMLCollection* Scripts();
already_AddRefed<nsContentList> GetElementsByName(const nsAString & aName)
{
return NS_GetFuncStringNodeList(this, MatchNameAttribute, nullptr,
UseExistingNameString, aName);
}
already_AddRefed<nsINodeList> GetItems(const nsAString& aTypeNames);
already_AddRefed<nsIDocument> Open(JSContext* cx,
const nsAString& aType,
const nsAString& aReplace,
mozilla::ErrorResult& rv);
already_AddRefed<nsIDOMWindow> Open(JSContext* cx,
const nsAString& aURL,
const nsAString& aName,
const nsAString& aFeatures,
bool aReplace,
mozilla::ErrorResult& rv);
void Close(mozilla::ErrorResult& rv);
void Write(JSContext* cx, const mozilla::dom::Sequence<nsString>& aText,
mozilla::ErrorResult& rv);
void Writeln(JSContext* cx, const mozilla::dom::Sequence<nsString>& aText,
mozilla::ErrorResult& rv);
// The XPCOM GetDesignMode() works OK for us, since it never throws.
void SetDesignMode(const nsAString& aDesignMode, mozilla::ErrorResult& rv);
bool ExecCommand(const nsAString& aCommandID, bool aDoShowUI,
const nsAString& aValue, mozilla::ErrorResult& rv);
bool QueryCommandEnabled(const nsAString& aCommandID,
mozilla::ErrorResult& rv);
bool QueryCommandIndeterm(const nsAString& aCommandID,
mozilla::ErrorResult& rv);
bool QueryCommandState(const nsAString& aCommandID, mozilla::ErrorResult& rv);
bool QueryCommandSupported(const nsAString& aCommandID);
void QueryCommandValue(const nsAString& aCommandID, nsAString& aValue,
mozilla::ErrorResult& rv);
// The XPCOM Get/SetFgColor work OK for us, since they never throw.
// The XPCOM Get/SetLinkColor work OK for us, since they never throw.
// The XPCOM Get/SetVLinkColor work OK for us, since they never throw.
// The XPCOM Get/SetALinkColor work OK for us, since they never throw.
// The XPCOM Get/SetBgColor work OK for us, since they never throw.
nsIHTMLCollection* Anchors();
nsIHTMLCollection* Applets();
void Clear() const
{
// Deprecated
}
already_AddRefed<nsISelection> GetSelection(mozilla::ErrorResult& rv);
// The XPCOM CaptureEvents works fine for us.
// The XPCOM ReleaseEvents works fine for us.
// The XPCOM RouteEvent works fine for us.
// We're picking up GetLocation from Document
already_AddRefed<nsIDOMLocation> GetLocation() const {
return nsIDocument::GetLocation();
}
protected:
nsresult GetBodySize(int32_t* aWidth,
int32_t* aHeight);
@ -201,6 +263,11 @@ protected:
nsresult WriteCommon(JSContext *cx, const nsAString& aText,
bool aNewlineTerminate);
// A version of WriteCommon used by WebIDL bindings
void WriteCommon(JSContext *cx,
const mozilla::dom::Sequence<nsString>& aText,
bool aNewlineTerminate,
mozilla::ErrorResult& rv);
nsresult CreateAndAddWyciwygChannel(void);
nsresult RemoveWyciwygChannel(void);
@ -212,12 +279,12 @@ protected:
void *GenerateParserKey(void);
nsCOMPtr<nsIDOMHTMLCollection> mImages;
nsCOMPtr<nsIDOMHTMLCollection> mApplets;
nsCOMPtr<nsIDOMHTMLCollection> mEmbeds;
nsCOMPtr<nsIDOMHTMLCollection> mLinks;
nsCOMPtr<nsIDOMHTMLCollection> mAnchors;
nsCOMPtr<nsIDOMHTMLCollection> mScripts;
nsRefPtr<nsContentList> mImages;
nsRefPtr<nsContentList> mApplets;
nsRefPtr<nsContentList> mEmbeds;
nsRefPtr<nsContentList> mLinks;
nsRefPtr<nsContentList> mAnchors;
nsRefPtr<nsContentList> mScripts;
nsRefPtr<nsContentList> mForms;
nsRefPtr<nsContentList> mFormControls;

View File

@ -296,6 +296,13 @@ DOMInterfaces = {
]
},
'HTMLDocument': {
'nativeType': 'nsHTMLDocument',
'resultNotAddRefed': [ 'body', 'head', 'images', 'embeds', 'plugins',
'links', 'forms', 'scripts', 'anchors', 'applets' ],
'implicitJSContext': [ 'open', 'write', 'writeln' ]
},
'HTMLElement': {
'nativeType': 'nsGenericHTMLElement',
'hasXPConnectImpls': True,
@ -997,6 +1004,7 @@ addExternalIface('DOMRequest')
addExternalIface('DOMStringList')
addExternalIface('File')
addExternalIface('HitRegionOptions', nativeType='nsISupports')
addExternalIface('HTMLHeadElement', nativeType='mozilla::dom::Element')
addExternalIface('LockedFile')
addExternalIface('MediaStream')
addExternalIface('NamedNodeMap')
@ -1009,6 +1017,7 @@ addExternalIface('Principal', nativeType='nsIPrincipal',
addExternalIface('ProcessingInstruction', nativeType='nsXMLProcessingInstruction')
addExternalIface('Range', nativeType='nsRange')
addExternalIface("Rect")
addExternalIface('Selection', nativeType='nsISelection')
addExternalIface('StyleSheetList')
addExternalIface('SVGAnimatedString')
addExternalIface('SVGLength')

View File

@ -0,0 +1,77 @@
/* -*- 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/.
*/
interface HTMLHeadElement;
interface Selection;
interface HTMLDocument : Document {
[Throws]
attribute DOMString? domain;
[Throws]
attribute DOMString cookie;
// DOM tree accessors
//(Not proxy yet)getter object (DOMString name);
[SetterThrows]
attribute HTMLElement? body;
readonly attribute HTMLHeadElement? head;
readonly attribute HTMLCollection images;
readonly attribute HTMLCollection embeds;
readonly attribute HTMLCollection plugins;
readonly attribute HTMLCollection links;
readonly attribute HTMLCollection forms;
readonly attribute HTMLCollection scripts;
NodeList getElementsByName(DOMString elementName);
NodeList getItems(optional DOMString typeNames = ""); // microdata
// dynamic markup insertion
[Throws]
Document open(optional DOMString type = "text/html", optional DOMString replace = "");
[Throws]
WindowProxy open(DOMString url, DOMString name, DOMString features, optional boolean replace = false);
[Throws]
void close();
[Throws]
void write(DOMString... text);
[Throws]
void writeln(DOMString... text);
[SetterThrows]
attribute DOMString designMode;
[Throws]
boolean execCommand(DOMString commandId, optional boolean showUI = false,
optional DOMString value = "");
[Throws]
boolean queryCommandEnabled(DOMString commandId);
[Throws]
boolean queryCommandIndeterm(DOMString commandId);
[Throws]
boolean queryCommandState(DOMString commandId);
boolean queryCommandSupported(DOMString commandId);
[Throws]
DOMString queryCommandValue(DOMString commandId);
[TreatNullAs=EmptyString] attribute DOMString fgColor;
[TreatNullAs=EmptyString] attribute DOMString linkColor;
[TreatNullAs=EmptyString] attribute DOMString vlinkColor;
[TreatNullAs=EmptyString] attribute DOMString alinkColor;
[TreatNullAs=EmptyString] attribute DOMString bgColor;
readonly attribute HTMLCollection anchors;
readonly attribute HTMLCollection applets;
void clear();
// https://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#selections
[Throws]
Selection getSelection();
// @deprecated These are old Netscape 4 methods. Do not use,
// the implementation is no-op.
// XXXbz do we actually need these anymore?
void captureEvents(long eventFlags);
void releaseEvents(long eventFlags);
void routeEvent(Event evt);
};