Bug 1342197 part 4. Move GetSelectionRange from nsTextControlFrame to the editor state. r=ehsan

At this point, all this method does is ensure editor initialization and then ask
the editor state for various information.  Let's cut out the middleman.

MozReview-Commit-ID: p491umScJO
This commit is contained in:
Boris Zbarsky
2017-02-28 12:41:37 -05:00
parent d5ebea2922
commit f7b36aa0e6
10 changed files with 151 additions and 103 deletions

View File

@@ -6607,17 +6607,30 @@ HTMLInputElement::GetFiles(nsIDOMFileList** aFileList)
return NS_OK;
}
nsresult
NS_IMETHODIMP
HTMLInputElement::GetSelectionRange(int32_t* aSelectionStart,
int32_t* aSelectionEnd)
{
nsIFormControlFrame* formControlFrame = GetFormControlFrame(true);
nsITextControlFrame* textControlFrame = do_QueryFrame(formControlFrame);
if (textControlFrame) {
return textControlFrame->GetSelectionRange(aSelectionStart, aSelectionEnd);
// Flush frames, because our editor state will want to work with the frame.
if (IsInComposedDoc()) {
GetComposedDoc()->FlushPendingNotifications(FlushType::Frames);
}
if (!GetPrimaryFrame()) {
// Can we return a selection range anyway here, now that it lives on our
// state? In fact, could we make this behave more like
// GetSelectionDirection, in the sense of working even when we have no
// frame, by just delegating entirely to mState? And then, do we really
// need the flush?
return NS_ERROR_FAILURE;
}
return NS_ERROR_FAILURE;
nsTextEditorState* state = GetEditorState();
if (!state) {
// Not a text control.
return NS_ERROR_FAILURE;
}
return state->GetSelectionRange(aSelectionStart, aSelectionEnd);
}
static void
@@ -6642,28 +6655,29 @@ HTMLInputElement::GetSelectionDirection(nsAString& aDirection, ErrorResult& aRv)
return;
}
nsresult rv = NS_ERROR_FAILURE;
nsIFormControlFrame* formControlFrame = GetFormControlFrame(true);
nsITextControlFrame* textControlFrame = do_QueryFrame(formControlFrame);
if (textControlFrame) {
nsITextControlFrame::SelectionDirection dir;
rv = textControlFrame->GetSelectionRange(nullptr, nullptr, &dir);
if (NS_SUCCEEDED(rv)) {
DirectionToName(dir, aDirection);
}
nsTextEditorState* state = GetEditorState();
if (!state) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
if (NS_FAILED(rv)) {
nsTextEditorState* state = GetEditorState();
if (state && state->IsSelectionCached()) {
DirectionToName(state->GetSelectionProperties().GetDirection(), aDirection);
nsresult rv = NS_ERROR_FAILURE;
if (formControlFrame) {
nsITextControlFrame::SelectionDirection dir;
rv = state->GetSelectionDirection(&dir);
if (NS_SUCCEEDED(rv)) {
DirectionToName(dir, aDirection);
return;
}
}
if (NS_FAILED(rv)) {
aRv.Throw(rv);
if (state->IsSelectionCached()) {
DirectionToName(state->GetSelectionProperties().GetDirection(), aDirection);
return;
}
aRv.Throw(rv);
}
NS_IMETHODIMP