mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
More XBL deCOMtamination (bug 194834). This checkin removes nsIXBLInsertionPoint and nsIAnonymousContentList. r=jkeiser, sr=jst.
This commit is contained in:
parent
d5e2e8f4ac
commit
fafc8f28c6
@ -5,6 +5,5 @@ nsIBindingManager.h
|
||||
nsIXBLBinding.h
|
||||
nsIXBLBindingAttachedHandler.h
|
||||
nsIXBLDocumentInfo.h
|
||||
nsIXBLInsertionPoint.h
|
||||
nsIXBLService.h
|
||||
|
||||
|
@ -33,7 +33,6 @@ EXPORTS = \
|
||||
nsIXBLBinding.h \
|
||||
nsIXBLBindingAttachedHandler.h \
|
||||
nsIXBLDocumentInfo.h \
|
||||
nsIXBLInsertionPoint.h \
|
||||
nsIXBLService.h \
|
||||
$(NULL)
|
||||
|
||||
|
@ -48,7 +48,6 @@
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
class nsIContent;
|
||||
class nsIXBLBinding;
|
||||
@ -58,6 +57,7 @@ class nsIAtom;
|
||||
class nsIStreamListener;
|
||||
class nsIXPConnectWrappedJS;
|
||||
class nsIDOMNodeList;
|
||||
class nsVoidArray;
|
||||
|
||||
// {55D70FE0-C8E5-11d3-97FB-00400553EEF0}
|
||||
#define NS_IBINDING_MANAGER_IID \
|
||||
@ -106,8 +106,9 @@ public:
|
||||
|
||||
/**
|
||||
* Set the insertion point children for the specified element.
|
||||
* The binding manager assumes ownership of aList.
|
||||
*/
|
||||
NS_IMETHOD SetContentListFor(nsIContent* aContent, nsISupportsArray* aList)=0;
|
||||
NS_IMETHOD SetContentListFor(nsIContent* aContent, nsVoidArray* aList)=0;
|
||||
|
||||
/**
|
||||
* Determine whether or not the explicit child list has been altered
|
||||
@ -122,8 +123,9 @@ public:
|
||||
|
||||
/**
|
||||
* Set the anonymous child content for the specified element.
|
||||
* The binding manager assumes ownership of aList.
|
||||
*/
|
||||
NS_IMETHOD SetAnonymousNodesFor(nsIContent* aContent, nsISupportsArray* aList) = 0;
|
||||
NS_IMETHOD SetAnonymousNodesFor(nsIContent* aContent, nsVoidArray* aList) = 0;
|
||||
|
||||
/**
|
||||
* Retrieves the anonymous list of children if the element has one;
|
||||
|
@ -55,6 +55,7 @@ class nsIDocument;
|
||||
class nsIDOMNodeList;
|
||||
class nsIScriptContext;
|
||||
class nsXBLPrototypeBinding;
|
||||
class nsVoidArray;
|
||||
|
||||
// {DDDBAD20-C8DF-11d3-97FB-00400553EEF0}
|
||||
#define NS_IXBLBINDING_IID \
|
||||
@ -103,7 +104,9 @@ public:
|
||||
NS_IMETHOD GetDocURI(nsCString& aResult) = 0;
|
||||
NS_IMETHOD GetID(nsCString& aResult) = 0;
|
||||
|
||||
NS_IMETHOD GetInsertionPointsFor(nsIContent* aParent, nsISupportsArray** aResult)=0;
|
||||
// Get the list of insertion points for aParent. The nsVoidArray is owned
|
||||
// by the binding, you should not delete it.
|
||||
NS_IMETHOD GetInsertionPointsFor(nsIContent* aParent, nsVoidArray** aResult)=0;
|
||||
|
||||
NS_IMETHOD GetInsertionPoint(nsIContent* aChild, nsIContent** aResult, PRUint32* aIndex,
|
||||
nsIContent** aDefaultContent) = 0;
|
||||
|
@ -1,79 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Original Author: David W. Hyatt (hyatt@netscape.com)
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsIXBLInsertionPoint_h__
|
||||
#define nsIXBLInsertionPoint_h__
|
||||
|
||||
class nsIContent;
|
||||
|
||||
// {3DAE842A-9436-4920-AC42-28C54C859066}
|
||||
#define NS_IXBLINSERTIONPOINT_IID \
|
||||
{ 0x3dae842a, 0x9436, 0x4920, { 0xac, 0x42, 0x28, 0xc5, 0x4c, 0x85, 0x90, 0x66 } }
|
||||
|
||||
class nsIXBLInsertionPoint : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXBLINSERTIONPOINT_IID)
|
||||
|
||||
NS_IMETHOD GetInsertionParent(nsIContent** aParentElement)=0;
|
||||
NS_IMETHOD GetInsertionIndex(PRInt32* aResult)=0;
|
||||
|
||||
NS_IMETHOD SetDefaultContent(nsIContent* aDefaultContent)=0;
|
||||
NS_IMETHOD GetDefaultContent(nsIContent** aDefaultContent)=0;
|
||||
|
||||
NS_IMETHOD SetDefaultContentTemplate(nsIContent* aDefaultContent)=0;
|
||||
NS_IMETHOD GetDefaultContentTemplate(nsIContent** aDefaultContent)=0;
|
||||
|
||||
NS_IMETHOD AddChild(nsIContent* aChildElement)=0;
|
||||
NS_IMETHOD InsertChildAt(PRInt32 aIndex, nsIContent* aChildElement)=0;
|
||||
NS_IMETHOD RemoveChild(nsIContent* aChildElement)=0;
|
||||
|
||||
NS_IMETHOD ChildCount(PRUint32* aResult)=0;
|
||||
|
||||
NS_IMETHOD ChildAt(PRUint32 aIndex, nsIContent** aResult)=0;
|
||||
|
||||
NS_IMETHOD Matches(nsIContent* aContent, PRUint32 aIndex, PRBool* aResult)=0;
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_NewXBLInsertionPoint(nsIContent* aParentElement, PRUint32 aIndex,
|
||||
nsIContent* aDefContent,
|
||||
nsIXBLInsertionPoint** aResult);
|
||||
|
||||
#endif // nsIXBLInsertionPoint_h__
|
@ -68,7 +68,7 @@
|
||||
#include "nsIXBLBinding.h"
|
||||
#include "nsIXBLDocumentInfo.h"
|
||||
#include "nsIXBLBindingAttachedHandler.h"
|
||||
#include "nsIXBLInsertionPoint.h"
|
||||
#include "nsXBLInsertionPoint.h"
|
||||
|
||||
#include "nsIStyleSheet.h"
|
||||
#include "nsIHTMLStyleSheet.h"
|
||||
@ -96,57 +96,45 @@
|
||||
// = nsAnonymousContentList
|
||||
// ==================================================================
|
||||
|
||||
// {CC949466-626E-4e3b-88EE-967DC5CEF7BF}
|
||||
#define NS_IANONYMOUSCONTENTLIST_IID \
|
||||
{ 0xcc949466, 0x626e, 0x4e3b, { 0x88, 0xee, 0x96, 0x7d, 0xc5, 0xce, 0xf7, 0xbf } }
|
||||
|
||||
class nsIAnonymousContentList : public nsISupports
|
||||
class nsAnonymousContentList : public nsGenericDOMNodeList
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IANONYMOUSCONTENTLIST_IID)
|
||||
|
||||
// nsIAnonymousContentList
|
||||
NS_IMETHOD GetInsertionPointCount(PRUint32* aCount)=0;
|
||||
NS_IMETHOD GetInsertionPointAt(PRUint32 i, nsIXBLInsertionPoint** aResult)=0;
|
||||
};
|
||||
|
||||
class nsAnonymousContentList : public nsGenericDOMNodeList, public nsIAnonymousContentList
|
||||
{
|
||||
public:
|
||||
nsAnonymousContentList(nsISupportsArray* aElements);
|
||||
nsAnonymousContentList(nsVoidArray* aElements);
|
||||
virtual ~nsAnonymousContentList();
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIDOMNodeList interface
|
||||
NS_DECL_NSIDOMNODELIST
|
||||
|
||||
// nsIAnonymousContentList
|
||||
NS_IMETHOD GetInsertionPointCount(PRUint32* aCount);
|
||||
NS_IMETHOD GetInsertionPointAt(PRUint32 i, nsIXBLInsertionPoint** aResult);
|
||||
|
||||
PRInt32 GetInsertionPointCount() { return mElements->Count(); }
|
||||
|
||||
nsXBLInsertionPoint* GetInsertionPointAt(PRInt32 i) { return NS_STATIC_CAST(nsXBLInsertionPoint*, mElements->ElementAt(i)); }
|
||||
|
||||
private:
|
||||
nsISupportsArray* mElements;
|
||||
nsVoidArray* mElements;
|
||||
};
|
||||
|
||||
MOZ_DECL_CTOR_COUNTER(nsAnonymousContentList)
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED1(nsAnonymousContentList, nsGenericDOMNodeList, nsIAnonymousContentList)
|
||||
|
||||
nsAnonymousContentList::nsAnonymousContentList(nsISupportsArray* aElements)
|
||||
nsAnonymousContentList::nsAnonymousContentList(nsVoidArray* aElements)
|
||||
: mElements(aElements)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsAnonymousContentList);
|
||||
|
||||
// We don't reference count our Anonymous reference (to avoid circular
|
||||
// references). We'll be told when the Anonymous goes away.
|
||||
mElements = aElements;
|
||||
NS_IF_ADDREF(mElements);
|
||||
}
|
||||
|
||||
|
||||
static PRBool PR_CALLBACK DeleteInsertionPoint(void* aElement, void* aData)
|
||||
{
|
||||
delete NS_STATIC_CAST(nsXBLInsertionPoint*, aElement);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsAnonymousContentList::~nsAnonymousContentList()
|
||||
{
|
||||
MOZ_COUNT_DTOR(nsAnonymousContentList);
|
||||
NS_IF_RELEASE(mElements);
|
||||
mElements->EnumerateForwards(DeleteInsertionPoint, nsnull);
|
||||
delete mElements;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -156,17 +144,11 @@ nsAnonymousContentList::GetLength(PRUint32* aLength)
|
||||
if (! aLength)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
PRUint32 cnt;
|
||||
mElements->Count(&cnt);
|
||||
PRInt32 cnt = mElements->Count();
|
||||
|
||||
*aLength = 0;
|
||||
nsCOMPtr<nsIXBLInsertionPoint> point;
|
||||
PRUint32 l;
|
||||
for (PRUint32 i = 0; i < cnt; i++) {
|
||||
point = getter_AddRefs((nsIXBLInsertionPoint*)(mElements->ElementAt(i)));
|
||||
point->ChildCount(&l);
|
||||
*aLength += l;
|
||||
}
|
||||
for (PRInt32 i = 0; i < cnt; i++)
|
||||
*aLength += NS_STATIC_CAST(nsXBLInsertionPoint*, mElements->ElementAt(i))->ChildCount();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -174,48 +156,26 @@ nsAnonymousContentList::GetLength(PRUint32* aLength)
|
||||
NS_IMETHODIMP
|
||||
nsAnonymousContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
|
||||
{
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mElements->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRInt32 cnt = mElements->Count();
|
||||
PRUint32 pointCount = 0;
|
||||
nsCOMPtr<nsIXBLInsertionPoint> point;
|
||||
for (PRUint32 i = 0; i < cnt; i++) {
|
||||
|
||||
for (PRInt32 i = 0; i < cnt; i++) {
|
||||
aIndex -= pointCount;
|
||||
|
||||
point = getter_AddRefs((nsIXBLInsertionPoint*)(mElements->ElementAt(i)));
|
||||
point->ChildCount(&pointCount);
|
||||
nsXBLInsertionPoint* point = NS_STATIC_CAST(nsXBLInsertionPoint*, mElements->ElementAt(i));
|
||||
pointCount = point->ChildCount();
|
||||
|
||||
if (aIndex < pointCount) {
|
||||
nsCOMPtr<nsIContent> result;
|
||||
rv = point->ChildAt(aIndex, getter_AddRefs(result));
|
||||
if (result && NS_SUCCEEDED(rv))
|
||||
nsCOMPtr<nsIContent> result = point->ChildAt(aIndex);
|
||||
if (result)
|
||||
return CallQueryInterface(result, aReturn);
|
||||
else return rv;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAnonymousContentList::GetInsertionPointCount(PRUint32* aCount)
|
||||
{
|
||||
*aCount = 0;
|
||||
if (mElements)
|
||||
mElements->Count(aCount);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAnonymousContentList::GetInsertionPointAt(PRUint32 i, nsIXBLInsertionPoint** aResult)
|
||||
{
|
||||
*aResult = nsnull;
|
||||
if (mElements)
|
||||
*aResult = (nsIXBLInsertionPoint*)mElements->ElementAt(i);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsDoubleHashtable stuff to create a generic string -> nsISupports
|
||||
// table
|
||||
|
||||
@ -378,11 +338,11 @@ public:
|
||||
NS_IMETHOD ResolveTag(nsIContent* aContent, PRInt32* aNameSpaceID, nsIAtom** aResult);
|
||||
|
||||
NS_IMETHOD GetContentListFor(nsIContent* aContent, nsIDOMNodeList** aResult);
|
||||
NS_IMETHOD SetContentListFor(nsIContent* aContent, nsISupportsArray* aList);
|
||||
NS_IMETHOD SetContentListFor(nsIContent* aContent, nsVoidArray* aList);
|
||||
NS_IMETHOD HasContentListFor(nsIContent* aContent, PRBool* aResult);
|
||||
|
||||
NS_IMETHOD GetAnonymousNodesFor(nsIContent* aContent, nsIDOMNodeList** aResult);
|
||||
NS_IMETHOD SetAnonymousNodesFor(nsIContent* aContent, nsISupportsArray* aList);
|
||||
NS_IMETHOD SetAnonymousNodesFor(nsIContent* aContent, nsVoidArray* aList);
|
||||
|
||||
NS_IMETHOD GetXBLChildNodesFor(nsIContent* aContent, nsIDOMNodeList** aResult);
|
||||
|
||||
@ -427,6 +387,13 @@ public:
|
||||
NS_DECL_NSIDOCUMENTOBSERVER
|
||||
|
||||
protected:
|
||||
nsresult GetXBLChildNodesInternal(nsIContent* aContent,
|
||||
nsIDOMNodeList** aResult,
|
||||
PRBool* aIsAnonymousContentList);
|
||||
nsresult GetAnonymousNodesInternal(nsIContent* aContent,
|
||||
nsIDOMNodeList** aResult,
|
||||
PRBool* aIsAnonymousContentList);
|
||||
|
||||
void GetEnclosingScope(nsIContent* aContent, nsIContent** aParent);
|
||||
void GetOutermostStyleScope(nsIContent* aContent, nsIContent** aParent);
|
||||
|
||||
@ -688,7 +655,7 @@ nsBindingManager::GetContentListFor(nsIContent* aContent, nsIDOMNodeList** aResu
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBindingManager::SetContentListFor(nsIContent* aContent, nsISupportsArray* aList)
|
||||
nsBindingManager::SetContentListFor(nsIContent* aContent, nsVoidArray* aList)
|
||||
{
|
||||
nsIDOMNodeList* contentList = nsnull;
|
||||
if (aList) {
|
||||
@ -711,8 +678,10 @@ nsBindingManager::HasContentListFor(nsIContent* aContent, PRBool* aResult)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBindingManager::GetAnonymousNodesFor(nsIContent* aContent, nsIDOMNodeList** aResult)
|
||||
nsresult
|
||||
nsBindingManager::GetAnonymousNodesInternal(nsIContent* aContent,
|
||||
nsIDOMNodeList** aResult,
|
||||
PRBool* aIsAnonymousContentList)
|
||||
{
|
||||
// Locate the primary binding and get its node list of anonymous children.
|
||||
*aResult = nsnull;
|
||||
@ -723,17 +692,27 @@ nsBindingManager::GetAnonymousNodesFor(nsIContent* aContent, nsIDOMNodeList** aR
|
||||
}
|
||||
|
||||
if (!*aResult) {
|
||||
*aIsAnonymousContentList = PR_FALSE;
|
||||
nsCOMPtr<nsIXBLBinding> binding;
|
||||
GetBinding(aContent, getter_AddRefs(binding));
|
||||
if (binding)
|
||||
return binding->GetAnonymousNodes(aResult);
|
||||
}
|
||||
} else
|
||||
*aIsAnonymousContentList = PR_TRUE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBindingManager::SetAnonymousNodesFor(nsIContent* aContent, nsISupportsArray* aList)
|
||||
nsBindingManager::GetAnonymousNodesFor(nsIContent* aContent,
|
||||
nsIDOMNodeList** aResult)
|
||||
{
|
||||
PRBool dummy;
|
||||
return GetAnonymousNodesInternal(aContent, aResult, &dummy);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBindingManager::SetAnonymousNodesFor(nsIContent* aContent, nsVoidArray* aList)
|
||||
{
|
||||
nsIDOMNodeList* contentList = nsnull;
|
||||
if (aList) {
|
||||
@ -744,15 +723,17 @@ nsBindingManager::SetAnonymousNodesFor(nsIContent* aContent, nsISupportsArray* a
|
||||
return SetOrRemoveObject(mAnonymousNodesTable, aContent, contentList);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBindingManager::GetXBLChildNodesFor(nsIContent* aContent, nsIDOMNodeList** aResult)
|
||||
nsresult
|
||||
nsBindingManager::GetXBLChildNodesInternal(nsIContent* aContent,
|
||||
nsIDOMNodeList** aResult,
|
||||
PRBool* aIsAnonymousContentList)
|
||||
{
|
||||
*aResult = nsnull;
|
||||
|
||||
PRUint32 length;
|
||||
|
||||
// Retrieve the anonymous content that we should build.
|
||||
GetAnonymousNodesFor(aContent, aResult);
|
||||
GetAnonymousNodesInternal(aContent, aResult, aIsAnonymousContentList);
|
||||
if (*aResult) {
|
||||
(*aResult)->GetLength(&length);
|
||||
if (length == 0)
|
||||
@ -767,11 +748,20 @@ nsBindingManager::GetXBLChildNodesFor(nsIContent* aContent, nsIDOMNodeList** aRe
|
||||
*aResult = NS_STATIC_CAST(nsIDOMNodeList*,
|
||||
LookupObject(mContentListTable, aContent));
|
||||
NS_IF_ADDREF(*aResult);
|
||||
*aIsAnonymousContentList = PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBindingManager::GetXBLChildNodesFor(nsIContent* aContent, nsIDOMNodeList** aResult)
|
||||
{
|
||||
PRBool dummy;
|
||||
return GetXBLChildNodesInternal(aContent, aResult, &dummy);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBindingManager::GetInsertionPoint(nsIContent* aParent, nsIContent* aChild, nsIContent** aResult, PRUint32* aIndex)
|
||||
{
|
||||
@ -1467,30 +1457,28 @@ nsBindingManager::ContentAppended(nsIDocument* aDocument,
|
||||
|
||||
if (ins) {
|
||||
nsCOMPtr<nsIDOMNodeList> nodeList;
|
||||
GetXBLChildNodesFor(ins, getter_AddRefs(nodeList));
|
||||
PRBool isAnonymousContentList;
|
||||
GetXBLChildNodesInternal(ins, getter_AddRefs(nodeList),
|
||||
&isAnonymousContentList);
|
||||
|
||||
if (nodeList) {
|
||||
nsCOMPtr<nsIAnonymousContentList> contentList(do_QueryInterface(nodeList));
|
||||
if (contentList) {
|
||||
// Find a non-pseudo-insertion point and just jam ourselves in.
|
||||
// This is not 100% correct. Hack city, baby.
|
||||
PRUint32 count;
|
||||
contentList->GetInsertionPointCount(&count);
|
||||
for (PRUint32 i =0; i < count; i++) {
|
||||
nsCOMPtr<nsIXBLInsertionPoint> point;
|
||||
contentList->GetInsertionPointAt(i, getter_AddRefs(point));
|
||||
PRInt32 index;
|
||||
point->GetInsertionIndex(&index);
|
||||
if (index != -1) {
|
||||
// We're real. Jam all the kids in.
|
||||
// XXX Check the filters to find the correct points.
|
||||
for (PRInt32 j = aNewIndexInContainer; j < childCount; j++) {
|
||||
aContainer->ChildAt(j, *getter_AddRefs(child));
|
||||
point->AddChild(child);
|
||||
SetInsertionParent(child, ins);
|
||||
}
|
||||
break;
|
||||
if (nodeList && isAnonymousContentList) {
|
||||
// Find a non-pseudo-insertion point and just jam ourselves in.
|
||||
// This is not 100% correct. Hack city, baby.
|
||||
nsAnonymousContentList* contentList = NS_STATIC_CAST(nsAnonymousContentList*, NS_STATIC_CAST(nsIDOMNodeList*, nodeList.get()));
|
||||
|
||||
PRInt32 count = contentList->GetInsertionPointCount();
|
||||
for (PRInt32 i = 0; i < count; i++) {
|
||||
nsXBLInsertionPoint* point = contentList->GetInsertionPointAt(i);
|
||||
PRInt32 index = point->GetInsertionIndex();
|
||||
if (index != -1) {
|
||||
// We're real. Jam all the kids in.
|
||||
// XXX Check the filters to find the correct points.
|
||||
for (PRInt32 j = aNewIndexInContainer; j < childCount; j++) {
|
||||
aContainer->ChildAt(j, *getter_AddRefs(child));
|
||||
point->AddChild(child);
|
||||
SetInsertionParent(child, ins);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1501,9 +1489,9 @@ nsBindingManager::ContentAppended(nsIDocument* aDocument,
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBindingManager::ContentInserted(nsIDocument* aDocument,
|
||||
nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer)
|
||||
nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer)
|
||||
{
|
||||
// XXX This is hacked just to make menus work again.
|
||||
if (aIndexInContainer == -1 || !mContentListTable.ops)
|
||||
@ -1515,27 +1503,24 @@ nsBindingManager::ContentInserted(nsIDocument* aDocument,
|
||||
|
||||
if (ins) {
|
||||
nsCOMPtr<nsIDOMNodeList> nodeList;
|
||||
GetXBLChildNodesFor(ins, getter_AddRefs(nodeList));
|
||||
PRBool isAnonymousContentList;
|
||||
GetXBLChildNodesInternal(ins, getter_AddRefs(nodeList),
|
||||
&isAnonymousContentList);
|
||||
|
||||
if (nodeList) {
|
||||
nsCOMPtr<nsIAnonymousContentList> contentList(do_QueryInterface(nodeList));
|
||||
if (contentList) {
|
||||
// Find a non-pseudo-insertion point and just jam ourselves in.
|
||||
// This is not 100% correct. Hack city, baby.
|
||||
PRUint32 count;
|
||||
contentList->GetInsertionPointCount(&count);
|
||||
for (PRUint32 i =0; i < count; i++) {
|
||||
nsCOMPtr<nsIXBLInsertionPoint> point;
|
||||
contentList->GetInsertionPointAt(i, getter_AddRefs(point));
|
||||
PRInt32 index;
|
||||
point->GetInsertionIndex(&index);
|
||||
if (index != -1) {
|
||||
// We're real. Jam the kid in.
|
||||
// XXX Check the filters to find the correct points.
|
||||
point->InsertChildAt(aIndexInContainer, aChild);
|
||||
SetInsertionParent(aChild, ins);
|
||||
break;
|
||||
}
|
||||
if (nodeList && isAnonymousContentList) {
|
||||
// Find a non-pseudo-insertion point and just jam ourselves in.
|
||||
// This is not 100% correct. Hack city, baby.
|
||||
nsAnonymousContentList* contentList = NS_STATIC_CAST(nsAnonymousContentList*, NS_STATIC_CAST(nsIDOMNodeList*, nodeList.get()));
|
||||
|
||||
PRInt32 count = contentList->GetInsertionPointCount();
|
||||
for (PRInt32 i = 0; i < count; i++) {
|
||||
nsXBLInsertionPoint* point = contentList->GetInsertionPointAt(i);
|
||||
if (point->GetInsertionIndex() != -1) {
|
||||
// We're real. Jam the kid in.
|
||||
// XXX Check the filters to find the correct points.
|
||||
point->InsertChildAt(aIndexInContainer, aChild);
|
||||
SetInsertionParent(aChild, ins);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1570,22 +1555,18 @@ nsBindingManager::ContentRemoved(nsIDocument* aDocument,
|
||||
|
||||
if (point) {
|
||||
nsCOMPtr<nsIDOMNodeList> nodeList;
|
||||
GetXBLChildNodesFor(point, getter_AddRefs(nodeList));
|
||||
PRBool isAnonymousContentList;
|
||||
GetXBLChildNodesInternal(point, getter_AddRefs(nodeList),
|
||||
&isAnonymousContentList);
|
||||
|
||||
if (nodeList) {
|
||||
nsCOMPtr<nsIAnonymousContentList> contentList(do_QueryInterface(nodeList));
|
||||
if (contentList) {
|
||||
// Find a non-pseudo-insertion point and remove ourselves.
|
||||
PRUint32 count;
|
||||
contentList->GetInsertionPointCount(&count);
|
||||
for (PRUint32 i =0; i < count; i++) {
|
||||
nsCOMPtr<nsIXBLInsertionPoint> point;
|
||||
contentList->GetInsertionPointAt(i, getter_AddRefs(point));
|
||||
PRInt32 index;
|
||||
point->GetInsertionIndex(&index);
|
||||
if (index != -1) {
|
||||
point->RemoveChild(aChild);
|
||||
}
|
||||
if (nodeList && isAnonymousContentList) {
|
||||
// Find a non-pseudo-insertion point and remove ourselves.
|
||||
nsAnonymousContentList* contentList = NS_STATIC_CAST(nsAnonymousContentList*, NS_STATIC_CAST(nsIDOMNodeList*, nodeList));
|
||||
PRInt32 count = contentList->GetInsertionPointCount();
|
||||
for (PRInt32 i =0; i < count; i++) {
|
||||
nsXBLInsertionPoint* point = contentList->GetInsertionPointAt(i);
|
||||
if (point->GetInsertionIndex() != -1) {
|
||||
point->RemoveChild(aChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,7 @@
|
||||
#include "nsINameSpace.h"
|
||||
#include "jsapi.h"
|
||||
#include "nsXBLService.h"
|
||||
#include "nsIXBLInsertionPoint.h"
|
||||
#include "nsXBLInsertionPoint.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsIScriptGlobalObjectOwner.h"
|
||||
#include "nsIScriptContext.h"
|
||||
@ -451,25 +451,20 @@ PRBool PR_CALLBACK BuildContentLists(nsHashKey* aKey, void* aData, void* aClosur
|
||||
nsCOMPtr<nsIContent> boundElement;
|
||||
binding->GetBoundElement(getter_AddRefs(boundElement));
|
||||
|
||||
nsISupportsArray* arr = (nsISupportsArray*)aData;
|
||||
PRUint32 count;
|
||||
arr->Count(&count);
|
||||
nsVoidArray* arr = NS_STATIC_CAST(nsVoidArray*, aData);
|
||||
PRInt32 count = arr->Count();
|
||||
|
||||
if (count == 0)
|
||||
return NS_OK;
|
||||
|
||||
// XXX Could this array just be altered in place and passed directly to
|
||||
// SetContentListFor? We'd save space if we could pull this off.
|
||||
nsCOMPtr<nsISupportsArray> contentList;
|
||||
NS_NewISupportsArray(getter_AddRefs(contentList));
|
||||
nsVoidArray* contentList = new nsVoidArray();
|
||||
|
||||
// Figure out the relevant content node.
|
||||
PRUint32 j = 0;
|
||||
nsCOMPtr<nsIXBLInsertionPoint> currPoint = getter_AddRefs((nsIXBLInsertionPoint*)arr->ElementAt(j));
|
||||
nsCOMPtr<nsIContent> parent;
|
||||
PRInt32 currIndex;
|
||||
currPoint->GetInsertionParent(getter_AddRefs(parent));
|
||||
currPoint->GetInsertionIndex(&currIndex);
|
||||
nsXBLInsertionPoint* currPoint = NS_STATIC_CAST(nsXBLInsertionPoint*, arr->ElementAt(0));
|
||||
nsCOMPtr<nsIContent> parent = currPoint->GetInsertionParent();
|
||||
PRInt32 currIndex = currPoint->GetInsertionIndex();
|
||||
|
||||
nsCOMPtr<nsIDOMNodeList> nodeList;
|
||||
if (parent == boundElement) {
|
||||
@ -482,9 +477,11 @@ PRBool PR_CALLBACK BuildContentLists(nsHashKey* aKey, void* aData, void* aClosur
|
||||
node->GetChildNodes(getter_AddRefs(nodeList));
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIXBLInsertionPoint> pseudoPoint;
|
||||
nsXBLInsertionPoint* pseudoPoint = nsnull;
|
||||
PRUint32 childCount;
|
||||
nodeList->GetLength(&childCount);
|
||||
PRInt32 j = 0;
|
||||
|
||||
for (PRUint32 i = 0; i < childCount; i++) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
nodeList->Item(i, getter_AddRefs(node));
|
||||
@ -496,8 +493,8 @@ PRBool PR_CALLBACK BuildContentLists(nsHashKey* aKey, void* aData, void* aClosur
|
||||
// Get the next real insertion point and update our currIndex.
|
||||
j++;
|
||||
if (j < count) {
|
||||
currPoint = getter_AddRefs((nsIXBLInsertionPoint*)arr->ElementAt(j));
|
||||
currPoint->GetInsertionIndex(&currIndex);
|
||||
currPoint = NS_STATIC_CAST(nsXBLInsertionPoint*, arr->ElementAt(j));
|
||||
currIndex = currPoint->GetInsertionIndex();
|
||||
}
|
||||
|
||||
// Null out our current pseudo-point.
|
||||
@ -505,7 +502,7 @@ PRBool PR_CALLBACK BuildContentLists(nsHashKey* aKey, void* aData, void* aClosur
|
||||
}
|
||||
|
||||
if (!pseudoPoint) {
|
||||
NS_NewXBLInsertionPoint(parent.get(), (PRUint32)-1, nsnull, getter_AddRefs(pseudoPoint));
|
||||
pseudoPoint = new nsXBLInsertionPoint(parent, (PRUint32) -1, nsnull);
|
||||
contentList->AppendElement(pseudoPoint);
|
||||
}
|
||||
|
||||
@ -514,8 +511,8 @@ PRBool PR_CALLBACK BuildContentLists(nsHashKey* aKey, void* aData, void* aClosur
|
||||
|
||||
// Add in all the remaining insertion points.
|
||||
for ( ; j < count; j++) {
|
||||
currPoint = getter_AddRefs((nsIXBLInsertionPoint*)arr->ElementAt(j));
|
||||
contentList->AppendElement(currPoint);
|
||||
currPoint = NS_STATIC_CAST(nsXBLInsertionPoint*, arr->ElementAt(j));
|
||||
contentList->AppendElement(currPoint);
|
||||
}
|
||||
|
||||
// Now set the content list using the binding manager,
|
||||
@ -538,18 +535,15 @@ PRBool PR_CALLBACK RealizeDefaultContent(nsHashKey* aKey, void* aData, void* aCl
|
||||
nsCOMPtr<nsIContent> boundElement;
|
||||
binding->GetBoundElement(getter_AddRefs(boundElement));
|
||||
|
||||
nsISupportsArray* arr = (nsISupportsArray*)aData;
|
||||
PRUint32 count;
|
||||
arr->Count(&count);
|
||||
nsVoidArray* arr = (nsVoidArray*)aData;
|
||||
PRInt32 count = arr->Count();
|
||||
|
||||
for (PRUint32 i = 0; i < count; i++) {
|
||||
nsCOMPtr<nsIXBLInsertionPoint> currPoint = getter_AddRefs((nsIXBLInsertionPoint*)arr->ElementAt(i));
|
||||
PRUint32 insCount;
|
||||
currPoint->ChildCount(&insCount);
|
||||
for (PRInt32 i = 0; i < count; i++) {
|
||||
nsXBLInsertionPoint* currPoint = NS_STATIC_CAST(nsXBLInsertionPoint*, arr->ElementAt(i));
|
||||
PRInt32 insCount = currPoint->ChildCount();
|
||||
|
||||
if (insCount == 0) {
|
||||
nsCOMPtr<nsIContent> defContent;
|
||||
currPoint->GetDefaultContentTemplate(getter_AddRefs(defContent));
|
||||
nsCOMPtr<nsIContent> defContent = currPoint->GetDefaultContentTemplate();
|
||||
if (defContent) {
|
||||
// We need to take this template and use it to realize the
|
||||
// actual default content (through cloning).
|
||||
@ -558,8 +552,7 @@ PRBool PR_CALLBACK RealizeDefaultContent(nsHashKey* aKey, void* aData, void* aCl
|
||||
nsCOMPtr<nsIDOMNode> clonedNode;
|
||||
elt->CloneNode(PR_TRUE, getter_AddRefs(clonedNode));
|
||||
|
||||
nsCOMPtr<nsIContent> insParent;
|
||||
currPoint->GetInsertionParent(getter_AddRefs(insParent));
|
||||
nsCOMPtr<nsIContent> insParent = currPoint->GetInsertionParent();
|
||||
|
||||
// Now that we have the cloned content, install the default content as
|
||||
// if it were additional anonymous content.
|
||||
@ -589,14 +582,12 @@ PRBool PR_CALLBACK RealizeDefaultContent(nsHashKey* aKey, void* aData, void* aCl
|
||||
|
||||
PRBool PR_CALLBACK ChangeDocumentForDefaultContent(nsHashKey* aKey, void* aData, void* aClosure)
|
||||
{
|
||||
nsISupportsArray* arr = (nsISupportsArray*)aData;
|
||||
PRUint32 count;
|
||||
arr->Count(&count);
|
||||
nsVoidArray* arr = NS_STATIC_CAST(nsVoidArray*, aData);
|
||||
PRInt32 count = arr->Count();
|
||||
|
||||
for (PRUint32 i = 0; i < count; i++) {
|
||||
nsCOMPtr<nsIXBLInsertionPoint> currPoint = getter_AddRefs((nsIXBLInsertionPoint*)arr->ElementAt(i));
|
||||
nsCOMPtr<nsIContent> defContent;
|
||||
currPoint->GetDefaultContent(getter_AddRefs(defContent));
|
||||
for (PRInt32 i = 0; i < count; i++) {
|
||||
nsXBLInsertionPoint* currPoint = NS_STATIC_CAST(nsXBLInsertionPoint*, arr->ElementAt(i));
|
||||
nsCOMPtr<nsIContent> defContent = currPoint->GetDefaultContent();
|
||||
|
||||
if (defContent)
|
||||
defContent->SetDocument(nsnull, PR_TRUE, PR_TRUE);
|
||||
@ -734,16 +725,13 @@ nsXBLBinding::GenerateAnonymousContent()
|
||||
bindingManager->SetInsertionParent(childContent, point);
|
||||
|
||||
// Find the correct nsIXBLInsertion point in our table.
|
||||
nsCOMPtr<nsIXBLInsertionPoint> insertionPoint;
|
||||
nsCOMPtr<nsISupportsArray> arr;
|
||||
GetInsertionPointsFor(point, getter_AddRefs(arr));
|
||||
PRUint32 arrCount;
|
||||
arr->Count(&arrCount);
|
||||
for (PRUint32 j = 0; j < arrCount; j++) {
|
||||
insertionPoint = getter_AddRefs((nsIXBLInsertionPoint*)arr->ElementAt(j));
|
||||
PRBool matches;
|
||||
insertionPoint->Matches(point, index, &matches);
|
||||
if (matches)
|
||||
nsVoidArray* arr;
|
||||
GetInsertionPointsFor(point, &arr);
|
||||
nsXBLInsertionPoint* insertionPoint = nsnull;
|
||||
PRInt32 arrCount = arr->Count();
|
||||
for (PRInt32 j = 0; j < arrCount; j++) {
|
||||
insertionPoint = NS_STATIC_CAST(nsXBLInsertionPoint*, arr->ElementAt(j));
|
||||
if (insertionPoint->Matches(point, index))
|
||||
break;
|
||||
insertionPoint = nsnull;
|
||||
}
|
||||
@ -767,11 +755,9 @@ nsXBLBinding::GenerateAnonymousContent()
|
||||
}
|
||||
else {
|
||||
// All of our children are shunted to this single insertion point.
|
||||
nsCOMPtr<nsISupportsArray> arr;
|
||||
GetInsertionPointsFor(singlePoint, getter_AddRefs(arr));
|
||||
PRUint32 arrCount;
|
||||
arr->Count(&arrCount);
|
||||
nsCOMPtr<nsIXBLInsertionPoint> insertionPoint = getter_AddRefs((nsIXBLInsertionPoint*)arr->ElementAt(0));
|
||||
nsVoidArray* arr;
|
||||
GetInsertionPointsFor(singlePoint, &arr);
|
||||
nsXBLInsertionPoint* insertionPoint = NS_STATIC_CAST(nsXBLInsertionPoint*, arr->ElementAt(0));
|
||||
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
nsCOMPtr<nsIContent> content;
|
||||
@ -1538,16 +1524,21 @@ nsXBLBinding::AllowScripts()
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXBLBinding::GetInsertionPointsFor(nsIContent* aParent, nsISupportsArray** aResult)
|
||||
nsXBLBinding::GetInsertionPointsFor(nsIContent* aParent, nsVoidArray** aResult)
|
||||
{
|
||||
if (!mInsertionPointTable)
|
||||
mInsertionPointTable = new nsSupportsHashtable(4);
|
||||
if (!mInsertionPointTable) {
|
||||
mInsertionPointTable = new nsObjectHashtable(nsnull, nsnull,
|
||||
nsnull, nsnull, 4);
|
||||
|
||||
NS_ENSURE_TRUE(mInsertionPointTable, NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
nsISupportsKey key(aParent);
|
||||
*aResult = NS_STATIC_CAST(nsISupportsArray*, mInsertionPointTable->Get(&key));
|
||||
*aResult = NS_STATIC_CAST(nsVoidArray*, mInsertionPointTable->Get(&key));
|
||||
|
||||
if (!*aResult) {
|
||||
NS_NewISupportsArray(aResult);
|
||||
*aResult = new nsVoidArray();
|
||||
NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
|
||||
mInsertionPointTable->Put(&key, *aResult);
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ class nsIAtom;
|
||||
class nsIDocument;
|
||||
class nsIScriptContext;
|
||||
class nsISupportsArray;
|
||||
class nsSupportsHashtable;
|
||||
class nsObjectHashtable;
|
||||
class nsIXBLService;
|
||||
class nsFixedSizeAllocator;
|
||||
class nsXBLEventHandler;
|
||||
@ -99,7 +99,7 @@ class nsXBLBinding: public nsIXBLBinding
|
||||
NS_IMETHOD GetDocURI(nsCString& aResult);
|
||||
NS_IMETHOD GetID(nsCString& aResult);
|
||||
|
||||
NS_IMETHOD GetInsertionPointsFor(nsIContent* aParent, nsISupportsArray** aResult);
|
||||
NS_IMETHOD GetInsertionPointsFor(nsIContent* aParent, nsVoidArray** aResult);
|
||||
|
||||
NS_IMETHOD GetInsertionPoint(nsIContent* aChild, nsIContent** aResult, PRUint32* aIndex, nsIContent** aDefaultContent);
|
||||
NS_IMETHOD GetSingleInsertionPoint(nsIContent** aResult, PRUint32* aIndex,
|
||||
@ -176,7 +176,7 @@ protected:
|
||||
|
||||
nsIContent* mBoundElement; // [WEAK] We have a reference, but we don't own it.
|
||||
|
||||
nsSupportsHashtable* mInsertionPointTable; // A hash from nsIContent* -> (a sorted array of nsIXBLInsertionPoint*)
|
||||
nsObjectHashtable* mInsertionPointTable; // A hash from nsIContent* -> (a sorted array of nsXBLInsertionPoint*)
|
||||
|
||||
PRPackedBool mIsStyleBinding;
|
||||
PRPackedBool mMarkedForDeath;
|
||||
|
@ -37,138 +37,54 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsXBLInsertionPoint.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
nsXBLInsertionPoint::nsXBLInsertionPoint(nsIContent* aParentElement, PRUint32 aIndex, nsIContent* aDefaultContent)
|
||||
:mElements(nsnull)
|
||||
nsXBLInsertionPoint::nsXBLInsertionPoint(nsIContent* aParentElement,
|
||||
PRUint32 aIndex,
|
||||
nsIContent* aDefaultContent)
|
||||
: mParentElement(aParentElement),
|
||||
mIndex(aIndex),
|
||||
mDefaultContentTemplate(aDefaultContent)
|
||||
{
|
||||
mParentElement = aParentElement;
|
||||
mIndex = aIndex;
|
||||
mDefaultContentTemplate = aDefaultContent;
|
||||
}
|
||||
|
||||
nsXBLInsertionPoint::~nsXBLInsertionPoint()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsXBLInsertionPoint, nsIXBLInsertionPoint)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXBLInsertionPoint::GetInsertionParent(nsIContent** aParentElement)
|
||||
already_AddRefed<nsIContent>
|
||||
nsXBLInsertionPoint::GetInsertionParent()
|
||||
{
|
||||
*aParentElement = mParentElement;
|
||||
NS_IF_ADDREF(mParentElement);
|
||||
return NS_OK;
|
||||
return mParentElement;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXBLInsertionPoint::GetInsertionIndex(PRInt32 *aResult)
|
||||
already_AddRefed<nsIContent>
|
||||
nsXBLInsertionPoint::GetDefaultContent()
|
||||
{
|
||||
*aResult = mIndex;
|
||||
return NS_OK;
|
||||
nsIContent* defaultContent = mDefaultContent;
|
||||
NS_IF_ADDREF(defaultContent);
|
||||
return defaultContent;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXBLInsertionPoint::SetDefaultContent(nsIContent* aDefaultContent)
|
||||
already_AddRefed<nsIContent>
|
||||
nsXBLInsertionPoint::GetDefaultContentTemplate()
|
||||
{
|
||||
mDefaultContent = aDefaultContent;
|
||||
return NS_OK;
|
||||
nsIContent* defaultContent = mDefaultContentTemplate;
|
||||
NS_IF_ADDREF(defaultContent);
|
||||
return defaultContent;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXBLInsertionPoint::GetDefaultContent(nsIContent** aDefaultContent)
|
||||
already_AddRefed<nsIContent>
|
||||
nsXBLInsertionPoint::ChildAt(PRUint32 aIndex)
|
||||
{
|
||||
*aDefaultContent = mDefaultContent;
|
||||
NS_IF_ADDREF(*aDefaultContent);
|
||||
return NS_OK;
|
||||
nsIContent* result = mElements.ObjectAt(aIndex);
|
||||
NS_IF_ADDREF(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXBLInsertionPoint::SetDefaultContentTemplate(nsIContent* aDefaultContent)
|
||||
PRBool
|
||||
nsXBLInsertionPoint::Matches(nsIContent* aContent, PRUint32 aIndex)
|
||||
{
|
||||
mDefaultContentTemplate = aDefaultContent;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXBLInsertionPoint::GetDefaultContentTemplate(nsIContent** aDefaultContent)
|
||||
{
|
||||
*aDefaultContent = mDefaultContentTemplate;
|
||||
NS_IF_ADDREF(*aDefaultContent);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXBLInsertionPoint::AddChild(nsIContent* aChildElement)
|
||||
{
|
||||
if (!mElements)
|
||||
NS_NewISupportsArray(getter_AddRefs(mElements));
|
||||
|
||||
mElements->AppendElement(aChildElement);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXBLInsertionPoint::InsertChildAt(PRInt32 aIndex, nsIContent* aChildElement)
|
||||
{
|
||||
if (!mElements)
|
||||
NS_NewISupportsArray(getter_AddRefs(mElements));
|
||||
|
||||
mElements->InsertElementAt(aChildElement, aIndex);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXBLInsertionPoint::RemoveChild(nsIContent* aChildElement)
|
||||
{
|
||||
if (mElements)
|
||||
mElements->RemoveElement(aChildElement);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXBLInsertionPoint::ChildCount(PRUint32* aResult)
|
||||
{
|
||||
*aResult = 0;
|
||||
if (mElements)
|
||||
mElements->Count(aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXBLInsertionPoint::ChildAt(PRUint32 aIndex, nsIContent** aResult)
|
||||
{
|
||||
if (!mElements) {
|
||||
*aResult = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
*aResult = (nsIContent*)(mElements->ElementAt(aIndex)); // Addref happens in return.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXBLInsertionPoint::Matches(nsIContent* aContent, PRUint32 aIndex, PRBool* aResult)
|
||||
{
|
||||
*aResult = (aContent == mParentElement && mIndex != -1 && ((PRInt32)aIndex) == mIndex);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewXBLInsertionPoint(nsIContent* aParentElement, PRUint32 aIndex, nsIContent* aDefContent,
|
||||
nsIXBLInsertionPoint** aResult)
|
||||
{
|
||||
*aResult = new nsXBLInsertionPoint(aParentElement, aIndex, aDefContent);
|
||||
if (!*aResult)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
return (aContent == mParentElement && mIndex != -1 && ((PRInt32)aIndex) == mIndex);
|
||||
}
|
||||
|
@ -40,49 +40,42 @@
|
||||
#ifndef nsXBLInsertionPoint_h__
|
||||
#define nsXBLInsertionPoint_h__
|
||||
|
||||
#include "nsIXBLInsertionPoint.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsXBLInsertionPoint : public nsIXBLInsertionPoint
|
||||
class nsXBLInsertionPoint
|
||||
{
|
||||
public:
|
||||
nsXBLInsertionPoint(nsIContent* aParentElement, PRUint32 aIndex, nsIContent* aDefContent);
|
||||
virtual ~nsXBLInsertionPoint();
|
||||
~nsXBLInsertionPoint();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
already_AddRefed<nsIContent> GetInsertionParent();
|
||||
PRInt32 GetInsertionIndex() { return mIndex; }
|
||||
|
||||
NS_IMETHOD GetInsertionParent(nsIContent** aParentElement);
|
||||
NS_IMETHOD GetInsertionIndex(PRInt32* aIndex);
|
||||
void SetDefaultContent(nsIContent* aDefaultContent) { mDefaultContent = aDefaultContent; }
|
||||
already_AddRefed<nsIContent> GetDefaultContent();
|
||||
|
||||
NS_IMETHOD SetDefaultContent(nsIContent* aDefaultContent);
|
||||
NS_IMETHOD GetDefaultContent(nsIContent** aDefaultContent);
|
||||
void SetDefaultContentTemplate(nsIContent* aDefaultContent) { mDefaultContentTemplate = aDefaultContent; }
|
||||
already_AddRefed<nsIContent> GetDefaultContentTemplate();
|
||||
|
||||
NS_IMETHOD SetDefaultContentTemplate(nsIContent* aDefaultContent);
|
||||
NS_IMETHOD GetDefaultContentTemplate(nsIContent** aDefaultContent);
|
||||
|
||||
NS_IMETHOD AddChild(nsIContent* aChildElement);
|
||||
NS_IMETHOD InsertChildAt(PRInt32 aIndex, nsIContent* aChildElement);
|
||||
NS_IMETHOD RemoveChild(nsIContent* aChildElement);
|
||||
void AddChild(nsIContent* aChildElement) { mElements.AppendObject(aChildElement); }
|
||||
void InsertChildAt(PRInt32 aIndex, nsIContent* aChildElement) { mElements.InsertObjectAt(aChildElement, aIndex); }
|
||||
void RemoveChild(nsIContent* aChildElement) { mElements.RemoveObject(aChildElement); }
|
||||
|
||||
NS_IMETHOD ChildCount(PRUint32* aResult);
|
||||
PRInt32 ChildCount() { return mElements.Count(); }
|
||||
|
||||
NS_IMETHOD ChildAt(PRUint32 aIndex, nsIContent** aResult);
|
||||
already_AddRefed<nsIContent> ChildAt(PRUint32 aIndex);
|
||||
|
||||
NS_IMETHOD Matches(nsIContent* aContent, PRUint32 aIndex, PRBool* aResult);
|
||||
PRBool Matches(nsIContent* aContent, PRUint32 aIndex);
|
||||
|
||||
protected:
|
||||
nsIContent* mParentElement; // This ref is weak. The parent of the <children> element.
|
||||
PRInt32 mIndex; // The index of this insertion point. -1 is a pseudo-point.
|
||||
nsCOMPtr<nsISupportsArray> mElements; // An array of elements present at the insertion point.
|
||||
nsCOMArray<nsIContent> mElements; // An array of elements present at the insertion point.
|
||||
nsCOMPtr<nsIContent> mDefaultContentTemplate ; // The template default content that will be cloned if
|
||||
// the insertion point is empty.
|
||||
nsCOMPtr<nsIContent> mDefaultContent; // The cloned default content obtained by cloning mDefaultContentTemplate.
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_NewXBLInsertionPoint(nsIContent* aParentElement, PRUint32 aIndex,
|
||||
nsIContent* aDefContent,
|
||||
nsIXBLInsertionPoint** aResult);
|
||||
|
||||
#endif
|
||||
|
@ -64,7 +64,7 @@
|
||||
#include "nsINameSpace.h"
|
||||
#include "nsXBLService.h"
|
||||
#include "nsXBLBinding.h"
|
||||
#include "nsIXBLInsertionPoint.h"
|
||||
#include "nsXBLInsertionPoint.h"
|
||||
#include "nsXBLPrototypeBinding.h"
|
||||
#include "nsFixedSizeAllocator.h"
|
||||
#include "xptinfo.h"
|
||||
@ -602,17 +602,16 @@ PRBool PR_CALLBACK InstantiateInsertionPoint(nsHashKey* aKey, void* aData, void*
|
||||
binding->GetBoundElement(getter_AddRefs(realContent));
|
||||
|
||||
// Now that we have the real content, look it up in our table.
|
||||
nsCOMPtr<nsISupportsArray> points;
|
||||
binding->GetInsertionPointsFor(realContent, getter_AddRefs(points));
|
||||
nsCOMPtr<nsIXBLInsertionPoint> insertionPoint;
|
||||
PRUint32 count;
|
||||
points->Count(&count);
|
||||
PRUint32 i = 0;
|
||||
nsVoidArray* points;
|
||||
binding->GetInsertionPointsFor(realContent, &points);
|
||||
nsXBLInsertionPoint* insertionPoint = nsnull;
|
||||
PRInt32 count = points->Count();
|
||||
PRInt32 i = 0;
|
||||
PRInt32 currIndex = 0;
|
||||
|
||||
for ( ; i < count; i++) {
|
||||
nsCOMPtr<nsIXBLInsertionPoint> currPoint = getter_AddRefs((nsIXBLInsertionPoint*)points->ElementAt(i));
|
||||
currPoint->GetInsertionIndex(&currIndex);
|
||||
nsXBLInsertionPoint* currPoint = NS_STATIC_CAST(nsXBLInsertionPoint*, points->ElementAt(i));
|
||||
currIndex = currPoint->GetInsertionIndex();
|
||||
if (currIndex == (PRInt32)index) {
|
||||
// This is a match. Break out of the loop and set our variable.
|
||||
insertionPoint = currPoint;
|
||||
@ -626,7 +625,7 @@ PRBool PR_CALLBACK InstantiateInsertionPoint(nsHashKey* aKey, void* aData, void*
|
||||
|
||||
if (!insertionPoint) {
|
||||
// We need to make a new insertion point.
|
||||
NS_NewXBLInsertionPoint(realContent, index, defContent, getter_AddRefs(insertionPoint));
|
||||
insertionPoint = new nsXBLInsertionPoint(realContent, index, defContent);
|
||||
points->InsertElementAt(insertionPoint, i);
|
||||
}
|
||||
|
||||
@ -857,25 +856,22 @@ nsXBLPrototypeBinding::LocateInstance(nsIContent* aBoundElement,
|
||||
tempBinding->GetBaseBinding(getter_AddRefs(currBinding));
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupportsArray> points;
|
||||
nsVoidArray* points;
|
||||
if (anonContent == copyParent)
|
||||
currBinding->GetInsertionPointsFor(aBoundElement, getter_AddRefs(points));
|
||||
currBinding->GetInsertionPointsFor(aBoundElement, &points);
|
||||
else
|
||||
currBinding->GetInsertionPointsFor(copyParent, getter_AddRefs(points));
|
||||
nsCOMPtr<nsIXBLInsertionPoint> insertionPoint;
|
||||
PRUint32 count;
|
||||
points->Count(&count);
|
||||
for (PRUint32 i = 0; i < count; i++) {
|
||||
currBinding->GetInsertionPointsFor(copyParent, &points);
|
||||
PRInt32 count = points->Count();
|
||||
for (PRInt32 i = 0; i < count; i++) {
|
||||
// Next we have to find the real insertion point for this proto insertion
|
||||
// point. If it does not contain any default content, then we should
|
||||
// return null, since the content is not in the clone.
|
||||
nsCOMPtr<nsIXBLInsertionPoint> currPoint = getter_AddRefs((nsIXBLInsertionPoint*)points->ElementAt(i));
|
||||
nsCOMPtr<nsIContent> defContent;
|
||||
currPoint->GetDefaultContentTemplate(getter_AddRefs(defContent));
|
||||
nsXBLInsertionPoint* currPoint = NS_STATIC_CAST(nsXBLInsertionPoint*, points->ElementAt(i));
|
||||
nsCOMPtr<nsIContent> defContent = currPoint->GetDefaultContentTemplate();
|
||||
if (defContent == childPoint) {
|
||||
// Now check to see if we even built default content at this
|
||||
// insertion point.
|
||||
currPoint->GetDefaultContent(getter_AddRefs(defContent));
|
||||
defContent = currPoint->GetDefaultContent();
|
||||
if (defContent) {
|
||||
// Find out the index of the template element within the <children> elt.
|
||||
PRInt32 index;
|
||||
|
Loading…
Reference in New Issue
Block a user