Bug 837416 - Part 2: Move HTMLStyleElement to Web IDL bindings; r=bzbarsky
authorEhsan Akhgari <ehsan@mozilla.com>
Sun, 03 Feb 2013 12:42:40 -0500
changeset 120708 ff480fbd99a38c67659c28edc9925a03d542aa4e
parent 120707 a3117442985d9295b56ff591a85e852a64f1915b
child 120709 eef81a08397653c2fdcc902ebc870ce2c8b50444
push id22376
push usereakhgari@mozilla.com
push dateSun, 03 Feb 2013 23:01:15 +0000
treeherdermozilla-inbound@ff480fbd99a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs837416
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 837416 - Part 2: Move HTMLStyleElement to Web IDL bindings; r=bzbarsky
content/base/src/nsStyleLinkElement.h
content/html/content/src/HTMLStyleElement.cpp
content/html/content/src/HTMLStyleElement.h
content/html/content/src/nsHTMLLinkElement.cpp
content/html/content/test/reflect.js
content/xml/content/src/XMLStylesheetProcessingInstruction.h
dom/bindings/Bindings.conf
dom/webidl/HTMLStyleElement.webidl
dom/webidl/LinkStyle.webidl
dom/webidl/WebIDL.mk
--- a/content/base/src/nsStyleLinkElement.h
+++ b/content/base/src/nsStyleLinkElement.h
@@ -36,16 +36,18 @@ public:
   nsStyleLinkElement();
   virtual ~nsStyleLinkElement();
 
   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) = 0;
 
   // nsIDOMLinkStyle
   NS_DECL_NSIDOMLINKSTYLE
 
+  nsIStyleSheet* GetSheet() { return mStyleSheet; }
+
   // nsIStyleSheetLinkingElement  
   NS_IMETHOD SetStyleSheet(nsIStyleSheet* aStyleSheet);
   NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aStyleSheet);
   NS_IMETHOD InitStyleLinkElement(bool aDontLoadStyle);
   NS_IMETHOD UpdateStyleSheet(nsICSSLoaderObserver* aObserver,
                               bool* aWillNotify,
                               bool* aIsAlternate);
   NS_IMETHOD SetEnableUpdates(bool aEnableUpdates);
@@ -73,18 +75,16 @@ protected:
 
   virtual already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) = 0;
   virtual void GetStyleSheetInfo(nsAString& aTitle,
                                  nsAString& aType,
                                  nsAString& aMedia,
                                  bool* aIsScoped,
                                  bool* aIsAlternate) = 0;
 
-  nsIStyleSheet* GetStyleSheet() { return mStyleSheet; }
-
   virtual mozilla::CORSMode GetCORSMode() const
   {
     // Default to no CORS
     return mozilla::CORS_NONE;
   }
 
   // CC methods
   void Unlink();
--- a/content/html/content/src/HTMLStyleElement.cpp
+++ b/content/html/content/src/HTMLStyleElement.cpp
@@ -1,13 +1,14 @@
 /* -*- Mode: C++; 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/. */
 #include "mozilla/dom/HTMLStyleElement.h"
+#include "mozilla/dom/HTMLStyleElementBinding.h"
 #include "nsIDOMLinkStyle.h"
 #include "nsIDOMEventTarget.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsIDOMStyleSheet.h"
 #include "nsIStyleSheet.h"
 #include "nsNetUtil.h"
 #include "nsIDocument.h"
@@ -22,16 +23,17 @@ DOMCI_NODE_DATA(HTMLStyleElement, mozill
 
 namespace mozilla {
 namespace dom {
 
 HTMLStyleElement::HTMLStyleElement(already_AddRefed<nsINodeInfo> aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
   AddMutationObserver(this);
+  SetIsDOMBinding();
 }
 
 HTMLStyleElement::~HTMLStyleElement()
 {
 }
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLStyleElement,
                                                   nsGenericHTMLElement)
@@ -59,34 +61,56 @@ NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLA
 
 
 NS_IMPL_ELEMENT_CLONE(HTMLStyleElement)
 
 
 NS_IMETHODIMP
 HTMLStyleElement::GetDisabled(bool* aDisabled)
 {
-  nsCOMPtr<nsIDOMStyleSheet> ss = do_QueryInterface(GetStyleSheet());
+  NS_ENSURE_ARG_POINTER(aDisabled);
+
+  *aDisabled = Disabled();
+  return NS_OK;
+}
+
+bool
+HTMLStyleElement::Disabled()
+{
+  nsCOMPtr<nsIDOMStyleSheet> ss = do_QueryInterface(GetSheet());
   if (!ss) {
-    *aDisabled = false;
-    return NS_OK;
+    return false;
   }
 
-  return ss->GetDisabled(aDisabled);
+  bool disabled = false;
+  ss->GetDisabled(&disabled);
+
+  return disabled;
 }
 
-NS_IMETHODIMP 
+NS_IMETHODIMP
 HTMLStyleElement::SetDisabled(bool aDisabled)
 {
-  nsCOMPtr<nsIDOMStyleSheet> ss = do_QueryInterface(GetStyleSheet());
+  ErrorResult error;
+  SetDisabled(aDisabled, error);
+  return error.ErrorCode();
+}
+
+void
+HTMLStyleElement::SetDisabled(bool aDisabled, ErrorResult& aError)
+{
+  nsCOMPtr<nsIDOMStyleSheet> ss = do_QueryInterface(GetSheet());
   if (!ss) {
-    return NS_OK;
+    return;
   }
 
-  return ss->SetDisabled(aDisabled);
+  nsresult result = ss->SetDisabled(aDisabled);
+  if (NS_FAILED(result)) {
+    aError.Throw(result);
+  }
 }
 
 NS_IMPL_STRING_ATTR(HTMLStyleElement, Media, media)
 NS_IMPL_BOOL_ATTR(HTMLStyleElement, Scoped, scoped)
 NS_IMPL_STRING_ATTR(HTMLStyleElement, Type, type)
 
 void
 HTMLStyleElement::CharacterDataChanged(nsIDocument* aDocument,
@@ -255,11 +279,18 @@ HTMLStyleElement::GetStyleSheetInfo(nsAS
     return;
   }
 
   // If we get here we assume that we're loading a css file, so set the
   // type to 'text/css'
   aType.AssignLiteral("text/css");
 }
 
+JSObject*
+HTMLStyleElement::WrapNode(JSContext *aCx, JSObject *aScope,
+                           bool *aTriedToWrap)
+{
+  return HTMLStyleElementBinding::Wrap(aCx, aScope, this, aTriedToWrap);
+}
+
 } // namespace dom
 } // namespace mozilla
 
--- a/content/html/content/src/HTMLStyleElement.h
+++ b/content/html/content/src/HTMLStyleElement.h
@@ -68,16 +68,38 @@ public:
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 
   // nsIMutationObserver
   NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
   NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
 
+  bool Disabled();
+  void SetDisabled(bool aDisabled, ErrorResult& aError);
+  void SetMedia(const nsAString& aMedia, ErrorResult& aError)
+  {
+    SetHTMLAttr(nsGkAtoms::media, aMedia, aError);
+  }
+  void SetType(const nsAString& aType, ErrorResult& aError)
+  {
+    SetHTMLAttr(nsGkAtoms::type, aType, aError);
+  }
+  bool Scoped()
+  {
+    return GetBoolAttr(nsGkAtoms::scoped);
+  }
+  void SetScoped(bool aScoped, ErrorResult& aError)
+  {
+    SetHTMLBoolAttr(nsGkAtoms::scoped, aScoped, aError);
+  }
+
+  virtual JSObject* WrapNode(JSContext *aCx, JSObject *aScope,
+                             bool *aTriedToWrap);
+
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 protected:
   already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline);
   void GetStyleSheetInfo(nsAString& aTitle,
                          nsAString& aType,
                          nsAString& aMedia,
--- a/content/html/content/src/nsHTMLLinkElement.cpp
+++ b/content/html/content/src/nsHTMLLinkElement.cpp
@@ -154,32 +154,32 @@ NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLA
 
 
 NS_IMPL_ELEMENT_CLONE(nsHTMLLinkElement)
 
 
 NS_IMETHODIMP
 nsHTMLLinkElement::GetDisabled(bool* aDisabled)
 {
-  nsCOMPtr<nsIDOMStyleSheet> ss = do_QueryInterface(GetStyleSheet());
+  nsCOMPtr<nsIDOMStyleSheet> ss = do_QueryInterface(GetSheet());
   nsresult result = NS_OK;
 
   if (ss) {
     result = ss->GetDisabled(aDisabled);
   } else {
     *aDisabled = false;
   }
 
   return result;
 }
 
 NS_IMETHODIMP 
 nsHTMLLinkElement::SetDisabled(bool aDisabled)
 {
-  nsCOMPtr<nsIDOMStyleSheet> ss = do_QueryInterface(GetStyleSheet());
+  nsCOMPtr<nsIDOMStyleSheet> ss = do_QueryInterface(GetSheet());
   nsresult result = NS_OK;
 
   if (ss) {
     result = ss->SetDisabled(aDisabled);
   }
 
   return result;
 }
@@ -327,17 +327,17 @@ nsHTMLLinkElement::SetAttr(int32_t aName
 
   if (NS_SUCCEEDED(rv) && aNameSpaceID == kNameSpaceID_None &&
       (aName == nsGkAtoms::href ||
        aName == nsGkAtoms::rel ||
        aName == nsGkAtoms::title ||
        aName == nsGkAtoms::media ||
        aName == nsGkAtoms::type)) {
     bool dropSheet = false;
-    if (aName == nsGkAtoms::rel && GetStyleSheet()) {
+    if (aName == nsGkAtoms::rel && GetSheet()) {
       uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(aValue);
       dropSheet = !(linkTypes & STYLESHEET);          
     }
     
     UpdateStyleSheetInternal(nullptr,
                              dropSheet ||
                              (aName == nsGkAtoms::title ||
                               aName == nsGkAtoms::media ||
--- a/content/html/content/test/reflect.js
+++ b/content/html/content/test/reflect.js
@@ -56,18 +56,17 @@ function reflectString(aParameters)
 
   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" ],
-    style: [ "media", "type" ]
+    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 {
     todo_is(element.getAttribute(contentAttr), "null",
--- a/content/xml/content/src/XMLStylesheetProcessingInstruction.h
+++ b/content/xml/content/src/XMLStylesheetProcessingInstruction.h
@@ -28,22 +28,16 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // CC
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(XMLStylesheetProcessingInstruction,
                                            ProcessingInstruction)
 
-  using nsStyleLinkElement::GetSheet;
-  nsIStyleSheet* GetSheet()
-  {
-    return GetStyleSheet();
-  }
-
   // nsIDOMNode
   virtual void SetNodeValueInternal(const nsAString& aNodeValue,
                                     mozilla::ErrorResult& aError);
 
   // nsIContent
   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
                               nsIContent* aBindingParent,
                               bool aCompileEventHandlers);
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -470,16 +470,23 @@ DOMInterfaces = {
 
 'HTMLTableSectionElement': {
     'hasInstanceInterface': 'nsIDOMHTMLTableSectionElement',
     'resultNotAddRefed': [
         'rows'
     ]
 },
 
+'HTMLStyleElement': {
+    'hasInstanceInterface': 'nsIDOMHTMLStyleElement',
+    'resultNotAddRefed': [
+        'sheet'
+    ]
+},
+
 'HTMLUListElement': {
     'headerFile' : 'mozilla/dom/HTMLSharedListElement.h'
 },
 
 'IID': [
 {
     'nativeType': 'nsIJSID',
     'headerFile': 'xpcjsid.h',
new file mode 100644
--- /dev/null
+++ b/dom/webidl/HTMLStyleElement.webidl
@@ -0,0 +1,22 @@
+/* -*- 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-style-element
+ * http://www.whatwg.org/specs/web-apps/current-work/#other-elements,-attributes-and-apis
+ */
+
+interface HTMLStyleElement : HTMLElement {
+           [SetterThrows]
+           attribute boolean disabled;
+           [SetterThrows]
+           attribute DOMString media;
+           [SetterThrows]
+           attribute DOMString type;
+           [SetterThrows]
+           attribute boolean scoped;
+};
+HTMLStyleElement implements LinkStyle;
+
new file mode 100644
--- /dev/null
+++ b/dom/webidl/LinkStyle.webidl
@@ -0,0 +1,14 @@
+/* -*- 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://dev.w3.org/csswg/cssom/#the-linkstyle-interface
+ */
+
+[NoInterfaceObject]
+interface LinkStyle {
+      readonly attribute StyleSheet? sheet;
+};
+
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -71,25 +71,27 @@ webidl_files = \
   HTMLLIElement.webidl \
   HTMLOListElement.webidl \
   HTMLOptionsCollection.webidl \
   HTMLParagraphElement.webidl \
   HTMLPreElement.webidl \
   HTMLPropertiesCollection.webidl \
   HTMLScriptElement.webidl \
   HTMLSpanElement.webidl \
+  HTMLStyleElement.webidl \
   HTMLTableCaptionElement.webidl \
   HTMLTableCellElement.webidl \
   HTMLTableColElement.webidl \
   HTMLTableElement.webidl \
   HTMLTableRowElement.webidl \
   HTMLTableSectionElement.webidl \
   HTMLTitleElement.webidl \
   HTMLUListElement.webidl \
   ImageData.webidl \
+  LinkStyle.webidl \
   Location.webidl \
   MutationObserver.webidl \
   Node.webidl \
   NodeFilter.webidl \
   NodeList.webidl \
   PaintRequest.webidl \
   PaintRequestList.webidl \
   PannerNode.webidl \