mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 1154183 part.4 Implement nsXBLWindowKeyHandler::GetElementForHandler() r=smaug
MozReview-Commit-ID: 9qsOLU3QCnr
This commit is contained in:
parent
77166dd790
commit
d62ef1ba67
@ -597,35 +597,9 @@ nsXBLWindowKeyHandler::WalkHandlersAndExecute(
|
||||
// Before executing this handler, check that it's not disabled,
|
||||
// and that it has something to do (oncommand of the <key> or its
|
||||
// <command> is non-empty).
|
||||
nsCOMPtr<nsIContent> keyContent = handler->GetHandlerElement();
|
||||
nsCOMPtr<Element> commandElement;
|
||||
|
||||
// See if we're in a XUL doc.
|
||||
nsCOMPtr<Element> chromeHandlerElement = GetElement();
|
||||
if (chromeHandlerElement && keyContent) {
|
||||
// We are. Obtain our command attribute.
|
||||
nsAutoString command;
|
||||
keyContent->GetAttr(kNameSpaceID_None, nsGkAtoms::command, command);
|
||||
if (!command.IsEmpty()) {
|
||||
// Locate the command element in question. Note that we
|
||||
// know "keyContent" is in a doc if we're dealing with it here.
|
||||
NS_ASSERTION(keyContent->IsInDoc(),
|
||||
"the key element must be in document");
|
||||
nsIDocument* doc = keyContent->GetCurrentDoc();
|
||||
if (doc) {
|
||||
commandElement = do_QueryInterface(doc->GetElementById(command));
|
||||
}
|
||||
|
||||
if (!commandElement) {
|
||||
NS_ERROR("A XUL <key> is observing a command that doesn't exist. "
|
||||
"Unable to execute key binding!");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!commandElement) {
|
||||
commandElement = do_QueryInterface(keyContent);
|
||||
if (!GetElementForHandler(handler, getter_AddRefs(commandElement))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (commandElement) {
|
||||
@ -653,6 +627,7 @@ nsXBLWindowKeyHandler::WalkHandlersAndExecute(
|
||||
}
|
||||
|
||||
nsCOMPtr<EventTarget> target;
|
||||
nsCOMPtr<Element> chromeHandlerElement = GetElement();
|
||||
if (chromeHandlerElement) {
|
||||
target = commandElement;
|
||||
} else {
|
||||
@ -722,6 +697,49 @@ nsXBLWindowKeyHandler::GetElement(bool* aIsDisabled)
|
||||
return element.forget();
|
||||
}
|
||||
|
||||
bool
|
||||
nsXBLWindowKeyHandler::GetElementForHandler(nsXBLPrototypeHandler* aHandler,
|
||||
Element** aElementForHandler)
|
||||
{
|
||||
MOZ_ASSERT(aElementForHandler);
|
||||
*aElementForHandler = nullptr;
|
||||
|
||||
nsCOMPtr<nsIContent> keyContent = aHandler->GetHandlerElement();
|
||||
|
||||
// See if we're in a XUL doc.
|
||||
nsCOMPtr<Element> chromeHandlerElement = GetElement();
|
||||
if (chromeHandlerElement && keyContent) {
|
||||
// We are. Obtain our command attribute.
|
||||
nsAutoString command;
|
||||
keyContent->GetAttr(kNameSpaceID_None, nsGkAtoms::command, command);
|
||||
if (!command.IsEmpty()) {
|
||||
// Locate the command element in question. Note that we
|
||||
// know "keyContent" is in a doc if we're dealing with it here.
|
||||
NS_ASSERTION(keyContent->IsInDoc(),
|
||||
"the key element must be in document");
|
||||
nsIDocument* doc = keyContent->GetCurrentDoc();
|
||||
if (NS_WARN_IF(!doc)) {
|
||||
return false;
|
||||
}
|
||||
nsCOMPtr<Element> commandElement =
|
||||
do_QueryInterface(doc->GetElementById(command));
|
||||
if (!commandElement) {
|
||||
NS_ERROR("A XUL <key> is observing a command that doesn't exist. "
|
||||
"Unable to execute key binding!");
|
||||
return false;
|
||||
}
|
||||
commandElement.swap(*aElementForHandler);
|
||||
}
|
||||
}
|
||||
|
||||
if (!*aElementForHandler) {
|
||||
nsCOMPtr<Element> keyElement = do_QueryInterface(keyContent);
|
||||
keyElement.swap(*aElementForHandler);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
already_AddRefed<nsXBLWindowKeyHandler>
|
||||
|
@ -90,6 +90,19 @@ protected:
|
||||
// whether the disabled attribute is set on the element (assuming the element
|
||||
// is non-null).
|
||||
already_AddRefed<mozilla::dom::Element> GetElement(bool* aIsDisabled = nullptr);
|
||||
|
||||
/**
|
||||
* GetElementForHandler() retrieves an element for the handler. The element
|
||||
* may be a command element or a key element.
|
||||
*
|
||||
* @param aHandler The handler.
|
||||
* @param aElementForHandler Must not be nullptr. The element is returned to
|
||||
* this.
|
||||
* @return true if the handler is valid. Otherwise, false.
|
||||
*/
|
||||
bool GetElementForHandler(nsXBLPrototypeHandler* aHandler,
|
||||
mozilla::dom::Element** aElementForHandler);
|
||||
|
||||
// Using weak pointer to the DOM Element.
|
||||
nsWeakPtr mWeakPtrForElement;
|
||||
mozilla::dom::EventTarget* mTarget; // weak ref
|
||||
|
Loading…
Reference in New Issue
Block a user