Bug 807465 - Less QIs in nsXULPopupManager::UpdateMenuItems; r=Enn

This commit is contained in:
Ms2ger 2012-11-04 09:05:25 +01:00
Родитель b903541457
Коммит 4dd22ae85f
1 изменённых файлов: 13 добавлений и 12 удалений

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

@ -35,8 +35,9 @@
#include "nsPIWindowRoot.h"
#include "nsFrameManager.h"
#include "nsIObserverService.h"
#include "mozilla/Services.h"
#include "mozilla/dom/Element.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/Services.h"
using namespace mozilla;
@ -1612,9 +1613,10 @@ nsXULPopupManager::UpdateMenuItems(nsIContent* aPopup)
// Walk all of the menu's children, checking to see if any of them has a
// command attribute. If so, then several attributes must potentially be updated.
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(aPopup->GetDocument()));
if (!domDoc)
nsCOMPtr<nsIDocument> document = aPopup->GetCurrentDoc();
if (!document) {
return;
}
for (nsCOMPtr<nsIContent> grandChild = aPopup->GetFirstChild();
grandChild;
@ -1625,13 +1627,12 @@ nsXULPopupManager::UpdateMenuItems(nsIContent* aPopup)
grandChild->GetAttr(kNameSpaceID_None, nsGkAtoms::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) {
nsRefPtr<dom::Element> commandElement =
document->GetElementById(command);
if (commandElement) {
nsAutoString commandValue;
// The menu's disabled state needs to be updated to match the command.
if (commandContent->GetAttr(kNameSpaceID_None, nsGkAtoms::disabled, commandValue))
if (commandElement->GetAttr(kNameSpaceID_None, nsGkAtoms::disabled, commandValue))
grandChild->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled, commandValue, true);
else
grandChild->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, true);
@ -1639,16 +1640,16 @@ nsXULPopupManager::UpdateMenuItems(nsIContent* aPopup)
// The menu's label, accesskey checked and hidden states need 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 (commandContent->GetAttr(kNameSpaceID_None, nsGkAtoms::label, commandValue))
if (commandElement->GetAttr(kNameSpaceID_None, nsGkAtoms::label, commandValue))
grandChild->SetAttr(kNameSpaceID_None, nsGkAtoms::label, commandValue, true);
if (commandContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, commandValue))
if (commandElement->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, commandValue))
grandChild->SetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, commandValue, true);
if (commandContent->GetAttr(kNameSpaceID_None, nsGkAtoms::checked, commandValue))
if (commandElement->GetAttr(kNameSpaceID_None, nsGkAtoms::checked, commandValue))
grandChild->SetAttr(kNameSpaceID_None, nsGkAtoms::checked, commandValue, true);
if (commandContent->GetAttr(kNameSpaceID_None, nsGkAtoms::hidden, commandValue))
if (commandElement->GetAttr(kNameSpaceID_None, nsGkAtoms::hidden, commandValue))
grandChild->SetAttr(kNameSpaceID_None, nsGkAtoms::hidden, commandValue, true);
}
}