зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1332105 Part 2 - Make Selection::LookUpSelection() return UniquePtr. r=dholbert
Selection::LookUpSelection()'s only caller, nsFrameSelection::LookUpSelection(), doesn't check the return value. Let's make it return UniquePtr directly like nsFrameSelection::LookUpSelection(). Rename aReturnDetails to aDetailsHead so that its role is clearer. aDetailsHead is of type UniquePtr<SelectionDetails> instead of UniquePtr<SelectionDetails>&& because the caller always wants to transfer the ownership of SelectionDetails into the function. MozReview-Commit-ID: 89Y7X1LTKON --HG-- extra : rebase_source : 730d601ccb87eb2b616c0a021129752ed5301a3a
This commit is contained in:
Родитель
f1d19f16fb
Коммит
55aa51e408
|
@ -138,12 +138,15 @@ public:
|
|||
// NS_IMETHOD GetPrimaryFrameForRangeEndpoint(nsIDOMNode *aNode, int32_t aOffset, bool aIsEndNode, nsIFrame **aResultFrame);
|
||||
NS_IMETHOD GetPrimaryFrameForAnchorNode(nsIFrame **aResultFrame);
|
||||
NS_IMETHOD GetPrimaryFrameForFocusNode(nsIFrame **aResultFrame, int32_t *aOffset, bool aVisual);
|
||||
NS_IMETHOD LookUpSelection(nsIContent *aContent,
|
||||
int32_t aContentOffset,
|
||||
int32_t aContentLength,
|
||||
UniquePtr<SelectionDetails>* aReturnDetails,
|
||||
SelectionType aSelectionType,
|
||||
bool aSlowCheck);
|
||||
|
||||
UniquePtr<SelectionDetails> LookUpSelection(
|
||||
nsIContent* aContent,
|
||||
int32_t aContentOffset,
|
||||
int32_t aContentLength,
|
||||
UniquePtr<SelectionDetails> aDetailsHead,
|
||||
SelectionType aSelectionType,
|
||||
bool aSlowCheck);
|
||||
|
||||
NS_IMETHOD Repaint(nsPresContext* aPresContext);
|
||||
|
||||
// Note: StartAutoScrollTimer might destroy arbitrary frames etc.
|
||||
|
|
|
@ -1895,10 +1895,10 @@ nsFrameSelection::LookUpSelection(nsIContent *aContent,
|
|||
|
||||
for (size_t j = 0; j < kPresentSelectionTypeCount; j++) {
|
||||
if (mDomSelections[j]) {
|
||||
mDomSelections[j]->LookUpSelection(aContent, aContentOffset,
|
||||
aContentLength, &details,
|
||||
ToSelectionType(1 << j),
|
||||
aSlowCheck);
|
||||
details = mDomSelections[j]->LookUpSelection(aContent, aContentOffset,
|
||||
aContentLength, Move(details),
|
||||
ToSelectionType(1 << j),
|
||||
aSlowCheck);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4595,29 +4595,36 @@ Selection::selectFrames(nsPresContext* aPresContext, nsRange* aRange,
|
|||
// of this function did in the case of 1 range. This would also mean that
|
||||
// the aSlowCheck flag would have meaning again.
|
||||
|
||||
NS_IMETHODIMP
|
||||
UniquePtr<SelectionDetails>
|
||||
Selection::LookUpSelection(nsIContent* aContent, int32_t aContentOffset,
|
||||
int32_t aContentLength,
|
||||
UniquePtr<SelectionDetails>* aReturnDetails,
|
||||
UniquePtr<SelectionDetails> aDetailsHead,
|
||||
SelectionType aSelectionType,
|
||||
bool aSlowCheck)
|
||||
{
|
||||
nsresult rv;
|
||||
if (!aContent || ! aReturnDetails)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!aContent) {
|
||||
return aDetailsHead;
|
||||
}
|
||||
|
||||
// it is common to have no ranges, to optimize that
|
||||
if (mRanges.Length() == 0)
|
||||
return NS_OK;
|
||||
if (mRanges.Length() == 0) {
|
||||
return aDetailsHead;
|
||||
}
|
||||
|
||||
nsTArray<nsRange*> overlappingRanges;
|
||||
rv = GetRangesForIntervalArray(aContent, aContentOffset,
|
||||
aContent, aContentOffset + aContentLength,
|
||||
false,
|
||||
&overlappingRanges);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (overlappingRanges.Length() == 0)
|
||||
return NS_OK;
|
||||
nsresult rv = GetRangesForIntervalArray(aContent, aContentOffset,
|
||||
aContent, aContentOffset + aContentLength,
|
||||
false,
|
||||
&overlappingRanges);
|
||||
if (NS_FAILED(rv)) {
|
||||
return aDetailsHead;
|
||||
}
|
||||
|
||||
if (overlappingRanges.Length() == 0) {
|
||||
return aDetailsHead;
|
||||
}
|
||||
|
||||
UniquePtr<SelectionDetails> detailsHead = Move(aDetailsHead);
|
||||
|
||||
for (uint32_t i = 0; i < overlappingRanges.Length(); i++) {
|
||||
nsRange* range = overlappingRanges[i];
|
||||
|
@ -4661,19 +4668,19 @@ Selection::LookUpSelection(nsIContent* aContent, int32_t aContentOffset,
|
|||
if (start < 0)
|
||||
continue; // the ranges do not overlap the input range
|
||||
|
||||
auto details = MakeUnique<SelectionDetails>();
|
||||
auto newHead = MakeUnique<SelectionDetails>();
|
||||
|
||||
details->mNext = Move(*aReturnDetails);
|
||||
details->mStart = start;
|
||||
details->mEnd = end;
|
||||
details->mSelectionType = aSelectionType;
|
||||
newHead->mNext = Move(detailsHead);
|
||||
newHead->mStart = start;
|
||||
newHead->mEnd = end;
|
||||
newHead->mSelectionType = aSelectionType;
|
||||
RangeData *rd = FindRangeData(range);
|
||||
if (rd) {
|
||||
details->mTextRangeStyle = rd->mTextRangeStyle;
|
||||
newHead->mTextRangeStyle = rd->mTextRangeStyle;
|
||||
}
|
||||
*aReturnDetails = Move(details);
|
||||
detailsHead = Move(newHead);
|
||||
}
|
||||
return NS_OK;
|
||||
return detailsHead;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
Загрузка…
Ссылка в новой задаче