Commit c3ea2d2b authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

PDF: Fix find text behavior.

Highlight the first search result immediately after finding it while the
search continues onwards. Instead of waiting for all the search results
to return before highlighting the first search result.

BUG=764635

Change-Id: I445ffb88527bd592fc5a51d499ea90d752a88918
Reviewed-on: https://chromium-review.googlesource.com/1013748
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: default avatarPaul Meyer <paulmeyer@chromium.org>
Reviewed-by: default avatardsinclair <dsinclair@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553843}
parent 8d5963f9
...@@ -167,11 +167,11 @@ TEST_F(FindTextTest, FindText) { ...@@ -167,11 +167,11 @@ TEST_F(FindTextTest, FindText) {
{ {
InSequence sequence; InSequence sequence;
for (int i = 0; i < 10; ++i) EXPECT_CALL(client, NotifyNumberOfFindResultsChanged(1, false));
EXPECT_CALL(client, NotifySelectedFindResultChanged(0));
for (int i = 1; i < 10; ++i)
EXPECT_CALL(client, NotifyNumberOfFindResultsChanged(i + 1, false)); EXPECT_CALL(client, NotifyNumberOfFindResultsChanged(i + 1, false));
EXPECT_CALL(client, NotifyNumberOfFindResultsChanged(10, true)); EXPECT_CALL(client, NotifyNumberOfFindResultsChanged(10, true));
EXPECT_CALL(client, NotifySelectedFindResultChanged(_)).Times(0);
} }
engine.StartFind("o", /*case_sensitive=*/true); engine.StartFind("o", /*case_sensitive=*/true);
......
...@@ -2410,6 +2410,7 @@ void PDFiumEngine::StartFind(const std::string& text, bool case_sensitive) { ...@@ -2410,6 +2410,7 @@ void PDFiumEngine::StartFind(const std::string& text, bool case_sensitive) {
character_to_start_searching_from = old_selection[0].char_index(); character_to_start_searching_from = old_selection[0].char_index();
last_page_to_search_ = next_page_to_search_; last_page_to_search_ = next_page_to_search_;
} }
search_in_progress_ = true;
} }
int current_page = next_page_to_search_; int current_page = next_page_to_search_;
...@@ -2449,6 +2450,8 @@ void PDFiumEngine::StartFind(const std::string& text, bool case_sensitive) { ...@@ -2449,6 +2450,8 @@ void PDFiumEngine::StartFind(const std::string& text, bool case_sensitive) {
(pages_.size() > 1 && current_page == next_page_to_search_)); (pages_.size() > 1 && current_page == next_page_to_search_));
if (end_of_search) { if (end_of_search) {
search_in_progress_ = false;
// Send the final notification. // Send the final notification.
client_->NotifyNumberOfFindResultsChanged(find_results_.size(), true); client_->NotifyNumberOfFindResultsChanged(find_results_.size(), true);
return; return;
...@@ -2553,6 +2556,7 @@ void PDFiumEngine::SearchUsingICU(const base::string16& term, ...@@ -2553,6 +2556,7 @@ void PDFiumEngine::SearchUsingICU(const base::string16& term,
} }
void PDFiumEngine::AddFindResult(const PDFiumRange& result) { void PDFiumEngine::AddFindResult(const PDFiumRange& result) {
bool first_result = find_results_.empty();
// Figure out where to insert the new location, since we could have // Figure out where to insert the new location, since we could have
// started searching midway and now we wrapped. // started searching midway and now we wrapped.
size_t result_index; size_t result_index;
...@@ -2568,6 +2572,11 @@ void PDFiumEngine::AddFindResult(const PDFiumRange& result) { ...@@ -2568,6 +2572,11 @@ void PDFiumEngine::AddFindResult(const PDFiumRange& result) {
find_results_.insert(find_results_.begin() + result_index, result); find_results_.insert(find_results_.begin() + result_index, result);
UpdateTickMarks(); UpdateTickMarks();
client_->NotifyNumberOfFindResultsChanged(find_results_.size(), false); client_->NotifyNumberOfFindResultsChanged(find_results_.size(), false);
if (first_result) {
DCHECK(!resume_find_index_);
DCHECK(!current_find_index_);
SelectFindResult(/*forward=*/true);
}
} }
bool PDFiumEngine::SelectFindResult(bool forward) { bool PDFiumEngine::SelectFindResult(bool forward) {
...@@ -2631,7 +2640,8 @@ bool PDFiumEngine::SelectFindResult(bool forward) { ...@@ -2631,7 +2640,8 @@ bool PDFiumEngine::SelectFindResult(bool forward) {
} }
client_->NotifySelectedFindResultChanged(current_find_index_.value()); client_->NotifySelectedFindResultChanged(current_find_index_.value());
client_->NotifyNumberOfFindResultsChanged(find_results_.size(), true); if (!search_in_progress_)
client_->NotifyNumberOfFindResultsChanged(find_results_.size(), true);
return true; return true;
} }
...@@ -2641,6 +2651,7 @@ void PDFiumEngine::StopFind() { ...@@ -2641,6 +2651,7 @@ void PDFiumEngine::StopFind() {
selecting_ = false; selecting_ = false;
find_results_.clear(); find_results_.clear();
search_in_progress_ = false;
next_page_to_search_ = -1; next_page_to_search_ = -1;
last_page_to_search_ = -1; last_page_to_search_ = -1;
last_character_index_to_search_ = -1; last_character_index_to_search_ = -1;
......
...@@ -724,6 +724,8 @@ class PDFiumEngine : public PDFEngine, ...@@ -724,6 +724,8 @@ class PDFiumEngine : public PDFEngine,
std::string current_find_text_; std::string current_find_text_;
// The results found. // The results found.
std::vector<PDFiumRange> find_results_; std::vector<PDFiumRange> find_results_;
// Whether a search is in progress.
bool search_in_progress_ = false;
// Which page to search next. // Which page to search next.
int next_page_to_search_ = -1; int next_page_to_search_ = -1;
// Where to stop searching. // Where to stop searching.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment