Remaining controls implement nsIXFormsContextControl, through nsXFormsControlStub, bug 280017, r=smaug, sr=bryner

This commit is contained in:
allan%beaufour.dk 2005-02-09 09:57:31 +00:00
Родитель c2480fc4f6
Коммит 9fc0546e03
14 изменённых файлов: 91 добавлений и 210 удалений

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

@ -36,7 +36,7 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
#include "nsIXFormsContextControl.idl"
interface nsIArray;
interface nsIDOMNode;
@ -46,7 +46,7 @@ interface nsIDOMElement;
* Interface implemented by all XForms form control classes.
*/
[uuid(8377c845-5d55-4eee-9a76-0f86751dcbc8)]
interface nsIXFormsControl : nsISupports
interface nsIXFormsControl : nsIXFormsContextControl
{
/**
* This tells the form control to update its node binding based on the

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

@ -67,16 +67,13 @@
* @see http://www.w3.org/TR/xforms/sliceF.html#id2645142
* @see http://bugzilla.mozilla.org/show_bug.cgi?id=271724
*/
class nsXFormsContextContainer : public nsXFormsControlStub,
public nsIXFormsContextControl
class nsXFormsContextContainer : public nsXFormsControlStub
{
protected:
/** The HTML representation for the node */
nsCOMPtr<nsIDOMElement> mHTMLElement;
public:
NS_DECL_ISUPPORTS_INHERITED
// nsIXTFXMLVisual overrides
NS_IMETHOD OnCreated(nsIXTFXMLVisualWrapper *aWrapper);
@ -94,15 +91,8 @@ public:
// nsIXFormsContextControl
NS_DECL_NSIXFORMSCONTEXTCONTROL
};
NS_IMPL_ISUPPORTS_INHERITED2(nsXFormsContextContainer,
nsXFormsXMLVisualStub,
nsIXFormsControl,
nsIXFormsContextControl)
// nsIXTFXMLVisual
NS_IMETHODIMP
nsXFormsContextContainer::OnCreated(nsIXTFXMLVisualWrapper *aWrapper)

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

@ -79,6 +79,11 @@ nsXFormsHintHelpListener::HandleEvent(nsIDOMEvent* aEvent)
return NS_OK;
}
NS_IMPL_ISUPPORTS_INHERITED2(nsXFormsControlStub,
nsXFormsXMLVisualStub,
nsIXFormsContextControl,
nsIXFormsControl)
NS_IMETHODIMP
nsXFormsControlStub::GetBoundNode(nsIDOMNode **aBoundNode)
{
@ -374,3 +379,39 @@ nsXFormsControlStub::AttributeSet(nsIAtom *aName, const nsAString &aValue)
return NS_OK;
}
// nsIXFormsContextControl
NS_IMETHODIMP
nsXFormsControlStub::SetContextNode(nsIDOMNode *aContextNode)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXFormsControlStub::GetContext(nsAString &aModelID,
nsIDOMNode **aContextNode,
PRInt32 *aContextPosition,
PRInt32 *aContextSize)
{
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;
}

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

@ -64,13 +64,17 @@ class nsIXTFXMLVisualWrapper;
* It also inherits from nsXFormsXMLVisualStub, and overrides a couple of its
* functions.
*
* @todo nsIXFormsContextControl-stub should probably also be included here
* (mBoundNode is in fact also the context) (XXX)
* @bug If a control has a model attribute, but no binding attributes we fail
* to set this as the context for children. We need to return the contextnode
* from EvaluateNodeBinding in that case, and return that in GetContext(). (XXX)
* @see http://bugzilla.mozilla.org/show_bug.cgi?id=280366
*/
class nsXFormsControlStub : public nsIXFormsControl,
public nsXFormsXMLVisualStub
{
public:
NS_DECL_ISUPPORTS_INHERITED
/** The standard notification flags set on nsIXTFElement */
const PRUint32 kStandardNotificationMask;
/**
@ -99,6 +103,9 @@ public:
NS_IMETHOD ParentChanged(nsIDOMElement *aNewParent);
NS_IMETHOD WillSetAttribute(nsIAtom *aName, const nsAString &aValue);
NS_IMETHOD AttributeSet(nsIAtom *aName, const nsAString &aValue);
// nsIXFormsContextControl
NS_DECL_NSIXFORMSCONTEXTCONTROL
/** Constructor */
nsXFormsControlStub() :

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

@ -51,7 +51,6 @@
#include "nsIXTFXMLVisualWrapper.h"
#include "nsXFormsControlStub.h"
#include "nsIXFormsContextControl.h"
#include "nsIModelElementPrivate.h"
#include "nsXFormsUtils.h"
@ -67,34 +66,19 @@
* @todo If a \<label\> is the first element child for \<group\> it is the
* label for the entire group
*
* @todo "Setting the input focus on a group results in the focus being set to
* the first form control in the navigation order within that group."
* (spec. 9.1.1)
*
* @bug If a group only has a model attribute, the group fails to set this for
* children, as it is impossible to distinguish between a failure and absence
* of binding attributes when calling ProcessNodeBinding().
* @todo With some small adjustments we could let nsXFormsContextContainer
* implement group, and get rid of this class (XXX).
*/
class nsXFormsGroupElement : public nsXFormsControlStub,
public nsIXFormsContextControl
class nsXFormsGroupElement : public nsXFormsControlStub
{
protected:
/** Tries to focus a child form control.*/
PRBool TryFocusChildControl(nsIDOMNode* aParent);
PRBool TryFocusChildControl(nsIDOMNode *aParent);
/** The UI HTML element used to represent the tag */
nsCOMPtr<nsIDOMHTMLDivElement> mHTMLElement;
/** The current ID of the model node is bound to */
nsString mModelID;
public:
NS_DECL_ISUPPORTS_INHERITED
// Constructor
nsXFormsGroupElement();
~nsXFormsGroupElement();
// nsIXTFXMLVisual overrides
NS_IMETHOD OnCreated(nsIXTFXMLVisualWrapper *aWrapper);
@ -106,31 +90,10 @@ public:
NS_IMETHOD OnDestroyed();
// nsIXFormsControl
NS_IMETHOD Bind();
NS_IMETHOD Refresh();
NS_IMETHOD TryFocus(PRBool* aOK);
// nsIXFormsContextControl
NS_DECL_NSIXFORMSCONTEXTCONTROL
NS_IMETHOD TryFocus(PRBool *aOK);
};
NS_IMPL_ISUPPORTS_INHERITED2(nsXFormsGroupElement,
nsXFormsXMLVisualStub,
nsIXFormsControl,
nsIXFormsContextControl)
MOZ_DECL_CTOR_COUNTER(nsXFormsGroupElement)
nsXFormsGroupElement::nsXFormsGroupElement()
{
MOZ_COUNT_CTOR(nsXFormsGroupElement);
}
nsXFormsGroupElement::~nsXFormsGroupElement()
{
MOZ_COUNT_DTOR(nsXFormsGroupElement);
}
// nsIXTFXMLVisual
NS_IMETHODIMP
nsXFormsGroupElement::OnCreated(nsIXTFXMLVisualWrapper *aWrapper)
@ -182,22 +145,6 @@ nsXFormsGroupElement::OnDestroyed()
// nsIXFormsControl
NS_IMETHODIMP
nsXFormsGroupElement::Bind()
{
mModelID.Truncate();
// Re-evaluate what instance node this element is bound to.
ResetBoundNode();
// Get model ID
nsCOMPtr<nsIDOMElement> modelElement = do_QueryInterface(mModel);
NS_ENSURE_TRUE(modelElement, NS_ERROR_FAILURE);
modelElement->GetAttribute(NS_LITERAL_STRING("id"), mModelID);
return NS_OK;
}
NS_IMETHODIMP
nsXFormsGroupElement::Refresh()
{
@ -250,35 +197,6 @@ nsXFormsGroupElement::TryFocus(PRBool* aOK)
return NS_OK;
}
// nsIXFormsContextControl
NS_IMETHODIMP
nsXFormsGroupElement::SetContextNode(nsIDOMNode *aContextNode)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
nsXFormsGroupElement::GetContext(nsAString& aModelID,
nsIDOMNode **aContextNode,
PRInt32 *aContextPosition,
PRInt32 *aContextSize)
{
#ifdef DEBUG_XF_GROUP
printf("nsXFormsGroupElement::GetContext()\n");
#endif
NS_ENSURE_ARG(aContextSize);
NS_ENSURE_ARG(aContextPosition);
*aContextPosition = 1;
*aContextSize = 1;
if (mBoundNode && aContextNode)
CallQueryInterface(mBoundNode, aContextNode); // addrefs
aModelID = mModelID;
return NS_OK;
}
// Factory
NS_HIDDEN_(nsresult)
NS_NewXFormsGroupElement(nsIXTFElement **aResult)

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

@ -111,9 +111,8 @@ private:
PRBool mIncremental;
};
NS_IMPL_ISUPPORTS_INHERITED3(nsXFormsInputElement,
nsXFormsXMLVisualStub,
nsIXFormsControl,
NS_IMPL_ISUPPORTS_INHERITED2(nsXFormsInputElement,
nsXFormsControlStub,
nsIDOMFocusListener,
nsIDOMEventListener)

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

@ -55,8 +55,6 @@
class nsXFormsLabelElement : public nsXFormsControlStub
{
public:
NS_DECL_ISUPPORTS_INHERITED
// nsIXFormsControl
NS_IMETHOD Refresh();
@ -79,10 +77,6 @@ private:
nsCOMPtr<nsIDOMElement> mInnerSpan;
};
NS_IMPL_ISUPPORTS_INHERITED1(nsXFormsLabelElement,
nsXFormsXMLVisualStub,
nsIXFormsControl)
NS_IMETHODIMP
nsXFormsLabelElement::OnCreated(nsIXTFXMLVisualWrapper *aWrapper)
{

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

@ -68,8 +68,6 @@
class nsXFormsOutputElement : public nsXFormsControlStub
{
public:
NS_DECL_ISUPPORTS_INHERITED
// nsIXTFXMLVisual overrides
NS_IMETHOD OnCreated(nsIXTFXMLVisualWrapper *aWrapper);
@ -93,10 +91,6 @@ private:
PRBool mHasBinding;
};
NS_IMPL_ISUPPORTS_INHERITED1(nsXFormsOutputElement,
nsXFormsXMLVisualStub,
nsIXFormsControl)
// nsIXTFXMLVisual
NS_IMETHODIMP

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

@ -143,8 +143,6 @@ protected:
const PRUint16 aType);
public:
NS_DECL_ISUPPORTS_INHERITED
// nsIXTFXMLVisual overrides
NS_IMETHOD OnCreated(nsIXTFXMLVisualWrapper *aWrapper);
@ -166,11 +164,6 @@ public:
nsXFormsRepeatElement() : mAddingChildren(PR_FALSE) {};
};
NS_IMPL_ISUPPORTS_INHERITED1(nsXFormsRepeatElement,
nsXFormsXMLVisualStub,
nsIXFormsControl)
// nsIXTFXMLVisual
NS_IMETHODIMP
nsXFormsRepeatElement::OnCreated(nsIXTFXMLVisualWrapper *aWrapper)
@ -450,7 +443,9 @@ nsXFormsRepeatElement::TryFocus(PRBool* aOK)
* only live here until this is implemented there. (XXX)
*/
nsresult
nsXFormsRepeatElement::GetIntAttr(const nsAString& aName, PRInt32* aVal, const PRUint16 aType)
nsXFormsRepeatElement::GetIntAttr(const nsAString &aName,
PRInt32 *aVal,
const PRUint16 aType)
{
nsresult rv = NS_OK;

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

@ -95,9 +95,8 @@ private:
nsVoidArray mOptions;
};
NS_IMPL_ISUPPORTS_INHERITED2(nsXFormsSelectElement,
nsXFormsXMLVisualStub,
nsIXFormsControl,
NS_IMPL_ISUPPORTS_INHERITED1(nsXFormsSelectElement,
nsXFormsControlStub,
nsIDOMEventListener)
// nsIXTFXMLVisual

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

@ -55,29 +55,25 @@
#include "nsIModelElementPrivate.h"
#include "nsIXFormsSwitchElement.h"
#include "nsIXFormsCaseElement.h"
#include "nsIXFormsContextControl.h"
/**
* Implementation of the XForms \<switch\> element.
*
* @see http://www.w3.org/TR/xforms/slice9.html#id2631571
*
* The implementation of the context control is based on
* nsXFormsGroupElement.
*/
class nsXFormsSwitchElement : public nsIXFormsSwitchElement,
public nsIXFormsContextControl,
public nsXFormsControlStub
{
public:
nsXFormsSwitchElement();
nsXFormsSwitchElement() : mAddingChildren(PR_FALSE) {}
NS_DECL_ISUPPORTS_INHERITED
NS_IMETHOD ChildInserted(nsIDOMNode *aChild, PRUint32 aIndex);
NS_IMETHOD ChildAppended(nsIDOMNode *aChild);
NS_IMETHOD WillRemoveChild(PRUint32 aIndex);
NS_IMETHOD BeginAddingChildren();
NS_IMETHOD DoneAddingChildren();
NS_IMETHOD OnDestroyed();
@ -88,11 +84,8 @@ public:
NS_DECL_NSIXFORMSSWITCHELEMENT
// nsIXFormsControl
NS_IMETHOD Bind();
NS_IMETHOD Refresh();
NS_DECL_NSIXFORMSCONTEXTCONTROL
private:
/**
* http://www.w3.org/TR/xforms/slice9.html#ui-case
@ -120,19 +113,13 @@ private:
nsCOMPtr<nsIDOMElement> mVisual;
nsCOMPtr<nsIDOMElement> mSelected;
PRBool mDoneAddingChildren;
nsString mModelID;
PRBool mAddingChildren;
};
nsXFormsSwitchElement::nsXFormsSwitchElement() : mDoneAddingChildren(PR_FALSE)
{
}
NS_IMPL_ISUPPORTS_INHERITED3(nsXFormsSwitchElement,
nsXFormsXMLVisualStub,
nsIXFormsSwitchElement,
nsIXFormsControl,
nsIXFormsContextControl)
NS_IMPL_ISUPPORTS_INHERITED1(nsXFormsSwitchElement,
nsXFormsControlStub,
nsIXFormsSwitchElement)
NS_IMETHODIMP
nsXFormsSwitchElement::OnCreated(nsIXTFXMLVisualWrapper *aWrapper)
@ -141,6 +128,7 @@ nsXFormsSwitchElement::OnCreated(nsIXTFXMLVisualWrapper *aWrapper)
NS_ENSURE_SUCCESS(rv, rv);
aWrapper->SetNotificationMask(kStandardNotificationMask |
nsIXTFElement::NOTIFY_BEGIN_ADDING_CHILDREN |
nsIXTFElement::NOTIFY_DONE_ADDING_CHILDREN |
nsIXTFElement::NOTIFY_CHILD_APPENDED |
nsIXTFElement::NOTIFY_CHILD_INSERTED |
@ -183,7 +171,7 @@ nsXFormsSwitchElement::OnDestroyed()
NS_IMETHODIMP
nsXFormsSwitchElement::ChildInserted(nsIDOMNode *aChild, PRUint32 aIndex)
{
if (mDoneAddingChildren)
if (!mAddingChildren)
CaseChanged(aChild, PR_FALSE);
return NS_OK;
}
@ -191,7 +179,7 @@ nsXFormsSwitchElement::ChildInserted(nsIDOMNode *aChild, PRUint32 aIndex)
NS_IMETHODIMP
nsXFormsSwitchElement::ChildAppended(nsIDOMNode *aChild)
{
if (mDoneAddingChildren)
if (!mAddingChildren)
CaseChanged(aChild, PR_FALSE);
return NS_OK;
}
@ -199,7 +187,7 @@ nsXFormsSwitchElement::ChildAppended(nsIDOMNode *aChild)
NS_IMETHODIMP
nsXFormsSwitchElement::WillRemoveChild(PRUint32 aIndex)
{
if (mDoneAddingChildren) {
if (!mAddingChildren) {
nsCOMPtr<nsIDOMNodeList> list;
mElement->GetChildNodes(getter_AddRefs(list));
if (list) {
@ -211,6 +199,13 @@ nsXFormsSwitchElement::WillRemoveChild(PRUint32 aIndex)
return NS_OK;
}
NS_IMETHODIMP
nsXFormsSwitchElement::BeginAddingChildren()
{
mAddingChildren = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsXFormsSwitchElement::DoneAddingChildren()
{
@ -218,29 +213,13 @@ nsXFormsSwitchElement::DoneAddingChildren()
return NS_OK;
Init();
mDoneAddingChildren = PR_TRUE;
mAddingChildren = PR_FALSE;
Refresh();
return NS_OK;
}
// nsIXFormsControl
NS_IMETHODIMP
nsXFormsSwitchElement::Bind()
{
mModelID.Truncate();
// Re-evaluate what instance node this element is bound to.
ResetBoundNode();
// Get model ID
nsCOMPtr<nsIDOMElement> modelElement = do_QueryInterface(mModel);
NS_ENSURE_TRUE(modelElement, NS_ERROR_FAILURE);
modelElement->GetAttribute(NS_LITERAL_STRING("id"), mModelID);
return NS_OK;
}
NS_IMETHODIMP
nsXFormsSwitchElement::Refresh()
{
@ -249,36 +228,6 @@ nsXFormsSwitchElement::Refresh()
// nsXFormsSwitchElement
NS_IMETHODIMP
nsXFormsSwitchElement::SetContextNode(nsIDOMNode *aContextNode)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
nsXFormsSwitchElement::GetContext(nsAString& aModelID,
nsIDOMNode **aContextNode,
PRInt32 *aContextPosition,
PRInt32 *aContextSize)
{
NS_ENSURE_ARG(aContextSize);
NS_ENSURE_ARG(aContextPosition);
/** @todo Not too elegant to call Process() here, but DoneAddingChildren is,
* logically, called on children before us. We need a notification
* that goes from the document node and DOWN, where the controls
* should Refresh().
*/
*aContextPosition = 1;
*aContextSize = 1;
if (mBoundNode && aContextNode)
CallQueryInterface(mBoundNode, aContextNode); // addrefs
aModelID = mModelID;
return NS_OK;
}
void
nsXFormsSwitchElement::Init(nsIDOMElement* aDeselected)
{

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

@ -52,8 +52,6 @@
class nsXFormsTriggerElement : public nsXFormsControlStub
{
public:
NS_DECL_ISUPPORTS_INHERITED
// nsIXTFXMLVisual overrides
NS_IMETHOD OnCreated(nsIXTFXMLVisualWrapper *aWrapper);
@ -69,10 +67,6 @@ protected:
nsCOMPtr<nsIDOMHTMLButtonElement> mButton;
};
NS_IMPL_ISUPPORTS_INHERITED1(nsXFormsTriggerElement,
nsXFormsXMLVisualStub,
nsIXFormsControl)
// nsIXTFXMLVisual
NS_IMETHODIMP

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

@ -102,9 +102,8 @@ private:
nsCOMPtr<nsIDOMHTMLInputElement> mInput;
};
NS_IMPL_ISUPPORTS_INHERITED3(nsXFormsUploadElement,
nsXFormsXMLVisualStub,
nsIXFormsControl,
NS_IMPL_ISUPPORTS_INHERITED2(nsXFormsUploadElement,
nsXFormsControlStub,
nsIDOMFocusListener,
nsIDOMEventListener)

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

@ -316,7 +316,6 @@ nsXFormsUtils::GetModel(nsIDOMElement *aElement,
PRUint32 aElementFlags)
{
nsCOMPtr<nsIModelElementPrivate> model;
nsCOMPtr<nsIDOMNode> contextNode;
nsCOMPtr<nsIDOMElement> bind;
@ -820,12 +819,15 @@ nsXFormsUtils::FindParentContext(nsIDOMElement *aElement,
nsAutoString contextModelID;
while (curNode) {
nsCOMPtr<nsIXFormsContextControl> contextControl = do_QueryInterface(curNode);
nsCOMPtr<nsIDOMElement> cElement = do_QueryInterface(curNode);
if (contextControl && cElement) {
if (contextControl) {
PRInt32 cSize;
PRInt32 cPosition;
nsCOMPtr<nsIDOMNode> tempNode;
rv = contextControl->GetContext(contextModelID, getter_AddRefs(tempNode), &cPosition, &cSize);
rv = contextControl->GetContext(contextModelID,
getter_AddRefs(tempNode),
&cPosition,
&cSize);
NS_ENSURE_SUCCESS(rv, rv);
// If the call failed, it means that we _have_ a parent which sets the
// context but it is invalid, ie. the XPath expression could have