Bug 1375131 - Part 3. Use stack class to save ranges before using on loop. r?masayuki
We have a possible loop like this bug. So we should use stack class for loop.
MozReview-Commit-ID: LQb9w8LEtbx
--- a/editor/libeditor/HTMLStyleEditor.cpp
+++ b/editor/libeditor/HTMLStyleEditor.cpp
@@ -130,20 +130,18 @@ HTMLEditor::SetInlineProperty(nsIAtom* a
bool cancel, handled;
TextRulesInfo ruleInfo(EditAction::setTextProperty);
// Protect the edit rules object from dying
nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
NS_ENSURE_SUCCESS(rv, rv);
if (!cancel && !handled) {
// Loop through the ranges in the selection
- uint32_t rangeCount = selection->RangeCount();
- for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; rangeIdx++) {
- RefPtr<nsRange> range = selection->GetRangeAt(rangeIdx);
-
+ AutoRangeArray arrayOfRanges(selection);
+ for (auto& range : arrayOfRanges.mRanges) {
// Adjust range to include any ancestors whose children are entirely
// selected
rv = PromoteInlineRange(*range);
NS_ENSURE_SUCCESS(rv, rv);
// Check for easy case: both range endpoints in same text node
nsCOMPtr<nsINode> startNode = range->GetStartParent();
nsCOMPtr<nsINode> endNode = range->GetEndParent();
@@ -1235,35 +1233,31 @@ HTMLEditor::RemoveInlinePropertyImpl(nsI
bool cancel, handled;
TextRulesInfo ruleInfo(EditAction::removeTextProperty);
// Protect the edit rules object from dying
nsCOMPtr<nsIEditRules> rules(mRules);
nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
NS_ENSURE_SUCCESS(rv, rv);
if (!cancel && !handled) {
// Loop through the ranges in the selection
- uint32_t rangeCount = selection->RangeCount();
// Since ranges might be modified by SplitStyleAboveRange, we need hold
// current ranges
- AutoTArray<OwningNonNull<nsRange>, 8> arrayOfRanges;
- for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; ++rangeIdx) {
- arrayOfRanges.AppendElement(*selection->GetRangeAt(rangeIdx));
- }
- for (auto& range : arrayOfRanges) {
+ AutoRangeArray arrayOfRanges(selection);
+ for (auto& range : arrayOfRanges.mRanges) {
if (aProperty == nsGkAtoms::name) {
// Promote range if it starts or end in a named anchor and we want to
// remove named anchors
- rv = PromoteRangeIfStartsOrEndsInNamedAnchor(range);
+ rv = PromoteRangeIfStartsOrEndsInNamedAnchor(*range);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
} else {
// Adjust range to include any ancestors whose children are entirely
// selected
- rv = PromoteInlineRange(range);
+ rv = PromoteInlineRange(*range);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
// Remove this style from ancestors of our range endpoints, splitting
// them as appropriate
rv = SplitStyleAboveRange(range, aProperty, aAttribute);
@@ -1389,20 +1383,18 @@ HTMLEditor::RelativeFontChange(FontSize
// Wrap with txn batching, rules sniffing, and selection preservation code
AutoEditBatch batchIt(this);
AutoRules beginRulesSniffing(this, EditAction::setTextProperty,
nsIEditor::eNext);
AutoSelectionRestorer selectionRestorer(selection, this);
AutoTransactionsConserveSelection dontSpazMySelection(this);
// Loop through the ranges in the selection
- uint32_t rangeCount = selection->RangeCount();
- for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; ++rangeIdx) {
- RefPtr<nsRange> range = selection->GetRangeAt(rangeIdx);
-
+ AutoRangeArray arrayOfRanges(selection);
+ for (auto& range : arrayOfRanges.mRanges) {
// Adjust range to include any ancestors with entirely selected children
nsresult rv = PromoteInlineRange(*range);
NS_ENSURE_SUCCESS(rv, rv);
// Check for easy case: both range endpoints in same text node
nsCOMPtr<nsINode> startNode = range->GetStartParent();
nsCOMPtr<nsINode> endNode = range->GetEndParent();
if (startNode == endNode && IsTextNode(startNode)) {