Skip to content

Commit

Permalink
PDF Viewer - Search results don't work after rotating pdf
Browse files Browse the repository at this point in the history
Currently search results are cleared when user rotates
pdf document. As a result, the forward/backward buttons in
find bar do not work if user rotates pdf document after
finding some text in the document.

This happens because |find_results_| is cleared in the method
InvalidateAllPages(), which is called after rotation.

This patch introduces a new method to restore find results state
after invalidate operation is done. New find operation is done
to ensure rects are correctly identified for search results and
correct region is highlighted on pressing forward/backward buttons
in find bar.

BUG=389782

Review URL: https://codereview.chromium.org/555803002

Cr-Commit-Position: refs/heads/master@{#298083}
  • Loading branch information
n.bansal authored and Commit bot committed Oct 3, 2014
1 parent e343b54 commit 3a8252c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
32 changes: 27 additions & 5 deletions pdf/pdfium/pdfium_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ PDFiumEngine::PDFiumEngine(PDFEngine::Client* client)
last_page_to_search_(-1),
last_character_index_to_search_(-1),
current_find_index_(-1),
resume_find_index_(-1),
permissions_(0),
fpdf_availability_(NULL),
next_timer_id_(0),
Expand Down Expand Up @@ -1683,6 +1684,12 @@ void PDFiumEngine::StartFind(const char* text, bool case_sensitive) {
if (end_of_search) {
// Send the final notification.
client_->NotifyNumberOfFindResultsChanged(find_results_.size(), true);

// When searching is complete, resume finding at a particular index.
if (resume_find_index_ != -1) {
current_find_index_ = resume_find_index_;
resume_find_index_ = -1;
}
} else {
pp::CompletionCallback callback =
find_factory_.NewCallback(&PDFiumEngine::ContinueFind);
Expand Down Expand Up @@ -1778,7 +1785,7 @@ void PDFiumEngine::AddFindResult(const PDFiumRange& result) {
find_results_.insert(find_results_.begin() + i, result);
UpdateTickMarks();

if (current_find_index_ == -1) {
if (current_find_index_ == -1 && resume_find_index_ == -1) {
// Select the first match.
SelectFindResult(true);
} else if (static_cast<int>(i) <= current_find_index_) {
Expand Down Expand Up @@ -1886,21 +1893,36 @@ void PDFiumEngine::ZoomUpdated(double new_zoom_level) {

void PDFiumEngine::RotateClockwise() {
current_rotation_ = (current_rotation_ + 1) % 4;

// Store the current find index so that we can resume finding at that
// particular index after we have recomputed the find results.
std::string current_find_text = current_find_text_;
resume_find_index_ = current_find_index_;

InvalidateAllPages();

if (!current_find_text.empty())
StartFind(current_find_text.c_str(), false);
}

void PDFiumEngine::RotateCounterclockwise() {
current_rotation_ = (current_rotation_ - 1) % 4;

// Store the current find index so that we can resume finding at that
// particular index after we have recomputed the find results.
std::string current_find_text = current_find_text_;
resume_find_index_ = current_find_index_;

InvalidateAllPages();

if (!current_find_text.empty())
StartFind(current_find_text.c_str(), false);
}

void PDFiumEngine::InvalidateAllPages() {
selection_.clear();
find_results_.clear();

CancelPaints();
StopFind();
LoadPageInfo(true);
UpdateTickMarks();
client_->Invalidate(pp::Rect(plugin_size_));
}

Expand Down
2 changes: 2 additions & 0 deletions pdf/pdfium/pdfium_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ class PDFiumEngine : public PDFEngine,
int last_character_index_to_search_; // -1 if search until end of page.
// Which result the user has currently selected.
int current_find_index_;
// Where to resume searching.
int resume_find_index_;

// Permissions bitfield.
unsigned long permissions_;
Expand Down

0 comments on commit 3a8252c

Please sign in to comment.