Implementation of setindex element and repeat-index functionality. Bug 278209, r=smaug+aaronr

This commit is contained in:
allan%beaufour.dk 2005-02-18 09:38:32 +00:00
Родитель 131186b3ed
Коммит 784c9d05f6
7 изменённых файлов: 988 добавлений и 166 удалений

Просмотреть файл

@ -83,6 +83,8 @@ XPIDLSRCS = \
nsIXFormsCaseElement.idl \
nsIXFormsSelectChild.idl \
nsIXFormsValueElement.idl \
nsIXFormsRepeatElement.idl \
nsIXFormsRepeatItemElement.idl \
$(NULL)
CPPSRCS = \
@ -118,6 +120,7 @@ CPPSRCS = \
nsXFormsSendElement.cpp \
nsXFormsSetFocusElement.cpp \
nsXFormsSetValueElement.cpp \
nsXFormsSetIndexElement.cpp \
nsXFormsInsertDeleteElement.cpp \
nsXFormsLoadElement.cpp \
nsXFormsMessageElement.cpp \

Просмотреть файл

@ -0,0 +1,91 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 XForms support.
*
* The Initial Developer of the Original Code is
* Novell, Inc.
* Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Allan Beaufour <abeaufour@novell.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* This interface is implemented by XForms \<repeat\> elements,
* used to control the ":repeat-index".
*/
#include "nsISupports.idl"
[uuid(419e780d-4f31-4aa4-bae8-a18099d77bb6)]
interface nsIXFormsRepeatElement : nsISupports
{
/**
* Set the current index, and return new value.
*
* @param aIndex The index
* @param aIsRefresh Is this part of a refresh event?
*/
void setIndex(inout unsigned long aIndex,
in boolean aIsRefresh);
/**
* The current index.
*/
readonly attribute unsigned long index;
/**
* Deselect current index.
*/
void deselect();
/**
* Sets whether the repeat is a parent to nested repeats
*/
attribute boolean isParent;
/**
* Set parent repeat (nested repeats)
*/
attribute nsIXFormsRepeatElement parent;
/**
* The tree level of this repeat (nested repeats)
*/
attribute unsigned long level;
/**
* Set currently selected repeat and index value (nested repeats)
*
* @param aCurrentRepeat The current repeat
* @param aIndex The current index value
*/
void setCurrentRepeat(in nsIXFormsRepeatElement aCurrentRepeat,
in unsigned long aIndex);
};

Просмотреть файл

@ -0,0 +1,54 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 XForms support.
*
* The Initial Developer of the Original Code is
* Novell, Inc.
* Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Allan Beaufour <abeaufour@novell.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* This interface is implemented by XForms \<contentcontainer\> elements,
* used to control the ":repeat-index".
*/
#include "nsISupports.idl"
[uuid(2bd6a7c7-ca59-408b-9a2a-c1bdef919fd5)]
interface nsIXFormsRepeatItemElement : nsISupports
{
/**
* This determines whether the element is the current index or not, so it
* can set the :repeat-index accordingly.
*/
attribute boolean indexState;
};

Просмотреть файл

@ -44,12 +44,16 @@
#include "nsIDOM3Node.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMEvent.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMSerializer.h"
#include "nsIDOMXPathResult.h"
#include "nsXFormsControlStub.h"
#include "nsIModelElementPrivate.h"
#include "nsIXFormsContextControl.h"
#include "nsIXFormsRepeatItemElement.h"
#include "nsIXFormsRepeatElement.h"
#include "nsXFormsUtils.h"
#ifdef DEBUG
@ -67,17 +71,21 @@
* @see http://www.w3.org/TR/xforms/sliceF.html#id2645142
* @see http://bugzilla.mozilla.org/show_bug.cgi?id=271724
*/
class nsXFormsContextContainer : public nsXFormsControlStub
class nsXFormsContextContainer : public nsXFormsControlStub,
public nsIXFormsRepeatItemElement
{
protected:
/** The HTML representation for the node */
nsCOMPtr<nsIDOMElement> mHTMLElement;
public:
NS_DECL_ISUPPORTS_INHERITED
// nsIXTFXMLVisual overrides
NS_IMETHOD OnCreated(nsIXTFXMLVisualWrapper *aWrapper);
// nsIXTFVisual overrides
NS_IMETHOD HandleDefault(nsIDOMEvent *aEvent, PRBool *aHandled);
NS_IMETHOD GetVisualContent(nsIDOMElement **aElement);
NS_IMETHOD GetInsertionPoint(nsIDOMElement **aElement);
@ -88,11 +96,16 @@ public:
// nsIXFormsControl
NS_IMETHOD Bind();
NS_IMETHOD Refresh();
NS_IMETHOD SetContextNode(nsIDOMNode *aContextNode);
// nsIXFormsContextControl
NS_DECL_NSIXFORMSCONTEXTCONTROL
// nsIXFormsRepeatItemElement
NS_DECL_NSIXFORMSREPEATITEMELEMENT
};
NS_IMPL_ISUPPORTS_INHERITED1(nsXFormsContextContainer,
nsXFormsControlStub,
nsIXFormsRepeatItemElement)
// nsIXTFXMLVisual
NS_IMETHODIMP
nsXFormsContextContainer::OnCreated(nsIXTFXMLVisualWrapper *aWrapper)
@ -149,6 +162,56 @@ nsXFormsContextContainer::GetInsertionPoint(nsIDOMElement **aElement)
}
// nsIXTFElement
NS_IMETHODIMP
nsXFormsContextContainer::HandleDefault(nsIDOMEvent *aEvent,
PRBool *aHandled)
{
if (!aEvent || !mElement)
return NS_OK;
nsAutoString type;
aEvent->GetType(type);
if (!type.EqualsLiteral("focus"))
return nsXFormsControlStub::HandleDefault(aEvent, aHandled);
/*
* Either we, or an element we contain, has gotten focus, so we need to set
* the repeat index. This is done through the \<repeat\> the
* nsXFormsContextContainer belongs to.
*
* Start by finding the \<repeat\> (our grandparent):
* <pre>
* <repeat> <-- gParent
* <div>
* <contextcontainer\> <-- this
* </div>
* </repeat>
* </pre>
*/
nsCOMPtr<nsIDOMNode> parent;
mElement->GetParentNode(getter_AddRefs(parent));
NS_ASSERTION(parent, "how can we get focus without a parent?");
nsCOMPtr<nsIDOMNode> gParent;
parent->GetParentNode(getter_AddRefs(gParent));
nsCOMPtr<nsIXFormsRepeatElement> repeat = do_QueryInterface(gParent);
if (!repeat)
// Not a child to a \<repeat\>
return NS_OK;
// Find our context position
nsAutoString posString;
mElement->GetAttribute(NS_LITERAL_STRING("contextposition"), posString);
NS_ASSERTION(!posString.IsEmpty(), "@contextposition n/a or empty on repeat child?");
PRInt32 errCode;
PRUint32 pos = posString.ToInteger(&errCode);
NS_ASSERTION(!errCode, "@contextposition != integer on repeat child?");
// Tell \<repeat\> about the new index position
return repeat->SetIndex(&pos, PR_FALSE);
}
NS_IMETHODIMP
nsXFormsContextContainer::OnDestroyed()
{
@ -174,6 +237,7 @@ nsXFormsContextContainer::CloneState(nsIDOMElement *aElement)
}
// nsIXFormsContextControl
NS_IMETHODIMP
nsXFormsContextContainer::SetContextNode(nsIDOMNode *aContextNode)
{
@ -181,29 +245,6 @@ nsXFormsContextContainer::SetContextNode(nsIDOMNode *aContextNode)
return NS_OK;
}
NS_IMETHODIMP
nsXFormsContextContainer::GetContext(nsAString &aModelID,
nsIDOMNode **aContextNode,
PRInt32 *aContextPosition,
PRInt32 *aContextSize)
{
NS_IF_ADDREF(*aContextNode = mBoundNode);
nsAutoString val;
mElement->GetAttribute(NS_LITERAL_STRING("contextsize"), val);
PRInt32 errCode;
*aContextSize = val.ToInteger(&errCode);
if (errCode) {
*aContextSize = 1;
}
mElement->GetAttribute(NS_LITERAL_STRING("contextposition"), val);
*aContextPosition = val.ToInteger(&errCode);
if (errCode) {
*aContextPosition = 1;
}
mElement->GetAttribute(NS_LITERAL_STRING("model"), aModelID);
return NS_OK;
}
// nsIXFormsControl
NS_IMETHODIMP
@ -218,6 +259,32 @@ nsXFormsContextContainer::Refresh()
return NS_OK;
}
// nsIXFormsRepeatItemElement
/**
* @todo Should set/get pseudo-element, not attribute (XXX)
* @see http://bugzilla.mozilla.org/show_bug.cgi?id=271724
*/
NS_IMETHODIMP
nsXFormsContextContainer::SetIndexState(PRBool aHasIndex)
{
if (mElement) {
NS_NAMED_LITERAL_STRING(repIndex, "repeat-index");
if (aHasIndex) {
mElement->SetAttribute(repIndex,
NS_LITERAL_STRING("1"));
} else {
mElement->RemoveAttribute(repIndex);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsContextContainer::GetIndexState(PRBool *aHasIndex)
{
return mElement->HasAttribute(NS_LITERAL_STRING("repeat-index"), aHasIndex);
}
// Factory
NS_HIDDEN_(nsresult)
NS_NewXFormsContextContainer(nsIXTFElement **aResult)

Просмотреть файл

@ -80,6 +80,7 @@ NS_HIDDEN_(nsresult) NS_NewXFormsRefreshElement(nsIXTFElement **aResult);
NS_HIDDEN_(nsresult) NS_NewXFormsActionElement(nsIXTFElement **aResult);
NS_HIDDEN_(nsresult) NS_NewXFormsLoadElement(nsIXTFElement **aResult);
NS_HIDDEN_(nsresult) NS_NewXFormsSetValueElement(nsIXTFElement **aResult);
NS_HIDDEN_(nsresult) NS_NewXFormsSetIndexElement(nsIXTFElement **aResult);
NS_HIDDEN_(nsresult) NS_NewXFormsMessageElement(nsIXTFElement **aResult);
NS_HIDDEN_(nsresult) NS_NewXFormsHintElement(nsIXTFElement **aResult);
@ -154,6 +155,8 @@ nsXFormsElementFactory::CreateElement(const nsAString& aTagName,
return NS_NewXFormsLoadElement(aElement);
if (aTagName.EqualsLiteral("setvalue"))
return NS_NewXFormsSetValueElement(aElement);
if (aTagName.EqualsLiteral("setindex"))
return NS_NewXFormsSetIndexElement(aElement);
if (aTagName.EqualsLiteral("message"))
return NS_NewXFormsMessageElement(aElement);
if (aTagName.EqualsLiteral("hint"))

Просмотреть файл

@ -54,10 +54,13 @@
#include "nsIDOMElement.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMHTMLDivElement.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMXPathResult.h"
#include "nsXFormsControlStub.h"
#include "nsIXFormsContextControl.h"
#include "nsIXFormsRepeatElement.h"
#include "nsIXFormsRepeatItemElement.h"
#include "nsXFormsAtoms.h"
#include "nsXFormsModelElement.h"
#include "nsXFormsUtils.h"
@ -70,6 +73,11 @@
* Implementation of the XForms \<repeat\> control.
* @see http://www.w3.org/TR/xforms/slice9.html#id2632123
*
* There are two main functions of repeat: 1) "Expanding its children" and 2)
* Maintaining the repeat-index. These are described here:
*
* <h2>Expanding its children</h2>
*
* On Refresh(), nsXFormsRepeatElement, does the following for each node in
* the nodeset the \<repeat\> tag is bound to:
*
@ -104,23 +112,85 @@
* will be expanded to:
* <pre>
* <repeat nodeset="n">
* <contextcontainer> (contextNode == "n[0]" and contextPosition == 1)
* Val: <output ref="."/> (that is: 'val1')
* </contextcontainer>
* <contextcontainer> (contextNode == "n[1]" and contextPosition == 2)
* Val: <output ref="."/> (that is: 'val2')
* </contextcontainer>
* (anonymous content)
* <contextcontainer> (contextNode == "n[0]" and contextPosition == 1)
* Val: <output ref="."/> (that is: 'val1')
* </contextcontainer>
* <contextcontainer> (contextNode == "n[1]" and contextPosition == 2)
* Val: <output ref="."/> (that is: 'val2')
* </contextcontainer>
* (/anonymous content)
* </repeat>
* </pre>
*
* Besides being a practical way to implement \<repeat\>, it also means that it
* is possible to CSS-style the individual "rows" in a \<repeat\>.
*
* @todo Support attribute based repeats (XXX), as in:
* <h2>Maintaining the repeat-index</h2>
*
* The repeat-index points to the current child contextcontainer selected,
* which should be fairly easy, was it not for "nested repeats".
*
* If the DOM document has the following:
* <pre>
* <repeat id="r_outer">
* <repeat id="r_inner"/>
* </repeat>
* </pre>
* r_inner is cloned like all other elements:
* <pre>
* <repeat id="r_outer">
* (anonymous content)
* <contextcontainer>
* <repeat id="r_inner"/>
* </contextcontainer>
* <contextcontainer>
* <repeat id="r_inner"/>
* </contextcontainer>
* (/anonymous content)
* (DOM content -- not shown)
* <repeat id="r_inner"/>
* (/DOM content)
* </repeat>
* </pre>
*
* So r_inner in fact exists three places; once in the DOM and twice in the
* anonymous content of r_outer. The problem is that repeat-index can only be
* set for one row for each repeat. The approach we use here is to check
* whether we clone any \<repeat\> elements in Refresh() using our own
* CloneNode() function. If a \<repeat\> is found, we mark the original (DOM)
* \<repeat\> inactive with regards to content (mIsParent), and basically just
* use it to store a pointer to the current cloned \<repeat\>
* (mCurrentRepeat). We also store a pointer to the (DOM) parent in the cloned
* repeat (mParent).
*
* There are two ways the repeat-index can be changed, 1) by \<setindex\>
* (nsXFormsSetIndexElement) and 2) by a \<contextcontainer\> getting
* focus. We thus listen for focus-events in
* nsXFormsContextContainer::HandleDefault().
*
* If a \<repeat\> changes the repeat-index, any nested repeats have their
* repeat-index reset to 1 (ResetInnerRepeats()).
*
* <h2>Notes / todo</h2>
*
* @todo Support attribute based repeats (XXX), as in: (XXX)
* \<html:table xforms:repeat-nodeset="..."\>
* @see http://www.w3.org/TR/xforms/index-all.html#ui.repeat.via.attrs
* @see http://bugzilla.mozilla.org/show_bug.cgi?id=280368
*
* @todo There are some nasty bits with nested repeats (XXX)
* 1) Should we delete or modify the @id on the cloned repeats?
* 2) What happens if you set attributes on the parent repeat?
* Should they propagate to the cloned repeats?
*
* @note Should we handle @number? The spec. says that it's a "Optional hint
* to the XForms Processor as to how many elements from the collection to
* display."
*/
class nsXFormsRepeatElement : public nsXFormsControlStub
class nsXFormsRepeatElement : public nsXFormsControlStub,
public nsIXFormsRepeatElement
{
protected:
/** The HTML representation for the node */
@ -128,6 +198,40 @@ protected:
/** True while children are being added */
PRBool mAddingChildren;
/**
* The current repeat-index, 0 if no row is selected (can happen for nested
* repeats) or there are no rows at all.
*
* @note That is the child \<contextcontainer\> at position mCurrentIndex -
* 1 (indexes go from 1, DOM from 0).
*/
PRUint32 mCurrentIndex;
/**
* The maximum index value
*/
PRUint32 mMaxIndex;
/** The parent repeat (nested repeats) */
nsCOMPtr<nsIXFormsRepeatElement> mParent;
/**
* The nested level of the repeat. That is, the number of \<repeat\>
* elements above us in the anonymous content tree. Used by
* ResetInnerRepeats().
*/
PRUint32 mLevel;
/**
* Are we a parent for nested repeats
*/
PRBool mIsParent;
/**
* The currently selected repeat (nested repeats)
*/
nsCOMPtr<nsIXFormsRepeatElement> mCurrentRepeat;
/**
* Retrieves an integer attribute and checks its type.
@ -142,7 +246,40 @@ protected:
PRInt32 *aVal,
const PRUint16 aType);
/**
* Set the repeat-index state for a given (nsIXFormsRepeatItemElement)
* child.
*
* @param aPosition The position of the child (1-based)
* @param aState The index state
* @param aIsRefresh Is this part of a refresh event
*/
nsresult SetChildIndex(PRUint32 aPosition,
PRBool aState,
PRBool aIsRefresh = PR_FALSE);
/**
* Resets inner repeat indexes to 1 for first level of nested repeats of
* |aNode|.
*
* @param aNode The node to search for repeats
* @param aIsRefresh Is this part of a refresh event
*/
nsresult ResetInnerRepeats(nsIDOMNode *aNode,
PRBool aIsRefresh);
/**
* Deep clones aSrc to aTarget, with special handling of \<repeat\> elements
* to take care of nested repeats.
*
* @param aSrc The source node
* @param aTarget The target node
*/
nsresult CloneNode(nsIDOMNode *aSrc, nsIDOMNode **aTarget);
public:
NS_DECL_ISUPPORTS_INHERITED
// nsIXTFXMLVisual overrides
NS_IMETHOD OnCreated(nsIXTFXMLVisualWrapper *aWrapper);
@ -161,17 +298,27 @@ public:
NS_IMETHOD Refresh();
NS_IMETHOD TryFocus(PRBool* aOK);
nsXFormsRepeatElement() : mAddingChildren(PR_FALSE) {};
// nsIXFormsRepeatElement
NS_DECL_NSIXFORMSREPEATELEMENT
// nsXFormsRepeatElement
nsXFormsRepeatElement() :
mAddingChildren(PR_FALSE),
mCurrentIndex(0),
mMaxIndex(0),
mLevel(1),
mIsParent(PR_FALSE)
{}
};
NS_IMPL_ISUPPORTS_INHERITED1(nsXFormsRepeatElement,
nsXFormsControlStub,
nsIXFormsRepeatElement)
// nsIXTFXMLVisual
NS_IMETHODIMP
nsXFormsRepeatElement::OnCreated(nsIXTFXMLVisualWrapper *aWrapper)
{
#ifdef DEBUG_XF_REPEAT
printf("nsXFormsRepeatElement::OnCreated(aWrapper=%p)\n", (void*) aWrapper);
#endif
nsresult rv = nsXFormsControlStub::OnCreated(aWrapper);
NS_ENSURE_SUCCESS(rv, rv);
@ -198,10 +345,6 @@ nsXFormsRepeatElement::OnCreated(nsIXTFXMLVisualWrapper *aWrapper)
NS_IMETHODIMP
nsXFormsRepeatElement::GetVisualContent(nsIDOMElement **aElement)
{
#ifdef DEBUG_XF_REPEAT
printf("nsXFormsRepeatElement::GetVisualContent()\n");
#endif
NS_IF_ADDREF(*aElement = mHTMLElement);
return NS_OK;
}
@ -218,10 +361,6 @@ nsXFormsRepeatElement::OnDestroyed()
NS_IMETHODIMP
nsXFormsRepeatElement::WillSetAttribute(nsIAtom *aName, const nsAString &aValue)
{
#ifdef DEBUG_XF_REPEAT
printf("nsXFormsRepeatElement::WillSetAttribute(aName=%p, aValue='%s')\n", (void*) aName, NS_ConvertUCS2toUTF8(aValue).get());
#endif
if (aName == nsXFormsAtoms::bind ||
aName == nsXFormsAtoms::nodeset ||
aName == nsXFormsAtoms::model) {
@ -236,10 +375,6 @@ nsXFormsRepeatElement::WillSetAttribute(nsIAtom *aName, const nsAString &aValue)
NS_IMETHODIMP
nsXFormsRepeatElement::AttributeSet(nsIAtom *aName, const nsAString &aValue)
{
#ifdef DEBUG_XF_REPEAT
printf("nsXFormsRepeatElement::AttributeSet(aName=%p, aValue=%s)\n", (void*) aName, NS_ConvertUCS2toUTF8(aValue).get());
#endif
if (aName == nsXFormsAtoms::bind ||
aName == nsXFormsAtoms::nodeset ||
aName == nsXFormsAtoms::model) {
@ -260,10 +395,6 @@ nsXFormsRepeatElement::BeginAddingChildren()
NS_IMETHODIMP
nsXFormsRepeatElement::DoneAddingChildren()
{
#ifdef DEBUG_XF_REPEAT
printf("nsXFormsRepeatElement::DoneAddingChildren()\n");
#endif
mAddingChildren = PR_FALSE;
Refresh();
@ -271,6 +402,165 @@ nsXFormsRepeatElement::DoneAddingChildren()
return NS_OK;
}
// nsIXFormsRepeatElement
NS_IMETHODIMP
nsXFormsRepeatElement::SetIndex(PRUint32 *aIndex,
PRBool aIsRefresh)
{
NS_ENSURE_ARG(aIndex);
#ifdef DEBUG_XF_REPEAT
printf("\tSetindex to %d (current: %d, max: %d), aIsRefresh=%d\n",
*aIndex, mCurrentIndex, mMaxIndex, aIsRefresh);
#endif
nsresult rv;
// Set repeat-index
if (mIsParent) {
NS_ASSERTION(mCurrentRepeat, "How can we be a repeat parent without a child?");
// We're the parent of nested repeats, set through the correct repeat
return mCurrentRepeat->SetIndex(aIndex, aIsRefresh);
}
// Do nothing if we are not showing anything
if (mMaxIndex == 0)
return NS_OK;
if (aIsRefresh && !mCurrentIndex) {
// If we are refreshing, get existing index value from parent
NS_ASSERTION(mParent, "SetIndex with aIsRefresh == PR_TRUE for a non-nested repeat?!");
rv = mParent->GetIndex(aIndex);
NS_ENSURE_SUCCESS(rv, rv);
}
// Check min. and max. value
if (*aIndex < 1) {
*aIndex = 1;
if (!aIsRefresh)
nsXFormsUtils::DispatchEvent(mElement, eEvent_ScrollFirst);
} else if (*aIndex > mMaxIndex) {
*aIndex = mMaxIndex;
if (!aIsRefresh)
nsXFormsUtils::DispatchEvent(mElement, eEvent_ScrollLast);
}
// Do nothing if setting to existing value
if (!aIsRefresh && mCurrentIndex && *aIndex == mCurrentIndex)
return NS_OK;
#ifdef DEBUG_XF_REPEAT
printf("\tWill set index to %d\n",
*aIndex);
#endif
// Set the repeat-index
rv = SetChildIndex(*aIndex, PR_TRUE, aIsRefresh);
NS_ENSURE_SUCCESS(rv, rv);
// Unset previous repeat-index
if (mCurrentIndex) {
// We had the previous selection, unset directly
SetChildIndex(mCurrentIndex, PR_FALSE, aIsRefresh);
} if (mParent) {
// Selection is in another repeat, inform parent (it will inform the
// previous owner of its new state)
rv = mParent->SetCurrentRepeat(this, *aIndex);
NS_ENSURE_SUCCESS(rv, rv);
}
// Set current index to new value
mCurrentIndex = *aIndex;
return NS_OK;
}
NS_IMETHODIMP
nsXFormsRepeatElement::GetIndex(PRUint32 *aIndex)
{
NS_ENSURE_ARG(aIndex);
if (mParent) {
return mParent->GetIndex(aIndex);
}
*aIndex = mCurrentIndex;
return NS_OK;
}
NS_IMETHODIMP
nsXFormsRepeatElement::Deselect(void)
{
if (!mCurrentIndex)
return NS_OK;
nsresult rv = SetChildIndex(mCurrentIndex, PR_FALSE);
if (NS_SUCCEEDED(rv)) {
mCurrentIndex = 0;
}
return rv;
}
NS_IMETHODIMP
nsXFormsRepeatElement::SetCurrentRepeat(nsIXFormsRepeatElement *aRepeat,
PRUint32 aIndex)
{
// Deselect the previous owner
if (mCurrentRepeat && aRepeat != mCurrentRepeat) {
nsresult rv = mCurrentRepeat->Deselect();
NS_ENSURE_SUCCESS(rv, rv);
}
mCurrentRepeat = aRepeat;
mCurrentIndex = aIndex;
return NS_OK;
}
// NB: CloneNode() assumes that this always succeeds
NS_IMETHODIMP
nsXFormsRepeatElement::GetIsParent(PRBool *aIsParent)
{
*aIsParent = mIsParent;
return NS_OK;
}
// NB: CloneNode() assumes that this always succeeds
NS_IMETHODIMP
nsXFormsRepeatElement::SetIsParent(PRBool aIsParent)
{
mIsParent = aIsParent;
return NS_OK;
}
// NB: CloneNode() assumes that this always succeeds
NS_IMETHODIMP
nsXFormsRepeatElement::SetParent(nsIXFormsRepeatElement *aParent)
{
mParent = aParent;
return NS_OK;
}
NS_IMETHODIMP
nsXFormsRepeatElement::GetParent(nsIXFormsRepeatElement **aParent)
{
NS_ENSURE_ARG_POINTER(aParent);
NS_IF_ADDREF(*aParent = mParent);
return NS_OK;
}
NS_IMETHODIMP
nsXFormsRepeatElement::SetLevel(PRUint32 aLevel)
{
mLevel = aLevel;
return NS_OK;
}
NS_IMETHODIMP
nsXFormsRepeatElement::GetLevel(PRUint32 *aLevel)
{
NS_ENSURE_ARG(aLevel);
*aLevel = mLevel;
return NS_OK;
}
// nsXFormsControl
@ -290,11 +580,7 @@ nsXFormsRepeatElement::Bind()
NS_IMETHODIMP
nsXFormsRepeatElement::Refresh()
{
#ifdef DEBUG_XF_REPEAT
printf("nsXFormsRepeatElement::Refresh()\n");
#endif
if (!mHTMLElement || mAddingChildren)
if (!mHTMLElement || mAddingChildren || mIsParent)
return NS_OK;
nsresult rv;
@ -316,135 +602,310 @@ nsXFormsRepeatElement::Refresh()
getter_AddRefs(result),
getter_AddRefs(model));
if (NS_FAILED(rv) | !result) {
if (NS_FAILED(rv) | !result | !model)
return rv;
}
/// @todo The result should be a _homogenous_ collection (spec. 9.3.1),
/// do/can/should we check this? (XXX)
/// @todo The spec says: "This node-set must consist of contiguous child
/// element nodes, with the same local name and namespace name of a common
/// parent node. The behavior of element repeat with respect to
/// non-homogeneous node-sets is undefined."
/// @see http://www.w3.org/TR/xforms/slice9.html#ui-repeat
///
/// Can/should we check this somehow? (XXX)
PRUint32 contextSize;
rv = result->GetSnapshotLength(&contextSize);
NS_ENSURE_SUCCESS(rv, rv);
if (model && contextSize > 0) {
// Get model ID
nsCOMPtr<nsIDOMElement> modelElement = do_QueryInterface(model);
NS_ENSURE_TRUE(modelElement, NS_ERROR_FAILURE);
nsAutoString modelID;
modelElement->GetAttribute(NS_LITERAL_STRING("id"), modelID);
if (!contextSize)
return NS_OK;
// Get model ID
nsCOMPtr<nsIDOMElement> modelElement = do_QueryInterface(model);
NS_ENSURE_TRUE(modelElement, NS_ERROR_FAILURE);
nsAutoString modelID;
modelElement->GetAttribute(NS_LITERAL_STRING("id"), modelID);
// Get attributes
PRUint32 startIndex;
rv = GetIntAttr(NS_LITERAL_STRING("startIndex"),
(PRInt32*) &startIndex,
// Get DOM document
nsCOMPtr<nsIDOMDocument> domDoc;
rv = mHTMLElement->GetOwnerDocument(getter_AddRefs(domDoc));
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString strSize;
strSize.AppendInt(contextSize);
mMaxIndex = contextSize;
for (PRUint32 i = 1; i < mMaxIndex + 1; ++i) {
// Create <contextcontainer>
nsCOMPtr<nsIDOMElement> riElement;
rv = domDoc->CreateElementNS(NS_LITERAL_STRING("http://www.w3.org/2002/xforms"),
NS_LITERAL_STRING("contextcontainer"),
getter_AddRefs(riElement));
NS_ENSURE_SUCCESS(rv, rv);
// Set context size, context position, and model as attributes
if (!modelID.IsEmpty()) {
riElement->SetAttribute(NS_LITERAL_STRING("model"), modelID);
}
nsAutoString strPos; strPos.AppendInt(i);
riElement->SetAttribute(NS_LITERAL_STRING("contextposition"), strPos);
riElement->SetAttribute(NS_LITERAL_STRING("contextsize"), strSize);
// Get and set context node
nsCOMPtr<nsIXFormsContextControl> riContext = do_QueryInterface(riElement);
NS_ENSURE_TRUE(riContext, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMNode> contextNode;
rv = result->SnapshotItem(i - 1, getter_AddRefs(contextNode));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMElement> contextElement = do_QueryInterface(contextNode);
NS_ENSURE_TRUE(contextElement, NS_ERROR_FAILURE);
rv = riContext->SetContextNode(contextElement);
NS_ENSURE_SUCCESS(rv, rv);
// Iterate over template children, clone them, and append them to <contextcontainer>
nsCOMPtr<nsIDOMNode> child;
rv = mElement->GetFirstChild(getter_AddRefs(child));
NS_ENSURE_SUCCESS(rv, rv);
while (child) {
nsCOMPtr<nsIDOMNode> childClone;
rv = CloneNode(child, getter_AddRefs(childClone));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMNode> newNode;
rv = riElement->AppendChild(childClone, getter_AddRefs(newNode));
NS_ENSURE_SUCCESS(rv, rv);
rv = child->GetNextSibling(getter_AddRefs(newNode));
NS_ENSURE_SUCCESS(rv, rv);
child = newNode;
}
// Append node
nsCOMPtr<nsIDOMNode> domNode;
rv = mHTMLElement->AppendChild(riElement, getter_AddRefs(domNode));
NS_ENSURE_SUCCESS(rv, rv);
// There is an awfull lot of evaluating being done by all the
// children, as they are created and inserted into the different
// places in the DOM, the only refresh necessary is the one when they
// are appended in mHTMLElement.
}
// XForms errata states that startindex is always '1' for nested repeats
// (http://www.w3.org/MarkUp/Forms/Group/Drafts/Sources/errata.html#E35a)
// so we'll not check it for those.
if (!mParent && !mCurrentIndex && mMaxIndex) {
// repeat-index has not been initialized, set it.
rv = GetIntAttr(NS_LITERAL_STRING("startindex"),
(PRInt32*) &mCurrentIndex,
nsISchemaBuiltinType::BUILTIN_TYPE_POSITIVEINTEGER);
if (NS_FAILED(rv)) {
if (rv == NS_ERROR_NOT_AVAILABLE) {
startIndex = 1;
mCurrentIndex = 1;
} else {
return rv;
}
}
PRUint32 number;
rv = GetIntAttr(NS_LITERAL_STRING("number"),
(PRInt32*) &number,
nsISchemaBuiltinType::BUILTIN_TYPE_NONNEGATIVEINTEGER);
if (NS_FAILED(rv)) {
if (rv == NS_ERROR_NOT_AVAILABLE) {
number = contextSize;
} else {
return rv;
}
}
// Get DOM document
nsCOMPtr<nsIDOMDocument> domDoc;
rv = mHTMLElement->GetOwnerDocument(getter_AddRefs(domDoc));
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString strSize;
strSize.AppendInt(contextSize);
// The spec. states the following for startIndex: "Optional 1-based
// initial value of the repeat index", I interpret this as "start
// showing element at position |startIndex|". So I iterate over the
// interval [max(1, startIndex),min(contextSize, number + startIndex)[
for (PRUint32 i = NS_MAX((PRUint32) 1, startIndex);
i < NS_MIN(contextSize + 1, number + startIndex);
++i) {
// Create <contextcontainer>
nsCOMPtr<nsIDOMElement> riElement;
rv = domDoc->CreateElementNS(NS_LITERAL_STRING("http://www.w3.org/2002/xforms"),
NS_LITERAL_STRING("contextcontainer"),
getter_AddRefs(riElement));
NS_ENSURE_SUCCESS(rv, rv);
// Set context size, context position, and model as attributes
if (!modelID.IsEmpty()) {
riElement->SetAttribute(NS_LITERAL_STRING("model"), modelID);
}
nsAutoString strPos; strPos.AppendInt(i);
riElement->SetAttribute(NS_LITERAL_STRING("contextposition"), strPos);
riElement->SetAttribute(NS_LITERAL_STRING("contextsize"), strSize);
// Get and set context node
nsCOMPtr<nsIXFormsContextControl> riContext = do_QueryInterface(riElement);
NS_ENSURE_TRUE(riContext, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMNode> contextNode;
rv = result->SnapshotItem(i - 1, getter_AddRefs(contextNode));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMElement> contextElement = do_QueryInterface(contextNode);
NS_ENSURE_TRUE(contextElement, NS_ERROR_FAILURE);
rv = riContext->SetContextNode(contextElement);
NS_ENSURE_SUCCESS(rv, rv);
// Iterate over template children, clone them, and append them to <contextcontainer>
nsCOMPtr<nsIDOMNode> child;
rv = mElement->GetFirstChild(getter_AddRefs(child));
NS_ENSURE_SUCCESS(rv, rv);
while (child) {
nsCOMPtr<nsIDOMNode> childClone;
rv = child->CloneNode(PR_TRUE, getter_AddRefs(childClone));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMNode> newNode;
rv = riElement->AppendChild(childClone, getter_AddRefs(newNode));
NS_ENSURE_SUCCESS(rv, rv);
rv = child->GetNextSibling(getter_AddRefs(newNode));
NS_ENSURE_SUCCESS(rv, rv);
child = newNode;
}
// Append node
nsCOMPtr<nsIDOMNode> domNode;
rv = mHTMLElement->AppendChild(riElement, getter_AddRefs(domNode));
NS_ENSURE_SUCCESS(rv, rv);
// There is an awfull lot of evaluating being done by all the
// children, as they are created and inserted into the different
// places in the DOM, the only refresh necessary is the one when they
// are appended in mHTMLElement.
if (mCurrentIndex < 1) {
mCurrentIndex = 1;
} else if (mCurrentIndex > mMaxIndex) {
mCurrentIndex = mMaxIndex;
}
}
// If we have the repeat-index, set it.
if (mCurrentIndex) {
SetChildIndex(mCurrentIndex, PR_TRUE, PR_TRUE);
}
return NS_OK;
}
/**
* @todo "Setting focus to a repeating structure sets the focus to
* the repeat item represented by the repeat index."
*/
NS_IMETHODIMP
nsXFormsRepeatElement::TryFocus(PRBool* aOK)
// nsXFormsRepeatElement
nsresult
nsXFormsRepeatElement::SetChildIndex(PRUint32 aPosition,
PRBool aState,
PRBool aIsRefresh)
{
*aOK = PR_FALSE;
#ifdef DEBUG_XF_REPEAT
printf("\tTrying to set index #%d to state '%d', aIsRefresh=%d\n",
aPosition, aState, aIsRefresh);
#endif
if (!mHTMLElement)
return NS_OK;
nsCOMPtr<nsIDOMNodeList> children;
mHTMLElement->GetChildNodes(getter_AddRefs(children));
NS_ENSURE_STATE(children);
nsCOMPtr<nsIDOMNode> child;
children->Item(aPosition - 1, // Indexes are 1-based, the DOM is 0-based
getter_AddRefs(child));
nsCOMPtr<nsIXFormsRepeatItemElement> repeatItem = do_QueryInterface(child);
NS_ENSURE_STATE(repeatItem);
nsresult rv;
PRBool curState;
rv = repeatItem->GetIndexState(&curState);
NS_ENSURE_SUCCESS(rv, rv);
if (curState != aState) {
rv = repeatItem->SetIndexState(aState);
NS_ENSURE_SUCCESS(rv, rv);
if (aState) {
// Reset inner repeats
rv = ResetInnerRepeats(child, aIsRefresh);
NS_ENSURE_SUCCESS(rv, rv);
}
}
return NS_OK;
}
nsresult
nsXFormsRepeatElement::ResetInnerRepeats(nsIDOMNode *aNode,
PRBool aIsRefresh)
{
#ifdef DEBUG_XF_REPEAT
printf("\taIsRefresh: %d\n",
aIsRefresh);
#endif
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aNode);
if (!element)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMNodeList> nodeList;
nsresult rv;
rv = element->GetElementsByTagNameNS(NS_LITERAL_STRING(NS_NAMESPACE_XFORMS),
NS_LITERAL_STRING("repeat"),
getter_AddRefs(nodeList));
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 childCount = 0;
nodeList->GetLength(&childCount);
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIXFormsRepeatElement> repeat;
PRUint32 index = 1;
for (PRUint32 i = 0; i < childCount; ++i) {
nodeList->Item(i, getter_AddRefs(node));
repeat = do_QueryInterface(node);
NS_ENSURE_STATE(repeat);
PRUint32 level;
repeat->GetLevel(&level);
if (level == mLevel + 1)
repeat->SetIndex(&index, aIsRefresh);
}
return NS_OK;
}
nsresult
nsXFormsRepeatElement::CloneNode(nsIDOMNode *aSrc,
nsIDOMNode **aTarget)
{
NS_ENSURE_ARG(aSrc);
NS_ENSURE_ARG_POINTER(aTarget);
// Clone aSrc
nsresult rv;
rv = aSrc->CloneNode(PR_FALSE, aTarget);
NS_ENSURE_SUCCESS(rv, rv);
// Check whether we have cloned a repeat
if (nsXFormsUtils::IsXFormsElement(aSrc, NS_LITERAL_STRING("repeat"))) {
nsCOMPtr<nsIXFormsRepeatElement> repSource = do_QueryInterface(aSrc);
NS_ENSURE_STATE(repSource);
nsCOMPtr<nsIXFormsRepeatElement> repClone = do_QueryInterface(*aTarget);
NS_ENSURE_STATE(repClone);
// Find top-most parent of these repeats
nsCOMPtr<nsIXFormsRepeatElement> parent = repSource;
nsCOMPtr<nsIXFormsRepeatElement> temp;
rv = parent->GetParent(getter_AddRefs(temp));
NS_ENSURE_SUCCESS(rv, rv);
while (temp) {
temp.swap(parent);
rv = parent->GetParent(getter_AddRefs(temp));
NS_ENSURE_SUCCESS(rv, rv);
}
// Set parent and level on clone
PRUint32 level;
repSource->GetLevel(&level);
repClone->SetLevel(level + 1);
repClone->SetParent(parent);
// Inform parent of new status, if it does not know already
PRBool isParent;
parent->GetIsParent(&isParent);
if (!isParent) {
rv = parent->SetCurrentRepeat(repClone, 1);
NS_ENSURE_SUCCESS(rv, rv);
parent->SetIsParent(PR_TRUE);
}
}
// Clone children of aSrc
nsCOMPtr<nsIDOMNode> tmp;
nsCOMPtr<nsIDOMNodeList> childNodes;
aSrc->GetChildNodes(getter_AddRefs(childNodes));
PRUint32 count = 0;
if (childNodes)
childNodes->GetLength(&count);
for (PRUint32 i = 0; i < count; ++i) {
nsCOMPtr<nsIDOMNode> child;
childNodes->Item(i, getter_AddRefs(child));
if (child) {
nsCOMPtr<nsIDOMNode> clone;
CloneNode(child, getter_AddRefs(clone));
if (clone) {
rv = (*aTarget)->AppendChild(clone, getter_AddRefs(tmp));
NS_ENSURE_SUCCESS(rv, rv);
}
}
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsRepeatElement::TryFocus(PRBool *aOK)
{
if (!mCurrentIndex) {
*aOK = PR_FALSE;
return NS_OK;
}
/**
* "Setting focus to a repeating structure sets the focus to
* the repeat item represented by the repeat index."
* @see http://www.w3.org/TR/xforms/slice10.html#action-setfocus
*/
nsCOMPtr<nsIDOMNodeList> children;
mHTMLElement->GetChildNodes(getter_AddRefs(children));
NS_ENSURE_STATE(children);
nsCOMPtr<nsIDOMNode> child;
children->Item(mCurrentIndex - 1, // Indexes are 1-based, the DOM is 0-based
getter_AddRefs(child));
nsCOMPtr<nsIXFormsControl> control = do_QueryInterface(child);
NS_ENSURE_STATE(control);
return control->TryFocus(aOK);
}
/**
* @todo This function will be part of the general schema support, so it will
* only live here until this is implemented there. (XXX)

Просмотреть файл

@ -0,0 +1,143 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 XForms support.
*
* The Initial Developer of the Original Code is
* Novell, Inc.
* Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Allan Beaufour <abeaufour@novell.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 MPL, 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 MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <math.h>
#include "nsIDOMDocument.h"
#include "nsIDOMXPathResult.h"
#include "nsIXFormsRepeatElement.h"
#include "nsXFormsActionModuleBase.h"
#include "nsXFormsActionElement.h"
#ifdef DEBUG
//#define DEBUG_XF_SETINDEX
#endif
/**
* Implementation of the XForms \<setindex\> element.
*
* To set the index for a \<repeat\>, we find the (DOM) \<repeat\> with the
* given @id, and call nsIXFormsRepeatElement::SetIndex() on it.
*
* @see http://www.w3.org/TR/xforms/slice9.html#action-setRepeatCursor
*/
class nsXFormsSetIndexElement : public nsXFormsActionModuleBase
{
public:
NS_DECL_NSIXFORMSACTIONMODULEELEMENT
};
NS_IMETHODIMP
nsXFormsSetIndexElement::HandleAction(nsIDOMEvent *aEvent,
nsIXFormsActionElement *aParentAction)
{
if (!mElement)
return NS_OK;
// Get @repeat and @index
nsAutoString id, index;
mElement->GetAttribute(NS_LITERAL_STRING("repeat"), id);
mElement->GetAttribute(NS_LITERAL_STRING("index"), index);
if (id.IsEmpty() || index.IsEmpty()) {
/// @todo Should we dispatch an exception, or just define that this does
/// not happen as it is a non-validating form as both are required
/// attributes, and index should be an integer? (XXX)
return NS_ERROR_ABORT;
}
// Find index (XPath) value
nsresult rv;
nsCOMPtr<nsIModelElementPrivate> model;
nsCOMPtr<nsIDOMXPathResult> result;
// EvaluateNodeBinding uses @bind if @index is not present, but we have
// checked that @index is present above
rv = nsXFormsUtils::EvaluateNodeBinding(mElement,
0,
NS_LITERAL_STRING("index"),
EmptyString(),
nsIDOMXPathResult::NUMBER_TYPE,
getter_AddRefs(model),
getter_AddRefs(result));
NS_ENSURE_SUCCESS(rv, rv);
if (!result) {
// beaufour: This makes sense, but is not according to the spec. I guess...
nsXFormsUtils::DispatchEvent(mElement, eEvent_BindingException);
return NS_ERROR_ABORT;
}
double indexDoub;
rv = result->GetNumberValue(&indexDoub);
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 indexInt = indexDoub < 1 ? 0 : (PRUint32) floor(indexDoub);
// Find the \<repeat\> with @id == |id|
nsCOMPtr<nsIDOMDocument> domDoc;
rv = mElement->GetOwnerDocument(getter_AddRefs(domDoc));
NS_ENSURE_SUCCESS(rv, rv);
#ifdef DEBUG_XF_SETINDEX
printf("<setindex>: Setting index '%s' to '%d'\n",
NS_ConvertUCS2toUTF8(id).get(),
indexInt);
#endif
nsCOMPtr<nsIDOMElement> repeatElem;
rv = domDoc->GetElementById(id, getter_AddRefs(repeatElem));
nsCOMPtr<nsIXFormsRepeatElement> repeat = do_QueryInterface(repeatElem);
if (!repeat) {
// beaufour: This makes sense, but is not according to the spec. I guess...
nsXFormsUtils::DispatchEvent(mElement, eEvent_BindingException);
return NS_ERROR_ABORT;
}
// Set the index = |indexInt|
return repeat->SetIndex(&indexInt, PR_FALSE);
}
NS_HIDDEN_(nsresult)
NS_NewXFormsSetIndexElement(nsIXTFElement **aResult)
{
*aResult = new nsXFormsSetIndexElement();
if (!*aResult)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aResult);
return NS_OK;
}