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

@@ -840,17 +840,24 @@ HTMLTextAreaElement::SetSelectionEnd(const Nullable<uint32_t>& aSelectionEnd,
}
}
nsresult
NS_IMETHODIMP
HTMLTextAreaElement::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;
return mState.GetSelectionRange(aSelectionStart, aSelectionEnd);
}
static void
@@ -880,22 +887,21 @@ HTMLTextAreaElement::GetSelectionDirection(nsAString& aDirection, ErrorResult& a
{
nsresult rv = NS_ERROR_FAILURE;
nsIFormControlFrame* formControlFrame = GetFormControlFrame(true);
nsITextControlFrame* textControlFrame = do_QueryFrame(formControlFrame);
if (textControlFrame) {
if (formControlFrame) {
nsITextControlFrame::SelectionDirection dir;
rv = textControlFrame->GetSelectionRange(nullptr, nullptr, &dir);
rv = mState.GetSelectionDirection(&dir);
if (NS_SUCCEEDED(rv)) {
DirectionToName(dir, aDirection);
return;
}
}
if (NS_FAILED(rv)) {
if (mState.IsSelectionCached()) {
DirectionToName(mState.GetSelectionProperties().GetDirection(), aDirection);
return;
}
aError.Throw(rv);
if (mState.IsSelectionCached()) {
DirectionToName(mState.GetSelectionProperties().GetDirection(), aDirection);
return;
}
aError.Throw(rv);
}
NS_IMETHODIMP