Bug 915962 - Part 1: Allow pressing space to scroll the document if an editable element or form control is not focused; r=roc

This commit is contained in:
Ehsan Akhgari 2015-04-18 18:12:18 -04:00
parent ca5f98c8c9
commit a4eed0c51a

View File

@ -23,6 +23,7 @@
#include "nsIDOMHTMLTextAreaElement.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsFocusManager.h"
#include "nsIFormControl.h"
#include "nsIDOMEventListener.h"
#include "nsPIDOMWindow.h"
#include "nsPIWindowRoot.h"
@ -475,34 +476,17 @@ nsXBLPrototypeHandler::DispatchXBLCommand(EventTarget* aTarget, nsIDOMEvent* aEv
nsFocusManager::GetFocusedDescendant(windowToCheck, true, getter_AddRefs(focusedWindow));
}
bool isLink = false;
nsIContent *content = focusedContent;
// If the focus is in an editable region, don't scroll.
if (focusedContent->IsEditable()) {
return NS_OK;
}
// if the focused element is a link then we do want space to
// scroll down. The focused element may be an element in a link,
// we need to check the parent node too. Only do this check if an
// element is focused and has a parent.
if (focusedContent && focusedContent->GetParent()) {
while (content) {
if (content->IsHTMLElement(nsGkAtoms::a)) {
isLink = true;
break;
}
if (content->HasAttr(kNameSpaceID_XLink, nsGkAtoms::type)) {
isLink = content->AttrValueIs(kNameSpaceID_XLink, nsGkAtoms::type,
nsGkAtoms::simple, eCaseMatters);
if (isLink) {
break;
}
}
content = content->GetParent();
}
if (!isLink)
// If the focus is in a form control, don't scroll.
for (nsIContent* c = focusedContent; c; c = c->GetParent()) {
nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(c);
if (formControl) {
return NS_OK;
}
}
}