landing xforms branch on trunk, not built by default. Bug 278896, sr=bryner on build config changes. If you build xforms, you now need to enable the schema-validation extension as well

git-svn-id: svn://10.0.0.236/trunk@167986 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
doronr%us.ibm.com
2005-01-19 16:05:31 +00:00
parent 992efeda11
commit cd53bba469
38 changed files with 2391 additions and 1757 deletions

View File

@@ -36,7 +36,6 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsXFormsStubElement.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOM3Node.h"
#include "nsIDOMElement.h"
@@ -45,7 +44,7 @@
#include "nsString.h"
#include "nsIXTFXMLVisualWrapper.h"
#include "nsIDOMDocument.h"
#include "nsIXFormsControl.h"
#include "nsXFormsControlStub.h"
#include "nsISchema.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsXFormsAtoms.h"
@@ -57,7 +56,7 @@
#include "nsIContent.h"
#include "nsIDOMXPathExpression.h"
#include "nsNetUtil.h"
#include "nsXFormsMDGEngine.h"
static void
ReleaseObject(void *aObject,
@@ -72,9 +71,8 @@ ReleaseObject(void *aObject,
/**
* Implementation of the \<upload\> element.
*/
class nsXFormsUploadElement : public nsXFormsXMLVisualStub,
public nsIDOMFocusListener,
public nsIXFormsControl
class nsXFormsUploadElement : public nsIDOMFocusListener,
public nsXFormsControlStub
{
public:
NS_DECL_ISUPPORTS_INHERITED
@@ -88,13 +86,9 @@ public:
// nsIXTFElement overrides
NS_IMETHOD OnDestroyed();
NS_IMETHOD DocumentChanged(nsIDOMDocument *aNewDocument);
NS_IMETHOD ParentChanged(nsIDOMElement *aNewParent);
NS_IMETHOD WillSetAttribute(nsIAtom *aName, const nsAString &aValue);
NS_IMETHOD AttributeSet(nsIAtom *aName, const nsAString &aValue);
// nsIXFormsControl
NS_DECL_NSIXFORMSCONTROL
NS_IMETHOD Refresh();
// nsIDOMEventListener
NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent);
@@ -103,12 +97,9 @@ public:
NS_IMETHOD Focus(nsIDOMEvent *aEvent);
NS_IMETHOD Blur(nsIDOMEvent *aEvent);
nsXFormsUploadElement() : mElement(nsnull) {}
private:
nsCOMPtr<nsIDOMElement> mLabel;
nsCOMPtr<nsIDOMHTMLInputElement> mInput;
nsIDOMElement *mElement;
};
NS_IMPL_ISUPPORTS_INHERITED3(nsXFormsUploadElement,
@@ -122,20 +113,8 @@ NS_IMPL_ISUPPORTS_INHERITED3(nsXFormsUploadElement,
NS_IMETHODIMP
nsXFormsUploadElement::OnCreated(nsIXTFXMLVisualWrapper *aWrapper)
{
aWrapper->SetNotificationMask(nsIXTFElement::NOTIFY_WILL_SET_ATTRIBUTE |
nsIXTFElement::NOTIFY_ATTRIBUTE_SET |
nsIXTFElement::NOTIFY_DOCUMENT_CHANGED |
nsIXTFElement::NOTIFY_PARENT_CHANGED);
nsCOMPtr<nsIDOMElement> node;
aWrapper->GetElementNode(getter_AddRefs(node));
// 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.
mElement = node;
NS_ASSERTION(mElement, "Wrapper is not an nsIDOMElement, we'll crash soon");
nsresult rv = nsXFormsControlStub::OnCreated(aWrapper);
NS_ENSURE_SUCCESS(rv, rv);
// Our anonymous content structure will look like this:
//
@@ -145,7 +124,7 @@ nsXFormsUploadElement::OnCreated(nsIXTFXMLVisualWrapper *aWrapper)
// </label>
nsCOMPtr<nsIDOMDocument> domDoc;
node->GetOwnerDocument(getter_AddRefs(domDoc));
mElement->GetOwnerDocument(getter_AddRefs(domDoc));
domDoc->CreateElementNS(NS_LITERAL_STRING(NS_NAMESPACE_XHTML),
NS_LITERAL_STRING("label"),
@@ -213,53 +192,7 @@ nsXFormsUploadElement::OnDestroyed()
targ->RemoveEventListener(NS_LITERAL_STRING("blur"), this, PR_FALSE);
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsUploadElement::DocumentChanged(nsIDOMDocument *aNewDocument)
{
// We need to re-evaluate our instance data binding when our document
// changes, since our context can change
if (aNewDocument)
Refresh();
return NS_OK;
}
NS_IMETHODIMP
nsXFormsUploadElement::ParentChanged(nsIDOMElement *aNewParent)
{
// We need to re-evaluate our instance data binding when our parent changes,
// since xmlns declarations or our context could have changed.
if (aNewParent)
Refresh();
return NS_OK;
}
NS_IMETHODIMP
nsXFormsUploadElement::WillSetAttribute(nsIAtom *aName, const nsAString &aValue)
{
if (aName == nsXFormsAtoms::bind || aName == nsXFormsAtoms::ref) {
nsCOMPtr<nsIDOMNode> modelNode = nsXFormsUtils::GetModel(mElement);
nsCOMPtr<nsIModelElementPrivate> model = do_QueryInterface(modelNode);
if (model)
model->RemoveFormControl(this);
}
return NS_OK;
}
NS_IMETHODIMP
nsXFormsUploadElement::AttributeSet(nsIAtom *aName, const nsAString &aValue)
{
if (aName == nsXFormsAtoms::bind || aName == nsXFormsAtoms::ref) {
Refresh();
}
return NS_OK;
return nsXFormsControlStub::OnDestroyed();
}
// nsIDOMEventListener
@@ -279,27 +212,7 @@ nsXFormsUploadElement::Focus(nsIDOMEvent *aEvent)
NS_IMETHODIMP
nsXFormsUploadElement::Blur(nsIDOMEvent *aEvent)
{
if (!mInput)
return NS_OK;
nsCOMPtr<nsIDOMNode> modelNode;
nsCOMPtr<nsIDOMElement> bindElement;
nsCOMPtr<nsIDOMXPathResult> result =
nsXFormsUtils::EvaluateNodeBinding(mElement,
nsXFormsUtils::ELEMENT_WITH_MODEL_ATTR,
NS_LITERAL_STRING("ref"),
EmptyString(),
nsIDOMXPathResult::FIRST_ORDERED_NODE_TYPE,
getter_AddRefs(modelNode),
getter_AddRefs(bindElement));
if (!result)
return NS_OK;
nsCOMPtr<nsIDOMNode> singleNode;
result->GetSingleNodeValue(getter_AddRefs(singleNode));
if (!singleNode)
if (!mInput || mBoundNode || mMDG)
return NS_OK;
nsAutoString value;
@@ -308,7 +221,7 @@ nsXFormsUploadElement::Blur(nsIDOMEvent *aEvent)
// store the file as a property on the selected content node. the submission
// code will read this value.
nsCOMPtr<nsIContent> content = do_QueryInterface(singleNode);
nsCOMPtr<nsIContent> content = do_QueryInterface(mBoundNode);
NS_ENSURE_STATE(content);
nsILocalFile *file = nsnull;
@@ -322,7 +235,7 @@ nsXFormsUploadElement::Blur(nsIDOMEvent *aEvent)
// sync with what is actually submitted.
nsCAutoString spec;
NS_GetURLSpecFromFile(file, spec);
nsXFormsUtils::SetNodeValue(singleNode, NS_ConvertUTF8toUTF16(spec));
mMDG->SetNodeValue(mBoundNode, NS_ConvertUTF8toUTF16(spec));
return NS_OK;
}
@@ -334,54 +247,23 @@ nsXFormsUploadElement::Refresh()
if (!mInput)
return NS_OK;
nsCOMPtr<nsIDOMNode> modelNode;
nsCOMPtr<nsIDOMElement> bindElement;
nsCOMPtr<nsIDOMXPathResult> result =
nsXFormsUtils::EvaluateNodeBinding(mElement,
nsXFormsUtils::ELEMENT_WITH_MODEL_ATTR,
NS_LITERAL_STRING("ref"),
EmptyString(),
nsIDOMXPathResult::FIRST_ORDERED_NODE_TYPE,
getter_AddRefs(modelNode),
getter_AddRefs(bindElement));
mBoundNode = nsnull;
nsCOMPtr<nsIModelElementPrivate> model = do_QueryInterface(modelNode);
// @bug / todo: If \<input\> has binding attributes that are invalid, we
// should clear the content. But the content should be left if the element
// is unbound.
// @see https://bugzilla.mozilla.org/show_bug.cgi?id=265216
if (!model)
return NS_OK;
model->AddFormControl(this);
nsCOMPtr<nsIDOMNode> resultNode;
if (result)
result->GetSingleNodeValue(getter_AddRefs(resultNode));
if (!resultNode)
return NS_OK;
// find out if the control should be made readonly
PRBool isReadOnly = PR_FALSE;
nsCOMPtr<nsIContent> nodeContent = do_QueryInterface(resultNode);
if (nodeContent) {
nsIDOMXPathExpression *expr =
NS_STATIC_CAST(nsIDOMXPathExpression*,
nodeContent->GetProperty(nsXFormsAtoms::readonly));
if (expr) {
expr->Evaluate(mElement,
nsIDOMXPathResult::BOOLEAN_TYPE, nsnull,
getter_AddRefs(result));
if (result) {
result->GetBooleanValue(&isReadOnly);
}
}
}
nsCOMPtr<nsIContent> content = do_QueryInterface(resultNode);
nsCOMPtr<nsIDOMXPathResult> result;
nsresult rv =
ProcessNodeBinding(NS_LITERAL_STRING("ref"),
nsIDOMXPathResult::FIRST_ORDERED_NODE_TYPE,
getter_AddRefs(result));
NS_ENSURE_SUCCESS(rv, rv);
if (result)
result->GetSingleNodeValue(getter_AddRefs(mBoundNode));
if (!mBoundNode)
return NS_OK;
nsCOMPtr<nsIContent> content = do_QueryInterface(mBoundNode);
NS_ENSURE_STATE(content);
nsILocalFile *file =
@@ -394,7 +276,7 @@ nsXFormsUploadElement::Refresh()
file->GetPath(value);
mInput->SetValue(value);
mInput->SetReadOnly(isReadOnly);
mInput->SetReadOnly(GetReadOnlyState());
return NS_OK;
}