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-01 23:19:33 +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 ***** */
|
|
|
|
|
|
|
|
#ifndef nsXFormsControlStub_h_
|
|
|
|
#define nsXFormsControlStub_h_
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIXTFElement.h"
|
2005-06-01 23:19:33 +04:00
|
|
|
#include "nsXFormsAtoms.h"
|
2005-01-30 02:53:32 +03:00
|
|
|
#include "nsIDOMEventListener.h"
|
2005-01-19 19:05:31 +03:00
|
|
|
|
2005-01-29 23:36:09 +03:00
|
|
|
#include "nsIModelElementPrivate.h"
|
2005-01-19 19:05:31 +03:00
|
|
|
#include "nsIXFormsControl.h"
|
2005-04-28 11:17:49 +04:00
|
|
|
#include "nsIXFormsRepeatElement.h"
|
2005-01-19 19:05:31 +03:00
|
|
|
#include "nsXFormsStubElement.h"
|
|
|
|
#include "nsXFormsUtils.h"
|
2005-06-01 23:19:33 +04:00
|
|
|
#include "nsIXTFBindableElementWrapper.h"
|
2005-06-21 20:47:29 +04:00
|
|
|
#include "nsIXFormsControlBase.h"
|
2005-01-19 19:05:31 +03:00
|
|
|
|
|
|
|
class nsIDOMEvent;
|
|
|
|
class nsIDOMXPathResult;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Common stub for all XForms controls that inherit from nsIXFormsControl and
|
|
|
|
* is bound to an instance node.
|
|
|
|
*/
|
2005-06-01 23:19:33 +04:00
|
|
|
class nsXFormsControlStubBase : public nsIXFormsControl
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
|
|
|
public:
|
2005-02-09 12:57:31 +03:00
|
|
|
|
2005-01-19 19:05:31 +03:00
|
|
|
/** The standard notification flags set on nsIXTFElement */
|
|
|
|
const PRUint32 kStandardNotificationMask;
|
2005-02-10 14:02:43 +03:00
|
|
|
|
2005-01-19 19:05:31 +03:00
|
|
|
/**
|
|
|
|
* The element flags for the controls passed to
|
|
|
|
* nsXFormsUtils:EvaluateNodeBinding()
|
|
|
|
*/
|
|
|
|
const PRUint32 kElementFlags;
|
|
|
|
|
|
|
|
// nsIXFormsControl
|
|
|
|
NS_IMETHOD GetBoundNode(nsIDOMNode **aBoundNode);
|
2006-05-22 13:06:14 +04:00
|
|
|
NS_IMETHOD BindToModel(PRBool aSetBoundNode = PR_FALSE);
|
2005-02-24 17:35:27 +03:00
|
|
|
NS_IMETHOD GetDependencies(nsCOMArray<nsIDOMNode> **aDependencies);
|
2005-01-19 19:05:31 +03:00
|
|
|
NS_IMETHOD GetElement(nsIDOMElement **aElement);
|
2006-05-22 13:06:14 +04:00
|
|
|
NS_IMETHOD ResetBoundNode(const nsString &aBindAttribute,
|
|
|
|
PRUint16 aResultType,
|
|
|
|
PRBool *aContextChanged);
|
|
|
|
NS_IMETHOD Bind(PRBool *aContextChanged);
|
2006-04-19 12:22:28 +04:00
|
|
|
NS_IMETHOD Refresh();
|
2006-05-15 18:14:52 +04:00
|
|
|
NS_IMETHOD GetOnDeferredBindList(PRBool *onList);
|
|
|
|
NS_IMETHOD SetOnDeferredBindList(PRBool putOnList);
|
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);
|
2006-02-23 14:25:07 +03:00
|
|
|
NS_IMETHOD GetUsesModelBinding(PRBool *aRes);
|
2006-05-24 07:45:45 +04:00
|
|
|
NS_IMETHOD GetDefaultIntrinsicState(PRInt32 *aRes);
|
|
|
|
NS_IMETHOD GetDisabledIntrinsicState(PRInt32 *aRes);
|
2005-01-19 19:05:31 +03:00
|
|
|
|
2005-06-01 23:19:33 +04:00
|
|
|
nsresult Create(nsIXTFElementWrapper *aWrapper);
|
|
|
|
// for nsIXTFElement
|
|
|
|
nsresult HandleDefault(nsIDOMEvent *aEvent,
|
|
|
|
PRBool *aHandled);
|
|
|
|
nsresult OnDestroyed();
|
2006-05-24 23:51:22 +04:00
|
|
|
nsresult WillChangeDocument(nsIDOMDocument *aNewDocument);
|
2005-06-01 23:19:33 +04:00
|
|
|
nsresult DocumentChanged(nsIDOMDocument *aNewDocument);
|
|
|
|
nsresult ParentChanged(nsIDOMElement *aNewParent);
|
|
|
|
nsresult WillSetAttribute(nsIAtom *aName, const nsAString &aValue);
|
|
|
|
nsresult AttributeSet(nsIAtom *aName, const nsAString &aValue);
|
|
|
|
nsresult WillRemoveAttribute(nsIAtom *aName);
|
|
|
|
nsresult AttributeRemoved(nsIAtom *aName);
|
2005-04-11 20:33:31 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function manages the mBindAttrsCount value. mBindAttrsCount will
|
|
|
|
* be incremented if a single node binding attribute is specified that isn't
|
|
|
|
* currently on the control AND aValue isn't empty. Otherwise, if the control
|
|
|
|
* already contains this attribute with a non-empty value and aValue is empty,
|
|
|
|
* then mBindAttrsCount is decremented.
|
|
|
|
*
|
|
|
|
* aName - Atom of the single node binding attribute ('bind', 'ref', etc.).
|
|
|
|
* Using an atom to make it a tad harder to misuse by passing in
|
|
|
|
* any old string, for instance. Since different controls may have
|
|
|
|
* different binding attrs, we do NO validation on the attr. We
|
|
|
|
* assume that the caller is smart enough to only send us a
|
|
|
|
* binding attr atom.
|
|
|
|
* aValue - The string value that the SNB attribute is being set to.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void AddRemoveSNBAttr(nsIAtom *aName, const nsAString &aValue);
|
2005-02-09 12:57:31 +03:00
|
|
|
|
|
|
|
// nsIXFormsContextControl
|
|
|
|
NS_DECL_NSIXFORMSCONTEXTCONTROL
|
2005-06-07 11:14:31 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_smaug
|
|
|
|
virtual const char* Name() { return "[undefined]"; }
|
|
|
|
#endif
|
2005-01-19 19:05:31 +03:00
|
|
|
|
2005-06-07 11:14:31 +04:00
|
|
|
|
2005-01-19 19:05:31 +03:00
|
|
|
/** Constructor */
|
2005-06-01 23:19:33 +04:00
|
|
|
nsXFormsControlStubBase() :
|
2005-01-19 19:05:31 +03:00
|
|
|
kStandardNotificationMask(nsIXTFElement::NOTIFY_WILL_SET_ATTRIBUTE |
|
|
|
|
nsIXTFElement::NOTIFY_ATTRIBUTE_SET |
|
2005-04-11 20:33:31 +04:00
|
|
|
nsIXTFElement::NOTIFY_WILL_REMOVE_ATTRIBUTE |
|
|
|
|
nsIXTFElement::NOTIFY_ATTRIBUTE_REMOVED |
|
2006-05-24 23:51:22 +04:00
|
|
|
nsIXTFElement::NOTIFY_WILL_CHANGE_DOCUMENT |
|
2005-01-19 19:05:31 +03:00
|
|
|
nsIXTFElement::NOTIFY_DOCUMENT_CHANGED |
|
|
|
|
nsIXTFElement::NOTIFY_PARENT_CHANGED |
|
|
|
|
nsIXTFElement::NOTIFY_HANDLE_DEFAULT),
|
2005-04-08 19:40:54 +04:00
|
|
|
kElementFlags(nsXFormsUtils::ELEMENT_WITH_MODEL_ATTR),
|
2005-04-11 20:33:31 +04:00
|
|
|
mHasParent(PR_FALSE),
|
2005-06-14 11:21:00 +04:00
|
|
|
mPreventLoop(PR_FALSE),
|
2006-02-23 14:25:07 +03:00
|
|
|
mUsesModelBinding(PR_FALSE),
|
2006-04-19 12:22:28 +04:00
|
|
|
mAppearDisabled(PR_FALSE),
|
2006-05-15 18:14:52 +04:00
|
|
|
mOnDeferredBindList(PR_FALSE),
|
2005-06-14 11:21:00 +04:00
|
|
|
mBindAttrsCount(0)
|
2005-01-19 19:05:31 +03:00
|
|
|
{};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/** The nsIXTFXMLVisualWrapper */
|
2005-06-07 11:14:31 +04:00
|
|
|
nsIDOMElement* mElement;
|
2005-01-19 19:05:31 +03:00
|
|
|
|
2005-02-10 14:02:43 +03:00
|
|
|
/** The node that the control is bound to. */
|
2005-04-28 11:17:49 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> mBoundNode;
|
2005-01-19 19:05:31 +03:00
|
|
|
|
2005-02-10 14:02:43 +03:00
|
|
|
/** Array of nsIDOMNodes that the control depends on. */
|
2005-04-28 11:17:49 +04:00
|
|
|
nsCOMArray<nsIDOMNode> mDependencies;
|
2005-01-19 19:05:31 +03:00
|
|
|
|
2005-01-29 23:36:09 +03:00
|
|
|
/** The model for the control */
|
2005-04-28 11:17:49 +04:00
|
|
|
nsCOMPtr<nsIModelElementPrivate> mModel;
|
2005-01-19 19:05:31 +03:00
|
|
|
|
2005-01-30 02:53:32 +03:00
|
|
|
/** This event listener is used to create xforms-hint and xforms-help events. */
|
2005-04-28 11:17:49 +04:00
|
|
|
nsCOMPtr<nsIDOMEventListener> mEventListener;
|
2005-01-30 02:53:32 +03:00
|
|
|
|
2005-04-08 19:40:54 +04:00
|
|
|
/** State that tells whether control has a parent or not */
|
2006-02-23 14:25:07 +03:00
|
|
|
PRPackedBool mHasParent;
|
2005-04-28 11:17:49 +04:00
|
|
|
|
2005-06-13 23:17:24 +04:00
|
|
|
/** State to prevent infinite loop when generating and handling xforms-next
|
|
|
|
* and xforms-previous events
|
|
|
|
*/
|
2006-02-23 14:25:07 +03:00
|
|
|
PRPackedBool mPreventLoop;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the control use a model bind? That is, does it have a @bind.
|
|
|
|
*/
|
|
|
|
PRPackedBool mUsesModelBinding;
|
2005-06-13 23:17:24 +04:00
|
|
|
|
2006-04-19 12:22:28 +04:00
|
|
|
/**
|
|
|
|
* Should the control appear disabled. This is f.x. used when a valid single
|
|
|
|
* node binding is not pointing to an instance data node.
|
|
|
|
*/
|
|
|
|
PRPackedBool mAppearDisabled;
|
|
|
|
|
2005-04-28 11:17:49 +04:00
|
|
|
/**
|
2006-05-15 18:14:52 +04:00
|
|
|
* Indicates whether this control is already on the deferred bind list
|
2005-04-28 11:17:49 +04:00
|
|
|
*/
|
2006-05-15 18:14:52 +04:00
|
|
|
PRPackedBool mOnDeferredBindList;
|
2005-04-08 19:40:54 +04:00
|
|
|
|
2005-04-11 20:33:31 +04:00
|
|
|
/**
|
|
|
|
* Used to keep track of whether this control has any single node binding
|
|
|
|
* attributes.
|
|
|
|
*/
|
2006-05-15 18:14:52 +04:00
|
|
|
PRInt8 mBindAttrsCount;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of repeats that the node binding depends on. This happens when using
|
|
|
|
* the index() function in the binding expression.
|
|
|
|
*/
|
|
|
|
nsCOMArray<nsIXFormsRepeatElement> mIndexesUsed;
|
2005-04-11 20:33:31 +04:00
|
|
|
|
2006-04-19 12:22:28 +04:00
|
|
|
/**
|
|
|
|
* Does control have a binding attribute?
|
|
|
|
*/
|
|
|
|
PRBool HasBindingAttribute() const { return mBindAttrsCount != 0; };
|
|
|
|
|
2005-01-27 22:30:03 +03:00
|
|
|
/** Returns the relevant state of the control */
|
|
|
|
PRBool GetRelevantState();
|
2005-01-19 19:05:31 +03:00
|
|
|
|
|
|
|
/**
|
2006-04-19 12:22:28 +04:00
|
|
|
* Processes the node binding of a control, get the current Model (mModel)
|
|
|
|
* and binds the control to it.
|
|
|
|
*
|
|
|
|
* @note Will return NS_OK_XFORMS_DEFERRED if the binding is being
|
|
|
|
* deferred.
|
|
|
|
*
|
|
|
|
* @param aBindingAttr The default binding attribute
|
|
|
|
* @param aResultType The XPath result type requested
|
|
|
|
* @param aResult The XPath result
|
|
|
|
* @param aModel The model
|
2005-01-19 19:05:31 +03:00
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
ProcessNodeBinding(const nsString &aBindingAttr,
|
|
|
|
PRUint16 aResultType,
|
|
|
|
nsIDOMXPathResult **aResult,
|
|
|
|
nsIModelElementPrivate **aModel = nsnull);
|
|
|
|
|
2005-01-30 02:53:32 +03:00
|
|
|
/**
|
|
|
|
* Reset (and reinitialize) the event listener, which is used to create
|
|
|
|
* xforms-hint and xforms-help events.
|
|
|
|
*/
|
|
|
|
void ResetHelpAndHint(PRBool aInitialize);
|
2005-04-11 20:33:31 +04:00
|
|
|
|
2006-03-29 14:49:28 +04:00
|
|
|
/**
|
|
|
|
* Checks whether an attribute is a binding attribute for the control. This
|
|
|
|
* should be overriden by controls that have "non-standard" binding
|
|
|
|
* attributes.
|
|
|
|
*
|
|
|
|
* @param aAttr The attribute to check.
|
|
|
|
*/
|
|
|
|
virtual PRBool IsBindingAttribute(const nsIAtom *aAttr) const;
|
|
|
|
|
2005-04-11 20:33:31 +04:00
|
|
|
/**
|
|
|
|
* Causes Bind() and Refresh() to be called if aName is the atom of a
|
|
|
|
* single node binding attribute for this control. Called by AttributeSet
|
|
|
|
* and AttributeRemoved.
|
|
|
|
*/
|
2006-06-06 17:52:03 +04:00
|
|
|
virtual void AfterSetAttribute(nsIAtom *aName);
|
2005-04-11 20:33:31 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes this control from its model's list of controls if a single node
|
|
|
|
* binding attribute is removed. Called by WillSetAttribute and
|
|
|
|
* WillRemoveAttribute.
|
|
|
|
*
|
|
|
|
* @param aName - atom of the attribute being changed
|
|
|
|
* @param aValue - value that the attribute is being changed to.
|
|
|
|
*/
|
2006-03-29 14:49:28 +04:00
|
|
|
void BeforeSetAttribute(nsIAtom *aName, const nsAString &aValue);
|
2005-04-28 11:17:49 +04:00
|
|
|
|
|
|
|
/** Removes the index change event listeners */
|
|
|
|
void RemoveIndexListeners();
|
2006-03-29 14:49:28 +04:00
|
|
|
|
|
|
|
/**
|
2006-04-19 18:52:36 +04:00
|
|
|
* Forces detaching from the model.
|
|
|
|
*
|
|
|
|
* @param aRebind Try rebinding to a new model?
|
2006-03-29 14:49:28 +04:00
|
|
|
*/
|
2006-04-19 18:52:36 +04:00
|
|
|
nsresult ForceModelDetach(PRBool aRebind);
|
2006-03-29 14:49:28 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the form control to the model, if the model has changed.
|
|
|
|
*
|
|
|
|
* @param aOldModel The previous model the control was bound to
|
|
|
|
* @param aParent The parent XForms control
|
|
|
|
*/
|
|
|
|
nsresult MaybeAddToModel(nsIModelElementPrivate *aOldModel,
|
|
|
|
nsIXFormsControl *aParent);
|
2005-01-19 19:05:31 +03:00
|
|
|
};
|
|
|
|
|
2005-06-01 23:19:33 +04:00
|
|
|
/**
|
|
|
|
* nsXFormsBindableControlStub inherits from nsXFormsBindableStub
|
|
|
|
*/
|
|
|
|
class nsXFormsBindableControlStub : public nsXFormsControlStubBase,
|
|
|
|
public nsXFormsBindableStub
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
// nsIXTFBindableElement overrides
|
|
|
|
/** This sets the notification mask and initializes mElement */
|
|
|
|
NS_IMETHOD OnCreated(nsIXTFBindableElementWrapper *aWrapper)
|
|
|
|
{
|
2005-08-10 11:58:29 +04:00
|
|
|
nsresult rv = nsXFormsBindableStub::OnCreated(aWrapper);
|
|
|
|
return NS_SUCCEEDED(rv) ? nsXFormsControlStubBase::Create(aWrapper) : rv;
|
2005-06-01 23:19:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIXTFElement overrides
|
|
|
|
NS_IMETHOD HandleDefault(nsIDOMEvent *aEvent,
|
|
|
|
PRBool *aHandled)
|
|
|
|
{
|
|
|
|
return nsXFormsControlStubBase::HandleDefault(aEvent, aHandled);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD OnDestroyed() {
|
|
|
|
return nsXFormsControlStubBase::OnDestroyed();
|
|
|
|
}
|
|
|
|
|
2006-05-24 23:51:22 +04:00
|
|
|
NS_IMETHOD WillChangeDocument(nsIDOMDocument *aNewDocument)
|
|
|
|
{
|
|
|
|
return nsXFormsControlStubBase::WillChangeDocument(aNewDocument);
|
|
|
|
}
|
|
|
|
|
2005-06-01 23:19:33 +04:00
|
|
|
NS_IMETHOD DocumentChanged(nsIDOMDocument *aNewDocument)
|
|
|
|
{
|
|
|
|
return nsXFormsControlStubBase::DocumentChanged(aNewDocument);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD ParentChanged(nsIDOMElement *aNewParent)
|
|
|
|
{
|
|
|
|
return nsXFormsControlStubBase::ParentChanged(aNewParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD WillSetAttribute(nsIAtom *aName, const nsAString &aValue)
|
|
|
|
{
|
|
|
|
return nsXFormsControlStubBase::WillSetAttribute(aName, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD AttributeSet(nsIAtom *aName, const nsAString &aValue)
|
|
|
|
{
|
|
|
|
return nsXFormsControlStubBase::AttributeSet(aName, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD WillRemoveAttribute(nsIAtom *aName)
|
|
|
|
{
|
|
|
|
return nsXFormsControlStubBase::WillRemoveAttribute(aName);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD AttributeRemoved(nsIAtom *aName)
|
|
|
|
{
|
|
|
|
return nsXFormsControlStubBase::AttributeRemoved(aName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Constructor */
|
|
|
|
nsXFormsBindableControlStub() : nsXFormsControlStubBase() {};
|
|
|
|
};
|
2005-01-19 19:05:31 +03:00
|
|
|
#endif
|