зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1699402 - Minor cleanup in HTMLDialogElement focusing steps. r=sefeng
This shouldn't change behavior, but I wrote this while looking at bug 1699259 (which didn't use this code after all) and I think it's ok. Differential Revision: https://phabricator.services.mozilla.com/D108927
This commit is contained in:
Родитель
fe2d6a2a27
Коммит
2b65233acf
|
@ -128,28 +128,28 @@ void HTMLDialogElement::FocusDialog() {
|
|||
}
|
||||
|
||||
Element* control = nullptr;
|
||||
nsIContent* child = GetFirstChild();
|
||||
while (child) {
|
||||
if (child->IsElement()) {
|
||||
nsIFrame* frame = child->GetPrimaryFrame();
|
||||
if (frame && frame->IsFocusable()) {
|
||||
if (child->AsElement()->HasAttr(kNameSpaceID_None,
|
||||
nsGkAtoms::autofocus)) {
|
||||
// Find the first descendant of element of subject that this
|
||||
// not inert and has autofucus attribute
|
||||
// inert bug: https://bugzilla.mozilla.org/show_bug.cgi?id=921504
|
||||
control = child->AsElement();
|
||||
for (auto* child = GetFirstChild(); child; child = child->GetNextNode(this)) {
|
||||
auto* element = Element::FromNode(child);
|
||||
if (!element) {
|
||||
continue;
|
||||
}
|
||||
nsIFrame* frame = element->GetPrimaryFrame();
|
||||
if (!frame || !frame->IsFocusable()) {
|
||||
continue;
|
||||
}
|
||||
if (element->HasAttr(nsGkAtoms::autofocus)) {
|
||||
// Find the first descendant of element of subject that this not inert and
|
||||
// has autofucus attribute.
|
||||
control = element;
|
||||
break;
|
||||
}
|
||||
// If there isn't one, then let control be the first non-inert
|
||||
// descendant element of subject, in tree order.
|
||||
if (!control) {
|
||||
control = child->AsElement();
|
||||
// If there isn't one, then let control be the first non-inert descendant
|
||||
// element of subject, in tree order.
|
||||
control = element;
|
||||
}
|
||||
}
|
||||
}
|
||||
child = child->GetNextNode(this);
|
||||
}
|
||||
|
||||
// If there isn't one of those either, then let control be subject.
|
||||
if (!control) {
|
||||
control = this;
|
||||
|
@ -163,13 +163,10 @@ void HTMLDialogElement::FocusDialog() {
|
|||
if (rv.Failed()) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
if (fm) {
|
||||
} else if (nsFocusManager* fm = nsFocusManager::GetFocusManager()) {
|
||||
// Clear the focus which ends up making the body gets focused
|
||||
fm->ClearFocus(OwnerDoc()->GetWindow());
|
||||
}
|
||||
}
|
||||
|
||||
// 4) Let topDocument be the active document of control's node document's
|
||||
// browsing context's top-level browsing context.
|
||||
|
@ -177,9 +174,8 @@ void HTMLDialogElement::FocusDialog() {
|
|||
// topDocument, then return.
|
||||
BrowsingContext* bc = control->OwnerDoc()->GetBrowsingContext();
|
||||
if (bc && bc->SameOriginWithTop()) {
|
||||
nsCOMPtr<nsIDocShell> docShell = bc->Top()->GetDocShell();
|
||||
if (docShell) {
|
||||
if (Document* topDocument = docShell->GetDocument()) {
|
||||
if (nsCOMPtr<nsIDocShell> docShell = bc->Top()->GetDocShell()) {
|
||||
if (Document* topDocument = docShell->GetExtantDocument()) {
|
||||
// 6) Empty topDocument's autofocus candidates.
|
||||
// 7) Set topDocument's autofocus processed flag to true.
|
||||
topDocument->SetAutoFocusFired();
|
||||
|
|
Загрузка…
Ссылка в новой задаче