Bug 892489 - Implement the WebIDL API for CSSRuleList; r=bz
authorMs2ger <ms2ger@gmail.com>
Wed, 24 Jul 2013 09:27:17 +0200
changeset 151936 9a01239e24335dca6c0c813678e8f1c6d46bb81b
parent 151935 e13c967434cfe1b7402fb1d8002e9887d6b33933
child 151937 df0fb2b7d6081918d2cb4d2db9b95821f68dc42c
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs892489
milestone25.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 892489 - Implement the WebIDL API for CSSRuleList; r=bz
dom/base/nsDOMClassInfo.cpp
layout/style/nsCSSRules.cpp
layout/style/nsCSSStyleSheet.cpp
layout/style/nsICSSRuleList.h
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -5259,17 +5259,17 @@ nsCSSRuleListSH::GetItemAt(nsISupports *
 
     // If this assertion fires the QI implementation for the object in
     // question doesn't use the nsICSSRuleList pointer as the nsISupports
     // pointer. That must be fixed, or we'll crash...
     NS_ABORT_IF_FALSE(list_qi == list, "Uh, fix QI!");
   }
 #endif
 
-  return list->GetItemAt(aIndex, aResult);
+  return list->Item(aIndex);
 }
 
 
 // Storage2SH
 
 // One reason we need a newResolve hook is that in order for
 // enumeration of storage object keys to work the keys we're
 // enumerating need to exist on the storage object for the JS engine
--- a/layout/style/nsCSSRules.cpp
+++ b/layout/style/nsCSSRules.cpp
@@ -130,19 +130,20 @@ Rule::SizeOfCOMArrayElementIncludingThis
 
 class GroupRuleRuleList MOZ_FINAL : public nsICSSRuleList
 {
 public:
   GroupRuleRuleList(GroupRule *aGroupRule);
 
   NS_DECL_ISUPPORTS
 
-  NS_DECL_NSIDOMCSSRULELIST
-
-  virtual nsIDOMCSSRule* GetItemAt(uint32_t aIndex, nsresult* aResult);
+  virtual nsIDOMCSSRule*
+  IndexedGetter(uint32_t aIndex, bool& aFound) MOZ_OVERRIDE;
+  virtual uint32_t
+  Length() MOZ_OVERRIDE;
 
   void DropReference() { mGroupRule = nullptr; }
 
 private:
   ~GroupRuleRuleList();
 
 private:
   GroupRule* mGroupRule;
@@ -166,57 +167,42 @@ NS_INTERFACE_MAP_BEGIN(GroupRuleRuleList
   NS_INTERFACE_MAP_ENTRY(nsISupports)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSGroupRuleRuleList)
 NS_INTERFACE_MAP_END
 
 
 NS_IMPL_ADDREF(GroupRuleRuleList)
 NS_IMPL_RELEASE(GroupRuleRuleList)
 
-NS_IMETHODIMP
-GroupRuleRuleList::GetLength(uint32_t* aLength)
+uint32_t
+GroupRuleRuleList::Length()
 {
-  if (mGroupRule) {
-    *aLength = (uint32_t)mGroupRule->StyleRuleCount();
-  } else {
-    *aLength = 0;
+  if (!mGroupRule) {
+    return 0;
   }
 
-  return NS_OK;
+  return SafeCast<uint32_t>(mGroupRule->StyleRuleCount());
 }
 
 nsIDOMCSSRule*
-GroupRuleRuleList::GetItemAt(uint32_t aIndex, nsresult* aResult)
+GroupRuleRuleList::IndexedGetter(uint32_t aIndex, bool& aFound)
 {
-  *aResult = NS_OK;
+  aFound = false;
 
   if (mGroupRule) {
     nsRefPtr<Rule> rule = mGroupRule->GetStyleRuleAt(aIndex);
     if (rule) {
+      aFound = true;
       return rule->GetDOMRule();
     }
   }
 
   return nullptr;
 }
 
-NS_IMETHODIMP
-GroupRuleRuleList::Item(uint32_t aIndex, nsIDOMCSSRule** aReturn)
-{
-  nsresult rv;
-  nsIDOMCSSRule* rule = GetItemAt(aIndex, &rv);
-  if (!rule) {
-    *aReturn = nullptr;
-    return rv;
-  }
-
-  NS_ADDREF(*aReturn = rule);
-  return NS_OK;
-}
-
 } // namespace css
 } // namespace mozilla
 
 // Must be outside the namespace
 DOMCI_DATA(CSSGroupRuleRuleList, css::GroupRuleRuleList)
 
 // -------------------------------------------
 // CharsetRule
--- a/layout/style/nsCSSStyleSheet.cpp
+++ b/layout/style/nsCSSStyleSheet.cpp
@@ -50,21 +50,20 @@ using namespace mozilla::dom;
 //
 class CSSRuleListImpl : public nsICSSRuleList
 {
 public:
   CSSRuleListImpl(nsCSSStyleSheet *aStyleSheet);
 
   NS_DECL_ISUPPORTS
 
-  // nsIDOMCSSRuleList interface
-  NS_IMETHOD    GetLength(uint32_t* aLength); 
-  NS_IMETHOD    Item(uint32_t aIndex, nsIDOMCSSRule** aReturn); 
-
-  virtual nsIDOMCSSRule* GetItemAt(uint32_t aIndex, nsresult* aResult);
+  virtual nsIDOMCSSRule*
+  IndexedGetter(uint32_t aIndex, bool& aFound) MOZ_OVERRIDE;
+  virtual uint32_t
+  Length() MOZ_OVERRIDE;
 
   void DropReference() { mStyleSheet = nullptr; }
 
 protected:
   virtual ~CSSRuleListImpl();
 
   nsCSSStyleSheet*  mStyleSheet;
 };
@@ -90,65 +89,47 @@ NS_INTERFACE_MAP_BEGIN(CSSRuleListImpl)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSRuleList)
 NS_INTERFACE_MAP_END
 
 
 NS_IMPL_ADDREF(CSSRuleListImpl)
 NS_IMPL_RELEASE(CSSRuleListImpl)
 
 
-NS_IMETHODIMP    
-CSSRuleListImpl::GetLength(uint32_t* aLength)
+uint32_t
+CSSRuleListImpl::Length()
 {
-  if (nullptr != mStyleSheet) {
-    int32_t count = mStyleSheet->StyleRuleCount();
-    *aLength = (uint32_t)count;
-  }
-  else {
-    *aLength = 0;
+  if (!mStyleSheet) {
+    return 0;
   }
 
-  return NS_OK;
+  return SafeCast<uint32_t>(mStyleSheet->StyleRuleCount());
 }
 
 nsIDOMCSSRule*    
-CSSRuleListImpl::GetItemAt(uint32_t aIndex, nsresult* aResult)
+CSSRuleListImpl::IndexedGetter(uint32_t aIndex, bool& aFound)
 {
+  aFound = false;
+
   if (mStyleSheet) {
     // ensure rules have correct parent
     if (mStyleSheet->EnsureUniqueInner() !=
           nsCSSStyleSheet::eUniqueInner_CloneFailed) {
       css::Rule* rule = mStyleSheet->GetStyleRuleAt(aIndex);
       if (rule) {
-        *aResult = NS_OK;
+        aFound = true;
         return rule->GetDOMRule();
       }
     }
   }
 
   // Per spec: "Return Value ... null if ... not a valid index."
-  *aResult = NS_OK;
   return nullptr;
 }
 
-NS_IMETHODIMP    
-CSSRuleListImpl::Item(uint32_t aIndex, nsIDOMCSSRule** aReturn)
-{
-  nsresult rv;
-  nsIDOMCSSRule* rule = GetItemAt(aIndex, &rv);
-  if (!rule) {
-    *aReturn = nullptr;
-
-    return rv;
-  }
-
-  NS_ADDREF(*aReturn = rule);
-  return NS_OK;
-}
-
 template <class Numeric>
 int32_t DoCompare(Numeric a, Numeric b)
 {
   if (a == b)
     return 0;
   if (a < b)
     return -1;
   return 1;
--- a/layout/style/nsICSSRuleList.h
+++ b/layout/style/nsICSSRuleList.h
@@ -1,26 +1,48 @@
 /* -*- 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/. */
 
-#ifndef nsICSSRuleList_h___
-#define nsICSSRuleList_h___
+#ifndef nsICSSRuleList_h
+#define nsICSSRuleList_h
 
+#include "nsIDOMCSSRule.h"
 #include "nsIDOMCSSRuleList.h"
 
 // IID for the nsICSSRuleList interface
 #define NS_ICSSRULELIST_IID \
-{ 0x7ae746fd, 0x259a, 0x4a69, \
- { 0x97, 0x2d, 0x2c, 0x10, 0xf7, 0xb0, 0x04, 0xa1 } }
+{ 0xccc0135a, 0xbcb6, 0x4654, \
+  { 0x8c, 0x78, 0x74, 0x35, 0x97, 0x9b, 0x88, 0x19 } }
 
 class nsICSSRuleList : public nsIDOMCSSRuleList
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICSSRULELIST_IID)
 
-  virtual nsIDOMCSSRule* GetItemAt(uint32_t aIndex, nsresult* aResult) = 0;
+  NS_IMETHOD
+  GetLength(uint32_t* aLength) MOZ_OVERRIDE MOZ_FINAL
+  {
+    *aLength = Length();
+    return NS_OK;
+  }
+  NS_IMETHOD
+  Item(uint32_t aIndex, nsIDOMCSSRule** aReturn) MOZ_OVERRIDE MOZ_FINAL
+  {
+    NS_IF_ADDREF(*aReturn = Item(aIndex));
+    return NS_OK;
+  }
+
+  // WebIDL API
+  nsIDOMCSSRule* Item(uint32_t aIndex)
+  {
+    bool unused;
+    return IndexedGetter(aIndex, unused);
+  }
+
+  virtual nsIDOMCSSRule* IndexedGetter(uint32_t aIndex, bool& aFound) = 0;
+  virtual uint32_t Length() = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsICSSRuleList, NS_ICSSRULELIST_IID)
 
-#endif /* nsICSSRuleList_h___ */
+#endif /* nsICSSRuleList_h */