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:
@@ -1549,6 +1549,73 @@ nsTextEditorState::SetSelectionProperties(nsTextEditorState::SelectionProperties
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditorState::GetSelectionRange(int32_t* aSelectionStart,
|
||||
int32_t* aSelectionEnd)
|
||||
{
|
||||
MOZ_ASSERT(mBoundFrame,
|
||||
"Caller didn't flush out frames and check for a frame?");
|
||||
MOZ_ASSERT(aSelectionStart);
|
||||
MOZ_ASSERT(aSelectionEnd);
|
||||
|
||||
// It's not clear that all the checks here are needed, but the previous
|
||||
// version of this code in nsTextControlFrame was doing them, so we keep them
|
||||
// for now.
|
||||
|
||||
nsresult rv = mBoundFrame->EnsureEditorInitialized();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsISelectionController* selCon = GetSelectionController();
|
||||
NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
||||
getter_AddRefs(selection));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
|
||||
|
||||
dom::Selection* sel = selection->AsSelection();
|
||||
mozilla::dom::Element* root = GetRootNode();
|
||||
NS_ENSURE_STATE(root);
|
||||
nsContentUtils::GetSelectionInTextControl(sel, root,
|
||||
*aSelectionStart, *aSelectionEnd);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextEditorState::GetSelectionDirection(nsITextControlFrame::SelectionDirection* aDirection)
|
||||
{
|
||||
MOZ_ASSERT(mBoundFrame,
|
||||
"Caller didn't flush out frames and check for a frame?");
|
||||
MOZ_ASSERT(aDirection);
|
||||
|
||||
// It's not clear that all the checks here are needed, but the previous
|
||||
// version of this code in nsTextControlFrame was doing them, so we keep them
|
||||
// for now.
|
||||
|
||||
nsresult rv = mBoundFrame->EnsureEditorInitialized();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsISelectionController* selCon = GetSelectionController();
|
||||
NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
||||
getter_AddRefs(selection));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
|
||||
|
||||
dom::Selection* sel = selection->AsSelection();
|
||||
nsDirection direction = sel->GetSelectionDirection();
|
||||
if (direction == eDirNext) {
|
||||
*aDirection = nsITextControlFrame::eForward;
|
||||
} else if (direction == eDirPrevious) {
|
||||
*aDirection = nsITextControlFrame::eBackward;
|
||||
} else {
|
||||
NS_NOTREACHED("Invalid nsDirection enum value");
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
HTMLInputElement*
|
||||
nsTextEditorState::GetParentNumberControl(nsFrame* aFrame) const
|
||||
@@ -1621,7 +1688,7 @@ nsTextEditorState::UnbindFromFrame(nsTextControlFrame* aFrame)
|
||||
}
|
||||
|
||||
// Save our selection state if needed.
|
||||
// Note that nsTextControlFrame::GetSelectionRange attempts to initialize the
|
||||
// Note that GetSelectionRange attempts to initialize the
|
||||
// editor before grabbing the range, and because this is not an acceptable
|
||||
// side effect for unbinding from a text control frame, we need to call
|
||||
// GetSelectionRange before calling DestroyEditor, and only if
|
||||
@@ -1636,13 +1703,15 @@ nsTextEditorState::UnbindFromFrame(nsTextControlFrame* aFrame)
|
||||
// parent control, because this text editor state will be destroyed
|
||||
// together with the native anonymous text control.
|
||||
SelectionProperties props;
|
||||
mBoundFrame->GetSelectionRange(&start, &end, &direction);
|
||||
GetSelectionRange(&start, &end);
|
||||
GetSelectionDirection(&direction);
|
||||
props.SetStart(start);
|
||||
props.SetEnd(end);
|
||||
props.SetDirection(direction);
|
||||
number->SetSelectionProperties(props);
|
||||
} else {
|
||||
mBoundFrame->GetSelectionRange(&start, &end, &direction);
|
||||
GetSelectionRange(&start, &end);
|
||||
GetSelectionDirection(&direction);
|
||||
mSelectionProperties.SetStart(start);
|
||||
mSelectionProperties.SetEnd(end);
|
||||
mSelectionProperties.SetDirection(direction);
|
||||
|
||||
Reference in New Issue
Block a user