Bug 861880 - Move TreeColumns to WebIDL; r=bz

This commit is contained in:
Ms2ger 2013-04-21 08:42:26 +02:00
parent a670bfb881
commit 778540f42f
8 changed files with 226 additions and 135 deletions

View File

@ -688,9 +688,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
#ifdef MOZ_XUL #ifdef MOZ_XUL
NS_DEFINE_CLASSINFO_DATA(TreeColumn, nsDOMGenericSH, NS_DEFINE_CLASSINFO_DATA(TreeColumn, nsDOMGenericSH,
DEFAULT_SCRIPTABLE_FLAGS) DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(TreeColumns, nsTreeColumnsSH,
ARRAY_SCRIPTABLE_FLAGS)
#endif #endif
NS_DEFINE_CLASSINFO_DATA(CSSMozDocumentRule, nsDOMGenericSH, NS_DEFINE_CLASSINFO_DATA(CSSMozDocumentRule, nsDOMGenericSH,
@ -1946,10 +1943,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_BEGIN(TreeColumn, nsITreeColumn) DOM_CLASSINFO_MAP_BEGIN(TreeColumn, nsITreeColumn)
DOM_CLASSINFO_MAP_ENTRY(nsITreeColumn) DOM_CLASSINFO_MAP_ENTRY(nsITreeColumn)
DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(TreeColumns, nsITreeColumns)
DOM_CLASSINFO_MAP_ENTRY(nsITreeColumns)
DOM_CLASSINFO_MAP_END
#endif #endif
DOM_CLASSINFO_MAP_BEGIN(CSSMozDocumentRule, nsIDOMCSSMozDocumentRule) DOM_CLASSINFO_MAP_BEGIN(CSSMozDocumentRule, nsIDOMCSSMozDocumentRule)
@ -7209,30 +7202,6 @@ nsCSSRuleListSH::GetItemAt(nsISupports *aNative, uint32_t aIndex,
return list->GetItemAt(aIndex, aResult); return list->GetItemAt(aIndex, aResult);
} }
#ifdef MOZ_XUL
// TreeColumns helper
nsISupports*
nsTreeColumnsSH::GetItemAt(nsISupports *aNative, uint32_t aIndex,
nsWrapperCache **aCache, nsresult *aResult)
{
nsTreeColumns* columns = nsTreeColumns::FromSupports(aNative);
return columns->GetColumnAt(aIndex);
}
nsISupports*
nsTreeColumnsSH::GetNamedItem(nsISupports *aNative,
const nsAString& aName,
nsWrapperCache **aCache,
nsresult *aResult)
{
nsTreeColumns* columns = nsTreeColumns::FromSupports(aNative);
return columns->GetNamedColumn(aName);
}
#endif
// Storage2SH // Storage2SH

View File

@ -989,37 +989,6 @@ class nsDOMTouchListSH : public nsArraySH
} }
}; };
#ifdef MOZ_XUL
// TreeColumns helper
class nsTreeColumnsSH : public nsNamedArraySH
{
protected:
nsTreeColumnsSH(nsDOMClassInfoData* aData) : nsNamedArraySH(aData)
{
}
virtual ~nsTreeColumnsSH()
{
}
virtual nsISupports* GetItemAt(nsISupports *aNative, uint32_t aIndex,
nsWrapperCache **aCache, nsresult *aResult);
// Override nsNamedArraySH::GetNamedItem()
virtual nsISupports* GetNamedItem(nsISupports *aNative,
const nsAString& aName,
nsWrapperCache **cache,
nsresult *aResult);
public:
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsTreeColumnsSH(aData);
}
};
#endif
// WebApps Storage helpers // WebApps Storage helpers
class nsStorage2SH : public nsDOMGenericSH class nsStorage2SH : public nsDOMGenericSH

View File

@ -96,7 +96,6 @@ DOMCI_CLASS(DOMStringList)
#ifdef MOZ_XUL #ifdef MOZ_XUL
DOMCI_CLASS(TreeColumn) DOMCI_CLASS(TreeColumn)
DOMCI_CLASS(TreeColumns)
#endif #endif
DOMCI_CLASS(CSSMozDocumentRule) DOMCI_CLASS(CSSMozDocumentRule)

View File

@ -1019,6 +1019,10 @@ DOMInterfaces = {
'nativeType': 'nsDOMTransitionEvent', 'nativeType': 'nsDOMTransitionEvent',
}, },
'TreeColumns': {
'nativeType': 'nsTreeColumns',
},
'TreeWalker': { 'TreeWalker': {
'wrapperCache': False, 'wrapperCache': False,
'resultNotAddRefed': [ 'root', 'currentNode' ], 'resultNotAddRefed': [ 'root', 'currentNode' ],
@ -1512,6 +1516,10 @@ addExternalIface('MozObserver', nativeType='nsIObserver', notflattened=True)
addExternalIface('MozRDFCompositeDataSource', nativeType='nsIRDFCompositeDataSource', addExternalIface('MozRDFCompositeDataSource', nativeType='nsIRDFCompositeDataSource',
notflattened=True) notflattened=True)
addExternalIface('MozRDFResource', nativeType='nsIRDFResource', notflattened=True) addExternalIface('MozRDFResource', nativeType='nsIRDFResource', notflattened=True)
addExternalIface('MozTreeBoxObject', nativeType='nsITreeBoxObject',
notflattened=True)
addExternalIface('MozTreeColumn', nativeType='nsITreeColumn',
headerFile='nsITreeColumns.h')
addExternalIface('MozXULTemplateBuilder', nativeType='nsIXULTemplateBuilder') addExternalIface('MozXULTemplateBuilder', nativeType='nsIXULTemplateBuilder')
addExternalIface('MozNamedAttrMap') addExternalIface('MozNamedAttrMap')
addExternalIface('nsIControllers', nativeType='nsIControllers') addExternalIface('nsIControllers', nativeType='nsIControllers')

View File

@ -0,0 +1,56 @@
/* 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 obtaone at http://mozilla.org/MPL/2.0/. */
interface MozTreeBoxObject;
interface MozTreeColumn;
interface TreeColumns {
/**
* The tree widget for these columns.
*/
readonly attribute MozTreeBoxObject? tree;
/**
* The number of columns.
*/
readonly attribute unsigned long count;
/**
* An alias for count (for the benefit of scripts which treat this as an
* array).
*/
readonly attribute unsigned long length;
/**
* Get the first/last column.
*/
MozTreeColumn? getFirstColumn();
MozTreeColumn? getLastColumn();
/**
* Attribute based column getters.
*/
MozTreeColumn? getPrimaryColumn();
MozTreeColumn? getSortedColumn();
MozTreeColumn? getKeyColumn();
/**
* Get the column for the given element.
*/
MozTreeColumn? getColumnFor(Element? element);
/**
* Parametric column getters.
*/
getter MozTreeColumn? getNamedColumn(DOMString id);
getter MozTreeColumn? getColumnAt(unsigned long index);
/**
* This method is called whenever a treecol is added or removed and
* the column cache needs to be rebuilt.
*/
void invalidateColumns();
void restoreNaturalOrder();
};

View File

@ -291,6 +291,7 @@ webidl_files = \
Touch.webidl \ Touch.webidl \
TouchEvent.webidl \ TouchEvent.webidl \
TransitionEvent.webidl \ TransitionEvent.webidl \
TreeColumns.webidl \
TreeWalker.webidl \ TreeWalker.webidl \
UIEvent.webidl \ UIEvent.webidl \
URL.webidl \ URL.webidl \

View File

@ -14,6 +14,10 @@
#include "nsINodeInfo.h" #include "nsINodeInfo.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsTreeBodyFrame.h" #include "nsTreeBodyFrame.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/TreeColumnsBinding.h"
using namespace mozilla;
// Column class that caches all the info about our column. // Column class that caches all the info about our column.
nsTreeColumn::nsTreeColumn(nsTreeColumns* aColumns, nsIContent* aContent) nsTreeColumn::nsTreeColumn(nsTreeColumns* aColumns, nsIContent* aContent)
@ -343,6 +347,7 @@ nsTreeColumns::nsTreeColumns(nsTreeBodyFrame* aTree)
: mTree(aTree), : mTree(aTree),
mFirstColumn(nullptr) mFirstColumn(nullptr)
{ {
SetIsDOMBinding();
} }
nsTreeColumns::~nsTreeColumns() nsTreeColumns::~nsTreeColumns()
@ -350,40 +355,66 @@ nsTreeColumns::~nsTreeColumns()
nsTreeColumns::InvalidateColumns(); nsTreeColumns::InvalidateColumns();
} }
DOMCI_DATA(TreeColumns, nsTreeColumns) NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(nsTreeColumns)
// QueryInterface implementation for nsTreeColumns // QueryInterface implementation for nsTreeColumns
NS_INTERFACE_MAP_BEGIN(nsTreeColumns) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsTreeColumns)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsITreeColumns) NS_INTERFACE_MAP_ENTRY(nsITreeColumns)
NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(TreeColumns)
NS_INTERFACE_MAP_END NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsTreeColumns) NS_IMPL_CYCLE_COLLECTING_ADDREF(nsTreeColumns)
NS_IMPL_RELEASE(nsTreeColumns) NS_IMPL_CYCLE_COLLECTING_RELEASE(nsTreeColumns)
nsIContent*
nsTreeColumns::GetParentObject() const
{
return mTree ? mTree->GetBaseElement() : nullptr;
}
/* virtual */ JSObject*
nsTreeColumns::WrapObject(JSContext* aCx, JSObject* aScope)
{
return dom::TreeColumnsBinding::Wrap(aCx, aScope, this);
}
nsITreeBoxObject*
nsTreeColumns::GetTree() const
{
return mTree ? mTree->GetTreeBoxObject() : nullptr;
}
NS_IMETHODIMP NS_IMETHODIMP
nsTreeColumns::GetTree(nsITreeBoxObject** _retval) nsTreeColumns::GetTree(nsITreeBoxObject** _retval)
{ {
NS_IF_ADDREF(*_retval = mTree ? mTree->GetTreeBoxObject() : nullptr); NS_IF_ADDREF(*_retval = GetTree());
return NS_OK; return NS_OK;
} }
uint32_t
nsTreeColumns::Count()
{
EnsureColumns();
uint32_t count = 0;
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
++count;
}
return count;
}
NS_IMETHODIMP NS_IMETHODIMP
nsTreeColumns::GetCount(int32_t* _retval) nsTreeColumns::GetCount(int32_t* _retval)
{ {
EnsureColumns(); *_retval = Count();
*_retval = 0;
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
++(*_retval);
}
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsTreeColumns::GetLength(int32_t* _retval) nsTreeColumns::GetLength(int32_t* _retval)
{ {
return GetCount(_retval); *_retval = Length();
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -393,20 +424,25 @@ nsTreeColumns::GetFirstColumn(nsITreeColumn** _retval)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsTreeColumn*
nsTreeColumns::GetLastColumn(nsITreeColumn** _retval) nsTreeColumns::GetLastColumn()
{ {
EnsureColumns(); EnsureColumns();
*_retval = nullptr;
nsTreeColumn* currCol = mFirstColumn; nsTreeColumn* currCol = mFirstColumn;
while (currCol) { while (currCol) {
nsTreeColumn* next = currCol->GetNext(); nsTreeColumn* next = currCol->GetNext();
if (!next) { if (!next) {
NS_ADDREF(*_retval = currCol); return currCol;
break;
} }
currCol = next; currCol = next;
} }
return nullptr;
}
NS_IMETHODIMP
nsTreeColumns::GetLastColumn(nsITreeColumn** _retval)
{
NS_IF_ADDREF(*_retval = GetLastColumn());
return NS_OK; return NS_OK;
} }
@ -417,32 +453,35 @@ nsTreeColumns::GetPrimaryColumn(nsITreeColumn** _retval)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsTreeColumn*
nsTreeColumns::GetSortedColumn(nsITreeColumn** _retval) nsTreeColumns::GetSortedColumn()
{ {
EnsureColumns(); EnsureColumns();
*_retval = nullptr;
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) { for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
if (currCol->mContent && if (currCol->mContent &&
nsContentUtils::HasNonEmptyAttr(currCol->mContent, kNameSpaceID_None, nsContentUtils::HasNonEmptyAttr(currCol->mContent, kNameSpaceID_None,
nsGkAtoms::sortDirection)) { nsGkAtoms::sortDirection)) {
NS_ADDREF(*_retval = currCol); return currCol;
return NS_OK;
} }
} }
return NS_OK; return nullptr;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsTreeColumns::GetKeyColumn(nsITreeColumn** _retval) nsTreeColumns::GetSortedColumn(nsITreeColumn** _retval)
{
NS_IF_ADDREF(*_retval = GetSortedColumn());
return NS_OK;
}
nsTreeColumn*
nsTreeColumns::GetKeyColumn()
{ {
EnsureColumns(); EnsureColumns();
*_retval = nullptr;
nsTreeColumn* first; nsTreeColumn* first = nullptr;
nsTreeColumn* primary; nsTreeColumn* primary = nullptr;
nsTreeColumn* sorted; nsTreeColumn* sorted = nullptr;
first = primary = sorted = nullptr;
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) { for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
// Skip hidden columns. // Skip hidden columns.
@ -471,44 +510,60 @@ nsTreeColumns::GetKeyColumn(nsITreeColumn** _retval)
} }
if (sorted) if (sorted)
*_retval = sorted; return sorted;
else if (primary) if (primary)
*_retval = primary; return primary;
else return first;
*_retval = first; }
NS_IF_ADDREF(*_retval); NS_IMETHODIMP
nsTreeColumns::GetKeyColumn(nsITreeColumn** _retval)
{
NS_IF_ADDREF(*_retval = GetKeyColumn());
return NS_OK; return NS_OK;
} }
nsTreeColumn*
nsTreeColumns::GetColumnFor(dom::Element* aElement)
{
EnsureColumns();
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
if (currCol->mContent == aElement) {
return currCol;
}
}
return nullptr;
}
NS_IMETHODIMP NS_IMETHODIMP
nsTreeColumns::GetColumnFor(nsIDOMElement* aElement, nsITreeColumn** _retval) nsTreeColumns::GetColumnFor(nsIDOMElement* aElement, nsITreeColumn** _retval)
{ {
EnsureColumns(); nsCOMPtr<dom::Element> element = do_QueryInterface(aElement);
*_retval = nullptr; NS_ADDREF(*_retval = GetColumnFor(element));
nsCOMPtr<nsIContent> element = do_QueryInterface(aElement);
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
if (currCol->mContent == element) {
NS_ADDREF(*_retval = currCol);
break;
}
}
return NS_OK; return NS_OK;
} }
nsITreeColumn* nsTreeColumn*
nsTreeColumns::GetNamedColumn(const nsAString& aId) nsTreeColumns::NamedGetter(const nsAString& aId, bool& aFound)
{ {
EnsureColumns(); EnsureColumns();
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) { for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
if (currCol->GetId().Equals(aId)) { if (currCol->GetId().Equals(aId)) {
aFound = true;
return currCol; return currCol;
} }
} }
aFound = false;
return nullptr; return nullptr;
} }
nsTreeColumn*
nsTreeColumns::GetNamedColumn(const nsAString& aId)
{
bool dummy;
return NamedGetter(aId, dummy);
}
NS_IMETHODIMP NS_IMETHODIMP
nsTreeColumns::GetNamedColumn(const nsAString& aId, nsITreeColumn** _retval) nsTreeColumns::GetNamedColumn(const nsAString& aId, nsITreeColumn** _retval)
{ {
@ -516,22 +571,40 @@ nsTreeColumns::GetNamedColumn(const nsAString& aId, nsITreeColumn** _retval)
return NS_OK; return NS_OK;
} }
nsITreeColumn* void
nsTreeColumns::GetColumnAt(int32_t aIndex) nsTreeColumns::GetSupportedNames(nsTArray<nsString>& aNames)
{
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
aNames.AppendElement(currCol->GetId());
}
}
nsTreeColumn*
nsTreeColumns::IndexedGetter(uint32_t aIndex, bool& aFound)
{ {
EnsureColumns(); EnsureColumns();
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) { for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
if (currCol->GetIndex() == aIndex) { if (currCol->GetIndex() == static_cast<int32_t>(aIndex)) {
aFound = true;
return currCol; return currCol;
} }
} }
aFound = false;
return nullptr; return nullptr;
} }
nsTreeColumn*
nsTreeColumns::GetColumnAt(uint32_t aIndex)
{
bool dummy;
return IndexedGetter(aIndex, dummy);
}
NS_IMETHODIMP NS_IMETHODIMP
nsTreeColumns::GetColumnAt(int32_t aIndex, nsITreeColumn** _retval) nsTreeColumns::GetColumnAt(int32_t aIndex, nsITreeColumn** _retval)
{ {
NS_IF_ADDREF(*_retval = GetColumnAt(aIndex)); NS_IF_ADDREF(*_retval = GetColumnAt(static_cast<uint32_t>(aIndex)));
return NS_OK; return NS_OK;
} }

View File

@ -12,6 +12,7 @@
#include "nsCoord.h" #include "nsCoord.h"
#include "nsCycleCollectionParticipant.h" #include "nsCycleCollectionParticipant.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsWrapperCache.h"
class nsTreeBodyFrame; class nsTreeBodyFrame;
class nsTreeColumns; class nsTreeColumns;
@ -19,6 +20,12 @@ class nsIFrame;
class nsIContent; class nsIContent;
struct nsRect; struct nsRect;
namespace mozilla {
namespace dom {
class Element;
} // namespace dom
} // namespace mozilla
#define NS_TREECOLUMN_IMPL_CID \ #define NS_TREECOLUMN_IMPL_CID \
{ /* 02cd1963-4b5d-4a6c-9223-814d3ade93a3 */ \ { /* 02cd1963-4b5d-4a6c-9223-814d3ade93a3 */ \
0x02cd1963, \ 0x02cd1963, \
@ -115,34 +122,46 @@ private:
NS_DEFINE_STATIC_IID_ACCESSOR(nsTreeColumn, NS_TREECOLUMN_IMPL_CID) NS_DEFINE_STATIC_IID_ACCESSOR(nsTreeColumn, NS_TREECOLUMN_IMPL_CID)
class nsTreeColumns MOZ_FINAL : public nsITreeColumns { class nsTreeColumns MOZ_FINAL : public nsITreeColumns
, public nsWrapperCache
{
public: public:
nsTreeColumns(nsTreeBodyFrame* aTree); nsTreeColumns(nsTreeBodyFrame* aTree);
~nsTreeColumns(); ~nsTreeColumns();
NS_DECL_ISUPPORTS NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsTreeColumns)
NS_DECL_NSITREECOLUMNS NS_DECL_NSITREECOLUMNS
nsITreeColumn* GetColumnAt(int32_t aIndex); nsIContent* GetParentObject() const;
nsITreeColumn* GetNamedColumn(const nsAString& aId); virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope) MOZ_OVERRIDE;
static nsTreeColumns* FromSupports(nsISupports* aSupports) // WebIDL
nsITreeBoxObject* GetTree() const;
uint32_t Count();
uint32_t Length()
{ {
#ifdef DEBUG return Count();
{
nsCOMPtr<nsITreeColumns> columns_qi = do_QueryInterface(aSupports);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsITreeColumns pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(columns_qi == static_cast<nsITreeColumns*>(aSupports),
"Uh, fix QI!");
}
#endif
return static_cast<nsTreeColumns*>(aSupports);
} }
nsTreeColumn* GetFirstColumn() { EnsureColumns(); return mFirstColumn; }
nsTreeColumn* GetLastColumn();
nsTreeColumn* GetPrimaryColumn();
nsTreeColumn* GetSortedColumn();
nsTreeColumn* GetKeyColumn();
nsTreeColumn* GetColumnFor(mozilla::dom::Element* aElement);
nsTreeColumn* IndexedGetter(uint32_t aIndex, bool& aFound);
nsTreeColumn* GetColumnAt(uint32_t aIndex);
nsTreeColumn* NamedGetter(const nsAString& aId, bool& aFound);
nsTreeColumn* GetNamedColumn(const nsAString& aId);
void GetSupportedNames(nsTArray<nsString>& aNames);
// Uses XPCOM InvalidateColumns().
// Uses XPCOM RestoreNaturalOrder().
friend class nsTreeBodyFrame; friend class nsTreeBodyFrame;
protected: protected:
void SetTree(nsTreeBodyFrame* aTree) { mTree = aTree; } void SetTree(nsTreeBodyFrame* aTree) { mTree = aTree; }
@ -150,9 +169,6 @@ protected:
// Builds our cache of column info. // Builds our cache of column info.
void EnsureColumns(); void EnsureColumns();
nsTreeColumn* GetFirstColumn() { EnsureColumns(); return mFirstColumn; }
nsTreeColumn* GetPrimaryColumn();
private: private:
nsTreeBodyFrame* mTree; nsTreeBodyFrame* mTree;