2004-12-06 23:31:15 +03:00
|
|
|
/* -*- 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) 2004
|
|
|
|
* 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 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 "nsIXTFXMLVisualWrapper.h"
|
|
|
|
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsISchema.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsMemory.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsSubstring.h"
|
|
|
|
|
|
|
|
#include "nsIDOM3EventTarget.h"
|
|
|
|
#include "nsIDOM3Node.h"
|
|
|
|
#include "nsIDOMDOMImplementation.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMEventTarget.h"
|
2005-02-18 12:38:32 +03:00
|
|
|
#include "nsIDOMNodeList.h"
|
2004-12-06 23:31:15 +03:00
|
|
|
#include "nsIDOMXPathResult.h"
|
2006-06-06 17:52:03 +04:00
|
|
|
#include "nsIDOMDocumentXBL.h"
|
2004-12-06 23:31:15 +03:00
|
|
|
|
2005-01-19 19:05:31 +03:00
|
|
|
#include "nsXFormsControlStub.h"
|
2004-12-06 23:31:15 +03:00
|
|
|
#include "nsIXFormsContextControl.h"
|
2005-02-18 12:38:32 +03:00
|
|
|
#include "nsIXFormsRepeatElement.h"
|
2006-04-26 13:54:12 +04:00
|
|
|
#include "nsIXFormsRepeatUIElement.h"
|
2005-02-18 12:38:32 +03:00
|
|
|
#include "nsIXFormsRepeatItemElement.h"
|
2004-12-06 23:31:15 +03:00
|
|
|
#include "nsXFormsAtoms.h"
|
|
|
|
#include "nsXFormsModelElement.h"
|
|
|
|
#include "nsXFormsUtils.h"
|
2006-04-26 13:54:12 +04:00
|
|
|
#include "nsXFormsDelegateStub.h"
|
2004-12-06 23:31:15 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
//#define DEBUG_XF_REPEAT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of the XForms \<repeat\> control.
|
|
|
|
* @see http://www.w3.org/TR/xforms/slice9.html#id2632123
|
|
|
|
*
|
2005-02-18 12:38:32 +03:00
|
|
|
* 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>
|
|
|
|
*
|
2004-12-06 23:31:15 +03:00
|
|
|
* On Refresh(), nsXFormsRepeatElement, does the following for each node in
|
|
|
|
* the nodeset the \<repeat\> tag is bound to:
|
|
|
|
*
|
2005-01-15 04:04:02 +03:00
|
|
|
* 1) Creates a new \<contextcontainer\> (nsXFormsContextContainer)
|
2004-12-06 23:31:15 +03:00
|
|
|
*
|
2006-04-26 13:54:12 +04:00
|
|
|
* 2) Clones all its children (that is children of its mElement)
|
2005-01-15 04:04:02 +03:00
|
|
|
* and appends them as children to the nsXFormsContextContainer
|
2004-12-06 23:31:15 +03:00
|
|
|
*
|
2005-01-15 04:04:02 +03:00
|
|
|
* 3) Sets the context node and size for the nsXFormsContextContainer, so
|
2004-12-06 23:31:15 +03:00
|
|
|
* that children can retrieve this through nsIXFormsContextControl.
|
|
|
|
*
|
2006-04-26 13:54:12 +04:00
|
|
|
* 4) Inserts the nsXFormsContextContainer into its visual content node.
|
2004-12-06 23:31:15 +03:00
|
|
|
*
|
|
|
|
* For example, this instance data:
|
|
|
|
* <pre>
|
|
|
|
* <instance>
|
|
|
|
* <data>
|
|
|
|
* <n>val1</n>
|
|
|
|
* <n>val2</n>
|
|
|
|
* </data>
|
|
|
|
* </instance>
|
|
|
|
* </pre>
|
|
|
|
*
|
|
|
|
* and this repeat:
|
|
|
|
* <pre>
|
|
|
|
* <repeat nodeset="n">
|
|
|
|
* Val: <output ref="."/>
|
|
|
|
* </repeat>
|
|
|
|
* </pre>
|
|
|
|
*
|
|
|
|
* will be expanded to:
|
|
|
|
* <pre>
|
|
|
|
* <repeat nodeset="n">
|
2006-04-26 13:54:12 +04:00
|
|
|
* (anonymous content) (XBL)
|
2005-02-18 12:38:32 +03:00
|
|
|
* <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>
|
2006-04-26 13:54:12 +04:00
|
|
|
* (/anonymous content) (XBL)
|
2004-12-06 23:31:15 +03:00
|
|
|
* </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\>.
|
|
|
|
*
|
2005-02-18 12:38:32 +03:00
|
|
|
* <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
|
2005-09-27 15:53:08 +04:00
|
|
|
* repeat-index reset to their starting index (ResetInnerRepeats()).
|
2005-02-18 12:38:32 +03:00
|
|
|
*
|
|
|
|
* <h2>Notes / todo</h2>
|
|
|
|
*
|
2005-09-27 15:53:08 +04:00
|
|
|
* @todo Support attribute based repeats, as in: (XXX)
|
2004-12-06 23:31:15 +03:00
|
|
|
* \<html:table xforms:repeat-nodeset="..."\>
|
|
|
|
* @see http://www.w3.org/TR/xforms/index-all.html#ui.repeat.via.attrs
|
2005-02-18 12:38:32 +03:00
|
|
|
* @see http://bugzilla.mozilla.org/show_bug.cgi?id=280368
|
|
|
|
*
|
2005-09-27 15:53:08 +04:00
|
|
|
* @todo What happens if you set attributes on the parent repeat?
|
|
|
|
* Should they propagate to the cloned repeats? (XXX)
|
2005-02-18 12:38:32 +03:00
|
|
|
*
|
|
|
|
* @note Should we handle @number? The spec. says that it's a "Optional hint
|
2005-09-27 15:53:08 +04:00
|
|
|
* to the XForms Processor as to how many elements from the collection to
|
|
|
|
* display."
|
|
|
|
* @see https://bugzilla.mozilla.org/show_bug.cgi?id=302026
|
2004-12-06 23:31:15 +03:00
|
|
|
*/
|
2006-04-26 13:54:12 +04:00
|
|
|
class nsXFormsRepeatElement : public nsXFormsDelegateStub,
|
2005-02-18 12:38:32 +03:00
|
|
|
public nsIXFormsRepeatElement
|
2004-12-06 23:31:15 +03:00
|
|
|
{
|
|
|
|
protected:
|
2005-02-18 12:38:32 +03:00
|
|
|
/**
|
|
|
|
* 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;
|
2006-05-22 13:06:14 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The number of "repeat rows" the repeat currently have unrolled.
|
|
|
|
*/
|
|
|
|
PRUint32 mCurrentRowCount;
|
2005-02-18 12:38:32 +03:00
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
/**
|
|
|
|
* True while children are being added
|
|
|
|
*/
|
|
|
|
PRPackedBool mAddingChildren;
|
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
/**
|
|
|
|
* Are we a parent for nested repeats
|
|
|
|
*/
|
2006-05-22 13:06:14 +04:00
|
|
|
PRPackedBool mIsParent;
|
2005-02-18 12:38:32 +03:00
|
|
|
|
2006-06-06 17:52:03 +04:00
|
|
|
/**
|
|
|
|
* Is the repeat attribute-based (ie. created by using xf:repeat-*
|
|
|
|
* attributes).
|
|
|
|
*
|
|
|
|
* @see http://www.w3.org/TR/xforms/slice9.html#ui.repeat.via.attrs
|
|
|
|
*/
|
|
|
|
PRPackedBool mIsAttributeBased;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A clone of the parent node (used when mIsAttributeBased), that is used by
|
|
|
|
* InsertTemplateContent().
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIDOMNode> mParentClone;
|
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
/**
|
|
|
|
* The currently selected repeat (nested repeats)
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIXFormsRepeatElement> mCurrentRepeat;
|
2005-04-28 11:17:49 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of controls using the repeat-index
|
|
|
|
*/
|
|
|
|
nsCOMArray<nsIXFormsControl> mIndexUsers;
|
2004-12-06 23:31:15 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves an integer attribute and checks its type.
|
|
|
|
*
|
|
|
|
* @param aName The attribute to retrieve
|
|
|
|
* @param aVal The value
|
|
|
|
* @param aType The attribute (Schema) type
|
|
|
|
* @return Normal error codes, and NS_ERROR_NOT_AVAILABLE if
|
|
|
|
* the attribute was empty/nonexistant
|
|
|
|
*/
|
2005-01-24 12:45:16 +03:00
|
|
|
nsresult GetIntAttr(const nsAString &aName,
|
|
|
|
PRInt32 *aVal,
|
|
|
|
const PRUint16 aType);
|
2004-12-06 23:31:15 +03:00
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2006-03-29 14:49:28 +04:00
|
|
|
PRBool IsBindingAttribute(const nsIAtom *aAttr) const;
|
2005-04-11 20:33:31 +04:00
|
|
|
|
2006-03-29 11:39:28 +04:00
|
|
|
/**
|
|
|
|
* Make sure that an index value is inside the valid index range.
|
|
|
|
*
|
|
|
|
* @param aIndex The index value to sanitize
|
|
|
|
* @param aIsScroll Send scroll events if first or last index?
|
|
|
|
*/
|
|
|
|
void SanitizeIndex(PRUint32 *aIndex, PRBool aIsScroll = PR_FALSE);
|
2005-04-11 20:33:31 +04:00
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
/**
|
|
|
|
* Unroll the template content into the visual rows by cloning template
|
|
|
|
* content and inserting into contextcontainers.
|
|
|
|
*/
|
|
|
|
nsresult UnrollRows(nsIDOMXPathResult *aNodeset);
|
|
|
|
|
2006-04-26 13:54:12 +04:00
|
|
|
/**
|
|
|
|
* Returns either the anonymous content of the repeat or null;
|
|
|
|
*/
|
|
|
|
already_AddRefed<nsIDOMElement> GetAnonymousContent();
|
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
/**
|
|
|
|
* Insert the template content for a repeat node into the given node.
|
|
|
|
*
|
|
|
|
* @param aNode The node to insert content into.
|
|
|
|
*/
|
|
|
|
nsresult InsertTemplateContent(nsIDOMNode *aNode);
|
|
|
|
|
2006-06-06 17:52:03 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the XBL binding parent for a node.
|
|
|
|
*
|
|
|
|
* @param aNode The node to get binding parent for
|
|
|
|
* @param aParent The returned binding parent
|
|
|
|
*/
|
|
|
|
nsresult GetBindingParent(nsIDOMNode *aNode, nsIDOMNode **aParent);
|
|
|
|
|
|
|
|
// nsXFormsControlStub override
|
|
|
|
virtual void AfterSetAttribute(nsIAtom *aName);
|
|
|
|
|
2004-12-06 23:31:15 +03:00
|
|
|
public:
|
2005-02-18 12:38:32 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2006-04-26 13:54:12 +04:00
|
|
|
// nsIXTFBindableElement overrides
|
|
|
|
NS_IMETHOD OnCreated(nsIXTFBindableElementWrapper *aWrapper);
|
2004-12-06 23:31:15 +03:00
|
|
|
|
|
|
|
// nsIXTFElement overrides
|
|
|
|
NS_IMETHOD OnDestroyed();
|
2005-01-24 12:45:16 +03:00
|
|
|
NS_IMETHOD BeginAddingChildren();
|
2004-12-06 23:31:15 +03:00
|
|
|
NS_IMETHOD DoneAddingChildren();
|
|
|
|
|
|
|
|
// nsIXFormsControl
|
2006-05-22 13:06:14 +04:00
|
|
|
NS_IMETHOD Bind(PRBool *aContextChanged);
|
2005-01-19 19:05:31 +03:00
|
|
|
NS_IMETHOD Refresh();
|
2005-01-27 22:30:03 +03:00
|
|
|
NS_IMETHOD TryFocus(PRBool* aOK);
|
2005-05-17 16:10:08 +04:00
|
|
|
NS_IMETHOD IsEventTarget(PRBool *aOK);
|
2005-01-24 12:45:16 +03:00
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
// nsIXFormsRepeatElement
|
|
|
|
NS_DECL_NSIXFORMSREPEATELEMENT
|
|
|
|
|
|
|
|
// nsXFormsRepeatElement
|
|
|
|
nsXFormsRepeatElement() :
|
|
|
|
mCurrentIndex(0),
|
|
|
|
mMaxIndex(0),
|
|
|
|
mLevel(1),
|
2006-05-22 13:06:14 +04:00
|
|
|
mCurrentRowCount(0),
|
|
|
|
mAddingChildren(PR_FALSE),
|
2006-06-06 17:52:03 +04:00
|
|
|
mIsParent(PR_FALSE),
|
|
|
|
mIsAttributeBased(PR_FALSE)
|
2005-02-18 12:38:32 +03:00
|
|
|
{}
|
2005-06-07 11:14:31 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_smaug
|
|
|
|
virtual const char* Name() { return "repeat"; }
|
|
|
|
#endif
|
2004-12-06 23:31:15 +03:00
|
|
|
};
|
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsXFormsRepeatElement,
|
2006-04-26 13:54:12 +04:00
|
|
|
nsXFormsDelegateStub,
|
2005-02-18 12:38:32 +03:00
|
|
|
nsIXFormsRepeatElement)
|
|
|
|
|
2004-12-06 23:31:15 +03:00
|
|
|
// nsIXTFXMLVisual
|
|
|
|
NS_IMETHODIMP
|
2006-04-26 13:54:12 +04:00
|
|
|
nsXFormsRepeatElement::OnCreated(nsIXTFBindableElementWrapper *aWrapper)
|
2004-12-06 23:31:15 +03:00
|
|
|
{
|
2006-06-06 17:52:03 +04:00
|
|
|
#ifdef DEBUG_XF_REPEAT
|
|
|
|
printf("nsXFormsRepeatElement::OnCreated()\n");
|
|
|
|
#endif
|
|
|
|
|
2006-04-26 13:54:12 +04:00
|
|
|
nsresult rv = nsXFormsDelegateStub::OnCreated(aWrapper);
|
2005-01-24 11:55:30 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
aWrapper->SetNotificationMask(kStandardNotificationMask |
|
2005-01-24 12:45:16 +03:00
|
|
|
nsIXTFElement::NOTIFY_BEGIN_ADDING_CHILDREN |
|
2005-01-24 11:55:30 +03:00
|
|
|
nsIXTFElement::NOTIFY_DONE_ADDING_CHILDREN);
|
2004-12-06 23:31:15 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIXTFElement
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsRepeatElement::OnDestroyed()
|
|
|
|
{
|
2005-04-28 11:17:49 +04:00
|
|
|
mIndexUsers.Clear();
|
2005-01-24 11:55:30 +03:00
|
|
|
|
2006-04-26 13:54:12 +04:00
|
|
|
return nsXFormsDelegateStub::OnDestroyed();
|
2004-12-06 23:31:15 +03:00
|
|
|
}
|
|
|
|
|
2005-01-24 12:45:16 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsRepeatElement::BeginAddingChildren()
|
|
|
|
{
|
|
|
|
mAddingChildren = PR_TRUE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-12-06 23:31:15 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsRepeatElement::DoneAddingChildren()
|
|
|
|
{
|
2005-02-18 12:38:32 +03:00
|
|
|
mAddingChildren = PR_FALSE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIXFormsRepeatElement
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsRepeatElement::SetIndex(PRUint32 *aIndex,
|
|
|
|
PRBool aIsRefresh)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aIndex);
|
2004-12-06 23:31:15 +03:00
|
|
|
#ifdef DEBUG_XF_REPEAT
|
2005-02-18 12:38:32 +03:00
|
|
|
printf("\tSetindex to %d (current: %d, max: %d), aIsRefresh=%d\n",
|
|
|
|
*aIndex, mCurrentIndex, mMaxIndex, aIsRefresh);
|
2004-12-06 23:31:15 +03:00
|
|
|
#endif
|
2005-02-18 12:38:32 +03:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Set repeat-index
|
|
|
|
if (mIsParent) {
|
2006-03-29 11:39:28 +04:00
|
|
|
NS_ASSERTION(mCurrentRepeat,
|
|
|
|
"How can we be a repeat parent without a child?");
|
2005-02-18 12:38:32 +03:00
|
|
|
// We're the parent of nested repeats, set through the correct repeat
|
|
|
|
return mCurrentRepeat->SetIndex(aIndex, aIsRefresh);
|
|
|
|
}
|
2004-12-06 23:31:15 +03:00
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
// Do nothing if we are not showing anything
|
2006-03-29 11:39:28 +04:00
|
|
|
if (mMaxIndex == 0) {
|
2006-05-24 11:32:10 +04:00
|
|
|
SanitizeIndex(aIndex, PR_TRUE);
|
|
|
|
mCurrentIndex = *aIndex;
|
2005-02-18 12:38:32 +03:00
|
|
|
return NS_OK;
|
2006-03-29 11:39:28 +04:00
|
|
|
}
|
2004-12-06 23:31:15 +03:00
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
if (aIsRefresh && !mCurrentIndex) {
|
|
|
|
// If we are refreshing, get existing index value from parent
|
2006-03-29 11:39:28 +04:00
|
|
|
NS_ASSERTION(mParent,
|
|
|
|
"SetIndex with aIsRefresh == PR_TRUE for a non-nested repeat?!");
|
2005-02-18 12:38:32 +03:00
|
|
|
rv = mParent->GetIndex(aIndex);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check min. and max. value
|
2006-03-29 11:39:28 +04:00
|
|
|
SanitizeIndex(aIndex, PR_TRUE);
|
2005-02-18 12:38:32 +03:00
|
|
|
|
|
|
|
// 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);
|
2004-12-06 23:31:15 +03:00
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
// Unset previous repeat-index
|
|
|
|
if (mCurrentIndex) {
|
|
|
|
// We had the previous selection, unset directly
|
|
|
|
SetChildIndex(mCurrentIndex, PR_FALSE, aIsRefresh);
|
2006-03-29 11:39:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mParent) {
|
2005-02-18 12:38:32 +03:00
|
|
|
// 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;
|
|
|
|
|
2005-04-28 11:17:49 +04:00
|
|
|
// Inform of index change
|
|
|
|
mParent ? mParent->IndexHasChanged() : IndexHasChanged();
|
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsRepeatElement::GetIndex(PRUint32 *aIndex)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aIndex);
|
2006-05-24 11:32:10 +04:00
|
|
|
if (mIsParent) {
|
|
|
|
if (!mCurrentRepeat) {
|
|
|
|
*aIndex = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return mCurrentRepeat->GetIndex(aIndex);
|
2005-02-18 12:38:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
*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;
|
|
|
|
}
|
|
|
|
|
2005-09-27 15:53:08 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsRepeatElement::GetStartingIndex(PRUint32 *aRes)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aRes);
|
|
|
|
|
|
|
|
nsresult rv = GetIntAttr(NS_LITERAL_STRING("startindex"),
|
|
|
|
(PRInt32*) aRes,
|
|
|
|
nsISchemaBuiltinType::BUILTIN_TYPE_POSITIVEINTEGER);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
*aRes = 1;
|
|
|
|
}
|
2006-03-29 11:39:28 +04:00
|
|
|
SanitizeIndex(aRes);
|
|
|
|
|
2005-09-27 15:53:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
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;
|
2005-09-27 15:53:08 +04:00
|
|
|
|
|
|
|
// Check aIndex. If it is 0, we should intialize to the starting index
|
|
|
|
if (!aIndex) {
|
|
|
|
GetStartingIndex(&aIndex);
|
|
|
|
}
|
2005-02-18 12:38:32 +03:00
|
|
|
mCurrentIndex = aIndex;
|
2005-09-27 15:53:08 +04:00
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-08-23 15:00:50 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsRepeatElement::GetCurrentRepeatRow(nsIDOMNode **aRow)
|
|
|
|
{
|
|
|
|
if (mCurrentRepeat) {
|
|
|
|
// nested repeats
|
|
|
|
return mCurrentRepeat->GetCurrentRepeatRow(aRow);
|
|
|
|
}
|
|
|
|
|
2006-04-26 13:54:12 +04:00
|
|
|
nsCOMPtr<nsIDOMElement> anon = GetAnonymousContent();
|
|
|
|
NS_ENSURE_STATE(anon);
|
|
|
|
|
2005-08-23 15:00:50 +04:00
|
|
|
nsCOMPtr<nsIDOMNodeList> children;
|
2006-04-26 13:54:12 +04:00
|
|
|
anon->GetChildNodes(getter_AddRefs(children));
|
2005-08-23 15:00:50 +04:00
|
|
|
NS_ENSURE_STATE(children);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> child;
|
|
|
|
children->Item(mCurrentIndex - 1, // Indexes are 1-based, the DOM is 0-based
|
|
|
|
getter_AddRefs(child));
|
|
|
|
NS_IF_ADDREF(*aRow = child);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-04-28 11:17:49 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsRepeatElement::AddIndexUser(nsIXFormsControl *aControl)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (mIndexUsers.IndexOf(aControl) == -1 && !mIndexUsers.AppendObject(aControl))
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsRepeatElement::RemoveIndexUser(nsIXFormsControl *aControl)
|
|
|
|
{
|
|
|
|
return mIndexUsers.RemoveObject(aControl) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsRepeatElement::IndexHasChanged()
|
|
|
|
{
|
2006-05-24 11:29:53 +04:00
|
|
|
NS_ENSURE_STATE(mModel);
|
2005-04-28 11:17:49 +04:00
|
|
|
///
|
|
|
|
/// @bug We need to handle \<bind\> elements too (XXX)
|
|
|
|
|
|
|
|
// copy the index array, as index users might add/remove themselves when
|
|
|
|
// they are rebound and refreshed().
|
|
|
|
nsCOMArray<nsIXFormsControl> indexes(mIndexUsers);
|
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
nsresult rv;
|
2005-04-28 11:17:49 +04:00
|
|
|
for (PRInt32 i = 0; i < indexes.Count(); ++i) {
|
|
|
|
nsCOMPtr<nsIXFormsControl> control = indexes[i];
|
2006-05-24 11:29:53 +04:00
|
|
|
rv = mModel->ForceRebind(control);
|
2006-05-22 13:06:14 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-04-28 11:17:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
// NB: CloneNode() assumes that this always succeeds
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsRepeatElement::GetIsParent(PRBool *aIsParent)
|
|
|
|
{
|
2005-09-27 15:53:08 +04:00
|
|
|
NS_ENSURE_ARG(aIsParent);
|
2005-02-18 12:38:32 +03:00
|
|
|
*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;
|
2005-09-27 14:54:39 +04:00
|
|
|
// We're an inner repeat owned by a parent, let it control whether we are
|
|
|
|
// selected or not.
|
|
|
|
Deselect();
|
2005-02-18 12:38:32 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsRepeatElement::GetParent(nsIXFormsRepeatElement **aParent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParent);
|
|
|
|
NS_IF_ADDREF(*aParent = mParent);
|
2004-12-06 23:31:15 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
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;
|
|
|
|
}
|
2004-12-06 23:31:15 +03:00
|
|
|
|
2006-03-29 11:39:28 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsRepeatElement::HandleNodeInsert(nsIDOMNode *aNode)
|
|
|
|
{
|
2006-04-26 13:54:12 +04:00
|
|
|
nsCOMPtr<nsIDOMElement> anon = GetAnonymousContent();
|
|
|
|
if (!anon) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-03-29 11:39:28 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOM3Node> node(do_QueryInterface(aNode));
|
|
|
|
NS_ENSURE_STATE(node);
|
|
|
|
|
|
|
|
// XXX, badness^2: If it is a insert we have to refresh before we can
|
|
|
|
// figure out whether the node is in our nodeset... refactor this so
|
|
|
|
// repeat actually gets the nodeset in Bind() and then uses it refresh,
|
|
|
|
// then we can "just" re-evaluate the nodeset, and only refresh if the
|
|
|
|
// node actually hits this repeat
|
|
|
|
|
|
|
|
// XXX, moreover it is also wrong to refresh at this point. It will happen
|
|
|
|
// in insert processing (and possibly deferred...)
|
|
|
|
nsresult rv = Refresh();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> child;
|
2006-04-26 13:54:12 +04:00
|
|
|
anon->GetFirstChild(getter_AddRefs(child));
|
2006-03-29 11:39:28 +04:00
|
|
|
|
|
|
|
PRUint32 index = 1;
|
|
|
|
while (child) {
|
|
|
|
nsCOMPtr<nsIXFormsContextControl> context(do_QueryInterface(child));
|
|
|
|
NS_ASSERTION(context,
|
|
|
|
"repeat child not implementing nsIXFormsContextControl?!");
|
|
|
|
|
|
|
|
nsAutoString modelID;
|
|
|
|
PRInt32 position, size;
|
|
|
|
nsCOMPtr<nsIDOMNode> boundNode;
|
|
|
|
rv = context->GetContext(modelID, getter_AddRefs(boundNode), &position,
|
|
|
|
&size);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
PRBool sameNode = PR_FALSE;
|
|
|
|
node->IsSameNode(boundNode, &sameNode);
|
|
|
|
if (sameNode) {
|
|
|
|
rv = SetIndex(&index, PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> tmp;
|
|
|
|
child->GetNextSibling(getter_AddRefs(tmp));
|
|
|
|
child.swap(tmp);
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-12-06 23:31:15 +03:00
|
|
|
// nsXFormsControl
|
2005-01-19 19:05:31 +03:00
|
|
|
|
2005-02-01 02:41:00 +03:00
|
|
|
NS_IMETHODIMP
|
2006-05-22 13:06:14 +04:00
|
|
|
nsXFormsRepeatElement::Bind(PRBool *aContextChanged)
|
2005-02-01 02:41:00 +03:00
|
|
|
{
|
2006-06-06 17:52:03 +04:00
|
|
|
#ifdef DEBUG_XF_REPEAT
|
|
|
|
printf("nsXFormsRepeatElement::Bind()\n");
|
|
|
|
#endif
|
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
NS_ENSURE_ARG(aContextChanged);
|
|
|
|
|
2006-06-06 17:52:03 +04:00
|
|
|
if (!nsXFormsUtils::IsDocumentReadyForBind(mElement)) {
|
|
|
|
nsXFormsModelElement::DeferElementBind(this);
|
2006-05-22 13:06:14 +04:00
|
|
|
*aContextChanged = PR_FALSE;
|
2006-04-26 13:54:12 +04:00
|
|
|
return NS_OK_XFORMS_DEFERRED;
|
|
|
|
}
|
2006-05-22 13:06:14 +04:00
|
|
|
|
|
|
|
nsresult rv = BindToModel();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
*aContextChanged = PR_TRUE;
|
2006-06-06 17:52:03 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXFormsRepeatElement::GetBindingParent(nsIDOMNode *aNode,
|
|
|
|
nsIDOMNode **aParent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNode);
|
|
|
|
NS_ENSURE_ARG_POINTER(aParent);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
aNode->GetOwnerDocument(getter_AddRefs(domDoc));
|
|
|
|
nsCOMPtr<nsIDOMDocumentXBL> docXBL(do_QueryInterface(domDoc));
|
|
|
|
NS_ENSURE_STATE(docXBL);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> parent;
|
|
|
|
docXBL->GetBindingParent(aNode, getter_AddRefs(parent));
|
|
|
|
NS_IF_ADDREF(*aParent = parent);
|
2006-05-22 13:06:14 +04:00
|
|
|
return NS_OK;
|
2005-02-01 02:41:00 +03:00
|
|
|
}
|
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
nsresult
|
|
|
|
nsXFormsRepeatElement::InsertTemplateContent(nsIDOMNode *aNode)
|
2004-12-06 23:31:15 +03:00
|
|
|
{
|
2006-06-06 17:52:03 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aNode);
|
2006-05-22 13:06:14 +04:00
|
|
|
|
2006-06-06 17:52:03 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMNode> insertionPoint;
|
|
|
|
|
|
|
|
// If we are attribute based we need to clone our parent (the element with
|
|
|
|
// the repeat-* attributes), and insert that as the first child.
|
|
|
|
if (mIsAttributeBased) {
|
|
|
|
NS_ENSURE_STATE(mParentClone);
|
|
|
|
nsCOMPtr<nsIDOMNode> parentClone;
|
|
|
|
rv = mParentClone->CloneNode(PR_FALSE, getter_AddRefs(parentClone));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aNode->AppendChild(parentClone, getter_AddRefs(insertionPoint));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
insertionPoint = aNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get template content
|
2006-05-22 13:06:14 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> child;
|
2006-06-06 17:52:03 +04:00
|
|
|
if (mIsAttributeBased) {
|
|
|
|
// If we are attribute based, we need to get our binding parent and get
|
|
|
|
// its first child or we will be looking at the binding document.
|
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
|
|
|
rv = GetBindingParent(mElement, getter_AddRefs(parent));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = parent->GetFirstChild(getter_AddRefs(child));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
rv = mElement->GetFirstChild(getter_AddRefs(child));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clone template
|
2006-05-22 13:06:14 +04:00
|
|
|
while (child) {
|
|
|
|
nsCOMPtr<nsIDOMNode> childClone;
|
|
|
|
rv = CloneNode(child, getter_AddRefs(childClone));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> newNode;
|
2006-06-06 17:52:03 +04:00
|
|
|
rv = insertionPoint->AppendChild(childClone, getter_AddRefs(newNode));
|
2006-05-22 13:06:14 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = child->GetNextSibling(getter_AddRefs(newNode));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
child = newNode;
|
2006-04-26 13:54:12 +04:00
|
|
|
}
|
2006-06-06 17:52:03 +04:00
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-06 17:52:03 +04:00
|
|
|
// XXX: If repeat is moved to a new position, we need to clear the unrolled
|
|
|
|
// content and clear mParentClone
|
2006-05-22 13:06:14 +04:00
|
|
|
nsresult
|
|
|
|
nsXFormsRepeatElement::UnrollRows(nsIDOMXPathResult *aNodeset)
|
|
|
|
{
|
2006-05-24 11:32:10 +04:00
|
|
|
#ifdef DEBUG_XF_REPEAT
|
|
|
|
printf("nsXFormsRepeatElement::UnrollRows()\n");
|
|
|
|
#endif
|
2006-05-22 13:06:14 +04:00
|
|
|
NS_ENSURE_STATE(mElement);
|
|
|
|
|
2006-04-26 13:54:12 +04:00
|
|
|
nsCOMPtr<nsIDOMElement> anon = GetAnonymousContent();
|
|
|
|
if (!anon) {
|
2004-12-06 23:31:15 +03:00
|
|
|
return NS_OK;
|
2006-04-26 13:54:12 +04:00
|
|
|
}
|
|
|
|
|
2004-12-06 23:31:15 +03:00
|
|
|
nsresult rv;
|
2006-05-22 13:06:14 +04:00
|
|
|
if (!aNodeset || !mModel) {
|
|
|
|
mMaxIndex = 0;
|
|
|
|
} else {
|
|
|
|
PRUint32 contextSize;
|
|
|
|
rv = aNodeset->GetSnapshotLength(&contextSize);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
mMaxIndex = contextSize;
|
2004-12-06 23:31:15 +03:00
|
|
|
}
|
|
|
|
|
2006-05-24 11:32:10 +04:00
|
|
|
#ifdef DEBUG_XF_REPEAT
|
|
|
|
printf("\tmMaxIndex: %d, mCurrentRowCount: %d\n",
|
|
|
|
mMaxIndex, mCurrentRowCount);
|
|
|
|
#endif
|
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
// STEP 1: Remove rows
|
|
|
|
nsCOMPtr<nsIDOMNode> tmp;
|
|
|
|
if (mMaxIndex < mCurrentRowCount) {
|
|
|
|
for (PRUint32 i = mMaxIndex; i < mCurrentRowCount; ++i) {
|
|
|
|
nsCOMPtr<nsIDOMNode> lastChild;
|
|
|
|
rv = anon->GetLastChild(getter_AddRefs(lastChild));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = anon->RemoveChild(lastChild, getter_AddRefs(tmp));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
} else if (mMaxIndex > mCurrentRowCount) {
|
|
|
|
// STEP 2: Add rows
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
rv = anon->GetOwnerDocument(getter_AddRefs(domDoc));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
for (PRUint32 i = mCurrentRowCount; i < mMaxIndex; ++i) {
|
|
|
|
// Create <contextcontainer>
|
|
|
|
nsCOMPtr<nsIDOMElement> container;
|
|
|
|
rv = domDoc->CreateElementNS(NS_LITERAL_STRING(NS_NAMESPACE_XFORMS),
|
|
|
|
NS_LITERAL_STRING("contextcontainer"),
|
|
|
|
getter_AddRefs(container));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
container->SetAttribute(NS_LITERAL_STRING("class"),
|
|
|
|
NS_LITERAL_STRING("xf-repeat-item"));
|
2005-11-02 01:47:22 +03:00
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
rv = anon->AppendChild(container, getter_AddRefs(tmp));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
2004-12-06 23:31:15 +03:00
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
// Repeat has no content
|
|
|
|
if (!mMaxIndex) {
|
|
|
|
mCurrentRowCount = 0;
|
2005-02-18 12:38:32 +03:00
|
|
|
return NS_OK;
|
2006-05-22 13:06:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// STEP 3: Update context on rows
|
|
|
|
nsCOMPtr<nsIDOMNode> child;
|
|
|
|
rv = anon->GetFirstChild(getter_AddRefs(child));
|
2005-02-18 12:38:32 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
for (PRUint32 i = 0; i < mMaxIndex; ++i) {
|
|
|
|
NS_ASSERTION(child, "Unrolled content does not match index size?!");
|
2005-06-02 11:00:11 +04:00
|
|
|
// Get context node
|
2005-02-18 12:38:32 +03:00
|
|
|
nsCOMPtr<nsIDOMNode> contextNode;
|
2006-05-22 13:06:14 +04:00
|
|
|
rv = aNodeset->SnapshotItem(i, getter_AddRefs(contextNode));
|
2005-02-18 12:38:32 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-06-02 11:00:11 +04:00
|
|
|
|
|
|
|
// Set context node, position, and size
|
2006-05-22 13:06:14 +04:00
|
|
|
nsCOMPtr<nsIXFormsContextControl> childContext = do_QueryInterface(child);
|
|
|
|
NS_ASSERTION(childContext,
|
|
|
|
"content child not implementing nsIXFormsContextControl?!");
|
2005-02-18 12:38:32 +03:00
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
rv = childContext->SetContext(contextNode, i + 1, mMaxIndex);
|
2005-11-16 09:49:37 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
// Next child
|
|
|
|
rv = child->GetNextSibling(getter_AddRefs(tmp));
|
2005-02-18 12:38:32 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-05-22 13:06:14 +04:00
|
|
|
tmp.swap(child);
|
|
|
|
}
|
2005-11-02 01:47:22 +03:00
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
// Rows deleted, nothing more to do
|
|
|
|
if (mCurrentRowCount >= mMaxIndex) {
|
|
|
|
mCurrentRowCount = mMaxIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-11-02 01:47:22 +03:00
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
// STEP 4: Insert template content into newly created rows
|
2006-06-06 17:52:03 +04:00
|
|
|
|
|
|
|
// If we are attribute based, prepare a clone of our parent
|
|
|
|
if (mIsAttributeBased && !mParentClone) {
|
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
|
|
|
rv = mElement->GetParentNode(getter_AddRefs(parent));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> parentClone;
|
|
|
|
rv = parent->CloneNode(PR_FALSE, getter_AddRefs(parentClone));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> parentCloneEl(do_QueryInterface(parentClone));
|
|
|
|
NS_ENSURE_STATE(parentCloneEl);
|
|
|
|
|
|
|
|
// Remove all possible repeat-* attributes
|
|
|
|
parentCloneEl->RemoveAttributeNS(NS_LITERAL_STRING(NS_NAMESPACE_XFORMS),
|
|
|
|
NS_LITERAL_STRING("repeat-model"));
|
|
|
|
parentCloneEl->RemoveAttributeNS(NS_LITERAL_STRING(NS_NAMESPACE_XFORMS),
|
|
|
|
NS_LITERAL_STRING("repeat-bind"));
|
|
|
|
parentCloneEl->RemoveAttributeNS(NS_LITERAL_STRING(NS_NAMESPACE_XFORMS),
|
|
|
|
NS_LITERAL_STRING("repeat-nodeset"));
|
|
|
|
parentCloneEl->RemoveAttributeNS(NS_LITERAL_STRING(NS_NAMESPACE_XFORMS),
|
|
|
|
NS_LITERAL_STRING("repeat-startindex"));
|
|
|
|
parentCloneEl->RemoveAttributeNS(NS_LITERAL_STRING(NS_NAMESPACE_XFORMS),
|
|
|
|
NS_LITERAL_STRING("repeat-number"));
|
|
|
|
|
|
|
|
// Save parent clone
|
|
|
|
mParentClone = parentCloneEl;
|
|
|
|
}
|
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
nsCOMPtr<nsIDOMNodeList> containerList;
|
|
|
|
rv = anon->GetChildNodes(getter_AddRefs(containerList));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-05-24 13:53:27 +04:00
|
|
|
for (PRUint32 j = mCurrentRowCount; j < mMaxIndex; ++j) {
|
2006-05-22 13:06:14 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> container;
|
2006-05-24 13:53:27 +04:00
|
|
|
rv = containerList->Item(j, getter_AddRefs(container));
|
2006-05-22 13:06:14 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = InsertTemplateContent(container);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-02-18 12:38:32 +03:00
|
|
|
}
|
2006-05-22 13:06:14 +04:00
|
|
|
|
|
|
|
mCurrentRowCount = mMaxIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsRepeatElement::Refresh()
|
|
|
|
{
|
2006-06-06 17:52:03 +04:00
|
|
|
#ifdef DEBUG_XF_REPEAT
|
|
|
|
printf("nsXFormsRepeatElement::Refresh()\n");
|
|
|
|
#endif
|
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
if (mAddingChildren || mIsParent)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsPostRefresh postRefresh = nsPostRefresh();
|
|
|
|
|
2006-05-24 11:32:10 +04:00
|
|
|
PRUint32 oldIndex = mCurrentIndex;
|
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
/// @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)
|
|
|
|
|
|
|
|
|
|
|
|
// Get the nodeset we are bound to
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDOMXPathResult> result;
|
|
|
|
rv = ProcessNodeBinding(NS_LITERAL_STRING("nodeset"),
|
|
|
|
nsIDOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
|
|
|
|
getter_AddRefs(result));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Unroll the repeat rows
|
|
|
|
rv = UnrollRows(result);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-02-18 12:38:32 +03:00
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
// Maintain the index
|
2006-05-24 11:32:10 +04:00
|
|
|
if (mCurrentIndex || !mMaxIndex) {
|
|
|
|
// Somebody might have been fooling around with our children since last
|
|
|
|
// refresh (either using delete or through script). Or we might have an
|
|
|
|
// empty nodeset. So fix the index value.
|
2006-03-29 11:39:28 +04:00
|
|
|
SanitizeIndex(&mCurrentIndex);
|
2006-04-26 13:54:12 +04:00
|
|
|
} else if (mMaxIndex) {
|
2005-02-18 12:38:32 +03:00
|
|
|
// repeat-index has not been initialized, set it.
|
2006-04-26 13:54:12 +04:00
|
|
|
if (!mParent) {
|
|
|
|
GetStartingIndex(&mCurrentIndex);
|
2006-05-04 16:15:07 +04:00
|
|
|
// Inform listeners of initial index value
|
|
|
|
IndexHasChanged();
|
2006-04-26 13:54:12 +04:00
|
|
|
} else if (mLevel > 1) {
|
|
|
|
// Set repeat-index for inner repeats. If parent <contextcontainer/>
|
|
|
|
// element is selected then mCurrentIndex is setted on starting index.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> temp = mElement;
|
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
|
|
|
nsCOMPtr<nsIXFormsRepeatItemElement> context;
|
|
|
|
|
|
|
|
while (!context) {
|
|
|
|
rv = temp->GetParentNode(getter_AddRefs(parent));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!parent)
|
|
|
|
break;
|
|
|
|
context = do_QueryInterface(parent);
|
|
|
|
temp.swap(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context) {
|
|
|
|
PRBool hasIndex = PR_FALSE;
|
|
|
|
context->GetIndexState(&hasIndex);
|
|
|
|
if (hasIndex) {
|
|
|
|
PRUint32 index = 0;
|
|
|
|
GetStartingIndex(&index);
|
|
|
|
SetIndex(&index, PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-02-18 12:38:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we have the repeat-index, set it.
|
2006-04-26 13:54:12 +04:00
|
|
|
if (mCurrentIndex) {
|
2005-02-18 12:38:32 +03:00
|
|
|
SetChildIndex(mCurrentIndex, PR_TRUE, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
2006-05-24 11:32:10 +04:00
|
|
|
if (mCurrentIndex != oldIndex) {
|
|
|
|
mParent ? mParent->IndexHasChanged() : IndexHasChanged();
|
|
|
|
}
|
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsXFormsRepeatElement
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXFormsRepeatElement::SetChildIndex(PRUint32 aPosition,
|
|
|
|
PRBool aState,
|
|
|
|
PRBool aIsRefresh)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_XF_REPEAT
|
|
|
|
printf("\tTrying to set index #%d to state '%d', aIsRefresh=%d\n",
|
|
|
|
aPosition, aState, aIsRefresh);
|
|
|
|
#endif
|
|
|
|
|
2006-04-26 13:54:12 +04:00
|
|
|
nsCOMPtr<nsIDOMElement> anon = GetAnonymousContent();
|
|
|
|
if (!anon)
|
2005-02-18 12:38:32 +03:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNodeList> children;
|
2006-04-26 13:54:12 +04:00
|
|
|
anon->GetChildNodes(getter_AddRefs(children));
|
2005-02-18 12:38:32 +03:00
|
|
|
NS_ENSURE_STATE(children);
|
|
|
|
|
2006-03-29 11:39:28 +04:00
|
|
|
PRUint32 index = aPosition - 1; // Indexes are 1-based, the DOM is 0-based;
|
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
nsCOMPtr<nsIDOMNode> child;
|
2006-03-29 11:39:28 +04:00
|
|
|
children->Item(index,
|
2005-02-18 12:38:32 +03:00
|
|
|
getter_AddRefs(child));
|
2006-03-29 11:39:28 +04:00
|
|
|
nsCOMPtr<nsIXFormsRepeatItemElement> repeatItem(do_QueryInterface(child));
|
|
|
|
NS_ASSERTION(repeatItem,
|
|
|
|
"repeat child not implementing nsIXFormsRepeatItemElement?!");
|
2005-02-18 12:38:32 +03:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
PRBool curState;
|
|
|
|
rv = repeatItem->GetIndexState(&curState);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (curState != aState) {
|
|
|
|
rv = repeatItem->SetIndexState(aState);
|
2005-01-19 19:05:31 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
if (aState) {
|
|
|
|
// Reset inner repeats
|
|
|
|
rv = ResetInnerRepeats(child, aIsRefresh);
|
2005-01-19 19:05:31 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-02-18 12:38:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-03-29 11:39:28 +04:00
|
|
|
void
|
|
|
|
nsXFormsRepeatElement::SanitizeIndex(PRUint32 *aIndex, PRBool aIsScroll)
|
|
|
|
{
|
|
|
|
if (!aIndex)
|
|
|
|
return;
|
2006-05-24 11:32:10 +04:00
|
|
|
#ifdef DEBUG_XF_REPEAT
|
|
|
|
printf("nsXFormsRepeatElement::SanitizeIndex()\n");
|
|
|
|
printf("\tCurrent index: %d\n", *aIndex);
|
|
|
|
#endif
|
2006-03-29 11:39:28 +04:00
|
|
|
if (*aIndex < 1) {
|
2006-05-24 11:32:10 +04:00
|
|
|
*aIndex = mMaxIndex ? 1 : 0;
|
2006-03-29 11:39:28 +04:00
|
|
|
if (aIsScroll)
|
|
|
|
nsXFormsUtils::DispatchEvent(mElement, eEvent_ScrollFirst);
|
|
|
|
} else if (*aIndex > mMaxIndex) {
|
|
|
|
*aIndex = mMaxIndex;
|
|
|
|
if (aIsScroll)
|
|
|
|
nsXFormsUtils::DispatchEvent(mElement, eEvent_ScrollLast);
|
|
|
|
}
|
2006-05-24 11:32:10 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_XF_REPEAT
|
|
|
|
printf("\tNew index: %d\n", *aIndex);
|
|
|
|
#endif
|
2006-03-29 11:39:28 +04:00
|
|
|
}
|
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
nsresult
|
|
|
|
nsXFormsRepeatElement::ResetInnerRepeats(nsIDOMNode *aNode,
|
|
|
|
PRBool aIsRefresh)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_XF_REPEAT
|
|
|
|
printf("\taIsRefresh: %d\n",
|
|
|
|
aIsRefresh);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aNode);
|
2004-12-06 23:31:15 +03:00
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
if (!element)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNodeList> nodeList;
|
|
|
|
nsresult rv;
|
2006-04-26 13:54:12 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> anon = GetAnonymousContent();
|
|
|
|
NS_ENSURE_STATE(anon);
|
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
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;
|
|
|
|
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);
|
2005-09-27 15:53:08 +04:00
|
|
|
if (level == mLevel + 1) {
|
|
|
|
PRUint32 index;
|
|
|
|
repeat->GetStartingIndex(&index);
|
2005-02-18 12:38:32 +03:00
|
|
|
repeat->SetIndex(&index, aIsRefresh);
|
2005-09-27 15:53:08 +04:00
|
|
|
}
|
2005-02-18 12:38:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2005-01-19 19:05:31 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-02-18 12:38:32 +03:00
|
|
|
}
|
2005-01-19 19:05:31 +03:00
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
// 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) {
|
2005-09-27 15:53:08 +04:00
|
|
|
rv = parent->SetCurrentRepeat(repClone, 0);
|
2005-01-19 19:05:31 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-02-18 12:38:32 +03:00
|
|
|
parent->SetIsParent(PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
2005-01-19 19:05:31 +03:00
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
// 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);
|
|
|
|
}
|
2004-12-06 23:31:15 +03:00
|
|
|
}
|
|
|
|
}
|
2005-02-18 12:38:32 +03:00
|
|
|
|
2004-12-06 23:31:15 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-27 22:30:03 +03:00
|
|
|
NS_IMETHODIMP
|
2005-02-18 12:38:32 +03:00
|
|
|
nsXFormsRepeatElement::TryFocus(PRBool *aOK)
|
2005-01-27 22:30:03 +03:00
|
|
|
{
|
2005-02-18 12:38:32 +03:00
|
|
|
if (!mCurrentIndex) {
|
|
|
|
*aOK = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-04-26 13:54:12 +04:00
|
|
|
nsCOMPtr<nsIDOMElement> anon = GetAnonymousContent();
|
|
|
|
if (!anon)
|
|
|
|
return NS_OK;
|
|
|
|
|
2005-02-18 12:38:32 +03:00
|
|
|
/**
|
|
|
|
* "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;
|
2006-04-26 13:54:12 +04:00
|
|
|
anon->GetChildNodes(getter_AddRefs(children));
|
2005-02-18 12:38:32 +03:00
|
|
|
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);
|
2005-01-27 22:30:03 +03:00
|
|
|
}
|
2005-05-17 16:10:08 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsRepeatElement::IsEventTarget(PRBool *aOK)
|
|
|
|
{
|
|
|
|
*aOK = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-01-27 22:30:03 +03:00
|
|
|
|
2004-12-06 23:31:15 +03:00
|
|
|
/**
|
|
|
|
* @todo This function will be part of the general schema support, so it will
|
|
|
|
* only live here until this is implemented there. (XXX)
|
|
|
|
*/
|
|
|
|
nsresult
|
2005-02-09 12:57:31 +03:00
|
|
|
nsXFormsRepeatElement::GetIntAttr(const nsAString &aName,
|
|
|
|
PRInt32 *aVal,
|
|
|
|
const PRUint16 aType)
|
2004-12-06 23:31:15 +03:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aVal);
|
|
|
|
|
|
|
|
nsAutoString attrVal;
|
|
|
|
mElement->GetAttribute(aName, attrVal);
|
|
|
|
|
|
|
|
/// @todo Is this the correct error to return? We need to distinguish between
|
|
|
|
/// an empty attribute and other errors. (XXX)
|
|
|
|
if (attrVal.IsEmpty()) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 errCode;
|
|
|
|
/// @todo ToInteger is extremely large, "xxx23xxx" will be parsed with no errors
|
|
|
|
/// as "23"... (XXX)
|
|
|
|
*aVal = attrVal.ToInteger(&errCode);
|
|
|
|
NS_ENSURE_TRUE(errCode == 0, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @todo Check maximum values? (XXX)
|
|
|
|
switch (aType) {
|
|
|
|
case nsISchemaBuiltinType::BUILTIN_TYPE_NONNEGATIVEINTEGER:
|
|
|
|
if (*aVal < 0) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsISchemaBuiltinType::BUILTIN_TYPE_POSITIVEINTEGER:
|
|
|
|
if (*aVal <= 0) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsISchemaBuiltinType::BUILTIN_TYPE_ANYTYPE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rv = NS_ERROR_INVALID_ARG; // or NOT_IMPLEMENTED?
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2006-03-29 14:49:28 +04:00
|
|
|
PRBool
|
|
|
|
nsXFormsRepeatElement::IsBindingAttribute(const nsIAtom *aAttr) const
|
2005-04-11 20:33:31 +04:00
|
|
|
{
|
2006-03-29 14:49:28 +04:00
|
|
|
if (aAttr == nsXFormsAtoms::bind ||
|
|
|
|
aAttr == nsXFormsAtoms::nodeset ||
|
|
|
|
aAttr == nsXFormsAtoms::model) {
|
|
|
|
return PR_TRUE;
|
2005-04-11 20:33:31 +04:00
|
|
|
}
|
2006-03-29 14:49:28 +04:00
|
|
|
|
|
|
|
return PR_FALSE;
|
2005-04-11 20:33:31 +04:00
|
|
|
}
|
|
|
|
|
2006-06-06 17:52:03 +04:00
|
|
|
void
|
|
|
|
nsXFormsRepeatElement::AfterSetAttribute(nsIAtom *aName)
|
|
|
|
{
|
|
|
|
if (aName == nsXFormsAtoms::attrBased) {
|
|
|
|
PRBool isAttributeBased;
|
|
|
|
nsresult rv =
|
|
|
|
mElement->HasAttributeNS(NS_LITERAL_STRING(NS_NAMESPACE_MOZ_XFORMS_TYPE),
|
|
|
|
NS_LITERAL_STRING("attrBased"),
|
|
|
|
&isAttributeBased);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mIsAttributeBased = isAttributeBased;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXFormsDelegateStub::AfterSetAttribute(aName);
|
|
|
|
}
|
|
|
|
|
2006-04-26 13:54:12 +04:00
|
|
|
already_AddRefed<nsIDOMElement>
|
|
|
|
nsXFormsRepeatElement::GetAnonymousContent()
|
|
|
|
{
|
|
|
|
nsIDOMElement* anon = nsnull;
|
|
|
|
nsCOMPtr<nsIXFormsRepeatUIElement> uiElement(do_QueryInterface(mElement));
|
|
|
|
if (uiElement) {
|
|
|
|
// addrefs
|
|
|
|
uiElement->GetAnonymousRepeatContent(&anon);
|
|
|
|
}
|
|
|
|
return anon;
|
|
|
|
}
|
|
|
|
|
2004-12-06 23:31:15 +03:00
|
|
|
// Factory
|
|
|
|
NS_HIDDEN_(nsresult)
|
|
|
|
NS_NewXFormsRepeatElement(nsIXTFElement **aResult)
|
|
|
|
{
|
|
|
|
*aResult = new nsXFormsRepeatElement();
|
|
|
|
if (!*aResult)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|