Bug 738196 - Part a: introduce a common superclass for nsDOMStyleSheetList and ShadowRootStyleSheetList; r=bz

This commit is contained in:
Ms2ger 2014-04-10 13:24:25 +02:00
parent 90d03e3ff8
commit a659a13bc6
7 changed files with 68 additions and 20 deletions

View File

@ -677,18 +677,23 @@ ShadowRootStyleSheetList::~ShadowRootStyleSheetList()
MOZ_COUNT_DTOR(ShadowRootStyleSheetList);
}
nsCSSStyleSheet*
ShadowRootStyleSheetList::GetItemAt(uint32_t aIndex)
{
nsTArray<nsRefPtr<nsCSSStyleSheet>>* sheets =
mShadowRoot->mProtoBinding->GetStyleSheets();
if (!sheets) {
return nullptr;
}
return sheets->SafeElementAt(aIndex);
}
NS_IMETHODIMP
ShadowRootStyleSheetList::Item(uint32_t aIndex, nsIDOMStyleSheet** aReturn)
{
nsTArray<nsRefPtr<nsCSSStyleSheet> >* sheets =
mShadowRoot->mProtoBinding->GetStyleSheets();
if (sheets) {
NS_IF_ADDREF(*aReturn = sheets->SafeElementAt(aIndex));
} else {
*aReturn = nullptr;
}
NS_IF_ADDREF(*aReturn = GetItemAt(aIndex));
return NS_OK;
}

View File

@ -7,6 +7,7 @@
#define mozilla_dom_shadowroot_h__
#include "mozilla/dom/DocumentFragment.h"
#include "mozilla/dom/StyleSheetList.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsTHashtable.h"
@ -169,7 +170,7 @@ protected:
bool mInsertionPointChanged;
};
class ShadowRootStyleSheetList : public nsIDOMStyleSheetList
class ShadowRootStyleSheetList : public StyleSheetList
{
public:
ShadowRootStyleSheetList(ShadowRoot* aShadowRoot);
@ -181,6 +182,8 @@ public:
// nsIDOMStyleSheetList
NS_DECL_NSIDOMSTYLESHEETLIST
virtual nsCSSStyleSheet* GetItemAt(uint32_t aIndex) MOZ_OVERRIDE;
protected:
nsRefPtr<ShadowRoot> mShadowRoot;
};

View File

@ -0,0 +1,41 @@
/* -*- 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 mozilla_dom_StyleSheetList_h
#define mozilla_dom_StyleSheetList_h
#include "nsIDOMStyleSheetList.h"
class nsCSSStyleSheet;
namespace mozilla {
namespace dom {
class StyleSheetList : public nsIDOMStyleSheetList
{
public:
static StyleSheetList* FromSupports(nsISupports* aSupports)
{
nsIDOMStyleSheetList* list = static_cast<nsIDOMStyleSheetList*>(aSupports);
#ifdef DEBUG
{
nsCOMPtr<nsIDOMStyleSheetList> list_qi = do_QueryInterface(aSupports);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsIDOMStyleSheetList pointer as the
// nsISupports pointer. That must be fixed, or we'll crash...
MOZ_ASSERT(list_qi == list, "Uh, fix QI!");
}
#endif
return static_cast<StyleSheetList*>(list);
}
virtual nsCSSStyleSheet* GetItemAt(uint32_t aIndex) = 0;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_StyleSheetList_h

View File

@ -72,6 +72,7 @@ EXPORTS.mozilla.dom += [
'Link.h',
'NodeIterator.h',
'ShadowRoot.h',
'StyleSheetList.h',
'Text.h',
'TreeWalker.h',
]

View File

@ -769,7 +769,7 @@ nsDOMStyleSheetList::GetLength(uint32_t* aLength)
return NS_OK;
}
nsIStyleSheet*
nsCSSStyleSheet*
nsDOMStyleSheetList::GetItemAt(uint32_t aIndex)
{
if (!mDocument || aIndex >= (uint32_t)mDocument->GetNumberOfStyleSheets()) {
@ -779,7 +779,7 @@ nsDOMStyleSheetList::GetItemAt(uint32_t aIndex)
nsIStyleSheet *sheet = mDocument->GetStyleSheetAt(aIndex);
NS_ASSERTION(sheet, "Must have a sheet");
return sheet;
return static_cast<nsCSSStyleSheet*>(sheet);
}
NS_IMETHODIMP

View File

@ -23,7 +23,6 @@
#include "nsIDOMXMLDocument.h"
#include "nsIDOMDocumentXBL.h"
#include "nsStubDocumentObserver.h"
#include "nsIDOMStyleSheetList.h"
#include "nsIScriptGlobalObject.h"
#include "nsIContent.h"
#include "nsIPrincipal.h"
@ -65,6 +64,7 @@
#include "mozilla/EventStates.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/dom/DOMImplementation.h"
#include "mozilla/dom/StyleSheetList.h"
#include "nsIDOMTouchEvent.h"
#include "nsDataHashtable.h"
#include "mozilla/TimeStamp.h"
@ -78,7 +78,6 @@
#define XML_DECLARATION_BITS_STANDALONE_YES (1 << 3)
class nsDOMStyleSheetList;
class nsDOMStyleSheetSetList;
class nsIOutputStream;
class nsDocument;
@ -436,7 +435,7 @@ public:
nsDocHeaderData* mNext;
};
class nsDOMStyleSheetList : public nsIDOMStyleSheetList,
class nsDOMStyleSheetList : public mozilla::dom::StyleSheetList,
public nsStubDocumentObserver
{
public:
@ -454,7 +453,7 @@ public:
// nsIMutationObserver
NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
nsIStyleSheet* GetItemAt(uint32_t aIndex);
virtual nsCSSStyleSheet* GetItemAt(uint32_t aIndex) MOZ_OVERRIDE;
protected:
int32_t mLength;

View File

@ -3686,10 +3686,9 @@ nsISupports*
nsStyleSheetListSH::GetItemAt(nsISupports *aNative, uint32_t aIndex,
nsWrapperCache **aCache, nsresult *rv)
{
nsIDOMStyleSheetList* list = static_cast<nsIDOMStyleSheetList*>(aNative);
nsCOMPtr<nsIDOMStyleSheet> sheet;
list->Item(aIndex, getter_AddRefs(sheet));
return sheet;
StyleSheetList* list = StyleSheetList::FromSupports(aNative);
nsIDOMStyleSheet* item = list->GetItemAt(aIndex);
return item;
}