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>
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
#include "nsIXTFXMLVisualWrapper.h"
|
2005-05-17 15:30:43 +04:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsXFormsModelElement.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);
|
|
|
|
if (code == nsIDOMKeyEvent::DOM_VK_F1)
|
|
|
|
nsXFormsUtils::DispatchEvent(targetNode, eEvent_Help);
|
|
|
|
} else {
|
|
|
|
nsXFormsUtils::DispatchEvent(targetNode, eEvent_Hint);
|
|
|
|
}
|
2005-01-30 02:53:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-19 19:05:31 +03:00
|
|
|
NS_IMETHODIMP
|
2005-06-01 23:19:33 +04:00
|
|
|
nsXFormsControlStubBase::GetBoundNode(nsIDOMNode **aBoundNode)
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aBoundNode = mBoundNode);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-06-01 23:19:33 +04:00
|
|
|
nsXFormsControlStubBase::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
|
2005-06-01 23:19:33 +04:00
|
|
|
nsXFormsControlStubBase::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
|
2005-06-01 23:19:33 +04:00
|
|
|
nsXFormsControlStubBase::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
|
2005-06-01 23:19:33 +04:00
|
|
|
nsXFormsControlStubBase::ResetBoundNode(const nsString &aBindAttribute,
|
|
|
|
PRUint16 aResultType,
|
|
|
|
nsIDOMXPathResult **aResult)
|
2005-02-01 02:41:00 +03:00
|
|
|
{
|
2005-04-28 11:17:49 +04:00
|
|
|
// Clear existing bound node, etc.
|
2005-02-01 02:41:00 +03:00
|
|
|
mBoundNode = nsnull;
|
2005-04-28 11:17:49 +04:00
|
|
|
mDependencies.Clear();
|
|
|
|
RemoveIndexListeners();
|
2005-02-01 02:41:00 +03:00
|
|
|
|
2005-04-11 20:33:31 +04:00
|
|
|
if (!mHasParent || !mBindAttrsCount)
|
2005-04-08 19:40:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2005-02-01 02:41:00 +03:00
|
|
|
nsCOMPtr<nsIDOMXPathResult> result;
|
|
|
|
nsresult rv =
|
2005-05-05 11:09:40 +04:00
|
|
|
ProcessNodeBinding(aBindAttribute,
|
|
|
|
aResultType,
|
|
|
|
getter_AddRefs(result));
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2005-05-05 11:09:40 +04:00
|
|
|
|
|
|
|
if (!result)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Get context node, if any
|
|
|
|
result->GetSingleNodeValue(getter_AddRefs(mBoundNode));
|
2005-02-01 02:41:00 +03:00
|
|
|
|
2005-05-05 11:09:40 +04:00
|
|
|
if (mBoundNode && mModel) {
|
|
|
|
mModel->SetStates(this, mBoundNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aResult) {
|
|
|
|
*aResult = nsnull;
|
|
|
|
result.swap(*aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2005-02-01 02:41:00 +03:00
|
|
|
}
|
|
|
|
|
2005-01-19 19:05:31 +03:00
|
|
|
NS_IMETHODIMP
|
2005-06-01 23:19:33 +04:00
|
|
|
nsXFormsControlStubBase::Bind()
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
2005-05-05 11:09:40 +04:00
|
|
|
return ResetBoundNode(NS_LITERAL_STRING("ref"),
|
|
|
|
nsIDOMXPathResult::FIRST_ORDERED_NODE_TYPE);
|
2005-01-19 19:05:31 +03:00
|
|
|
}
|
|
|
|
|
2005-01-27 22:30:03 +03:00
|
|
|
NS_IMETHODIMP
|
2005-06-01 23:19:33 +04:00
|
|
|
nsXFormsControlStubBase::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
|
2005-06-01 23:19:33 +04:00
|
|
|
nsXFormsControlStubBase::IsEventTarget(PRBool *aOK)
|
2005-05-17 16:10:08 +04:00
|
|
|
{
|
|
|
|
*aOK = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-27 22:30:03 +03:00
|
|
|
|
2005-01-19 19:05:31 +03:00
|
|
|
nsresult
|
2005-06-01 23:19:33 +04:00
|
|
|
nsXFormsControlStubBase::ProcessNodeBinding(const nsString &aBindingAttr,
|
2005-01-19 19:05:31 +03:00
|
|
|
PRUint16 aResultType,
|
|
|
|
nsIDOMXPathResult **aResult,
|
|
|
|
nsIModelElementPrivate **aModel)
|
|
|
|
{
|
2005-04-28 11:17:49 +04:00
|
|
|
nsStringArray indexesUsed;
|
2005-01-19 19:05:31 +03:00
|
|
|
|
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.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
mElement->GetOwnerDocument(getter_AddRefs(domDoc));
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
|
|
|
if (!doc) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsIDocument *test = NS_STATIC_CAST(nsIDocument *,
|
|
|
|
doc->GetProperty(nsXFormsAtoms::readyForBindProperty));
|
|
|
|
if (!test) {
|
|
|
|
nsXFormsModelElement::DeferElementBind(domDoc, this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-02-24 17:35:27 +03:00
|
|
|
nsresult rv;
|
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,
|
2005-04-28 11:17:49 +04:00
|
|
|
&mDependencies,
|
|
|
|
&indexesUsed);
|
|
|
|
NS_ENSURE_STATE(mModel);
|
|
|
|
|
|
|
|
mModel->AddFormControl(this);
|
|
|
|
if (aModel)
|
|
|
|
NS_ADDREF(*aModel = mModel);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && indexesUsed.Count()) {
|
|
|
|
// add index listeners on repeat elements
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < indexesUsed.Count(); ++i) {
|
|
|
|
// Find the repeat element and add |this| as a listener
|
|
|
|
nsCOMPtr<nsIDOMElement> repElem;
|
2005-05-17 15:30:43 +04:00
|
|
|
domDoc->GetElementById(*(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);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
rv = mIndexesUsed.AppendObject(rep);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-01-19 19:05:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-18 12:48:13 +03:00
|
|
|
return rv;
|
2005-01-19 19:05:31 +03:00
|
|
|
}
|
|
|
|
|
2005-01-30 02:53:32 +03:00
|
|
|
void
|
2005-06-01 23:19:33 +04:00
|
|
|
nsXFormsControlStubBase::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");
|
|
|
|
NS_NAMED_LITERAL_STRING(focus, "focus");
|
|
|
|
NS_NAMED_LITERAL_STRING(keypress, "keypress");
|
|
|
|
|
|
|
|
if (mEventListener) {
|
|
|
|
targ->RemoveEventListener(mouseover, mEventListener, PR_TRUE);
|
|
|
|
targ->RemoveEventListener(focus, mEventListener, PR_TRUE);
|
|
|
|
targ->RemoveEventListener(keypress, mEventListener, PR_TRUE);
|
|
|
|
mEventListener = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aInitialize) {
|
|
|
|
mEventListener = new nsXFormsHintHelpListener();
|
|
|
|
if (!mEventListener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
targ->AddEventListener(mouseover, mEventListener, PR_TRUE);
|
|
|
|
targ->AddEventListener(focus, mEventListener, PR_TRUE);
|
|
|
|
targ->AddEventListener(keypress, mEventListener, PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-19 19:05:31 +03:00
|
|
|
PRBool
|
2005-06-01 23:19:33 +04:00
|
|
|
nsXFormsControlStubBase::GetReadOnlyState()
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
|
|
|
PRBool res = PR_FALSE;
|
2005-01-29 23:36:09 +03:00
|
|
|
if (mElement) {
|
|
|
|
mElement->HasAttribute(NS_LITERAL_STRING("read-only"), &res);
|
|
|
|
}
|
2005-01-19 19:05:31 +03:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2005-01-27 22:30:03 +03:00
|
|
|
PRBool
|
2005-06-01 23:19:33 +04:00
|
|
|
nsXFormsControlStubBase::GetRelevantState()
|
2005-01-27 22:30:03 +03:00
|
|
|
{
|
2005-01-29 23:36:09 +03:00
|
|
|
PRBool res = PR_FALSE;
|
|
|
|
if (mElement) {
|
|
|
|
mElement->HasAttribute(NS_LITERAL_STRING("enabled"), &res);
|
|
|
|
}
|
2005-01-27 22:30:03 +03:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2005-06-01 23:19:33 +04:00
|
|
|
nsresult
|
|
|
|
nsXFormsControlStubBase::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-01-19 19:05:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-01 23:19:33 +04:00
|
|
|
nsresult
|
|
|
|
nsXFormsControlStubBase::Create(nsIXTFElementWrapper *aWrapper)
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
|
|
|
aWrapper->SetNotificationMask(kStandardNotificationMask);
|
|
|
|
|
|
|
|
aWrapper->GetElementNode(getter_AddRefs(mElement));
|
|
|
|
NS_ASSERTION(mElement, "Wrapper is not an nsIDOMElement, we'll crash soon");
|
|
|
|
|
2005-01-30 02:53:32 +03:00
|
|
|
ResetHelpAndHint(PR_TRUE);
|
|
|
|
|
2005-01-19 19:05:31 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-01 23:19:33 +04:00
|
|
|
nsresult
|
|
|
|
nsXFormsControlStubBase::OnDestroyed()
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
2005-01-30 02:53:32 +03:00
|
|
|
ResetHelpAndHint(PR_FALSE);
|
2005-04-28 11:17:49 +04:00
|
|
|
RemoveIndexListeners();
|
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
|
|
|
mElement = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-01 23:19:33 +04:00
|
|
|
nsresult
|
|
|
|
nsXFormsControlStubBase::DocumentChanged(nsIDOMDocument *aNewDocument)
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
|
|
|
// We need to re-evaluate our instance data binding when our document
|
|
|
|
// changes, since our context can change
|
|
|
|
if (aNewDocument) {
|
|
|
|
Bind();
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-01 23:19:33 +04:00
|
|
|
nsresult
|
|
|
|
nsXFormsControlStubBase::ParentChanged(nsIDOMElement *aNewParent)
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
2005-04-08 19:40:54 +04:00
|
|
|
mHasParent = aNewParent != nsnull;
|
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.
|
2005-04-08 19:40:54 +04:00
|
|
|
if (mHasParent) {
|
2005-01-19 19:05:31 +03:00
|
|
|
Bind();
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-01 23:19:33 +04:00
|
|
|
nsresult
|
|
|
|
nsXFormsControlStubBase::WillSetAttribute(nsIAtom *aName, const nsAString &aValue)
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
2005-04-11 20:33:31 +04:00
|
|
|
MaybeRemoveFromModel(aName, aValue);
|
2005-01-19 19:05:31 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-01 23:19:33 +04:00
|
|
|
nsresult
|
|
|
|
nsXFormsControlStubBase::AttributeSet(nsIAtom *aName, const nsAString &aValue)
|
2005-01-19 19:05:31 +03:00
|
|
|
{
|
2005-04-11 20:33:31 +04:00
|
|
|
MaybeBindAndRefresh(aName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-01-19 19:05:31 +03:00
|
|
|
|
2005-06-01 23:19:33 +04:00
|
|
|
nsresult
|
|
|
|
nsXFormsControlStubBase::WillRemoveAttribute(nsIAtom *aName)
|
2005-04-11 20:33:31 +04:00
|
|
|
{
|
|
|
|
MaybeRemoveFromModel(aName, EmptyString());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-01 23:19:33 +04:00
|
|
|
nsresult
|
|
|
|
nsXFormsControlStubBase::AttributeRemoved(nsIAtom *aName)
|
2005-04-11 20:33:31 +04:00
|
|
|
{
|
|
|
|
MaybeBindAndRefresh(aName);
|
2005-01-19 19:05:31 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-02-09 12:57:31 +03:00
|
|
|
|
|
|
|
// nsIXFormsContextControl
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-06-02 11:00:11 +04:00
|
|
|
nsXFormsControlStubBase::SetContext(nsIDOMNode *aContextNode,
|
|
|
|
PRInt32 aContextPosition,
|
|
|
|
PRInt32 aContextSize)
|
2005-02-09 12:57:31 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-06-01 23:19:33 +04:00
|
|
|
nsXFormsControlStubBase::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);
|
|
|
|
|
|
|
|
*aContextPosition = 1;
|
|
|
|
*aContextSize = 1;
|
|
|
|
|
|
|
|
if (mBoundNode && aContextNode) {
|
|
|
|
CallQueryInterface(mBoundNode, aContextNode); // addrefs
|
|
|
|
NS_ASSERTION(*aContextNode, "could not QI context node from bound node?");
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @todo expensive to run this
|
|
|
|
nsCOMPtr<nsIDOMElement> model = do_QueryInterface(mModel);
|
|
|
|
if (model) {
|
|
|
|
model->GetAttribute(NS_LITERAL_STRING("id"), aModelID);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-11 20:33:31 +04:00
|
|
|
void
|
2005-06-01 23:19:33 +04:00
|
|
|
nsXFormsControlStubBase::ResetProperties()
|
2005-04-11 20:33:31 +04:00
|
|
|
{
|
|
|
|
if (!mElement) {
|
|
|
|
return;
|
|
|
|
}
|
2005-05-05 11:09:40 +04:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @todo removes the attributes we use, until bug 271720 is landed (XXX)
|
|
|
|
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(kStateAttributes); ++i) {
|
|
|
|
mElement->RemoveAttribute(kStateAttributes[i]);
|
|
|
|
}
|
2005-04-11 20:33:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-06-01 23:19:33 +04:00
|
|
|
nsXFormsControlStubBase::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!");
|
|
|
|
if (!mBindAttrsCount) {
|
|
|
|
ResetProperties();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-06-01 23:19:33 +04:00
|
|
|
nsXFormsControlStubBase::MaybeBindAndRefresh(nsIAtom *aName)
|
2005-04-11 20:33:31 +04:00
|
|
|
{
|
|
|
|
if (aName == nsXFormsAtoms::bind ||
|
|
|
|
aName == nsXFormsAtoms::ref ||
|
|
|
|
aName == nsXFormsAtoms::model) {
|
|
|
|
|
|
|
|
Bind();
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-06-01 23:19:33 +04:00
|
|
|
nsXFormsControlStubBase::MaybeRemoveFromModel(nsIAtom *aName,
|
|
|
|
const nsAString &aValue)
|
2005-04-11 20:33:31 +04:00
|
|
|
{
|
|
|
|
if (aName == nsXFormsAtoms::model ||
|
|
|
|
aName == nsXFormsAtoms::bind ||
|
|
|
|
aName == nsXFormsAtoms::ref) {
|
|
|
|
if (mModel)
|
|
|
|
mModel->RemoveFormControl(this);
|
|
|
|
|
|
|
|
if (aName != nsXFormsAtoms::model) {
|
|
|
|
AddRemoveSNBAttr(aName, aValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-06-01 23:19:33 +04:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED2(nsXFormsControlStub,
|
|
|
|
nsXFormsXMLVisualStub,
|
|
|
|
nsIXFormsContextControl,
|
|
|
|
nsIXFormsControl)
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED2(nsXFormsBindableControlStub,
|
|
|
|
nsXFormsBindableStub,
|
|
|
|
nsIXFormsContextControl,
|
|
|
|
nsIXFormsControl)
|
|
|
|
|