Fix for 71740. r=jag, sr=shaver

This commit is contained in:
hyatt%netscape.com 2001-03-21 08:15:49 +00:00
Родитель 3718b9dfae
Коммит 48541117d5
2 изменённых файлов: 120 добавлений и 1 удалений

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

@ -1381,7 +1381,23 @@ nsMenuFrame::Execute()
nsIFrame* me = this;
if (NS_SUCCEEDED(result) && shell) {
shell->GetViewManager(getter_AddRefs(kungFuDeathGrip));
shell->HandleDOMEventWithTarget(mContent, &event, &status);
// See if we have a command elt. If so, we execute on the command instead
// of on our content element.
nsAutoString command;
mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::command, command);
if (!command.IsEmpty()) {
nsCOMPtr<nsIDocument> doc;
mContent->GetDocument(*getter_AddRefs(doc));
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(doc));
nsCOMPtr<nsIDOMElement> commandElt;
domDoc->GetElementById(command, getter_AddRefs(commandElt));
nsCOMPtr<nsIContent> commandContent(do_QueryInterface(commandElt));
if (commandContent)
shell->HandleDOMEventWithTarget(commandContent, &event, &status);
}
else
shell->HandleDOMEventWithTarget(mContent, &event, &status);
}
// XXX HACK. Just gracefully exit if the node has been removed, e.g., window.close()
@ -1434,6 +1450,58 @@ nsMenuFrame::OnCreate()
if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
return PR_FALSE;
// The menu is going to show, and the create handler has executed.
// We should now walk all of our menu item children, checking to see if any
// of them has a command attribute. If so, then several attributes must
// potentially be updated.
if (child) {
nsCOMPtr<nsIDocument> doc;
child->GetDocument(*getter_AddRefs(doc));
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(doc));
PRInt32 count;
child->ChildCount(count);
for (PRInt32 i = 0; i < count; i++) {
nsCOMPtr<nsIContent> grandChild;
child->ChildAt(i, *getter_AddRefs(grandChild));
nsCOMPtr<nsIAtom> tag;
grandChild->GetTag(*getter_AddRefs(tag));
if (tag.get() == nsXULAtoms::menuitem) {
// See if we have a command attribute.
nsAutoString command;
grandChild->GetAttribute(kNameSpaceID_None, nsXULAtoms::command, command);
if (!command.IsEmpty()) {
// We do! Look it up in our document
nsCOMPtr<nsIDOMElement> commandElt;
domDoc->GetElementById(command, getter_AddRefs(commandElt));
nsCOMPtr<nsIContent> commandContent(do_QueryInterface(commandElt));
nsAutoString commandDisabled, menuDisabled;
commandContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, commandDisabled);
grandChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, menuDisabled);
if (!commandDisabled.Equals(menuDisabled)) {
// The menu's disabled state needs to be updated to match the command.
if (commandDisabled.IsEmpty())
grandChild->UnsetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, PR_TRUE);
else grandChild->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, commandDisabled, PR_TRUE);
}
nsAutoString commandValue, menuValue;
commandContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, commandValue);
grandChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, menuValue);
if (!commandValue.Equals(menuValue)) {
// The menu's value state needs to be updated to match the command.
// Note that (unlike the disabled state) if the command has *no* value, we
// assume the menu is supplying its own.
if (!commandValue.IsEmpty())
grandChild->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, commandValue, PR_TRUE);
}
}
}
}
}
return PR_TRUE;
}

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

@ -634,8 +634,59 @@ nsPopupSetFrame::OnCreate(nsIContent* aPopupContent)
if (NS_SUCCEEDED(rv) && shell) {
rv = shell->HandleDOMEventWithTarget(aPopupContent, &event, &status);
}
if ( NS_FAILED(rv) || status == nsEventStatus_eConsumeNoDefault )
return PR_FALSE;
// The menu is going to show, and the create handler has executed.
// We should now walk all of our menu item children, checking to see if any
// of them has a command attribute. If so, then several attributes must
// potentially be updated.
nsCOMPtr<nsIDocument> doc;
aPopupContent->GetDocument(*getter_AddRefs(doc));
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(doc));
PRInt32 count;
aPopupContent->ChildCount(count);
for (PRInt32 i = 0; i < count; i++) {
nsCOMPtr<nsIContent> grandChild;
aPopupContent->ChildAt(i, *getter_AddRefs(grandChild));
nsCOMPtr<nsIAtom> tag;
grandChild->GetTag(*getter_AddRefs(tag));
if (tag.get() == nsXULAtoms::menuitem) {
// See if we have a command attribute.
nsAutoString command;
grandChild->GetAttribute(kNameSpaceID_None, nsXULAtoms::command, command);
if (!command.IsEmpty()) {
// We do! Look it up in our document
nsCOMPtr<nsIDOMElement> commandElt;
domDoc->GetElementById(command, getter_AddRefs(commandElt));
nsCOMPtr<nsIContent> commandContent(do_QueryInterface(commandElt));
nsAutoString commandDisabled, menuDisabled;
commandContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, commandDisabled);
grandChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, menuDisabled);
if (!commandDisabled.Equals(menuDisabled)) {
// The menu's disabled state needs to be updated to match the command.
if (commandDisabled.IsEmpty())
grandChild->UnsetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, PR_TRUE);
else grandChild->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, commandDisabled, PR_TRUE);
}
nsAutoString commandValue, menuValue;
commandContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, commandValue);
grandChild->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, menuValue);
if (!commandValue.Equals(menuValue)) {
// The menu's value state needs to be updated to match the command.
// Note that (unlike the disabled state) if the command has *no* value, we
// assume the menu is supplying its own.
if (!commandValue.IsEmpty())
grandChild->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, commandValue, PR_TRUE);
}
}
}
}
}
return PR_TRUE;