Bug 331081, Nested repeats are not working on trunk, r=aaronr+allan

This commit is contained in:
Olli.Pettay%helsinki.fi 2006-04-04 19:51:31 +00:00
Родитель b2e1cccf99
Коммит 6b03bf8607
2 изменённых файлов: 72 добавлений и 29 удалений

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

@ -43,7 +43,7 @@
#include "nsISupports.idl"
[uuid(2bd6a7c7-ca59-408b-9a2a-c1bdef919fd5)]
[uuid(a60f5ef2-6c3d-4c57-af19-033734354115)]
interface nsIXFormsRepeatItemElement : nsISupports
{
/**
@ -51,4 +51,9 @@ interface nsIXFormsRepeatItemElement : nsISupports
* can set the :repeat-index accordingly.
*/
attribute boolean indexState;
/**
* This returns the context position of the repeat item.
*/
readonly attribute long contextPosition;
};

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

@ -45,6 +45,7 @@
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMEvent.h"
#include "nsIDOMNSEvent.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMSerializer.h"
#include "nsIDOMXPathResult.h"
@ -137,40 +138,70 @@ nsXFormsContextContainer::HandleDefault(nsIDOMEvent *aEvent,
nsAutoString type;
aEvent->GetType(type);
if (!type.EqualsLiteral("focus"))
// Need to use "DOMFocusIn" here, "focus" doesn't bubble
if (!type.EqualsLiteral("DOMFocusIn"))
return nsXFormsBindableControlStub::HandleDefault(aEvent, aHandled);
if (!nsXFormsUtils::EventHandlingAllowed(aEvent, mElement))
return NS_OK;
/*
* 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;
// Need to explicitly create the parent chain. This ensures that this code
// works both in 1.8, which has the old event dispatching code, and also in
// the later versions of Gecko with the new event dispatching.
// See also Bug 331081.
nsCOMPtr<nsIDOMNSEvent> event = do_QueryInterface(aEvent);
NS_ENSURE_STATE(event);
nsCOMPtr<nsIDOMEventTarget> target;
event->GetOriginalTarget(getter_AddRefs(target));
nsCOMPtr<nsIDOMNode> currentNode = do_QueryInterface(target);
// Tell \<repeat\> about the new index position
PRUint32 tmp = mContextPosition;
return repeat->SetIndex(&tmp, PR_FALSE);
nsCOMArray<nsIDOMNode> containerStack(4);
while (currentNode) {
nsCOMPtr<nsIXFormsRepeatItemElement> repeatItem =
do_QueryInterface(currentNode);
if (repeatItem) {
containerStack.AppendObject(currentNode);
}
nsCOMPtr<nsIDOMNode> parent;
currentNode->GetParentNode(getter_AddRefs(parent));
currentNode.swap(parent);
}
for (PRInt32 i = containerStack.Count() - 1; i >= 0; --i) {
nsCOMPtr<nsIDOMNode> node = containerStack[i];
if (node) {
// 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):
// <repeat> <-- gParent
// <div>
// <contextcontainer\> <-- this
// </div>
// </repeat>
nsCOMPtr<nsIDOMNode> parent;
node->GetParentNode(getter_AddRefs(parent));
if (parent) {
nsCOMPtr<nsIDOMNode> grandParent;
parent->GetParentNode(getter_AddRefs(grandParent));
nsCOMPtr<nsIXFormsRepeatElement> repeat =
do_QueryInterface(grandParent);
nsCOMPtr<nsIXFormsRepeatItemElement> repeatItem =
do_QueryInterface(node);
if (repeat && repeatItem) {
PRInt32 position = 1;
repeatItem->GetContextPosition(&position);
// Tell <repeat> about the new index position
PRUint32 tmp = position;
repeat->SetIndex(&tmp, PR_FALSE);
}
}
}
}
*aHandled = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
@ -279,6 +310,13 @@ nsXFormsContextContainer::GetIndexState(PRBool *aHasIndex)
return NS_OK;
}
NS_IMETHODIMP
nsXFormsContextContainer::GetContextPosition(PRInt32 *aContextPosition)
{
*aContextPosition = mContextPosition;
return NS_OK;
}
// Factory
NS_HIDDEN_(nsresult)
NS_NewXFormsContextContainer(nsIXTFElement **aResult)