From 85aa37d6cbb80183cf34411f4ba7342d755ee44e Mon Sep 17 00:00:00 2001 From: "allan%beaufour.dk" Date: Mon, 20 Mar 2006 10:47:06 +0000 Subject: [PATCH] [XForms] Fix excessive refreshing for delegate controls. Bug 327985, r=aaronr+me, patch by surkov@dc.baikal.ru --- extensions/xforms/nsXFormsDelegateStub.cpp | 10 ++-- extensions/xforms/nsXFormsLabelElement.cpp | 5 +- extensions/xforms/nsXFormsOutputElement.cpp | 57 +++++++++------------ extensions/xforms/nsXFormsUploadElement.cpp | 3 +- extensions/xforms/nsXFormsUtils.h | 7 +++ 5 files changed, 45 insertions(+), 37 deletions(-) diff --git a/extensions/xforms/nsXFormsDelegateStub.cpp b/extensions/xforms/nsXFormsDelegateStub.cpp index d248a7294b1..e1dd8925b97 100644 --- a/extensions/xforms/nsXFormsDelegateStub.cpp +++ b/extensions/xforms/nsXFormsDelegateStub.cpp @@ -102,19 +102,19 @@ NS_IMETHODIMP nsXFormsDelegateStub::Refresh() { if (mRepeatState == eType_Template) - return NS_OK; + return NS_OK_XFORMS_NOREFRESH; const nsVoidArray* list = nsPostRefresh::PostRefreshList(); if (list && list->IndexOf(this) >= 0) { // This control will be refreshed later. - return NS_OK; + return NS_OK_XFORMS_NOREFRESH; } SetMozTypeAttribute(); nsCOMPtr widget = do_QueryInterface(mElement); if (!widget) - return NS_OK; + return NS_ERROR_FAILURE; return widget->Refresh(); } @@ -224,6 +224,10 @@ nsXFormsDelegateStub::UpdateRepeatState() mRepeatState = eType_Template; break; } + if (nsXFormsUtils::IsXFormsElement(parent, NS_LITERAL_STRING("itemset"))) { + mRepeatState = eType_Template; + break; + } nsCOMPtr tmp; parent->GetParentNode(getter_AddRefs(tmp)); parent = tmp; diff --git a/extensions/xforms/nsXFormsLabelElement.cpp b/extensions/xforms/nsXFormsLabelElement.cpp index ed5760729c8..89c72636704 100644 --- a/extensions/xforms/nsXFormsLabelElement.cpp +++ b/extensions/xforms/nsXFormsLabelElement.cpp @@ -259,7 +259,10 @@ nsXFormsLabelElement::LoadExternalLabel(const nsAString& aSrc) NS_IMETHODIMP nsXFormsLabelElement::Refresh() { - nsXFormsDelegateStub::Refresh(); + nsresult rv = nsXFormsDelegateStub::Refresh(); + if (NS_FAILED(rv) || rv == NS_OK_XFORMS_NOREFRESH) + return rv; + nsCOMPtr parent; mElement->GetParentNode(getter_AddRefs(parent)); diff --git a/extensions/xforms/nsXFormsOutputElement.cpp b/extensions/xforms/nsXFormsOutputElement.cpp index fb189e101f7..d4adb2aed45 100755 --- a/extensions/xforms/nsXFormsOutputElement.cpp +++ b/extensions/xforms/nsXFormsOutputElement.cpp @@ -85,6 +85,7 @@ public: private: PRBool mHasBinding; nsString mValue; + PRBool mValueIsDirty; }; // nsIXFormsControl @@ -142,43 +143,35 @@ nsXFormsOutputElement::Bind() NS_IMETHODIMP nsXFormsOutputElement::Refresh() { - if (mRepeatState == eType_Template) - return NS_OK; - - nsresult rv = NS_OK; - SetDOMStringToNull(mValue); - - if (mModel) { - if (mHasBinding) { - if (mBoundNode) { - nsXFormsUtils::GetNodeValue(mBoundNode, mValue); - } - } else { - nsCOMPtr result; - rv = ProcessNodeBinding(NS_LITERAL_STRING("value"), - nsIDOMXPathResult::STRING_TYPE, - getter_AddRefs(result)); - NS_ENSURE_SUCCESS(rv, rv); - - if (result) { - rv = result->GetStringValue(mValue); - NS_ENSURE_SUCCESS(rv, rv); - } - } - } - - SetMozTypeAttribute(); - - nsCOMPtr widget = do_QueryInterface(mElement); - if (widget) - widget->Refresh(); - - return rv; + mValueIsDirty = PR_TRUE; + return nsXFormsDelegateStub::Refresh(); } NS_IMETHODIMP nsXFormsOutputElement::GetValue(nsAString& aValue) { + NS_ENSURE_STATE(mModel); + + if (mValueIsDirty) { + if (mHasBinding) { + NS_ENSURE_STATE(mBoundNode); + nsXFormsUtils::GetNodeValue(mBoundNode, mValue); + } else { + nsCOMPtr result; + nsresult rv = ProcessNodeBinding(NS_LITERAL_STRING("value"), + nsIDOMXPathResult::STRING_TYPE, + getter_AddRefs(result)); + NS_ENSURE_SUCCESS(rv, rv); + + if (result) { + SetDOMStringToNull(mValue); + rv = result->GetStringValue(mValue); + NS_ENSURE_SUCCESS(rv, rv); + } + } + mValueIsDirty = PR_FALSE; + } + aValue = mValue; return NS_OK; } diff --git a/extensions/xforms/nsXFormsUploadElement.cpp b/extensions/xforms/nsXFormsUploadElement.cpp index 81bd480b721..fd646324178 100644 --- a/extensions/xforms/nsXFormsUploadElement.cpp +++ b/extensions/xforms/nsXFormsUploadElement.cpp @@ -121,7 +121,8 @@ nsXFormsUploadElement::Refresh() // type 'anyURI', 'base64Binary', or 'hexBinary'. nsresult rv = nsXFormsDelegateStub::Refresh(); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv) || rv == NS_OK_XFORMS_NOREFRESH) + return rv; if (!mBoundNode) return NS_OK; diff --git a/extensions/xforms/nsXFormsUtils.h b/extensions/xforms/nsXFormsUtils.h index c14486279c6..a5803e5e10b 100644 --- a/extensions/xforms/nsXFormsUtils.h +++ b/extensions/xforms/nsXFormsUtils.h @@ -66,6 +66,13 @@ class nsIDOMEvent; #define NS_NAMESPACE_SOAP_ENVELOPE "http://schemas.xmlsoap.org/soap/envelope/" #define NS_NAMESPACE_MOZ_XFORMS_LAZY "http://www.mozilla.org/projects/xforms/2005/lazy" +/** + * Error codes + */ + +#define NS_OK_XFORMS_NOREFRESH \ +NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_GENERAL, 1) + /** * XForms event types *