Bug 1314080 Part 1: Rename CollectClientRects method and add a new parameter for collecting text. r?smaug
MozReview-Commit-ID: KQPky6Fh8sG
--- a/dom/base/nsRange.cpp
+++ b/dom/base/nsRange.cpp
@@ -25,16 +25,17 @@
#include "nsContentUtils.h"
#include "nsGenericDOMDataNode.h"
#include "nsTextFrame.h"
#include "nsFontFaceList.h"
#include "mozilla/dom/DocumentFragment.h"
#include "mozilla/dom/DocumentType.h"
#include "mozilla/dom/RangeBinding.h"
#include "mozilla/dom/DOMRect.h"
+#include "mozilla/dom/DOMStringList.h"
#include "mozilla/dom/ShadowRoot.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/Telemetry.h"
#include "mozilla/Likely.h"
#include "nsCSSFrameConstructor.h"
#include "nsStyleStruct.h"
#include "nsStyleStructInlines.h"
#include "nsComputedDOMStyle.h"
@@ -2925,21 +2926,22 @@ static nsresult GetPartialTextRect(nsLay
r = nsLayoutUtils::TransformFrameRectToAncestor(f, r, relativeTo);
aCallback->AddRect(r);
}
}
return NS_OK;
}
/* static */ void
-nsRange::CollectClientRects(nsLayoutUtils::RectCallback* aCollector,
- nsRange* aRange,
- nsINode* aStartParent, int32_t aStartOffset,
- nsINode* aEndParent, int32_t aEndOffset,
- bool aClampToEdge, bool aFlushLayout)
+nsRange::CollectClientRectsAndText(nsLayoutUtils::RectCallback* aCollector,
+ mozilla::dom::DOMStringList* aTextList,
+ nsRange* aRange,
+ nsINode* aStartParent, int32_t aStartOffset,
+ nsINode* aEndParent, int32_t aEndOffset,
+ bool aClampToEdge, bool aFlushLayout)
{
// Hold strong pointers across the flush
nsCOMPtr<nsINode> startContainer = aStartParent;
nsCOMPtr<nsINode> endContainer = aEndParent;
// Flush out layout so our frames are up to date.
if (!aStartParent->IsInUncomposedDoc()) {
return;
@@ -3022,18 +3024,18 @@ already_AddRefed<DOMRect>
nsRange::GetBoundingClientRect(bool aClampToEdge, bool aFlushLayout)
{
RefPtr<DOMRect> rect = new DOMRect(ToSupports(this));
if (!mStartParent) {
return rect.forget();
}
nsLayoutUtils::RectAccumulator accumulator;
- CollectClientRects(&accumulator, this, mStartParent, mStartOffset,
- mEndParent, mEndOffset, aClampToEdge, aFlushLayout);
+ CollectClientRectsAndText(&accumulator, nullptr, this, mStartParent,
+ mStartOffset, mEndParent, mEndOffset, aClampToEdge, aFlushLayout);
nsRect r = accumulator.mResultRect.IsEmpty() ? accumulator.mFirstRect :
accumulator.mResultRect;
rect->SetLayoutRect(r);
return rect.forget();
}
NS_IMETHODIMP
@@ -3050,18 +3052,18 @@ nsRange::GetClientRects(bool aClampToEdg
return nullptr;
}
RefPtr<DOMRectList> rectList =
new DOMRectList(static_cast<nsIDOMRange*>(this));
nsLayoutUtils::RectListBuilder builder(rectList);
- CollectClientRects(&builder, this, mStartParent, mStartOffset,
- mEndParent, mEndOffset, aClampToEdge, aFlushLayout);
+ CollectClientRectsAndText(&builder, nullptr, this, mStartParent,
+ mStartOffset, mEndParent, mEndOffset, aClampToEdge, aFlushLayout);
return rectList.forget();
}
NS_IMETHODIMP
nsRange::GetUsedFontFaces(nsIDOMFontFaceList** aResult)
{
*aResult = nullptr;
--- a/dom/base/nsRange.h
+++ b/dom/base/nsRange.h
@@ -258,21 +258,26 @@ public:
* where aNode is a descendant of a range's common ancestor node).
* If a nsRange starts in (aNode, aEndOffset) or if it ends in
* (aNode, aStartOffset) then it is non-overlapping and the result is false
* for that nsRange. Collapsed ranges always counts as non-overlapping.
*/
static bool IsNodeSelected(nsINode* aNode, uint32_t aStartOffset,
uint32_t aEndOffset);
- static void CollectClientRects(nsLayoutUtils::RectCallback* aCollector,
- nsRange* aRange,
- nsINode* aStartParent, int32_t aStartOffset,
- nsINode* aEndParent, int32_t aEndOffset,
- bool aClampToEdge, bool aFlushLayout);
+ /**
+ * This helper function gets rects and correlated text for the given range.
+ * @param aTextList optional where nullptr = don't retrieve text
+ */
+ static void CollectClientRectsAndText(nsLayoutUtils::RectCallback* aCollector,
+ mozilla::dom::DOMStringList* aTextList,
+ nsRange* aRange,
+ nsINode* aStartParent, int32_t aStartOffset,
+ nsINode* aEndParent, int32_t aEndOffset,
+ bool aClampToEdge, bool aFlushLayout);
/**
* Scan this range for -moz-user-select:none nodes and split it up into
* multiple ranges to exclude those nodes. The resulting ranges are put
* in aOutRanges. If no -moz-user-select:none node is found in the range
* then |this| is unmodified and is the only range in aOutRanges.
* Otherwise, |this| will be modified so that it ends before the first
* -moz-user-select:none node and additional ranges may also be created.
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -9200,17 +9200,17 @@ nsLayoutUtils::GetSelectionBoundingRect(
nsIFrame* relativeTo = GetContainingBlockForClientRect(frame);
res = TransformFrameRectToAncestor(frame, res, relativeTo);
}
} else {
int32_t rangeCount = aSel->RangeCount();
RectAccumulator accumulator;
for (int32_t idx = 0; idx < rangeCount; ++idx) {
nsRange* range = aSel->GetRangeAt(idx);
- nsRange::CollectClientRects(&accumulator, range,
+ nsRange::CollectClientRectsAndText(&accumulator, nullptr, range,
range->GetStartParent(), range->StartOffset(),
range->GetEndParent(), range->EndOffset(),
true, false);
}
res = accumulator.mResultRect.IsEmpty() ? accumulator.mFirstRect :
accumulator.mResultRect;
}
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -5881,17 +5881,17 @@ bool
Selection::ContainsPoint(const nsPoint& aPoint)
{
if (IsCollapsed()) {
return false;
}
PointInRectChecker checker(aPoint);
for (uint32_t i = 0; i < RangeCount(); i++) {
nsRange* range = GetRangeAt(i);
- nsRange::CollectClientRects(&checker, range,
+ nsRange::CollectClientRectsAndText(&checker, nullptr, range,
range->GetStartParent(), range->StartOffset(),
range->GetEndParent(), range->EndOffset(),
true, false);
if (checker.MatchFound()) {
return true;
}
}
return false;