Bug 1343695 Part 1: Retrieve text content with GetRenderedText.
MozReview-Commit-ID: 4VLoaTlDELG
--- a/dom/base/nsRange.cpp
+++ b/dom/base/nsRange.cpp
@@ -2968,23 +2968,16 @@ GetTextFrameForContent(nsIContent* aCont
static nsresult GetPartialTextRect(nsLayoutUtils::RectCallback* aCallback,
Sequence<nsString>* aTextList,
nsIContent* aContent, int32_t aStartOffset,
int32_t aEndOffset, bool aClampToEdge,
bool aFlushLayout)
{
nsTextFrame* textFrame = GetTextFrameForContent(aContent, aFlushLayout);
if (textFrame) {
- // If we'll need it later, collect the full content text now.
- nsAutoString textContent;
- if (aTextList) {
- mozilla::ErrorResult err; // ignored
- aContent->GetTextContent(textContent, err);
- }
-
nsIFrame* relativeTo = nsLayoutUtils::GetContainingBlockForClientRect(textFrame);
for (nsTextFrame* f = textFrame; f; f = static_cast<nsTextFrame*>(f->GetNextContinuation())) {
int32_t fstart = f->GetContentOffset(), fend = f->GetContentEnd();
if (fend <= aStartOffset || fstart >= aEndOffset)
continue;
// Calculate the text content offsets we'll need if text is requested.
int32_t textContentStart = fstart;
@@ -3005,21 +2998,23 @@ static nsresult GetPartialTextRect(nsLay
ExtractRectFromOffset(f, aEndOffset, &r, !rtl, aClampToEdge);
textContentEnd = aEndOffset;
}
r = nsLayoutUtils::TransformFrameRectToAncestor(f, r, relativeTo);
aCallback->AddRect(r);
// Finally capture the text, if requested.
if (aTextList) {
- const nsAString& textSubstring =
- Substring(textContent,
- textContentStart,
- (textContentEnd - textContentStart));
- aTextList->AppendElement(textSubstring, fallible);
+ nsIFrame::RenderedText renderedText = f->GetRenderedText(
+ textContentStart,
+ textContentEnd,
+ nsIFrame::TextOffsetType::OFFSETS_IN_CONTENT_TEXT,
+ nsIFrame::TrailingWhitespace::DONT_TRIM_TRAILING_WHITESPACE);
+
+ aTextList->AppendElement(renderedText.mString, fallible);
}
}
}
return NS_OK;
}
/* static */ void
nsRange::CollectClientRectsAndText(nsLayoutUtils::RectCallback* aCollector,
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -4013,26 +4013,23 @@ struct MOZ_RAII BoxToRectAndText : publi
static void AccumulateText(nsIFrame* aFrame, nsAString& aResult) {
MOZ_ASSERT(aFrame);
// Get all the text in aFrame and child frames, while respecting
// the content offsets in each of the nsTextFrames.
if (aFrame->GetType() == nsGkAtoms::textFrame) {
nsTextFrame* textFrame = static_cast<nsTextFrame*>(aFrame);
- nsIContent* content = textFrame->GetContent();
- nsAutoString textContent;
- mozilla::ErrorResult err; // ignored
- content->GetTextContent(textContent, err);
-
- const nsAString& textSubstring =
- Substring(textContent,
- textFrame->GetContentOffset(),
- textFrame->GetContentLength());
- aResult.Append(textSubstring);
+ nsIFrame::RenderedText renderedText = textFrame->GetRenderedText(
+ textFrame->GetContentOffset(),
+ textFrame->GetContentOffset() + textFrame->GetContentLength(),
+ nsIFrame::TextOffsetType::OFFSETS_IN_CONTENT_TEXT,
+ nsIFrame::TrailingWhitespace::DONT_TRIM_TRAILING_WHITESPACE);
+
+ aResult.Append(renderedText.mString);
}
for (nsIFrame* child = aFrame->PrincipalChildList().FirstChild();
child;
child = child->GetNextSibling()) {
AccumulateText(child, aResult);
}
}