Remove direct access to MDG in nsIModelElementPrivate and save pointer to model in nsXFormsControlStub. Bug 278370, r=smaug, sr=bryner

This commit is contained in:
allan%beaufour.dk 2005-01-29 20:36:09 +00:00
Родитель 094f5173e0
Коммит 120d7ed22c
10 изменённых файлов: 67 добавлений и 77 удалений

Просмотреть файл

@ -41,7 +41,7 @@
interface nsIXFormsControl;
interface nsISchemaType;
interface nsIInstanceElementPrivate;
interface nsXFormsMDGEngine;
interface nsIDOMNode;
/**
* Private interface implemented by the model element for other
@ -78,12 +78,17 @@ interface nsIModelElementPrivate : nsIXFormsModelElement
nsIInstanceElementPrivate findInstanceElement(in AString id);
/**
* The model's MDG.
*
* @bug nsXFormsMDGEngine is not an interface.
* @see https://bugzilla.mozilla.org/show_bug.cgi?id=278370
* Set the value of an instance node.
*/
readonly attribute nsXFormsMDGEngine MDG;
void setNodeValue(in nsIDOMNode contextNode,
in AString nodeValue,
out boolean nodeChanged);
/**
* Get the value of an instance node.
*/
void getNodeValue(in nsIDOMNode contextNode,
out AString nodeValue);
/**
* Validates the instance node against the schemas loaded by the model.

Просмотреть файл

@ -92,7 +92,6 @@ nsXFormsControlStub::ProcessNodeBinding(const nsString &aBindingAttr,
{
nsresult rv;
mMDG = nsnull;
if (!mDependencies) {
rv = NS_NewArray(getter_AddRefs(mDependencies));
} else {
@ -100,23 +99,21 @@ nsXFormsControlStub::ProcessNodeBinding(const nsString &aBindingAttr,
}
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIModelElementPrivate> model;
rv = nsXFormsUtils::EvaluateNodeBinding(mElement,
kElementFlags,
aBindingAttr,
EmptyString(),
aResultType,
getter_AddRefs(model),
getter_AddRefs(mModel),
aResult,
mDependencies);
NS_ENSURE_SUCCESS(rv, rv);
if (model) {
model->AddFormControl(this);
model->GetMDG(&mMDG);
if (mModel) {
mModel->AddFormControl(this);
if (aModel) {
NS_ADDREF(*aModel = model);
NS_ADDREF(*aModel = mModel);
}
}
@ -127,25 +124,19 @@ PRBool
nsXFormsControlStub::GetReadOnlyState()
{
PRBool res = PR_FALSE;
if (mBoundNode && mMDG) {
const nsXFormsNodeState* ns = mMDG->GetNodeState(mBoundNode);
if (ns) {
res = ns->IsReadonly();
}
}
if (mElement) {
mElement->HasAttribute(NS_LITERAL_STRING("read-only"), &res);
}
return res;
}
PRBool
nsXFormsControlStub::GetRelevantState()
{
PRBool res = PR_TRUE;
if (mBoundNode && mMDG) {
const nsXFormsNodeState* ns = mMDG->GetNodeState(mBoundNode);
if (ns) {
res = ns->IsRelevant();
}
}
PRBool res = PR_FALSE;
if (mElement) {
mElement->HasAttribute(NS_LITERAL_STRING("enabled"), &res);
}
return res;
}
@ -153,8 +144,10 @@ void
nsXFormsControlStub::ToggleProperty(const nsAString &aOn,
const nsAString &aOff)
{
mElement->SetAttribute(aOn, NS_LITERAL_STRING("1"));
mElement->RemoveAttribute(aOff);
if (mElement) {
mElement->SetAttribute(aOn, NS_LITERAL_STRING("1"));
mElement->RemoveAttribute(aOff);
}
}
NS_IMETHODIMP
@ -220,7 +213,10 @@ nsXFormsControlStub::OnCreated(nsIXTFXMLVisualWrapper *aWrapper)
NS_IMETHODIMP
nsXFormsControlStub::OnDestroyed()
{
mMDG = nsnull;
if (mModel) {
mModel->RemoveFormControl(this);
mModel = nsnull;
}
mElement = nsnull;
return NS_OK;
@ -258,9 +254,8 @@ nsXFormsControlStub::WillSetAttribute(nsIAtom *aName, const nsAString &aValue)
if (aName == nsXFormsAtoms::model ||
aName == nsXFormsAtoms::bind ||
aName == nsXFormsAtoms::ref) {
nsCOMPtr<nsIModelElementPrivate> model = nsXFormsUtils::GetModel(mElement);
if (model)
model->RemoveFormControl(this);
if (mModel)
mModel->RemoveFormControl(this);
}
return NS_OK;

Просмотреть файл

@ -47,15 +47,14 @@
#include "nsIDOMNode.h"
#include "nsIXTFElement.h"
#include "nsIModelElementPrivate.h"
#include "nsIXFormsControl.h"
#include "nsXFormsStubElement.h"
#include "nsXFormsUtils.h"
class nsIDOMEvent;
class nsIDOMXPathResult;
class nsIModelElementPrivate;
class nsIXTFXMLVisualWrapper;
class nsXFormsMDGEngine;
/**
* Common stub for all XForms controls that inherit from nsIXFormsControl and
@ -66,10 +65,6 @@ class nsXFormsMDGEngine;
*
* @todo nsIXFormsContextControl-stub should probably also be included here
* (mBoundNode is in fact also the context) (XXX)
*
* @todo I guess it would make sense to call
* nsIModelElementPrivate->RemoveFormControl in OnDestroyed()? (XXX)
* We should possible save the model as a member variable...
*/
class nsXFormsControlStub : public nsIXFormsControl,
public nsXFormsXMLVisualStub
@ -110,8 +105,7 @@ public:
nsIXTFElement::NOTIFY_DOCUMENT_CHANGED |
nsIXTFElement::NOTIFY_PARENT_CHANGED |
nsIXTFElement::NOTIFY_HANDLE_DEFAULT),
kElementFlags(nsXFormsUtils::ELEMENT_WITH_MODEL_ATTR),
mMDG(nsnull)
kElementFlags(nsXFormsUtils::ELEMENT_WITH_MODEL_ATTR)
{};
protected:
@ -134,8 +128,8 @@ protected:
*/
nsCOMPtr<nsIMutableArray> mDependencies;
/** The MDG for the control */
nsXFormsMDGEngine *mMDG;
/** The model for the control */
nsCOMPtr<nsIModelElementPrivate> mModel;
/** Returns the read only state of the control (ie. mBoundNode) */
PRBool GetReadOnlyState();

Просмотреть файл

@ -56,7 +56,6 @@
#include "nsIModelElementPrivate.h"
#include "nsIContent.h"
#include "nsIDOMXPathExpression.h"
#include "nsXFormsMDGEngine.h"
/**
* Implementation of the \<input\>, \<secret\>, and \<textarea\> elements.
@ -224,7 +223,7 @@ nsXFormsInputElement::Focus(nsIDOMEvent *aEvent)
NS_IMETHODIMP
nsXFormsInputElement::Blur(nsIDOMEvent *aEvent)
{
if (!mControl && !mBoundNode && !mMDG)
if (!mControl && !mBoundNode && !mModel)
return NS_OK;
nsAutoString value;
@ -249,11 +248,10 @@ nsXFormsInputElement::Blur(nsIDOMEvent *aEvent)
}
PRBool changed;
nsresult rv = mMDG->SetNodeValue(mBoundNode, value, PR_TRUE, &changed);
nsresult rv = mModel->SetNodeValue(mBoundNode, value, &changed);
NS_ENSURE_SUCCESS(rv, rv);
if (changed) {
nsCOMPtr<nsIModelElementPrivate> modelPriv = nsXFormsUtils::GetModel(mElement);
nsCOMPtr<nsIDOMNode> model = do_QueryInterface(modelPriv);
nsCOMPtr<nsIDOMNode> model = do_QueryInterface(mModel);
if (model) {
rv = nsXFormsUtils::DispatchEvent(model, eEvent_Recalculate);
@ -295,7 +293,7 @@ nsXFormsInputElement::Bind()
NS_IMETHODIMP
nsXFormsInputElement::Refresh()
{
if (!mControl && !mMDG)
if (!mControl || !mModel)
return NS_OK;
nsAutoString text;
@ -316,9 +314,7 @@ nsXFormsInputElement::Refresh()
if (mType == eType_Input) {
nsCOMPtr<nsISchemaType> type;
/// @todo: Enable type support. This will be moved away from the model,
/// will it not? (XXX)
// model->GetTypeForControl(this, getter_AddRefs(type));
mModel->GetTypeForControl(this, getter_AddRefs(type));
nsCOMPtr<nsISchemaBuiltinType> biType = do_QueryInterface(type);
PRUint16 typeValue = nsISchemaBuiltinType::BUILTIN_TYPE_STRING;
if (biType)

Просмотреть файл

@ -52,7 +52,6 @@
#include "nsIXTFXMLVisualWrapper.h"
#include "nsIXFormsContextControl.h"
#include "nsIModelElementPrivate.h"
#include "nsXFormsMDGEngine.h"
/**
* nsXFormsItemElement implements the XForms \<item\> element.
@ -322,12 +321,9 @@ nsXFormsItemElement::WriteSelectedItems(nsIDOMNode *aContainer)
/// @see https://bugzilla.mozilla.org/show_bug.cgi?id=278207
/// Wherever its final resting place might be, it should be shared
/// with the code in nsXFormsInputElement
nsXFormsMDGEngine* MDG;
model->GetMDG(&MDG);
NS_ENSURE_STATE(MDG);
PRBool changed;
rv = MDG->SetNodeValue(textNode, value, PR_TRUE, &changed);
rv = model->SetNodeValue(textNode, value, &changed);
NS_ENSURE_SUCCESS(rv, rv);
if (changed) {
rv = nsXFormsUtils::DispatchEvent(modelNode, eEvent_Recalculate);

Просмотреть файл

@ -771,14 +771,25 @@ nsXFormsModelElement::FindInstanceElement(const nsAString &aID,
return NS_OK;
}
nsresult
nsXFormsModelElement::GetMDG(nsXFormsMDGEngine **aMDG)
{
if (aMDG)
*aMDG = &mMDG;
return NS_OK;
NS_IMETHODIMP
nsXFormsModelElement::SetNodeValue(nsIDOMNode *aContextNode,
const nsAString &aNodeValue,
PRBool *aNodeChanged)
{
return mMDG.SetNodeValue(aContextNode,
aNodeValue,
PR_TRUE,
aNodeChanged);
}
NS_IMETHODIMP
nsXFormsModelElement::GetNodeValue(nsIDOMNode *aContextNode,
nsAString &aNodeValue)
{
return mMDG.GetNodeValue(aContextNode,
aNodeValue);
}
NS_IMETHODIMP
nsXFormsModelElement::ValidateNode(nsIDOMNode *aInstanceNode, PRBool *aResult)
{

Просмотреть файл

@ -184,9 +184,8 @@ nsXFormsOutputElement::WillSetAttribute(nsIAtom *aName, const nsAString &aValue)
aName == nsXFormsAtoms::ref ||
aName == nsXFormsAtoms::model ||
aName == nsXFormsAtoms::value) {
nsCOMPtr<nsIModelElementPrivate> model = nsXFormsUtils::GetModel(mElement);
if (model)
model->RemoveFormControl(this);
if (mModel)
mModel->RemoveFormControl(this);
}
return NS_OK;

Просмотреть файл

@ -231,9 +231,8 @@ nsXFormsRepeatElement::WillSetAttribute(nsIAtom *aName, const nsAString &aValue)
if (aName == nsXFormsAtoms::bind ||
aName == nsXFormsAtoms::nodeset ||
aName == nsXFormsAtoms::model) {
nsCOMPtr<nsIModelElementPrivate> model = nsXFormsUtils::GetModel(mElement);
if (model) {
model->RemoveFormControl(this);
if (mModel) {
mModel->RemoveFormControl(this);
}
}

Просмотреть файл

@ -104,13 +104,8 @@ nsXFormsSetValueElement::HandleAction(nsIDOMEvent* aEvent,
n3->GetTextContent(value);
}
nsXFormsMDGEngine* MDG;
modelPriv->GetMDG(&MDG);
if (!MDG)
return NS_ERROR_FAILURE;
PRBool changed;
rv = MDG->SetNodeValue(singleNode, value, PR_TRUE, &changed);
rv = modelPriv->SetNodeValue(singleNode, value, &changed);
NS_ENSURE_SUCCESS(rv, rv);
if (changed) {

Просмотреть файл

@ -56,7 +56,6 @@
#include "nsIContent.h"
#include "nsIDOMXPathExpression.h"
#include "nsNetUtil.h"
#include "nsXFormsMDGEngine.h"
static void
ReleaseObject(void *aObject,
@ -213,7 +212,7 @@ nsXFormsUploadElement::Focus(nsIDOMEvent *aEvent)
NS_IMETHODIMP
nsXFormsUploadElement::Blur(nsIDOMEvent *aEvent)
{
if (!mInput || mBoundNode || mMDG)
if (!mInput || !mBoundNode || !mModel)
return NS_OK;
nsAutoString value;
@ -236,7 +235,8 @@ nsXFormsUploadElement::Blur(nsIDOMEvent *aEvent)
// sync with what is actually submitted.
nsCAutoString spec;
NS_GetURLSpecFromFile(file, spec);
mMDG->SetNodeValue(mBoundNode, NS_ConvertUTF8toUTF16(spec));
PRBool changed;
mModel->SetNodeValue(mBoundNode, NS_ConvertUTF8toUTF16(spec), &changed);
return NS_OK;
}