mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1780199 - Fix accesskey on file input. r=edgar
By not propagating to the inner button. This probably broke with bug 505355 since it made the button not focusable. Differential Revision: https://phabricator.services.mozilla.com/D153321
This commit is contained in:
parent
8deb3ebb31
commit
8cbde5463a
@ -36,6 +36,8 @@
|
||||
<button id="button5" style="display:none" accesskey="1">Button 5</button>
|
||||
<button id="button6" style="display:none" accesskey="2">Button 6</button>
|
||||
<textarea id="textarea1" accesskey="2"></textarea>
|
||||
<!-- Test for file input -->
|
||||
<input type=file id="file" accesskey="f">
|
||||
<script>
|
||||
|
||||
function performAccessKey(aKey) {
|
||||
@ -138,6 +140,21 @@ add_task(async function modifyAccessKey() {
|
||||
await promise;
|
||||
});
|
||||
|
||||
add_task(async function file_picker() {
|
||||
const file = document.getElementById("file");
|
||||
const MockFilePicker = SpecialPowers.MockFilePicker;
|
||||
MockFilePicker.init(window);
|
||||
MockFilePicker.returnValue = MockFilePicker.returnCancel;
|
||||
|
||||
let clicked = false;
|
||||
file.addEventListener("click", function(e) { clicked = true; });
|
||||
|
||||
performAccessKey("f");
|
||||
ok(clicked, "Should've activated the picker");
|
||||
|
||||
MockFilePicker.reset();
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -203,10 +203,8 @@ void nsFileControlFrame::DestroyFrom(nsIFrame* aDestructRoot,
|
||||
nsBlockFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
|
||||
}
|
||||
|
||||
static already_AddRefed<Element> MakeAnonButton(Document* aDoc,
|
||||
const char* labelKey,
|
||||
HTMLInputElement* aInputElement,
|
||||
const nsAString& aAccessKey) {
|
||||
static already_AddRefed<Element> MakeAnonButton(
|
||||
Document* aDoc, const char* labelKey, HTMLInputElement* aInputElement) {
|
||||
RefPtr<Element> button = aDoc->CreateHTMLElement(nsGkAtoms::button);
|
||||
// NOTE: SetIsNativeAnonymousRoot() has to be called before setting any
|
||||
// attribute.
|
||||
@ -218,11 +216,10 @@ static already_AddRefed<Element> MakeAnonButton(Document* aDoc,
|
||||
nsContentUtils::GetMaybeLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
|
||||
labelKey, aDoc, buttonTxt);
|
||||
|
||||
auto* nim = aDoc->NodeInfoManager();
|
||||
// Set the browse button text. It's a bit of a pain to do because we want to
|
||||
// make sure we are not notifying.
|
||||
RefPtr<nsTextNode> textContent = new (button->NodeInfo()->NodeInfoManager())
|
||||
nsTextNode(button->NodeInfo()->NodeInfoManager());
|
||||
|
||||
RefPtr textContent = new (nim) nsTextNode(nim);
|
||||
textContent->SetText(buttonTxt, false);
|
||||
|
||||
IgnoredErrorResult error;
|
||||
@ -231,13 +228,7 @@ static already_AddRefed<Element> MakeAnonButton(Document* aDoc,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Make sure access key and tab order for the element actually redirect to the
|
||||
// file picking button.
|
||||
auto* buttonElement = HTMLButtonElement::FromNode(button);
|
||||
if (!aAccessKey.IsEmpty()) {
|
||||
buttonElement->SetAccessKey(aAccessKey, IgnoreErrors());
|
||||
}
|
||||
|
||||
// We allow tabbing over the input itself, not the button.
|
||||
buttonElement->SetTabIndex(-1, IgnoreErrors());
|
||||
return button.forget();
|
||||
@ -246,17 +237,9 @@ static already_AddRefed<Element> MakeAnonButton(Document* aDoc,
|
||||
nsresult nsFileControlFrame::CreateAnonymousContent(
|
||||
nsTArray<ContentInfo>& aElements) {
|
||||
nsCOMPtr<Document> doc = mContent->GetComposedDoc();
|
||||
RefPtr fileContent = HTMLInputElement::FromNode(mContent);
|
||||
|
||||
RefPtr<HTMLInputElement> fileContent =
|
||||
HTMLInputElement::FromNodeOrNull(mContent);
|
||||
|
||||
// The access key is transferred to the "Choose files..." button only. In
|
||||
// effect that access key allows access to the control via that button, then
|
||||
// the user can tab between the two buttons.
|
||||
nsAutoString accessKey;
|
||||
fileContent->GetAccessKey(accessKey);
|
||||
|
||||
mBrowseFilesOrDirs = MakeAnonButton(doc, "Browse", fileContent, accessKey);
|
||||
mBrowseFilesOrDirs = MakeAnonButton(doc, "Browse", fileContent);
|
||||
if (!mBrowseFilesOrDirs) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user