Bug 302497 - selected attribute on case element should only determine initial state. r=doronr/allan, a=mkaply. Not part of default build.

This commit is contained in:
pedemont%us.ibm.com 2005-08-11 16:15:17 +00:00
Родитель 771750aae1
Коммит 199a95782c
3 изменённых файлов: 39 добавлений и 42 удалений

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

@ -41,9 +41,18 @@
/**
* Interface implemented by the case element.
*/
[scriptable, uuid(7dd9c79b-5fa2-4a0a-8aa7-f2629281c743)]
[scriptable, uuid(28c8c223-ca17-4b58-b3ca-189864eefe32)]
interface nsIXFormsCaseElement : nsISupports
{
/**
* According to the XForms 1.0 Errata, the "selected" attribute only
* determines the initial selected state. This provides
* access to the initial state of the "selected" attribute, since it can
* be programmatically changed via the DOM.
* (see http://www.w3.org/2003/10/REC-xforms-10-20031014-errata.html#E25b)
*/
readonly attribute boolean initialSelectedState;
/**
* Used by switch elements to mark case element selected or deselected.
*/

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

@ -60,19 +60,16 @@ public:
NS_IMETHOD OnCreated(nsIXTFBindableElementWrapper *aWrapper);
NS_IMETHOD OnDestroyed();
NS_IMETHOD BeginAddingChildren();
NS_IMETHOD DoneAddingChildren();
NS_IMETHOD AttributeSet(nsIAtom *aName, const nsAString &aNewValue);
nsXFormsCaseElement()
: mElement(nsnull), mDoneAddingChildren(PR_TRUE), mSelected(PR_FALSE)
: mElement(nsnull), mSelected(PR_FALSE), mCachedSelectedAttr(PR_FALSE)
{
}
protected:
nsIDOMElement* mElement;
PRPackedBool mDoneAddingChildren;
PRPackedBool mSelected;
PRPackedBool mCachedSelectedAttr;
};
NS_IMPL_ISUPPORTS_INHERITED1(nsXFormsCaseElement,
@ -85,10 +82,6 @@ nsXFormsCaseElement::OnCreated(nsIXTFBindableElementWrapper *aWrapper)
nsresult rv = nsXFormsBindableStub::OnCreated(aWrapper);
NS_ENSURE_SUCCESS(rv, rv);
aWrapper->SetNotificationMask(nsIXTFElement::NOTIFY_ATTRIBUTE_SET |
nsIXTFElement::NOTIFY_BEGIN_ADDING_CHILDREN |
nsIXTFElement::NOTIFY_DONE_ADDING_CHILDREN);
nsCOMPtr<nsIDOMElement> node;
aWrapper->GetElementNode(getter_AddRefs(node));
@ -109,30 +102,9 @@ nsXFormsCaseElement::OnDestroyed()
}
NS_IMETHODIMP
nsXFormsCaseElement::BeginAddingChildren()
nsXFormsCaseElement::GetInitialSelectedState(PRBool *aInitialSelectedState)
{
mDoneAddingChildren = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
nsXFormsCaseElement::DoneAddingChildren()
{
mDoneAddingChildren = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsXFormsCaseElement::AttributeSet(nsIAtom *aName, const nsAString &aNewValue)
{
if (mDoneAddingChildren && mElement && aName == nsXFormsAtoms::selected) {
nsCOMPtr<nsIDOMNode> parent;
mElement->GetParentNode(getter_AddRefs(parent));
nsCOMPtr<nsIXFormsSwitchElement> switchEl(do_QueryInterface(parent));
if (switchEl)
switchEl->SetSelected(mElement, aNewValue.EqualsLiteral("true"));
}
*aInitialSelectedState = mCachedSelectedAttr;
return NS_OK;
}
@ -152,6 +124,13 @@ nsXFormsCaseElement::SetSelected(PRBool aEnable)
NS_IMETHODIMP
nsXFormsCaseElement::WidgetAttached()
{
// cache the value of the "selected" attr
nsAutoString value;
mElement->GetAttribute(NS_LITERAL_STRING("selected"), value);
if (value.EqualsLiteral("true") || value.EqualsLiteral("1")) {
mCachedSelectedAttr = PR_TRUE;
}
nsCOMPtr<nsIXFormsCaseUIElement> caseUI(do_QueryInterface(mElement));
if (caseUI) {
caseUI->CaseSelected(mSelected);

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

@ -209,14 +209,19 @@ nsXFormsSwitchElement::FindFirstSelectedCase(nsIDOMElement* aDeselected)
if (nsXFormsUtils::IsXFormsElement(child, NS_LITERAL_STRING("case"))) {
if (!firstCase)
firstCase = childElement;
nsAutoString selected;
childElement->GetAttribute(NS_LITERAL_STRING("selected"), selected);
if (selected.EqualsLiteral("true")) {
firstCase = childElement;
break;
nsCOMPtr<nsIXFormsCaseElement> caseElem(do_QueryInterface(child));
if (caseElem) {
PRBool selected;
caseElem->GetInitialSelectedState(&selected);
if (selected) {
firstCase = childElement;
break;
}
}
}
}
nsCOMPtr<nsIDOMNode> tmp;
child->GetNextSibling(getter_AddRefs(tmp));
child.swap(tmp);
@ -364,10 +369,14 @@ nsXFormsSwitchElement::CaseChanged(nsIDOMNode* aCase, PRBool aRemoved)
if (!nsXFormsUtils::IsXFormsElement(aCase, NS_LITERAL_STRING("case")))
return;
nsAutoString sel;
element->GetAttribute(NS_LITERAL_STRING("selected"), sel);
if (sel.EqualsLiteral("true"))
SetSelected(element, PR_TRUE);
nsCOMPtr<nsIXFormsCaseElement> caseElem(do_QueryInterface(element));
if (caseElem) {
PRBool selected;
caseElem->GetInitialSelectedState(&selected);
if (selected) {
SetSelected(element, PR_TRUE);
}
}
}
NS_IMETHODIMP