2005-01-19 19:05:31 +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>
|
2005-06-08 19:33:18 +04:00
|
|
|
* Olli Pettay <Olli.Pettay@helsinki.fi>
|
2005-01-19 19:05:31 +03:00
|
|
|
*
|
|
|
|
* 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 "nsIModelElementPrivate.h"
|
|
|
|
#include "nsXFormsControlStub.h"
|
|
|
|
#include "nsXFormsMDGEngine.h"
|
|
|
|
|
2005-04-28 11:17:49 +04:00
|
|
|
#include "nsIDOMDocument.h"
|
2005-01-19 19:05:31 +03:00
|
|
|
#include "nsIDOMEvent.h"
|
2005-01-30 02:53:32 +03:00
|
|
|
#include "nsIDOMKeyEvent.h"
|
|
|
|
#include "nsIDOMEventTarget.h"
|
2005-01-19 19:05:31 +03:00
|
|
|
#include "nsIDOMXPathResult.h"
|
2005-05-17 15:30:43 +04:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsXFormsModelElement.h"
|
2005-06-13 23:17:24 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIFocusController.h"
|
2005-08-24 13:43:27 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2005-10-19 11:39:36 +04:00
|
|
|
#include "nsIEventStateManager.h"
|
2005-10-22 19:20:46 +04:00
|
|
|
#include "nsIContent.h"
|
2006-03-29 14:49:28 +04:00
|
|
|
#include "nsIDOM3Node.h"
|
2006-05-30 17:41:14 +04:00
|
|
|
#include "nsIDOMAttr.h"
|
2005-01-19 19:05:31 +03:00
|
|
|
|
2005-01-30 02:53:32 +03:00
|
|
|
/** This class is used to generate xforms-hint and xforms-help events.*/
|
|
|
|
class nsXFormsHintHelpListener : public nsIDOMEventListener {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsXFormsHintHelpListener, nsIDOMEventListener)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsHintHelpListener::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
if (!aEvent)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> target;
|
|
|
|
aEvent->GetCurrentTarget(getter_AddRefs(target));
|
|
|
|
nsCOMPtr<nsIDOMNode> targetNode(do_QueryInterface(target));
|
2005-05-03 23:39:38 +04:00
|
|
|
if (nsXFormsUtils::EventHandlingAllowed(aEvent, targetNode)) {
|
|
|
|
nsCOMPtr<nsIDOMKeyEvent> keyEvent(do_QueryInterface(aEvent));
|
|
|
|
if (keyEvent) {
|
|
|
|
PRUint32 code = 0;
|
|
|
|
keyEvent->GetKeyCode(&code);
|
2005-07-13 18:36:43 +04:00
|
|
|
if (code == nsIDOMKeyEvent::DOM_VK_F1) {
|
|
|
|
PRBool defaultEnabled = PR_TRUE;
|
|
|
|
nsresult rv = nsXFormsUtils::DispatchEvent(targetNode, eEvent_Help,
|
|
|
|
&defaultEnabled);
|
|
|
|
|
|
|
|
// If the xforms event's default behavior was disabled, prevent the DOM
|
|
|
|
// event's default action as well. This means that the F1 key was
|
|
|
|
// handled (a help dialog was shown) and we don't want the browser to
|
|
|
|
// show it's help dialog.
|
|
|
|
if (NS_SUCCEEDED(rv) && !defaultEnabled)
|
|
|
|
aEvent->PreventDefault();
|
|
|
|
}
|
2005-05-03 23:39:38 +04:00
|
|
|
} else {
|
2005-06-08 19:33:18 +04:00
|
|
|
nsAutoString type;
|
|
|
|
aEvent->GetType(type);
|
|
|
|
nsXFormsUtils::DispatchEvent(targetNode,
|
|
|
|
(type.EqualsLiteral("mouseover") ||
|
|
|
|
type.EqualsLiteral("focus"))
|
|
|
|
? eEvent_Hint : eEvent_MozHintOff);
|
2005-05-03 23:39:38 +04:00
|
|
|
}
|
2005-01-30 02:53:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-19 19:05:31 +03:00
|
|
|
NS_IMETHODIMP
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::GetBoundNode(nsIDOMNode **aBoundNode)
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aBoundNode = mBoundNode);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::GetDependencies(nsCOMArray<nsIDOMNode> **aDependencies)
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
2005-02-24 17:35:27 +03:00
|
|
|
if (aDependencies)
|
|
|
|
*aDependencies = &mDependencies;
|
2005-01-19 19:05:31 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::GetElement(nsIDOMElement **aElement)
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aElement = mElement);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-28 11:17:49 +04:00
|
|
|
void
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::RemoveIndexListeners()
|
2005-04-28 11:17:49 +04:00
|
|
|
{
|
|
|
|
if (!mIndexesUsed.Count())
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < mIndexesUsed.Count(); ++i) {
|
|
|
|
nsCOMPtr<nsIXFormsRepeatElement> rep = mIndexesUsed[i];
|
|
|
|
rep->RemoveIndexUser(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
mIndexesUsed.Clear();
|
|
|
|
}
|
|
|
|
|
2005-02-01 02:41:00 +03:00
|
|
|
NS_IMETHODIMP
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::ResetBoundNode(const nsString &aBindAttribute,
|
|
|
|
PRUint16 aResultType,
|
|
|
|
PRBool *aContextChanged)
|
2005-02-01 02:41:00 +03:00
|
|
|
{
|
2006-05-22 13:06:14 +04:00
|
|
|
NS_ENSURE_ARG(aContextChanged);
|
|
|
|
|
2005-04-28 11:17:49 +04:00
|
|
|
// Clear existing bound node, etc.
|
2006-05-22 13:06:14 +04:00
|
|
|
*aContextChanged = mBoundNode ? PR_TRUE : PR_FALSE;
|
|
|
|
nsCOMPtr<nsIDOMNode> oldBoundNode;
|
|
|
|
oldBoundNode.swap(mBoundNode);
|
2006-02-23 14:25:07 +03:00
|
|
|
mUsesModelBinding = PR_FALSE;
|
2006-04-19 12:22:28 +04:00
|
|
|
mAppearDisabled = PR_FALSE;
|
2005-04-28 11:17:49 +04:00
|
|
|
mDependencies.Clear();
|
|
|
|
RemoveIndexListeners();
|
2005-02-01 02:41:00 +03:00
|
|
|
|
2007-03-28 00:09:39 +04:00
|
|
|
if (!mHasParent || !mHasDoc || !HasBindingAttribute())
|
2006-09-21 20:49:13 +04:00
|
|
|
return NS_OK_XFORMS_NOTREADY;
|
2005-04-08 19:40:54 +04:00
|
|
|
|
2005-02-01 02:41:00 +03:00
|
|
|
nsCOMPtr<nsIDOMXPathResult> result;
|
2006-04-19 12:22:28 +04:00
|
|
|
nsresult rv = ProcessNodeBinding(aBindAttribute, aResultType,
|
|
|
|
getter_AddRefs(result));
|
2005-05-05 11:09:40 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2005-05-04 12:31:56 +04:00
|
|
|
nsXFormsUtils::ReportError(NS_LITERAL_STRING("controlBindError"), mElement);
|
2005-05-05 11:09:40 +04:00
|
|
|
return rv;
|
2005-05-04 12:31:56 +04:00
|
|
|
}
|
2006-04-19 12:22:28 +04:00
|
|
|
|
2007-03-28 00:09:39 +04:00
|
|
|
if (rv == NS_OK_XFORMS_DEFERRED || rv == NS_OK_XFORMS_NOTREADY || !result) {
|
2006-04-19 12:22:28 +04:00
|
|
|
// Binding was deferred, or not bound
|
2006-05-22 13:06:14 +04:00
|
|
|
return rv;
|
2006-04-19 12:22:28 +04:00
|
|
|
}
|
|
|
|
|
2006-02-23 14:25:07 +03:00
|
|
|
// Get context node, if any
|
|
|
|
if (mUsesModelBinding) {
|
|
|
|
// When bound via @bind, we'll get a snapshot back
|
|
|
|
result->SnapshotItem(0, getter_AddRefs(mBoundNode));
|
|
|
|
} else {
|
|
|
|
result->GetSingleNodeValue(getter_AddRefs(mBoundNode));
|
|
|
|
}
|
2005-02-01 02:41:00 +03:00
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
*aContextChanged = (oldBoundNode != mBoundNode);
|
|
|
|
|
2007-01-20 01:22:07 +03:00
|
|
|
// Some controls may not be bound to certain types of content. If the content
|
|
|
|
// is a disallowed type, report the error and dispatch a binding exception
|
|
|
|
// event.
|
2007-01-26 00:25:04 +03:00
|
|
|
PRBool isAllowed = IsContentAllowed();
|
2007-01-20 01:22:07 +03:00
|
|
|
|
|
|
|
if (!mBoundNode || !isAllowed) {
|
2006-04-19 12:22:28 +04:00
|
|
|
// If there's no result (ie, no instance node) returned by the above, it
|
|
|
|
// means that the binding is not pointing to an instance data node, so we
|
|
|
|
// should disable the control.
|
|
|
|
mAppearDisabled = PR_TRUE;
|
2005-06-29 22:14:43 +04:00
|
|
|
|
2007-01-20 01:22:07 +03:00
|
|
|
if (!isAllowed) {
|
|
|
|
// build the error string that we want output to the ErrorConsole
|
|
|
|
nsAutoString localName;
|
|
|
|
mElement->GetLocalName(localName);
|
|
|
|
const PRUnichar *strings[] = { localName.get() };
|
|
|
|
|
|
|
|
nsXFormsUtils::ReportError(
|
|
|
|
NS_LITERAL_STRING("boundTypeErrorComplexContent"),
|
|
|
|
strings, 1, mElement, mElement);
|
|
|
|
|
|
|
|
nsXFormsUtils::DispatchEvent(mElement, eEvent_BindingException);
|
|
|
|
}
|
|
|
|
|
2006-04-19 12:22:28 +04:00
|
|
|
nsCOMPtr<nsIXTFElementWrapper> wrapper(do_QueryInterface(mElement));
|
|
|
|
NS_ENSURE_STATE(wrapper);
|
2005-10-19 11:39:36 +04:00
|
|
|
|
2006-05-24 07:45:45 +04:00
|
|
|
PRInt32 iState;
|
|
|
|
GetDisabledIntrinsicState(&iState);
|
|
|
|
return wrapper->SetIntrinsicState(iState);
|
2005-05-05 11:09:40 +04:00
|
|
|
}
|
|
|
|
|
2006-05-30 17:41:14 +04:00
|
|
|
// Check for presence of @xsi:type on bound node and add as a dependency
|
|
|
|
nsCOMPtr<nsIDOMElement> boundEl(do_QueryInterface(mBoundNode));
|
|
|
|
if (boundEl) {
|
|
|
|
nsCOMPtr<nsIDOMAttr> attrNode;
|
|
|
|
rv = boundEl->GetAttributeNodeNS(NS_LITERAL_STRING(NS_NAMESPACE_XML_SCHEMA_INSTANCE),
|
|
|
|
NS_LITERAL_STRING("type"),
|
|
|
|
getter_AddRefs(attrNode));
|
|
|
|
if (NS_SUCCEEDED(rv) && attrNode) {
|
|
|
|
mDependencies.AppendObject(attrNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-05 11:09:40 +04:00
|
|
|
return NS_OK;
|
2005-02-01 02:41:00 +03:00
|
|
|
}
|
|
|
|
|
2005-01-19 19:05:31 +03:00
|
|
|
NS_IMETHODIMP
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::Bind(PRBool* aContextChanged)
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
2005-05-05 11:09:40 +04:00
|
|
|
return ResetBoundNode(NS_LITERAL_STRING("ref"),
|
2006-05-22 13:06:14 +04:00
|
|
|
nsIDOMXPathResult::FIRST_ORDERED_NODE_TYPE,
|
|
|
|
aContextChanged);
|
2005-01-19 19:05:31 +03:00
|
|
|
}
|
|
|
|
|
2006-04-19 12:22:28 +04:00
|
|
|
NS_IMETHODIMP
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::Refresh()
|
2006-04-19 12:22:28 +04:00
|
|
|
{
|
|
|
|
// XXX: In theory refresh should never be called when there is no model,
|
|
|
|
// but that's definately not the case now.
|
|
|
|
return (mModel && !mAppearDisabled) ? mModel->SetStates(this, mBoundNode)
|
|
|
|
: NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-27 22:30:03 +03:00
|
|
|
NS_IMETHODIMP
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::TryFocus(PRBool* aOK)
|
2005-01-27 22:30:03 +03:00
|
|
|
{
|
|
|
|
*aOK = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-17 16:10:08 +04:00
|
|
|
NS_IMETHODIMP
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::IsEventTarget(PRBool *aOK)
|
2005-05-17 16:10:08 +04:00
|
|
|
{
|
|
|
|
*aOK = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-02-23 14:25:07 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::GetUsesModelBinding(PRBool *aRes)
|
2006-02-23 14:25:07 +03:00
|
|
|
{
|
|
|
|
*aRes = mUsesModelBinding;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-01-27 22:30:03 +03:00
|
|
|
|
2007-03-16 05:06:06 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsControlStub::GetUsesSingleNodeBinding(PRBool *aRes)
|
|
|
|
{
|
|
|
|
*aRes = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-15 18:14:52 +04:00
|
|
|
NS_IMETHODIMP
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::GetOnDeferredBindList(PRBool *aOnList)
|
2006-05-15 18:14:52 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aOnList);
|
|
|
|
*aOnList = mOnDeferredBindList;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::SetOnDeferredBindList(PRBool aPutOnList)
|
2006-05-15 18:14:52 +04:00
|
|
|
{
|
|
|
|
mOnDeferredBindList = aPutOnList;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-24 07:45:45 +04:00
|
|
|
NS_IMETHODIMP
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::GetDefaultIntrinsicState(PRInt32 *aState)
|
2006-05-24 07:45:45 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aState);
|
|
|
|
*aState = kDefaultIntrinsicState;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::GetDisabledIntrinsicState(PRInt32 *aState)
|
2006-05-24 07:45:45 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aState);
|
|
|
|
*aState = kDisabledIntrinsicState;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-03-29 14:49:28 +04:00
|
|
|
nsresult
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::MaybeAddToModel(nsIModelElementPrivate *aOldModel,
|
|
|
|
nsIXFormsControl *aParent)
|
2006-03-29 14:49:28 +04:00
|
|
|
{
|
2007-03-07 20:46:57 +03:00
|
|
|
if (GetRepeatState() == eType_Template) {
|
|
|
|
// No sense going any further. A template control has no need to bind,
|
|
|
|
// refresh, etc. so no reason to put it on the model's control list
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-03-29 14:49:28 +04:00
|
|
|
// XXX: just doing pointer comparison would be nice....
|
|
|
|
PRBool sameModel = PR_FALSE;
|
2006-04-19 18:52:36 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (mModel) {
|
|
|
|
nsCOMPtr<nsIDOM3Node> n3Model(do_QueryInterface(mModel));
|
|
|
|
nsCOMPtr<nsIDOMNode> nOldModel(do_QueryInterface(aOldModel));
|
|
|
|
NS_ASSERTION(n3Model, "model element not supporting nsIDOM3Node?!");
|
|
|
|
rv = n3Model->IsSameNode(nOldModel, &sameModel);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
sameModel = !aOldModel;
|
|
|
|
}
|
|
|
|
|
2006-03-29 14:49:28 +04:00
|
|
|
if (!sameModel) {
|
|
|
|
if (aOldModel) {
|
|
|
|
rv = aOldModel->RemoveFormControl(this);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2006-04-19 18:52:36 +04:00
|
|
|
if (mModel) {
|
|
|
|
rv = mModel->AddFormControl(this, aParent);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2006-03-29 14:49:28 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-19 19:05:31 +03:00
|
|
|
nsresult
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::ProcessNodeBinding(const nsString &aBindingAttr,
|
|
|
|
PRUint16 aResultType,
|
|
|
|
nsIDOMXPathResult **aResult,
|
|
|
|
nsIModelElementPrivate **aModel)
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
2005-04-28 11:17:49 +04:00
|
|
|
nsStringArray indexesUsed;
|
2005-01-19 19:05:31 +03:00
|
|
|
|
2006-04-19 12:22:28 +04:00
|
|
|
if (aResult) {
|
|
|
|
*aResult = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aModel) {
|
|
|
|
*aModel = nsnull;
|
|
|
|
}
|
|
|
|
|
2005-05-17 15:30:43 +04:00
|
|
|
// let's not go through all of this rigamarol if we don't have a chance
|
|
|
|
// in heck of binding anyhow. Check to see if the models will be receptive
|
|
|
|
// to some binding. readyForBindProperty is set when they are. Make sure
|
|
|
|
// to return NS_OK so that we don't start complaining about binding
|
|
|
|
// failures in this situation.
|
|
|
|
|
2006-06-06 17:52:03 +04:00
|
|
|
if (!nsXFormsUtils::IsDocumentReadyForBind(mElement)) {
|
|
|
|
nsXFormsModelElement::DeferElementBind(this);
|
2006-04-19 12:22:28 +04:00
|
|
|
return NS_OK_XFORMS_DEFERRED;
|
2005-05-17 15:30:43 +04:00
|
|
|
}
|
|
|
|
|
2005-02-24 17:35:27 +03:00
|
|
|
nsresult rv;
|
2006-02-23 14:25:07 +03:00
|
|
|
PRBool usesModelBinding;
|
2006-03-29 14:49:28 +04:00
|
|
|
nsCOMPtr<nsIModelElementPrivate> oldModel(mModel);
|
|
|
|
nsCOMPtr<nsIXFormsControl> parentControl;
|
2005-01-19 19:05:31 +03:00
|
|
|
rv = nsXFormsUtils::EvaluateNodeBinding(mElement,
|
|
|
|
kElementFlags,
|
|
|
|
aBindingAttr,
|
|
|
|
EmptyString(),
|
|
|
|
aResultType,
|
2005-01-29 23:36:09 +03:00
|
|
|
getter_AddRefs(mModel),
|
2005-01-19 19:05:31 +03:00
|
|
|
aResult,
|
2006-02-23 14:25:07 +03:00
|
|
|
&usesModelBinding,
|
2006-03-29 14:49:28 +04:00
|
|
|
getter_AddRefs(parentControl),
|
2005-04-28 11:17:49 +04:00
|
|
|
&mDependencies,
|
|
|
|
&indexesUsed);
|
2006-04-19 12:22:28 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-28 00:09:39 +04:00
|
|
|
|
|
|
|
// if NS_OK_XFORMS_NOTREADY, mModel probably won't exist or might no longer
|
|
|
|
// be valid, so shouldn't continue.
|
|
|
|
if (rv == NS_OK_XFORMS_NOTREADY) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2005-04-28 11:17:49 +04:00
|
|
|
NS_ENSURE_STATE(mModel);
|
2006-03-29 14:49:28 +04:00
|
|
|
|
|
|
|
rv = MaybeAddToModel(oldModel, parentControl);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-04-28 11:17:49 +04:00
|
|
|
if (aModel)
|
|
|
|
NS_ADDREF(*aModel = mModel);
|
|
|
|
|
2006-12-11 13:54:09 +03:00
|
|
|
mUsesModelBinding = usesModelBinding;
|
2006-06-06 17:52:03 +04:00
|
|
|
|
2006-12-11 13:54:09 +03:00
|
|
|
if (indexesUsed.Count()) {
|
2005-04-28 11:17:49 +04:00
|
|
|
// add index listeners on repeat elements
|
2006-02-23 14:25:07 +03:00
|
|
|
|
2005-04-28 11:17:49 +04:00
|
|
|
for (PRInt32 i = 0; i < indexesUsed.Count(); ++i) {
|
|
|
|
// Find the repeat element and add |this| as a listener
|
|
|
|
nsCOMPtr<nsIDOMElement> repElem;
|
2006-12-11 13:54:09 +03:00
|
|
|
nsXFormsUtils::GetElementByContextId(mElement, *(indexesUsed[i]),
|
|
|
|
getter_AddRefs(repElem));
|
2005-04-28 11:17:49 +04:00
|
|
|
nsCOMPtr<nsIXFormsRepeatElement> rep(do_QueryInterface(repElem));
|
2005-04-28 11:23:38 +04:00
|
|
|
if (!rep)
|
|
|
|
continue;
|
|
|
|
|
2005-04-28 11:17:49 +04:00
|
|
|
rv = rep->AddIndexUser(this);
|
2006-12-11 13:54:09 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-04-28 11:17:49 +04:00
|
|
|
rv = mIndexesUsed.AppendObject(rep);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-01-19 19:05:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-11 13:54:09 +03:00
|
|
|
return NS_OK;
|
2005-01-19 19:05:31 +03:00
|
|
|
}
|
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
NS_IMETHODIMP
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::BindToModel(PRBool aSetBoundNode)
|
2006-03-29 14:49:28 +04:00
|
|
|
{
|
2007-03-07 20:46:57 +03:00
|
|
|
if (GetRepeatState() == eType_Template) {
|
|
|
|
// No sense going any further. A template control has no need to bind,
|
|
|
|
// refresh, etc. so no reason to put it on the model's control list
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-03-29 14:49:28 +04:00
|
|
|
nsCOMPtr<nsIModelElementPrivate> oldModel(mModel);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIXFormsControl> parentControl;
|
2006-04-06 12:08:55 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> boundNode;
|
|
|
|
mModel = nsXFormsUtils::GetModel(mElement, getter_AddRefs(parentControl),
|
|
|
|
kElementFlags,
|
|
|
|
getter_AddRefs(boundNode));
|
|
|
|
if (aSetBoundNode) {
|
|
|
|
mBoundNode.swap(boundNode);
|
|
|
|
}
|
2006-03-29 14:49:28 +04:00
|
|
|
|
|
|
|
return MaybeAddToModel(oldModel, parentControl);
|
|
|
|
}
|
|
|
|
|
2005-01-30 02:53:32 +03:00
|
|
|
void
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::ResetHelpAndHint(PRBool aInitialize)
|
2005-01-30 02:53:32 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> targ(do_QueryInterface(mElement));
|
|
|
|
if (!targ)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_STRING(mouseover, "mouseover");
|
2005-06-08 19:33:18 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(mouseout, "mouseout");
|
2005-01-30 02:53:32 +03:00
|
|
|
NS_NAMED_LITERAL_STRING(focus, "focus");
|
2005-06-08 19:33:18 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(blur, "blur");
|
2005-01-30 02:53:32 +03:00
|
|
|
NS_NAMED_LITERAL_STRING(keypress, "keypress");
|
|
|
|
|
|
|
|
if (mEventListener) {
|
|
|
|
targ->RemoveEventListener(mouseover, mEventListener, PR_TRUE);
|
2005-06-08 19:33:18 +04:00
|
|
|
targ->RemoveEventListener(mouseout, mEventListener, PR_TRUE);
|
2005-01-30 02:53:32 +03:00
|
|
|
targ->RemoveEventListener(focus, mEventListener, PR_TRUE);
|
2005-06-08 19:33:18 +04:00
|
|
|
targ->RemoveEventListener(blur, mEventListener, PR_TRUE);
|
2005-01-30 02:53:32 +03:00
|
|
|
targ->RemoveEventListener(keypress, mEventListener, PR_TRUE);
|
|
|
|
mEventListener = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aInitialize) {
|
|
|
|
mEventListener = new nsXFormsHintHelpListener();
|
|
|
|
if (!mEventListener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
targ->AddEventListener(mouseover, mEventListener, PR_TRUE);
|
2005-06-08 19:33:18 +04:00
|
|
|
targ->AddEventListener(mouseout, mEventListener, PR_TRUE);
|
2005-01-30 02:53:32 +03:00
|
|
|
targ->AddEventListener(focus, mEventListener, PR_TRUE);
|
2005-06-08 19:33:18 +04:00
|
|
|
targ->AddEventListener(blur, mEventListener, PR_TRUE);
|
2005-01-30 02:53:32 +03:00
|
|
|
targ->AddEventListener(keypress, mEventListener, PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-27 22:30:03 +03:00
|
|
|
PRBool
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::GetRelevantState()
|
2005-01-27 22:30:03 +03:00
|
|
|
{
|
2005-01-29 23:36:09 +03:00
|
|
|
PRBool res = PR_FALSE;
|
2005-10-22 19:20:46 +04:00
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mElement));
|
|
|
|
if (content && (content->IntrinsicState() & NS_EVENT_STATE_ENABLED)) {
|
|
|
|
res = PR_TRUE;
|
2005-01-29 23:36:09 +03:00
|
|
|
}
|
2005-01-27 22:30:03 +03:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-10-08 18:15:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsControlStub::HandleDefault(nsIDOMEvent *aEvent,
|
|
|
|
PRBool *aHandled)
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aHandled);
|
2005-05-05 11:09:40 +04:00
|
|
|
*aHandled = PR_FALSE;
|
2005-01-19 19:05:31 +03:00
|
|
|
|
2005-05-03 23:39:38 +04:00
|
|
|
if (nsXFormsUtils::EventHandlingAllowed(aEvent, mElement)) {
|
|
|
|
|
2005-02-01 19:02:54 +03:00
|
|
|
// Check that we are the target of the event
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> target;
|
|
|
|
aEvent->GetTarget(getter_AddRefs(target));
|
|
|
|
nsCOMPtr<nsIDOMElement> targetE(do_QueryInterface(target));
|
|
|
|
if (targetE && targetE != mElement) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle event
|
2005-01-19 19:05:31 +03:00
|
|
|
nsAutoString type;
|
|
|
|
aEvent->GetType(type);
|
|
|
|
|
2005-05-05 11:09:40 +04:00
|
|
|
if (type.EqualsASCII(sXFormsEventsEntries[eEvent_Focus].name)) {
|
|
|
|
TryFocus(aHandled);
|
2005-06-13 23:17:24 +04:00
|
|
|
} else if (type.Equals(NS_LITERAL_STRING("keypress"))) {
|
|
|
|
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aEvent);
|
|
|
|
if (keyEvent) {
|
|
|
|
PRUint32 keycode;
|
|
|
|
keyEvent->GetKeyCode(&keycode);
|
|
|
|
if (keycode == nsIDOMKeyEvent::DOM_VK_TAB) {
|
|
|
|
PRBool extraKey = PR_FALSE;
|
|
|
|
|
|
|
|
keyEvent->GetAltKey(&extraKey);
|
|
|
|
if (extraKey) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
keyEvent->GetCtrlKey(&extraKey);
|
|
|
|
if (extraKey) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
keyEvent->GetMetaKey(&extraKey);
|
|
|
|
if (extraKey) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
keyEvent->GetShiftKey(&extraKey);
|
|
|
|
mPreventLoop = PR_TRUE;
|
|
|
|
if (extraKey) {
|
|
|
|
nsXFormsUtils::DispatchEvent(mElement, eEvent_Previous);
|
|
|
|
} else {
|
|
|
|
nsXFormsUtils::DispatchEvent(mElement, eEvent_Next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (type.EqualsASCII(sXFormsEventsEntries[eEvent_Next].name) ||
|
|
|
|
type.EqualsASCII(sXFormsEventsEntries[eEvent_Previous].name)) {
|
|
|
|
|
|
|
|
// only continue this processing if xforms-next or xforms-previous were
|
|
|
|
// dispatched by the form and not as part of the 'tab' and 'shift+tab'
|
|
|
|
// processing
|
|
|
|
if (mPreventLoop) {
|
|
|
|
mPreventLoop = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
mElement->GetOwnerDocument(getter_AddRefs(domDoc));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
|
|
|
// element isn't in a document, yet? Odd, indeed. Well, if not in
|
|
|
|
// document, these two events have no meaning.
|
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
// An inelegant way to retrieve this to be sure, but we are
|
|
|
|
// guaranteed that the focus controller outlives us, so it
|
|
|
|
// is safe to hold on to it (since we can't die until it has
|
|
|
|
// died).
|
2005-11-29 02:56:44 +03:00
|
|
|
nsIFocusController *focusController =
|
|
|
|
doc->GetWindow()->GetRootFocusController();
|
2005-06-13 23:17:24 +04:00
|
|
|
if (focusController &&
|
|
|
|
type.EqualsASCII(sXFormsEventsEntries[eEvent_Next].name)) {
|
|
|
|
focusController->MoveFocus(PR_TRUE, nsnull);
|
|
|
|
} else {
|
|
|
|
focusController->MoveFocus(PR_FALSE, nsnull);
|
|
|
|
}
|
2005-08-24 13:43:27 +04:00
|
|
|
} else if (type.EqualsASCII(sXFormsEventsEntries[eEvent_BindingException].name)) {
|
2006-05-17 23:30:36 +04:00
|
|
|
// we threw up a popup during the nsXFormsUtils::DispatchEvent that sent
|
|
|
|
// this error to this control
|
|
|
|
*aHandled = PR_TRUE;
|
2005-01-19 19:05:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-07 11:14:31 +04:00
|
|
|
#ifdef DEBUG_smaug
|
|
|
|
static nsVoidArray* sControlList = nsnull;
|
|
|
|
class ControlDebug
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ControlDebug() {
|
|
|
|
sControlList = new nsVoidArray();
|
|
|
|
NS_ASSERTION(sControlList, "Out of memory!");
|
|
|
|
}
|
|
|
|
|
|
|
|
~ControlDebug() {
|
|
|
|
for (PRInt32 i = 0; i < sControlList->Count(); ++i) {
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub* control =
|
|
|
|
NS_STATIC_CAST(nsXFormsControlStub*, sControlList->ElementAt(i));
|
2005-06-07 11:14:31 +04:00
|
|
|
if (control) {
|
|
|
|
printf("Possible leak, <xforms:%s>\n", control->Name());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete sControlList;
|
|
|
|
sControlList = nsnull;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static ControlDebug tester = ControlDebug();
|
|
|
|
#endif
|
|
|
|
|
2006-10-08 18:15:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsControlStub::OnCreated(nsIXTFElementWrapper *aWrapper)
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsStubElement::OnCreated(aWrapper);
|
2005-01-19 19:05:31 +03:00
|
|
|
aWrapper->SetNotificationMask(kStandardNotificationMask);
|
|
|
|
|
2005-06-07 11:14:31 +04:00
|
|
|
// It's ok to keep a weak pointer to mElement. mElement will have an
|
|
|
|
// owning reference to this object, so as long as we null out mElement in
|
|
|
|
// OnDestroyed, it will always be valid.
|
|
|
|
nsCOMPtr<nsIDOMElement> node;
|
|
|
|
aWrapper->GetElementNode(getter_AddRefs(node));
|
|
|
|
mElement = node;
|
2005-01-19 19:05:31 +03:00
|
|
|
NS_ASSERTION(mElement, "Wrapper is not an nsIDOMElement, we'll crash soon");
|
|
|
|
|
2005-06-07 11:14:31 +04:00
|
|
|
#ifdef DEBUG_smaug
|
|
|
|
sControlList->AppendElement(this);
|
|
|
|
#endif
|
|
|
|
|
2005-01-19 19:05:31 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-10-08 18:15:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsControlStub::OnDestroyed()
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
2005-04-28 11:17:49 +04:00
|
|
|
RemoveIndexListeners();
|
2006-02-23 14:25:07 +03:00
|
|
|
mDependencies.Clear();
|
2005-01-30 02:53:32 +03:00
|
|
|
|
2005-01-29 23:36:09 +03:00
|
|
|
if (mModel) {
|
|
|
|
mModel->RemoveFormControl(this);
|
|
|
|
mModel = nsnull;
|
|
|
|
}
|
2005-01-19 19:05:31 +03:00
|
|
|
|
2007-03-28 00:09:39 +04:00
|
|
|
mAbortedBindListContainer = nsnull;
|
|
|
|
|
2005-06-07 11:14:31 +04:00
|
|
|
#ifdef DEBUG_smaug
|
|
|
|
sControlList->RemoveElement(this);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mElement = nsnull;
|
2005-01-19 19:05:31 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-03-29 14:49:28 +04:00
|
|
|
nsresult
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::ForceModelDetach(PRBool aRebind)
|
2006-03-29 14:49:28 +04:00
|
|
|
{
|
2007-03-28 00:09:39 +04:00
|
|
|
// We shouldn't bother binding if the control is part of a template, but we
|
|
|
|
// need to run through RemoveFormControl in the event that this control
|
|
|
|
// was just moved under a repeat or itemset and wasn't there originally.
|
2006-03-29 14:49:28 +04:00
|
|
|
if (mModel) {
|
|
|
|
// Remove from model, so Bind() will be forced to reattach
|
|
|
|
mModel->RemoveFormControl(this);
|
|
|
|
mModel = nsnull;
|
|
|
|
}
|
2006-04-19 18:52:36 +04:00
|
|
|
|
2007-03-28 00:09:39 +04:00
|
|
|
if (!aRebind || GetRepeatState() == eType_Template) {
|
2006-04-19 18:52:36 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-22 13:06:14 +04:00
|
|
|
PRBool dummy;
|
|
|
|
nsresult rv = Bind(&dummy);
|
2006-03-29 14:49:28 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-28 00:09:39 +04:00
|
|
|
|
|
|
|
if (rv == NS_OK_XFORMS_DEFERRED || rv == NS_OK_XFORMS_NOTREADY) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there were any controls that had already tried to bind but failed
|
|
|
|
// to because this control wasn't ready yet, then try them again.
|
|
|
|
PRInt32 arraySize = mAbortedBindList.Count();
|
|
|
|
if (arraySize) {
|
|
|
|
for (PRInt32 i = 0; i < arraySize; ++i) {
|
|
|
|
nsCOMPtr<nsIXFormsControl> control = mAbortedBindList.ObjectAt(i);
|
|
|
|
if (control) {
|
|
|
|
control->RebindAndRefresh();
|
|
|
|
control->SetAbortedBindListContainer(nsnull);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mAbortedBindList.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Refresh();
|
2006-03-29 14:49:28 +04:00
|
|
|
}
|
|
|
|
|
2006-10-08 18:15:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsControlStub::WillChangeDocument(nsIDOMDocument *aNewDocument)
|
2006-05-24 23:51:22 +04:00
|
|
|
{
|
2007-03-28 00:09:39 +04:00
|
|
|
// This control is moving to another document or just plain getting removed
|
|
|
|
// from its current document. In either case, we know that we don't care
|
|
|
|
// about the bind-ready notification we might have been waiting on.
|
|
|
|
nsCOMPtr<nsIXFormsContextControl> ctxtControl;
|
|
|
|
GetAbortedBindListContainer(getter_AddRefs(ctxtControl));
|
|
|
|
if (ctxtControl) {
|
|
|
|
ctxtControl->AddRemoveAbortedControl(this, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are in the middle of getting set up in the current document then
|
|
|
|
// then we need to make sure that if other controls getting set up in
|
|
|
|
// the current document are depending on this control to help them, that
|
|
|
|
// we remove that dependency.
|
|
|
|
PRInt32 arraySize = mAbortedBindList.Count();
|
|
|
|
if (arraySize) {
|
|
|
|
for (PRInt32 i = 0; i < arraySize; ++i) {
|
|
|
|
nsCOMPtr<nsIXFormsControl> control = mAbortedBindList.ObjectAt(i);
|
|
|
|
control->SetAbortedBindListContainer(nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
mAbortedBindList.Clear();
|
|
|
|
}
|
|
|
|
|
2007-03-07 20:46:57 +03:00
|
|
|
SetRepeatState(eType_Unknown);
|
2006-05-24 23:51:22 +04:00
|
|
|
ResetHelpAndHint(PR_FALSE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-03-29 14:49:28 +04:00
|
|
|
|
2006-10-08 18:15:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsControlStub::DocumentChanged(nsIDOMDocument *aNewDocument)
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
2007-03-28 00:09:39 +04:00
|
|
|
mHasDoc = aNewDocument != nsnull;
|
|
|
|
|
2006-05-24 23:51:22 +04:00
|
|
|
if (aNewDocument) {
|
|
|
|
ResetHelpAndHint(PR_TRUE);
|
|
|
|
|
|
|
|
// If we are inserted into a document and we have no model, we are probably
|
|
|
|
// being initialized, so we should set our intrinsic state to the default
|
|
|
|
// value
|
|
|
|
if (!mModel && mElement) {
|
|
|
|
nsCOMPtr<nsIXTFElementWrapper> xtfWrap(do_QueryInterface(mElement));
|
|
|
|
NS_ENSURE_STATE(xtfWrap);
|
|
|
|
PRInt32 iState;
|
|
|
|
GetDefaultIntrinsicState(&iState);
|
|
|
|
xtfWrap->SetIntrinsicState(iState);
|
|
|
|
}
|
2006-04-05 01:09:57 +04:00
|
|
|
}
|
|
|
|
|
2007-03-28 00:09:39 +04:00
|
|
|
return ForceModelDetach(mHasParent && mHasDoc);
|
2005-01-19 19:05:31 +03:00
|
|
|
}
|
|
|
|
|
2007-03-07 20:46:57 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsControlStub::WillChangeParent(nsIDOMElement *aNewParent)
|
|
|
|
{
|
2007-03-28 00:09:39 +04:00
|
|
|
nsCOMPtr<nsIXFormsContextControl> ctxtControl;
|
|
|
|
GetAbortedBindListContainer(getter_AddRefs(ctxtControl));
|
|
|
|
if (ctxtControl) {
|
|
|
|
ctxtControl->AddRemoveAbortedControl(this, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
2007-03-07 20:46:57 +03:00
|
|
|
SetRepeatState(eType_Unknown);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-08 18:15:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsControlStub::ParentChanged(nsIDOMElement *aNewParent)
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
2005-04-08 19:40:54 +04:00
|
|
|
mHasParent = aNewParent != nsnull;
|
2007-03-07 20:46:57 +03:00
|
|
|
|
|
|
|
UpdateRepeatState(aNewParent);
|
|
|
|
|
2005-01-19 19:05:31 +03:00
|
|
|
// We need to re-evaluate our instance data binding when our parent changes,
|
|
|
|
// since xmlns declarations or our context could have changed.
|
2007-03-28 00:09:39 +04:00
|
|
|
return ForceModelDetach(mHasParent && mHasDoc);
|
2005-01-19 19:05:31 +03:00
|
|
|
}
|
|
|
|
|
2006-10-08 18:15:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsControlStub::WillSetAttribute(nsIAtom *aName, const nsAString &aValue)
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
2006-03-29 14:49:28 +04:00
|
|
|
BeforeSetAttribute(aName, aValue);
|
2005-01-19 19:05:31 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-10-08 18:15:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsControlStub::AttributeSet(nsIAtom *aName, const nsAString &aValue)
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
2006-03-29 14:49:28 +04:00
|
|
|
AfterSetAttribute(aName);
|
2005-04-11 20:33:31 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-01-19 19:05:31 +03:00
|
|
|
|
2006-10-08 18:15:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsControlStub::WillRemoveAttribute(nsIAtom *aName)
|
2005-04-11 20:33:31 +04:00
|
|
|
{
|
2006-03-29 14:49:28 +04:00
|
|
|
BeforeSetAttribute(aName, EmptyString());
|
2005-04-11 20:33:31 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-10-08 18:15:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsControlStub::AttributeRemoved(nsIAtom *aName)
|
2005-04-11 20:33:31 +04:00
|
|
|
{
|
2006-03-29 14:49:28 +04:00
|
|
|
AfterSetAttribute(aName);
|
2005-01-19 19:05:31 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-02-09 12:57:31 +03:00
|
|
|
|
2007-03-28 00:09:39 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsControlStub::RebindAndRefresh()
|
|
|
|
{
|
|
|
|
ForceModelDetach(PR_TRUE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-02-09 12:57:31 +03:00
|
|
|
// nsIXFormsContextControl
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::SetContext(nsIDOMNode *aContextNode,
|
|
|
|
PRInt32 aContextPosition,
|
|
|
|
PRInt32 aContextSize)
|
2005-02-09 12:57:31 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::GetContext(nsAString &aModelID,
|
|
|
|
nsIDOMNode **aContextNode,
|
|
|
|
PRInt32 *aContextPosition,
|
|
|
|
PRInt32 *aContextSize)
|
2005-02-09 12:57:31 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aContextSize);
|
|
|
|
NS_ENSURE_ARG(aContextPosition);
|
2007-03-28 00:09:39 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aContextNode);
|
2005-02-09 12:57:31 +03:00
|
|
|
|
|
|
|
*aContextPosition = 1;
|
|
|
|
*aContextSize = 1;
|
2007-03-28 00:09:39 +04:00
|
|
|
*aContextNode = nsnull;
|
2005-02-09 12:57:31 +03:00
|
|
|
|
2005-08-02 13:23:21 +04:00
|
|
|
if (aContextNode) {
|
|
|
|
if (mBoundNode) {
|
|
|
|
// We are bound to a node: This is the context node
|
2006-04-06 12:08:55 +04:00
|
|
|
NS_ADDREF(*aContextNode = mBoundNode);
|
2005-08-02 13:23:21 +04:00
|
|
|
} else if (mModel) {
|
2007-03-28 00:09:39 +04:00
|
|
|
// If there is no bound node, it could be because everything isn't ready,
|
|
|
|
// yet. If mHasDoc or mHasParent are false, then we haven't had a chance
|
|
|
|
// to bind. This could happen if the nodes in this chain are being added
|
|
|
|
// via DOM manipulation rather than via the parser.
|
|
|
|
if (HasBindingAttribute() && (!mHasDoc || !mHasParent)) {
|
|
|
|
return NS_OK_XFORMS_NOTREADY;
|
|
|
|
}
|
|
|
|
|
2005-08-02 13:23:21 +04:00
|
|
|
// We are bound to a model: The document element of its default instance
|
|
|
|
// document is the context node
|
|
|
|
nsCOMPtr<nsIDOMDocument> instanceDoc;
|
|
|
|
mModel->GetInstanceDocument(EmptyString(), getter_AddRefs(instanceDoc));
|
|
|
|
NS_ENSURE_STATE(instanceDoc);
|
|
|
|
|
|
|
|
nsIDOMElement* docElement;
|
|
|
|
instanceDoc->GetDocumentElement(&docElement); // addrefs
|
|
|
|
NS_ENSURE_STATE(docElement);
|
|
|
|
*aContextNode = docElement; // addref'ed above
|
2007-03-28 00:09:39 +04:00
|
|
|
} else {
|
|
|
|
if (HasBindingAttribute() && (!mHasDoc || !mHasParent)) {
|
|
|
|
return NS_OK_XFORMS_NOTREADY;
|
|
|
|
}
|
2005-08-02 13:23:21 +04:00
|
|
|
}
|
2005-02-09 12:57:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @todo expensive to run this
|
|
|
|
nsCOMPtr<nsIDOMElement> model = do_QueryInterface(mModel);
|
|
|
|
if (model) {
|
|
|
|
model->GetAttribute(NS_LITERAL_STRING("id"), aModelID);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-28 00:09:39 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsControlStub::AddRemoveAbortedControl(nsIXFormsControl *aControl,
|
|
|
|
PRBool aAdd)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (aAdd) {
|
|
|
|
rv = mAbortedBindList.AppendObject(aControl);
|
|
|
|
aControl->SetAbortedBindListContainer(this);
|
|
|
|
} else {
|
|
|
|
rv = mAbortedBindList.RemoveObject(aControl);
|
|
|
|
aControl->SetAbortedBindListContainer(nsnull);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsControlStub::GetAbortedBindListContainer(
|
|
|
|
nsIXFormsContextControl **aControlContainingList)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aControlContainingList);
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aControlContainingList = mAbortedBindListContainer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXFormsControlStub::SetAbortedBindListContainer(
|
|
|
|
nsIXFormsContextControl *aControlContainingList)
|
|
|
|
{
|
|
|
|
// A control should never be on more than one aborted bind list. There is
|
|
|
|
// probably a chance through some crazy DOM stirring for a control to be
|
|
|
|
// waiting on notification from a context control and then the control finds
|
|
|
|
// itself trying to bind again under a whole different parent tree. So we'll
|
|
|
|
// have the control remove itself from the old list and link itself to the
|
|
|
|
// new list.
|
|
|
|
|
|
|
|
if (mAbortedBindListContainer && aControlContainingList) {
|
|
|
|
if (!SameCOMIdentity(mAbortedBindListContainer, aControlContainingList)) {
|
|
|
|
mAbortedBindListContainer->AddRemoveAbortedControl(this, PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mAbortedBindListContainer = aControlContainingList;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-11 20:33:31 +04:00
|
|
|
void
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::AddRemoveSNBAttr(nsIAtom *aName, const nsAString &aValue)
|
2005-04-11 20:33:31 +04:00
|
|
|
{
|
|
|
|
nsAutoString attrStr, attrValue;
|
|
|
|
aName->ToString(attrStr);
|
|
|
|
mElement->GetAttribute(attrStr, attrValue);
|
|
|
|
|
|
|
|
// if we are setting a single node binding attribute that we don't already
|
|
|
|
// have, bump the count.
|
|
|
|
if (!aValue.IsEmpty() && attrValue.IsEmpty()) {
|
|
|
|
++mBindAttrsCount;
|
|
|
|
} else if (!attrValue.IsEmpty()) {
|
|
|
|
// if we are setting a currently existing binding attribute to have an
|
|
|
|
// empty value, treat it like the binding attr is being removed.
|
|
|
|
--mBindAttrsCount;
|
|
|
|
NS_ASSERTION(mBindAttrsCount>=0, "bad mojo! mBindAttrsCount < 0!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-29 14:49:28 +04:00
|
|
|
PRBool
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::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::ref ||
|
|
|
|
aAttr == nsXFormsAtoms::model) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2005-04-11 20:33:31 +04:00
|
|
|
|
2006-03-29 14:49:28 +04:00
|
|
|
void
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::AfterSetAttribute(nsIAtom *aName)
|
2006-03-29 14:49:28 +04:00
|
|
|
{
|
|
|
|
if (IsBindingAttribute(aName)) {
|
2006-05-22 13:06:14 +04:00
|
|
|
PRBool dummy;
|
|
|
|
nsresult rv = Bind(&dummy);
|
2006-09-21 20:49:13 +04:00
|
|
|
if (NS_SUCCEEDED(rv) &&
|
|
|
|
rv != NS_OK_XFORMS_DEFERRED && rv != NS_OK_XFORMS_NOTREADY)
|
2006-04-19 12:22:28 +04:00
|
|
|
Refresh();
|
2005-04-11 20:33:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::BeforeSetAttribute(nsIAtom *aName,
|
|
|
|
const nsAString &aValue)
|
2005-04-11 20:33:31 +04:00
|
|
|
{
|
2006-03-29 14:49:28 +04:00
|
|
|
if (IsBindingAttribute(aName)) {
|
2005-08-02 13:23:21 +04:00
|
|
|
AddRemoveSNBAttr(aName, aValue);
|
2005-04-11 20:33:31 +04:00
|
|
|
}
|
|
|
|
}
|
2005-06-01 23:19:33 +04:00
|
|
|
|
2006-09-21 20:49:13 +04:00
|
|
|
nsresult
|
2006-10-08 18:15:02 +04:00
|
|
|
nsXFormsControlStub::GetBoundBuiltinType(PRUint16 *aBuiltinType)
|
2006-09-21 20:49:13 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aBuiltinType);
|
|
|
|
*aBuiltinType = 0;
|
|
|
|
|
|
|
|
NS_ENSURE_STATE(mModel);
|
|
|
|
|
|
|
|
// get type of bound instance data
|
|
|
|
nsCOMPtr<nsISchemaType> schemaType;
|
|
|
|
nsresult rv = mModel->GetTypeForControl(this, getter_AddRefs(schemaType));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return mModel->GetRootBuiltinType(schemaType, aBuiltinType);
|
|
|
|
}
|
|
|
|
|
2007-01-26 00:25:04 +03:00
|
|
|
PRBool
|
|
|
|
nsXFormsControlStub::IsContentAllowed()
|
2007-01-20 01:22:07 +03:00
|
|
|
{
|
2007-01-26 00:25:04 +03:00
|
|
|
return PR_TRUE;
|
2007-01-20 01:22:07 +03:00
|
|
|
}
|
|
|
|
|
2007-01-26 00:25:04 +03:00
|
|
|
PRBool
|
|
|
|
nsXFormsControlStub::IsContentComplex()
|
2007-01-20 01:22:07 +03:00
|
|
|
{
|
2007-01-26 00:25:04 +03:00
|
|
|
PRBool isComplex = PR_FALSE;
|
2007-01-20 01:22:07 +03:00
|
|
|
|
|
|
|
if (mBoundNode) {
|
|
|
|
// If the bound node has any Element children, then it has complexContent.
|
|
|
|
nsCOMPtr<nsIDOMNode> currentNode;
|
|
|
|
mBoundNode->GetFirstChild(getter_AddRefs(currentNode));
|
|
|
|
while (currentNode) {
|
|
|
|
PRUint16 nodeType;
|
|
|
|
currentNode->GetNodeType(&nodeType);
|
|
|
|
if (nodeType == nsIDOMNode::ELEMENT_NODE) {
|
2007-01-26 00:25:04 +03:00
|
|
|
isComplex = PR_TRUE;
|
2007-01-20 01:22:07 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
currentNode->GetNextSibling(getter_AddRefs(node));
|
|
|
|
currentNode.swap(node);
|
|
|
|
}
|
|
|
|
}
|
2007-01-26 00:25:04 +03:00
|
|
|
return isComplex;
|
2007-01-20 01:22:07 +03:00
|
|
|
}
|
2006-09-21 20:49:13 +04:00
|
|
|
|
2007-03-07 20:46:57 +03:00
|
|
|
nsRepeatState
|
|
|
|
nsXFormsControlStub::GetRepeatState()
|
|
|
|
{
|
|
|
|
return mRepeatState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXFormsControlStub::SetRepeatState(nsRepeatState aState)
|
|
|
|
{
|
|
|
|
mRepeatState = aState;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRepeatState
|
|
|
|
nsXFormsControlStub::UpdateRepeatState(nsIDOMNode *aParent)
|
|
|
|
{
|
|
|
|
nsRepeatState repeatState = eType_NotApplicable;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> parent = aParent;
|
|
|
|
while (parent) {
|
|
|
|
if (nsXFormsUtils::IsXFormsElement(parent, NS_LITERAL_STRING("contextcontainer"))) {
|
|
|
|
repeatState = eType_GeneratedContent;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (nsXFormsUtils::IsXFormsElement(parent, NS_LITERAL_STRING("repeat"))) {
|
|
|
|
repeatState = eType_Template;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (nsXFormsUtils::IsXFormsElement(parent, NS_LITERAL_STRING("itemset"))) {
|
|
|
|
repeatState = eType_Template;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMNode> tmp;
|
|
|
|
parent->GetParentNode(getter_AddRefs(tmp));
|
|
|
|
parent = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetRepeatState(repeatState);
|
|
|
|
return repeatState;
|
|
|
|
}
|
|
|
|
|
2006-10-08 18:15:02 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED3(nsXFormsControlStub,
|
|
|
|
nsXFormsStubElement,
|
2005-06-01 23:19:33 +04:00
|
|
|
nsIXFormsContextControl,
|
2005-08-10 11:58:29 +04:00
|
|
|
nsIXFormsControl,
|
|
|
|
nsIXFormsControlBase)
|
2005-06-01 23:19:33 +04:00
|
|
|
|