Bug 1343275 part 1. Get selection faster in some nsTextEditorState methods. r=ehsan
MozReview-Commit-ID: 2v0r3jtua1O
This commit is contained in:
@@ -224,6 +224,8 @@ public:
|
||||
void SetScrollableFrame(nsIScrollableFrame *aScrollableFrame);
|
||||
nsFrameSelection* GetConstFrameSelection()
|
||||
{ return mFrameSelection; }
|
||||
// Will return null if !mFrameSelection.
|
||||
Selection* GetSelection(SelectionType aSelectionType);
|
||||
|
||||
//NSISELECTIONCONTROLLER INTERFACES
|
||||
NS_IMETHOD SetDisplaySelection(int16_t toggle) override;
|
||||
@@ -306,6 +308,16 @@ nsTextInputSelectionImpl::SetScrollableFrame(nsIScrollableFrame *aScrollableFram
|
||||
}
|
||||
}
|
||||
|
||||
Selection*
|
||||
nsTextInputSelectionImpl::GetSelection(SelectionType aSelectionType)
|
||||
{
|
||||
if (!mFrameSelection) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return mFrameSelection->GetSelection(aSelectionType);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextInputSelectionImpl::SetDisplaySelection(int16_t aToggle)
|
||||
{
|
||||
@@ -1584,21 +1596,12 @@ nsTextEditorState::GetSelectionRange(int32_t* aSelectionStart,
|
||||
return;
|
||||
}
|
||||
|
||||
nsISelectionController* selCon = GetSelectionController();
|
||||
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
nsresult rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
||||
getter_AddRefs(selection));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
aRv.Throw(rv);
|
||||
return;
|
||||
}
|
||||
if (NS_WARN_IF(!selection)) {
|
||||
Selection* sel = mSelCon->GetSelection(SelectionType::eNormal);
|
||||
if (NS_WARN_IF(!sel)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
dom::Selection* sel = selection->AsSelection();
|
||||
mozilla::dom::Element* root = GetRootNode();
|
||||
if (NS_WARN_IF(!root)) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
@@ -1621,21 +1624,12 @@ nsTextEditorState::GetSelectionDirection(ErrorResult& aRv)
|
||||
return GetSelectionProperties().GetDirection();
|
||||
}
|
||||
|
||||
nsISelectionController* selCon = GetSelectionController();
|
||||
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
nsresult rv = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
||||
getter_AddRefs(selection));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
aRv.Throw(rv);
|
||||
return nsITextControlFrame::eForward; // Doesn't really matter
|
||||
}
|
||||
if (NS_WARN_IF(!selection)) {
|
||||
Selection* sel = mSelCon->GetSelection(SelectionType::eNormal);
|
||||
if (NS_WARN_IF(!sel)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nsITextControlFrame::eForward; // Doesn't really matter
|
||||
}
|
||||
|
||||
dom::Selection* sel = selection->AsSelection();
|
||||
nsDirection direction = sel->GetSelectionDirection();
|
||||
if (direction == eDirNext) {
|
||||
return nsITextControlFrame::eForward;
|
||||
|
||||
Reference in New Issue
Block a user