From d2ed12d9e6c1cecc74748d1680e75db71690f5cb Mon Sep 17 00:00:00 2001 From: Brad Werth Date: Wed, 1 Mar 2017 16:15:22 -0800 Subject: [PATCH] Bug 1343695 Part 1: Retrieve text content with GetRenderedText. r=mats MozReview-Commit-ID: 4VLoaTlDELG --HG-- extra : rebase_source : d48bc3f175cc88d76087e4371e2b9efead517613 --- dom/base/nsRange.cpp | 19 +++++++------------ layout/base/nsLayoutUtils.cpp | 15 ++++++--------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/dom/base/nsRange.cpp b/dom/base/nsRange.cpp index 4a0a4d518469..5a1bad5cad5f 100644 --- a/dom/base/nsRange.cpp +++ b/dom/base/nsRange.cpp @@ -2973,13 +2973,6 @@ static nsresult GetPartialTextRect(nsLayoutUtils::RectCallback* aCallback, { 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(f->GetNextContinuation())) { int32_t fstart = f->GetContentOffset(), fend = f->GetContentEnd(); @@ -3010,11 +3003,13 @@ static nsresult GetPartialTextRect(nsLayoutUtils::RectCallback* aCallback, // 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); } } } diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 2c8f4349d74c..e4dcc4669bcd 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -4018,16 +4018,13 @@ struct MOZ_RAII BoxToRectAndText : public BoxToRect { if (aFrame->GetType() == nsGkAtoms::textFrame) { nsTextFrame* textFrame = static_cast(aFrame); - nsIContent* content = textFrame->GetContent(); - nsAutoString textContent; - mozilla::ErrorResult err; // ignored - content->GetTextContent(textContent, err); + nsIFrame::RenderedText renderedText = textFrame->GetRenderedText( + textFrame->GetContentOffset(), + textFrame->GetContentOffset() + textFrame->GetContentLength(), + nsIFrame::TextOffsetType::OFFSETS_IN_CONTENT_TEXT, + nsIFrame::TrailingWhitespace::DONT_TRIM_TRAILING_WHITESPACE); - const nsAString& textSubstring = - Substring(textContent, - textFrame->GetContentOffset(), - textFrame->GetContentLength()); - aResult.Append(textSubstring); + aResult.Append(renderedText.mString); } for (nsIFrame* child = aFrame->PrincipalChildList().FirstChild();