Bug 839022 - Convert HTMLSourceElement to WebIDL. r=Ms2ger
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 07 Feb 2013 10:39:10 -0500
changeset 121174 9115c939592591b0f16f7f45feaf0c718603c0f1
parent 121173 964d45caa4dc84fcbd909caec2d478d0a1e848e1
child 121175 0c9b624f525f289fd32af01ef9187f632a8d3a5f
push id24276
push userryanvm@gmail.com
push dateThu, 07 Feb 2013 21:40:43 +0000
treeherdermozilla-central@eb8f60c782da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
bugs839022
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 839022 - Convert HTMLSourceElement to WebIDL. r=Ms2ger
content/html/content/src/HTMLSourceElement.cpp
content/html/content/src/HTMLSourceElement.h
content/html/content/test/reflect.js
dom/bindings/Bindings.conf
dom/webidl/HTMLSourceElement.webidl
dom/webidl/WebIDL.mk
--- a/content/html/content/src/HTMLSourceElement.cpp
+++ b/content/html/content/src/HTMLSourceElement.cpp
@@ -1,25 +1,27 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* 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/. */
 
 #include "mozilla/dom/HTMLSourceElement.h"
+#include "mozilla/dom/HTMLSourceElementBinding.h"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Source)
 DOMCI_NODE_DATA(HTMLSourceElement, mozilla::dom::HTMLSourceElement)
 
 namespace mozilla {
 namespace dom {
 
 HTMLSourceElement::HTMLSourceElement(already_AddRefed<nsINodeInfo> aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
+  SetIsDOMBinding();
 }
 
 HTMLSourceElement::~HTMLSourceElement()
 {
 }
 
 
 NS_IMPL_ADDREF_INHERITED(HTMLSourceElement, Element)
@@ -70,10 +72,17 @@ HTMLSourceElement::BindToTree(nsIDocumen
     return NS_OK;
 
   nsHTMLMediaElement* media = static_cast<nsHTMLMediaElement*>(aParent);
   media->NotifyAddedSource();
 
   return NS_OK;
 }
 
+JSObject*
+HTMLSourceElement::WrapNode(JSContext* aCx, JSObject* aScope,
+                            bool* aTriedToWrap)
+{
+  return HTMLSourceElementBinding::Wrap(aCx, aScope, this, aTriedToWrap);
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/content/html/content/src/HTMLSourceElement.h
+++ b/content/html/content/src/HTMLSourceElement.h
@@ -31,28 +31,60 @@ public:
   NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT_TO_GENERIC
 
   // nsIDOMHTMLSourceElement
   NS_DECL_NSIDOMHTMLSOURCEELEMENT
 
-  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
+  virtual nsresult Clone(nsINodeInfo* aNodeInfo, nsINode** aResult) const;
 
   // Override BindToTree() so that we can trigger a load when we add a
   // child source element.
-  virtual nsresult BindToTree(nsIDocument *aDocument, nsIContent *aParent,
-                              nsIContent *aBindingParent,
+  virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
+                              nsIContent* aBindingParent,
                               bool aCompileEventHandlers);
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 
+  // WebIDL
+  void GetSrc(nsString& aSrc)
+  {
+    GetURIAttr(nsGkAtoms::src, nullptr, aSrc);
+  }
+  void SetSrc(const nsAString& aSrc, mozilla::ErrorResult& rv)
+  {
+    SetHTMLAttr(nsGkAtoms::src, aSrc, rv);
+  }
+
+  void GetType(nsString& aType)
+  {
+    GetHTMLAttr(nsGkAtoms::type, aType);
+  }
+  void SetType(const nsAString& aType, ErrorResult& rv)
+  {
+    SetHTMLAttr(nsGkAtoms::type, aType, rv);
+  }
+
+  void GetMedia(nsString& aMedia)
+  {
+    GetHTMLAttr(nsGkAtoms::media, aMedia);
+  }
+  void SetMedia(const nsAString& aMedia, mozilla::ErrorResult& rv)
+  {
+    SetHTMLAttr(nsGkAtoms::media, aMedia, rv);
+  }
+
+protected:
+  virtual JSObject* WrapNode(JSContext* aCx, JSObject* aScope,
+                             bool* aTriedToWrap) MOZ_OVERRIDE;
+
 protected:
   virtual void GetItemValueText(nsAString& text);
   virtual void SetItemValueText(const nsAString& text);
 };
 
 } // namespace dom
 } // namespace mozilla
 
--- a/content/html/content/test/reflect.js
+++ b/content/html/content/test/reflect.js
@@ -55,17 +55,16 @@ function reflectString(aParameters)
   element.removeAttribute(contentAttr);
 
   element[idlAttr] = null;
   // TODO: remove this ugly hack when null stringification will work as expected.
   var todoAttrs = {
     form: [ "acceptCharset", "name", "target" ],
     input: [ "accept", "alt", "formTarget", "max", "min", "name", "pattern", "placeholder", "step", "defaultValue" ],
     link: [ "crossOrigin" ],
-    source: [ "media" ],
     textarea: [ "name", "placeholder" ]
   };
   if (!(element.localName in todoAttrs) || todoAttrs[element.localName].indexOf(idlAttr) == -1) {
     is(element.getAttribute(contentAttr), "null",
        "null should have been stringified to 'null'");
     is(element[idlAttr], "null", "null should have been stringified to 'null'");
     element.removeAttribute(contentAttr);
   } else {
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -465,16 +465,20 @@ DOMInterfaces = {
     'headerFile': 'HTMLPropertiesCollection.h',
     'resultNotAddRefed': [ 'item', 'namedItem', 'names' ]
 },
 
 'HTMLScriptElement': {
   'hasInstanceInterface': 'nsIDOMHTMLScriptElement',
 },
 
+'HTMLSourceElement': {
+    'hasInstanceInterface': 'nsIDOMHTMLSourceElement',
+},
+
 'HTMLTableCellElement': {
     'hasInstanceInterface': 'nsIDOMHTMLTableCellElement'
 },
 
 'HTMLTableColElement': {
     'hasInstanceInterface': 'nsIDOMHTMLTableColElement'
 },
 
new file mode 100644
--- /dev/null
+++ b/dom/webidl/HTMLSourceElement.webidl
@@ -0,0 +1,21 @@
+/* -*- 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-source-element
+ *
+ * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and
+ * Opera Software ASA. You are granted a license to use, reproduce
+ * and create derivative works of this document.
+ */
+
+interface HTMLSourceElement : HTMLElement {
+           [SetterThrows]
+           attribute DOMString src;
+           [SetterThrows]
+           attribute DOMString type;
+           [SetterThrows]
+           attribute DOMString media;
+};
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -191,16 +191,22 @@ webidl_files = \
   XMLHttpRequestEventTarget.webidl \
   XMLHttpRequestUpload.webidl \
   XMLSerializer.webidl \
   XMLStylesheetProcessingInstruction.webidl \
   XPathEvaluator.webidl \
   XULElement.webidl \
   $(NULL)
 
+ifdef MOZ_MEDIA
+webidl_files += \
+  HTMLSourceElement.webidl \
+  $(NULL)
+endif
+
 ifdef MOZ_WEBGL
 webidl_files += \
   WebGLRenderingContext.webidl \
   $(NULL)
 endif
 
 ifdef MOZ_WEBRTC
 webidl_files += \