Bug 1154183 part.6 Add nsXBLWindowKeyHandler::IsExecuteableElement() r=smaug

MozReview-Commit-ID: 8FyDzkfHihH
This commit is contained in:
Masayuki Nakano 2016-03-19 23:16:21 +09:00
Родитель 5b0e7ecdae
Коммит ac1b2491bc
2 изменённых файлов: 31 добавлений и 11 удалений

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

@ -603,19 +603,11 @@ nsXBLWindowKeyHandler::WalkHandlersAndExecute(
}
if (commandElement) {
nsAutoString value;
commandElement->GetAttribute(NS_LITERAL_STRING("disabled"), value);
if (value.EqualsLiteral("true")) {
continue; // this handler is disabled, try the next one
if (!IsExecutableElement(commandElement)) {
continue;
}
// Check that there is an oncommand handler
commandElement->GetAttribute(NS_LITERAL_STRING("oncommand"), value);
if (value.IsEmpty()) {
continue; // nothing to do
}
if (aOutReservedForChrome) {
nsAutoString value;
// The caller wants to know if this is a reserved command
commandElement->GetAttribute(NS_LITERAL_STRING("reserved"), value);
*aOutReservedForChrome = value.EqualsLiteral("true");
@ -629,6 +621,7 @@ nsXBLWindowKeyHandler::WalkHandlersAndExecute(
nsCOMPtr<EventTarget> target;
nsCOMPtr<Element> chromeHandlerElement = GetElement();
if (chromeHandlerElement) {
// XXX commandElement may be nullptr...
target = commandElement;
} else {
target = mTarget;
@ -746,6 +739,27 @@ nsXBLWindowKeyHandler::GetElementForHandler(nsXBLPrototypeHandler* aHandler,
return true;
}
bool
nsXBLWindowKeyHandler::IsExecutableElement(Element* aElement) const
{
if (!aElement) {
return false;
}
nsAutoString value;
aElement->GetAttribute(NS_LITERAL_STRING("disabled"), value);
if (value.EqualsLiteral("true")) {
return false;
}
aElement->GetAttribute(NS_LITERAL_STRING("oncommand"), value);
if (value.IsEmpty()) {
return false;
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////
already_AddRefed<nsXBLWindowKeyHandler>

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

@ -103,6 +103,12 @@ protected:
bool GetElementForHandler(nsXBLPrototypeHandler* aHandler,
mozilla::dom::Element** aElementForHandler);
/**
* IsExecutableElement() returns true if aElement is executable.
* Otherwise, false. aElement should be a command element or a key element.
*/
bool IsExecutableElement(mozilla::dom::Element* aElement) const;
// Using weak pointer to the DOM Element.
nsWeakPtr mWeakPtrForElement;
mozilla::dom::EventTarget* mTarget; // weak ref