Backed out 3 changesets (bug 1677263, bug 1679460, bug 1679461) for test_focus.xhtml failures CLOSED TREE

Backed out changeset 03db12dabc63 (bug 1677263)
Backed out changeset 75de13448090 (bug 1679460)
Backed out changeset 4f4fd8e7ce93 (bug 1679461)
This commit is contained in:
Bogdan Tara 2020-12-02 21:16:28 +02:00
Родитель c1b7803fbd
Коммит 225a24f0bc
8 изменённых файлов: 91 добавлений и 57 удалений

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

@ -3020,11 +3020,17 @@ void HTMLInputElement::Select() {
return;
}
TextControlState* state = GetEditorState();
MOZ_ASSERT(state, "Single line text controls are expected to have a state");
// XXX Bug? We have to give the input focus before contents can be
// selected
if (FocusState() != eUnfocusable) {
RefPtr<nsFrameSelection> fs = state->GetConstFrameSelection();
FocusTristate state = FocusState();
if (state == eUnfocusable) {
return;
}
TextControlState* tes = GetEditorState();
if (tes) {
RefPtr<nsFrameSelection> fs = tes->GetConstFrameSelection();
if (fs && fs->MouseDownRecorded()) {
// This means that we're being called while the frame selection has a
// mouse down event recorded to adjust the caret during the mouse up
@ -3033,24 +3039,27 @@ void HTMLInputElement::Select() {
// select() call takes effect.
fs->SetDelayedCaretData(nullptr);
}
if (RefPtr<nsFocusManager> fm = nsFocusManager::GetFocusManager()) {
fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL);
// A focus event handler may change the type attribute, which will destroy
// the previous state object.
state = GetEditorState();
if (!state) {
return;
}
}
}
// Directly call TextControlState::SetSelectionRange because
// HTMLInputElement::SetSelectionRange only applies to fewer types
state->SetSelectionRange(0, UINT32_MAX,
nsITextControlFrame::SelectionDirection::eNone,
IgnoredErrorResult());
nsFocusManager* fm = nsFocusManager::GetFocusManager();
RefPtr<nsPresContext> presContext = GetPresContext(eForComposedDoc);
if (state == eInactiveWindow) {
if (fm) fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL);
SelectAll(presContext);
return;
}
DispatchSelectEvent(presContext);
if (fm) {
fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL);
// ensure that the element is actually focused
if (this == fm->GetFocusedElement()) {
// Now Select all the text!
SelectAll(presContext);
}
}
}
void HTMLInputElement::DispatchSelectEvent(nsPresContext* aPresContext) {

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

@ -670,7 +670,7 @@ class HTMLInputElement final : public TextControlElement,
already_AddRefed<nsINodeList> GetLabels();
MOZ_CAN_RUN_SCRIPT void Select();
void Select();
Nullable<uint32_t> GetSelectionStart(ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT void SetSelectionStart(const Nullable<uint32_t>& aValue,

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

@ -132,14 +132,37 @@ nsresult HTMLTextAreaElement::Clone(dom::NodeInfo* aNodeInfo,
// nsIContent
void HTMLTextAreaElement::Select() {
if (FocusState() != eUnfocusable) {
if (RefPtr<nsFocusManager> fm = nsFocusManager::GetFocusManager()) {
fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL);
}
// XXX Bug? We have to give the input focus before contents can be
// selected
FocusTristate state = FocusState();
if (state == eUnfocusable) {
return;
}
SetSelectionRange(0, UINT32_MAX, mozilla::dom::Optional<nsAString>(),
IgnoredErrorResult());
nsFocusManager* fm = nsFocusManager::GetFocusManager();
RefPtr<nsPresContext> presContext = GetPresContext(eForComposedDoc);
if (state == eInactiveWindow) {
if (fm) fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL);
SelectAll(presContext);
return;
}
WidgetGUIEvent event(true, eFormSelect, nullptr);
// XXXbz HTMLInputElement guards against this reentering; shouldn't we?
EventDispatcher::Dispatch(static_cast<nsIContent*>(this), presContext,
&event);
if (fm) {
fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL);
// ensure that the element is actually focused
if (this == fm->GetFocusedElement()) {
// Now Select all the text!
SelectAll(presContext);
}
}
}
NS_IMETHODIMP

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

@ -254,7 +254,7 @@ class HTMLTextAreaElement final : public TextControlElement,
// via bindings.
void SetCustomValidity(const nsAString& aError);
MOZ_CAN_RUN_SCRIPT void Select();
void Select();
Nullable<uint32_t> GetSelectionStart(ErrorResult& aError);
MOZ_CAN_RUN_SCRIPT void SetSelectionStart(
const Nullable<uint32_t>& aSelectionStart, ErrorResult& aError);

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

@ -2212,6 +2212,11 @@ void TextControlState::SetSelectionDirection(const nsAString& aDirection,
nsITextControlFrame::SelectionDirection dir =
DirectionStringToSelectionDirection(aDirection);
if (IsSelectionCached()) {
GetSelectionProperties().SetDirection(dir);
return;
}
uint32_t start, end;
GetSelectionRange(&start, &end, aRv);
if (aRv.Failed()) {

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

@ -426,6 +426,15 @@ function startTest()
is(t19.selectionEnd, 5, "input focused from tab key selectionEnd");
t19.setSelectionRange(0, 0);
gLastFocusMethod = 0;
var selectFired = false;
function selectListener() { selectFired = true; }
t19.addEventListener("select", selectListener, false);
expectFocusShift(() => t19.select(),
null, getById("t" + 19), true, "input.select()");
t19.removeEventListener("select", selectListener, false);
ok(selectFired, "select event fires for input");
// mouse clicking
gLastFocusMethod = fm.FLAG_BYMOUSE;
for (idx = kTabbableSteps; idx >= 1; idx--) {

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

@ -43,7 +43,7 @@ const actions = [
},
{
label: "setRangeText()",
action: el => el.setRangeText("newmiddle", el.selectionStart, el.selectionEnd, "select")
action: el => el.setRangeText("newmiddle")
}
];
@ -79,30 +79,6 @@ els.forEach((el) => {
}, 200);
});
}, `${elLabel}: ${action.label} a second time (must not fire select)`);
promise_test(async t => {
const element = el.cloneNode(true);
element.onselect = e => {
element.onselect = null;
};
action.action(element);
// step_wait properly timeouts before the whole test collapses
await t.step_wait(() => !element.onselect, "event didn't fire", 200, 10);
}, `${elLabel}: ${action.label} disconnected node`);
// Intentionally still using promise_test, as assert_unreachable does not
// make the test fail inside a listener while t.unreached_func() does.
promise_test(async t => {
const element = el.cloneNode(true);
const listener = t.unreached_func("the select event must not fire synchronously");
element.onselect = listener;
action.action(element);
element.onselect = null;
}, `${elLabel}: ${action.label} event queue`);
});
});
</script>

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

@ -95,9 +95,12 @@
// to the character that immediately follows the text entry cursor.
assert_equals(el.selectionStart, el.value.length,
"SelectionStart offset without selection in " + el.id);
if (!el.parentNode) {
return;
}
el.select();
assert_equals(el.selectionStart, 0, "SelectionStart offset");
el.remove();
el.parentNode.removeChild(el);
}, "test SelectionStart offset for input that is " +
(append ? "appended" : " not appended"));
}
@ -109,9 +112,12 @@
// to the character that immediately follows the text entry cursor.
assert_equals(el.selectionStart, el.value.length,
"SelectionStart offset without selection in " + el.id);
if (!el.parentNode) {
return;
}
el.select();
assert_equals(el.selectionStart, 0, "SelectionStart offset");
el.remove();
el.parentNode.removeChild(el);
}, "test SelectionStart offset for textarea that is " +
(append ? "appended" : " not appended"));
}
@ -123,9 +129,12 @@
// to the character that immediately follows the text entry cursor.
assert_equals(el.selectionEnd, el.value.length,
"SelectionEnd offset without selection in " + el.id);
if (!el.parentNode) {
return;
}
el.select();
assert_equals(el.selectionEnd, el.value.length, "SelectionEnd offset");
el.remove();
el.parentNode.removeChild(el);
}, "test SelectionEnd offset for input that is " +
(append ? "appended" : " not appended"));
}
@ -138,9 +147,12 @@
// to the character that immediately follows the text entry cursor.
assert_equals(el.selectionEnd, el.value.length,
"SelectionEnd offset without selection in " + el.id);
if (!el.parentNode) {
return;
}
el.select();
assert_equals(el.selectionEnd, el.value.length, "SelectionEnd offset");
el.remove();
el.parentNode.removeChild(el);
}, "test SelectionEnd offset for textarea that is " +
(append ? "appended" : " not appended"));
}