fix crash in nsMenuX::OnCreate(). b=443455 r=smichaud sr=roc a=ss
git-svn-id: svn://10.0.0.236/trunk@253333 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
5d4b7a3514
commit
042e8aac0c
@ -741,58 +741,65 @@ PRBool nsMenuX::OnCreate()
|
|||||||
// now need to walk our menu items, checking to see if any of them have
|
// now need to walk our menu items, checking to see if any of them have
|
||||||
// a command attribute. If so, several apptributes must potentially
|
// a command attribute. If so, several apptributes must potentially
|
||||||
// be updated.
|
// be updated.
|
||||||
if (popupContent) {
|
|
||||||
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(popupContent->GetDocument()));
|
|
||||||
|
|
||||||
PRUint32 count = popupContent->GetChildCount();
|
// Get new popup content first since it might have changed as a result of the
|
||||||
for (PRUint32 i = 0; i < count; i++) {
|
// NS_XUL_POPUP_SHOWING event above.
|
||||||
nsIContent *grandChild = popupContent->GetChildAt(i);
|
GetMenuPopupContent(getter_AddRefs(popupContent));
|
||||||
if (grandChild->Tag() == nsWidgetAtoms::menuitem) {
|
if (!popupContent)
|
||||||
// See if we have a command attribute.
|
return PR_TRUE;
|
||||||
nsAutoString command;
|
|
||||||
grandChild->GetAttr(kNameSpaceID_None, nsWidgetAtoms::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));
|
|
||||||
|
|
||||||
if (commandContent) {
|
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(popupContent->GetDocument()));
|
||||||
nsAutoString commandDisabled, menuDisabled;
|
if (!domDoc)
|
||||||
commandContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, commandDisabled);
|
return PR_TRUE;
|
||||||
grandChild->GetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, menuDisabled);
|
|
||||||
if (!commandDisabled.Equals(menuDisabled)) {
|
|
||||||
// The menu's disabled state needs to be updated to match the command.
|
|
||||||
if (commandDisabled.IsEmpty())
|
|
||||||
grandChild->UnsetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, PR_TRUE);
|
|
||||||
else
|
|
||||||
grandChild->SetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, commandDisabled, PR_TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The menu's value and checked states need to be updated to match the command.
|
PRUint32 count = popupContent->GetChildCount();
|
||||||
// Note that (unlike the disabled state) if the command has *no* value for either, we
|
for (PRUint32 i = 0; i < count; i++) {
|
||||||
// assume the menu is supplying its own.
|
nsIContent *grandChild = popupContent->GetChildAt(i);
|
||||||
nsAutoString commandChecked, menuChecked;
|
if (grandChild->Tag() == nsWidgetAtoms::menuitem) {
|
||||||
commandContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, commandChecked);
|
// See if we have a command attribute.
|
||||||
grandChild->GetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, menuChecked);
|
nsAutoString command;
|
||||||
if (!commandChecked.Equals(menuChecked)) {
|
grandChild->GetAttr(kNameSpaceID_None, nsWidgetAtoms::command, command);
|
||||||
if (!commandChecked.IsEmpty())
|
if (!command.IsEmpty()) {
|
||||||
grandChild->SetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, commandChecked, PR_TRUE);
|
// We do! Look it up in our document
|
||||||
}
|
nsCOMPtr<nsIDOMElement> commandElt;
|
||||||
|
domDoc->GetElementById(command, getter_AddRefs(commandElt));
|
||||||
nsAutoString commandValue, menuValue;
|
nsCOMPtr<nsIContent> commandContent(do_QueryInterface(commandElt));
|
||||||
commandContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::label, commandValue);
|
|
||||||
grandChild->GetAttr(kNameSpaceID_None, nsWidgetAtoms::label, menuValue);
|
if (commandContent) {
|
||||||
if (!commandValue.Equals(menuValue)) {
|
nsAutoString commandDisabled, menuDisabled;
|
||||||
if (!commandValue.IsEmpty())
|
commandContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, commandDisabled);
|
||||||
grandChild->SetAttr(kNameSpaceID_None, nsWidgetAtoms::label, commandValue, PR_TRUE);
|
grandChild->GetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, menuDisabled);
|
||||||
}
|
if (!commandDisabled.Equals(menuDisabled)) {
|
||||||
|
// The menu's disabled state needs to be updated to match the command.
|
||||||
|
if (commandDisabled.IsEmpty())
|
||||||
|
grandChild->UnsetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, PR_TRUE);
|
||||||
|
else
|
||||||
|
grandChild->SetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, commandDisabled, PR_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The menu's value and checked states need to be updated to match the command.
|
||||||
|
// Note that (unlike the disabled state) if the command has *no* value for either, we
|
||||||
|
// assume the menu is supplying its own.
|
||||||
|
nsAutoString commandChecked, menuChecked;
|
||||||
|
commandContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, commandChecked);
|
||||||
|
grandChild->GetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, menuChecked);
|
||||||
|
if (!commandChecked.Equals(menuChecked)) {
|
||||||
|
if (!commandChecked.IsEmpty())
|
||||||
|
grandChild->SetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, commandChecked, PR_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
nsAutoString commandValue, menuValue;
|
||||||
|
commandContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::label, commandValue);
|
||||||
|
grandChild->GetAttr(kNameSpaceID_None, nsWidgetAtoms::label, menuValue);
|
||||||
|
if (!commandValue.Equals(menuValue)) {
|
||||||
|
if (!commandValue.IsEmpty())
|
||||||
|
grandChild->SetAttr(kNameSpaceID_None, nsWidgetAtoms::label, commandValue, PR_TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return PR_TRUE;
|
return PR_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user