Bug 1679461 - Use SetSelectionRange in Select(), regardless of focus state r=masayuki

SelectAll() also is no-op without a frame, so this replaces it with SetSelectionRange.

Differential Revision: https://phabricator.services.mozilla.com/D98184
This commit is contained in:
Kagami Sascha Rosylight
2020-12-02 19:27:19 +00:00
parent f91ab1a158
commit cf1b536d67
5 changed files with 30 additions and 74 deletions

View File

@@ -3020,17 +3020,11 @@ void HTMLInputElement::Select() {
return;
}
// XXX Bug? We have to give the input focus before contents can be
// selected
TextControlState* state = GetEditorState();
MOZ_ASSERT(state, "Single line text controls are expected to have a state");
FocusTristate state = FocusState();
if (state == eUnfocusable) {
return;
}
TextControlState* tes = GetEditorState();
if (tes) {
RefPtr<nsFrameSelection> fs = tes->GetConstFrameSelection();
if (FocusState() != eUnfocusable) {
RefPtr<nsFrameSelection> fs = state->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
@@ -3039,27 +3033,24 @@ void HTMLInputElement::Select() {
// select() call takes effect.
fs->SetDelayedCaretData(nullptr);
}
}
nsFocusManager* fm = nsFocusManager::GetFocusManager();
if (RefPtr<nsFocusManager> fm = nsFocusManager::GetFocusManager()) {
fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL);
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);
// 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());
}
void HTMLInputElement::DispatchSelectEvent(nsPresContext* aPresContext) {