From 4bbe6e8a416a7c98a82405c1871139bc0a12c0aa Mon Sep 17 00:00:00 2001 From: David Zbarsky Date: Sat, 5 Jan 2013 04:41:28 -0500 Subject: [PATCH] Bug 826947: Convert HTMLScriptElement to WebIDL r=bz --- .../html/content/src/HTMLScriptElement.cpp | 86 +++++++++++++++++-- content/html/content/src/HTMLScriptElement.h | 18 ++++ content/html/content/test/reflect.js | 1 - content/html/content/test/test_bug389797.html | 2 +- dom/base/nsDOMClassInfo.cpp | 1 + dom/bindings/Bindings.conf | 4 + dom/webidl/HTMLScriptElement.webidl | 37 ++++++++ dom/webidl/WebIDL.mk | 1 + 8 files changed, 143 insertions(+), 7 deletions(-) create mode 100644 dom/webidl/HTMLScriptElement.webidl diff --git a/content/html/content/src/HTMLScriptElement.cpp b/content/html/content/src/HTMLScriptElement.cpp index 0878abf3a8bd..765f9b5694a8 100644 --- a/content/html/content/src/HTMLScriptElement.cpp +++ b/content/html/content/src/HTMLScriptElement.cpp @@ -4,12 +4,10 @@ * 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/. */ -#include "nsIDOMHTMLScriptElement.h" #include "nsIDOMEventTarget.h" #include "nsGkAtoms.h" #include "nsStyleConsts.h" #include "nsIDocument.h" -#include "nsScriptElement.h" #include "nsIURI.h" #include "nsNetUtil.h" #include "nsContentUtils.h" @@ -24,6 +22,7 @@ #include "nsTArray.h" #include "nsDOMJSUtils.h" #include "mozilla/dom/HTMLScriptElement.h" +#include "mozilla/dom/HTMLScriptElementBinding.h" NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(Script) @@ -32,11 +31,18 @@ DOMCI_NODE_DATA(HTMLScriptElement, mozilla::dom::HTMLScriptElement) namespace mozilla { namespace dom { +JSObject* +HTMLScriptElement::WrapNode(JSContext *aCx, JSObject *aScope, bool *aTriedToWrap) +{ + return HTMLScriptElementBinding::Wrap(aCx, aScope, this, aTriedToWrap); +} + HTMLScriptElement::HTMLScriptElement(already_AddRefed aNodeInfo, FromParser aFromParser) : nsGenericHTMLElement(aNodeInfo) , nsScriptElement(aFromParser) { + SetIsDOMBinding(); AddMutationObserver(this); } @@ -127,7 +133,15 @@ HTMLScriptElement::GetText(nsAString& aValue) NS_IMETHODIMP HTMLScriptElement::SetText(const nsAString& aValue) { - return nsContentUtils::SetNodeTextContent(this, aValue, true); + ErrorResult rv; + SetText(aValue, rv); + return rv.ErrorCode(); +} + +void +HTMLScriptElement::SetText(const nsAString& aValue, ErrorResult& rv) +{ + rv = nsContentUtils::SetNodeTextContent(this, aValue, true); } @@ -139,18 +153,80 @@ NS_IMPL_STRING_ATTR(HTMLScriptElement, HtmlFor, _for) NS_IMPL_STRING_ATTR(HTMLScriptElement, Event, event) NS_IMPL_STRING_ATTR(HTMLScriptElement, CrossOrigin, crossorigin) +void +HTMLScriptElement::SetCharset(const nsAString& aCharset, ErrorResult& rv) +{ + SetHTMLAttr(nsGkAtoms::charset, aCharset, rv); +} + +void +HTMLScriptElement::SetDefer(bool aDefer, ErrorResult& rv) +{ + SetHTMLBoolAttr(nsGkAtoms::defer, aDefer, rv); +} + +bool +HTMLScriptElement::Defer() +{ + return GetBoolAttr(nsGkAtoms::defer); +} + +void +HTMLScriptElement::SetSrc(const nsAString& aSrc, ErrorResult& rv) +{ + rv = SetAttrHelper(nsGkAtoms::src, aSrc); +} + +void +HTMLScriptElement::SetType(const nsAString& aType, ErrorResult& rv) +{ + SetHTMLAttr(nsGkAtoms::type, aType, rv); +} + +void +HTMLScriptElement::SetHtmlFor(const nsAString& aHtmlFor, ErrorResult& rv) +{ + SetHTMLAttr(nsGkAtoms::_for, aHtmlFor, rv); +} + +void +HTMLScriptElement::SetEvent(const nsAString& aEvent, ErrorResult& rv) +{ + SetHTMLAttr(nsGkAtoms::event, aEvent, rv); +} + +void +HTMLScriptElement::SetCrossOrigin(const nsAString& aCrossOrigin, ErrorResult& rv) +{ + SetHTMLAttr(nsGkAtoms::crossorigin, aCrossOrigin, rv); +} + nsresult HTMLScriptElement::GetAsync(bool* aValue) { - *aValue = mForceAsync || GetBoolAttr(nsGkAtoms::async); + *aValue = Async(); return NS_OK; } +bool +HTMLScriptElement::Async() +{ + return mForceAsync || GetBoolAttr(nsGkAtoms::async); +} + nsresult HTMLScriptElement::SetAsync(bool aValue) +{ + ErrorResult rv; + SetAsync(aValue, rv); + return rv.ErrorCode(); +} + +void +HTMLScriptElement::SetAsync(bool aValue, ErrorResult& rv) { mForceAsync = false; - return SetBoolAttr(nsGkAtoms::async, aValue); + SetHTMLBoolAttr(nsGkAtoms::async, aValue, rv); } nsresult diff --git a/content/html/content/src/HTMLScriptElement.h b/content/html/content/src/HTMLScriptElement.h index e6acbc507528..49049947d61c 100644 --- a/content/html/content/src/HTMLScriptElement.h +++ b/content/html/content/src/HTMLScriptElement.h @@ -7,6 +7,8 @@ #ifndef mozilla_dom_HTMLScriptElement_h #define mozilla_dom_HTMLScriptElement_h +#include "nsIDOMHTMLScriptElement.h" +#include "nsScriptElement.h" #include "nsGenericHTMLElement.h" #include "mozilla/Attributes.h" @@ -70,7 +72,23 @@ public: virtual nsXPCClassInfo* GetClassInfo(); virtual nsIDOMNode* AsDOMNode() { return this; } + + // WebIDL + void SetText(const nsAString& aValue, ErrorResult& rv); + void SetCharset(const nsAString& aCharset, ErrorResult& rv); + void SetDefer(bool aDefer, ErrorResult& rv); + bool Defer(); + void SetSrc(const nsAString& aSrc, ErrorResult& rv); + void SetType(const nsAString& aType, ErrorResult& rv); + void SetHtmlFor(const nsAString& aHtmlFor, ErrorResult& rv); + void SetEvent(const nsAString& aEvent, ErrorResult& rv); + void SetCrossOrigin(const nsAString& aCrossOrigin, ErrorResult& rv); + bool Async(); + void SetAsync(bool aValue, ErrorResult& rv); + protected: + virtual JSObject* WrapNode(JSContext *aCx, JSObject *aScope, + bool *aTriedToWrap) MOZ_OVERRIDE; // nsScriptElement virtual bool HasScriptContent(); }; diff --git a/content/html/content/test/reflect.js b/content/html/content/test/reflect.js index 7c1ea22c61e2..e141fb3a0bc3 100644 --- a/content/html/content/test/reflect.js +++ b/content/html/content/test/reflect.js @@ -63,7 +63,6 @@ function reflectString(aParameters) img: [ "align" ], input: [ "accept", "alt", "formTarget", "max", "min", "name", "pattern", "placeholder", "step", "defaultValue" ], link: [ "crossOrigin" ], - script: [ "crossOrigin" ], source: [ "media" ], table: [ "border", "width" ], tbody: [ "align", "vAlign", "ch" ], diff --git a/content/html/content/test/test_bug389797.html b/content/html/content/test/test_bug389797.html index 4e098a39b9bd..35b36097eaa9 100644 --- a/content/html/content/test/test_bug389797.html +++ b/content/html/content/test/test_bug389797.html @@ -195,7 +195,7 @@ HTML_TAG("pre", "Pre"); HTML_TAG("q", "Quote"); HTML_TAG("s", ""); HTML_TAG("samp", ""); -HTML_TAG("script", "Script", [], [ "nsIScriptLoaderObserver" ]); +HTML_TAG("script", "Script", [ "nsIScriptLoaderObserver" ], []); HTML_TAG("section", "") HTML_TAG("select", "Select", ["nsIDOMHTMLSelectElement"]); HTML_TAG("small", ""); diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 77bb605cbcc8..85bf2eb8c2ae 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -2750,6 +2750,7 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(HTMLScriptElement, nsIDOMHTMLScriptElement) + DOM_CLASSINFO_MAP_ENTRY(nsIScriptLoaderObserver) DOM_CLASSINFO_MAP_ENTRY(nsIDOMHTMLScriptElement) DOM_CLASSINFO_GENERIC_HTML_MAP_ENTRIES DOM_CLASSINFO_MAP_END diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 0e564339cd97..7ad13231e92e 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -418,6 +418,10 @@ DOMInterfaces = { 'resultNotAddRefed': [ 'item', 'namedItem', 'names' ] }, +'HTMLScriptElement': { + 'hasInstanceInterface': 'nsIDOMHTMLScriptElement', +}, + 'HTMLUListElement': { 'headerFile' : 'mozilla/dom/HTMLSharedListElement.h' }, diff --git a/dom/webidl/HTMLScriptElement.webidl b/dom/webidl/HTMLScriptElement.webidl new file mode 100644 index 000000000000..16482f5de56a --- /dev/null +++ b/dom/webidl/HTMLScriptElement.webidl @@ -0,0 +1,37 @@ +/* -*- 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 + * http://www.whatwg.org/specs/web-apps/current-work/#the-script-element + * http://www.whatwg.org/specs/web-apps/current-work/#other-elements,-attributes-and-apis + */ + +interface HTMLScriptElement : HTMLElement { + [SetterThrows] + attribute DOMString src; + [SetterThrows] + attribute DOMString type; + [SetterThrows] + attribute DOMString charset; + [SetterThrows] + attribute boolean async; + [SetterThrows] + attribute boolean defer; + [SetterThrows] + attribute DOMString crossOrigin; + [SetterThrows] + attribute DOMString text; +/* +}; + +// http://www.whatwg.org/specs/web-apps/current-work/#other-elements,-attributes-and-apis +partial interface HTMLScriptElement { +*/ + [SetterThrows] + attribute DOMString event; + [SetterThrows] + attribute DOMString htmlFor; +}; + diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index 6148d120130b..d0ea3d795de1 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -71,6 +71,7 @@ webidl_files = \ HTMLParagraphElement.webidl \ HTMLPreElement.webidl \ HTMLPropertiesCollection.webidl \ + HTMLScriptElement.webidl \ HTMLSpanElement.webidl \ HTMLTitleElement.webidl \ HTMLUListElement.webidl \