Add PDFiumRange::AllTextOnPage() factory method
Add a simpler way to create a PDFiumRange that represents all the text on the page. Make callsites easier to read and more foolproof. Change-Id: I7271940e5f2da7271c097df121b52affa63061ca Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5886131 Reviewed-by: Alan Screen <awscreen@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/main@{#1360000}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
385a9d41b6
commit
9c36c864d1
@ -1690,8 +1690,7 @@ bool PDFiumEngine::ExtendSelection(int page_index, int char_index) {
|
||||
// First make sure that there are no gaps in selection, i.e. if mousedown on
|
||||
// page one but we only get mousemove over page three, we want page two.
|
||||
for (int i = last_page_index + 1; i < page_index; ++i) {
|
||||
selection_.push_back(
|
||||
PDFiumRange(pages_[i].get(), 0, pages_[i]->GetCharCount()));
|
||||
selection_.push_back(PDFiumRange::AllTextOnPage(pages_[i].get()));
|
||||
}
|
||||
|
||||
int count = pages_[last_page_index]->GetCharCount();
|
||||
@ -1707,8 +1706,7 @@ bool PDFiumEngine::ExtendSelection(int page_index, int char_index) {
|
||||
// First make sure that there are no gaps in selection, i.e. if mousedown on
|
||||
// page three but we only get mousemove over page one, we want page two.
|
||||
for (int i = last_page_index - 1; i > page_index; --i) {
|
||||
selection_.push_back(
|
||||
PDFiumRange(pages_[i].get(), 0, pages_[i]->GetCharCount()));
|
||||
selection_.push_back(PDFiumRange::AllTextOnPage(pages_[i].get()));
|
||||
}
|
||||
|
||||
int count = pages_[page_index]->GetCharCount();
|
||||
@ -2367,8 +2365,9 @@ void PDFiumEngine::SelectAll() {
|
||||
|
||||
selection_.clear();
|
||||
for (const auto& page : pages_) {
|
||||
if (page->available())
|
||||
selection_.push_back(PDFiumRange(page.get(), 0, page->GetCharCount()));
|
||||
if (page->available()) {
|
||||
selection_.push_back(PDFiumRange::AllTextOnPage(page.get()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,11 @@ bool IsIgnorableCharacter(char16_t c) {
|
||||
return c == kZeroWidthSpace || c == kPDFSoftHyphenMarker;
|
||||
}
|
||||
|
||||
// static
|
||||
PDFiumRange PDFiumRange::AllTextOnPage(PDFiumPage* page) {
|
||||
return PDFiumRange(page, 0, page->GetCharCount());
|
||||
}
|
||||
|
||||
PDFiumRange::PDFiumRange(PDFiumPage* page, int char_index, int char_count)
|
||||
: page_unload_preventer_(page),
|
||||
page_(page),
|
||||
|
@ -27,6 +27,10 @@ bool IsIgnorableCharacter(char16_t c);
|
||||
// Describes location of a string of characters.
|
||||
class PDFiumRange {
|
||||
public:
|
||||
// Shorthand for the 3-params ctor, with `char_index` set to 0 and
|
||||
// `char_count` set to the number of characters in `page`.
|
||||
static PDFiumRange AllTextOnPage(PDFiumPage* page);
|
||||
|
||||
PDFiumRange(PDFiumPage* page, int char_index, int char_count);
|
||||
PDFiumRange(const PDFiumRange&);
|
||||
PDFiumRange& operator=(const PDFiumRange&);
|
||||
|
Reference in New Issue
Block a user