OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "pdf/pdfium/pdfium_engine.h" | 5 #include "pdf/pdfium/pdfium_engine.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 doc_(NULL), | 560 doc_(NULL), |
561 form_(NULL), | 561 form_(NULL), |
562 defer_page_unload_(false), | 562 defer_page_unload_(false), |
563 selecting_(false), | 563 selecting_(false), |
564 mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA, | 564 mouse_down_state_(PDFiumPage::NONSELECTABLE_AREA, |
565 PDFiumPage::LinkTarget()), | 565 PDFiumPage::LinkTarget()), |
566 next_page_to_search_(-1), | 566 next_page_to_search_(-1), |
567 last_page_to_search_(-1), | 567 last_page_to_search_(-1), |
568 last_character_index_to_search_(-1), | 568 last_character_index_to_search_(-1), |
569 current_find_index_(-1), | 569 current_find_index_(-1), |
| 570 resume_find_index_(-1), |
570 permissions_(0), | 571 permissions_(0), |
571 fpdf_availability_(NULL), | 572 fpdf_availability_(NULL), |
572 next_timer_id_(0), | 573 next_timer_id_(0), |
573 last_page_mouse_down_(-1), | 574 last_page_mouse_down_(-1), |
574 first_visible_page_(-1), | 575 first_visible_page_(-1), |
575 most_visible_page_(-1), | 576 most_visible_page_(-1), |
576 called_do_document_action_(false), | 577 called_do_document_action_(false), |
577 render_grayscale_(false), | 578 render_grayscale_(false), |
578 progressive_paint_timeout_(0), | 579 progressive_paint_timeout_(0), |
579 getting_password_(false) { | 580 getting_password_(false) { |
(...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1676 // Only one page but didn't start midway. | 1677 // Only one page but didn't start midway. |
1677 ((pages_.size() == 1 && last_character_index_to_search_ == -1) || | 1678 ((pages_.size() == 1 && last_character_index_to_search_ == -1) || |
1678 // Started midway, but only 1 page and we already looped around. | 1679 // Started midway, but only 1 page and we already looped around. |
1679 (pages_.size() == 1 && !first_search) || | 1680 (pages_.size() == 1 && !first_search) || |
1680 // Started midway, and we've just looped around. | 1681 // Started midway, and we've just looped around. |
1681 (pages_.size() > 1 && current_page == next_page_to_search_)); | 1682 (pages_.size() > 1 && current_page == next_page_to_search_)); |
1682 | 1683 |
1683 if (end_of_search) { | 1684 if (end_of_search) { |
1684 // Send the final notification. | 1685 // Send the final notification. |
1685 client_->NotifyNumberOfFindResultsChanged(find_results_.size(), true); | 1686 client_->NotifyNumberOfFindResultsChanged(find_results_.size(), true); |
| 1687 |
| 1688 // When searching is complete, resume finding at a particular index. |
| 1689 if (resume_find_index_ != -1) { |
| 1690 current_find_index_ = resume_find_index_; |
| 1691 resume_find_index_ = -1; |
| 1692 } |
1686 } else { | 1693 } else { |
1687 pp::CompletionCallback callback = | 1694 pp::CompletionCallback callback = |
1688 find_factory_.NewCallback(&PDFiumEngine::ContinueFind); | 1695 find_factory_.NewCallback(&PDFiumEngine::ContinueFind); |
1689 pp::Module::Get()->core()->CallOnMainThread( | 1696 pp::Module::Get()->core()->CallOnMainThread( |
1690 0, callback, case_sensitive ? 1 : 0); | 1697 0, callback, case_sensitive ? 1 : 0); |
1691 } | 1698 } |
1692 } | 1699 } |
1693 | 1700 |
1694 void PDFiumEngine::SearchUsingPDFium(const base::string16& term, | 1701 void PDFiumEngine::SearchUsingPDFium(const base::string16& term, |
1695 bool case_sensitive, | 1702 bool case_sensitive, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1771 for (i = 0; i < find_results_.size(); ++i) { | 1778 for (i = 0; i < find_results_.size(); ++i) { |
1772 if (find_results_[i].page_index() > page_index || | 1779 if (find_results_[i].page_index() > page_index || |
1773 (find_results_[i].page_index() == page_index && | 1780 (find_results_[i].page_index() == page_index && |
1774 find_results_[i].char_index() > char_index)) { | 1781 find_results_[i].char_index() > char_index)) { |
1775 break; | 1782 break; |
1776 } | 1783 } |
1777 } | 1784 } |
1778 find_results_.insert(find_results_.begin() + i, result); | 1785 find_results_.insert(find_results_.begin() + i, result); |
1779 UpdateTickMarks(); | 1786 UpdateTickMarks(); |
1780 | 1787 |
1781 if (current_find_index_ == -1) { | 1788 if (current_find_index_ == -1 && resume_find_index_ == -1) { |
1782 // Select the first match. | 1789 // Select the first match. |
1783 SelectFindResult(true); | 1790 SelectFindResult(true); |
1784 } else if (static_cast<int>(i) <= current_find_index_) { | 1791 } else if (static_cast<int>(i) <= current_find_index_) { |
1785 // Update the current match index | 1792 // Update the current match index |
1786 current_find_index_++; | 1793 current_find_index_++; |
1787 client_->NotifySelectedFindResultChanged(current_find_index_); | 1794 client_->NotifySelectedFindResultChanged(current_find_index_); |
1788 } | 1795 } |
1789 client_->NotifyNumberOfFindResultsChanged(find_results_.size(), false); | 1796 client_->NotifyNumberOfFindResultsChanged(find_results_.size(), false); |
1790 } | 1797 } |
1791 | 1798 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1879 CancelPaints(); | 1886 CancelPaints(); |
1880 | 1887 |
1881 current_zoom_ = new_zoom_level; | 1888 current_zoom_ = new_zoom_level; |
1882 | 1889 |
1883 CalculateVisiblePages(); | 1890 CalculateVisiblePages(); |
1884 UpdateTickMarks(); | 1891 UpdateTickMarks(); |
1885 } | 1892 } |
1886 | 1893 |
1887 void PDFiumEngine::RotateClockwise() { | 1894 void PDFiumEngine::RotateClockwise() { |
1888 current_rotation_ = (current_rotation_ + 1) % 4; | 1895 current_rotation_ = (current_rotation_ + 1) % 4; |
| 1896 |
| 1897 // Store the current find index so that we can resume finding at that |
| 1898 // particular index after we have recomputed the find results. |
| 1899 std::string current_find_text = current_find_text_; |
| 1900 resume_find_index_ = current_find_index_; |
| 1901 |
1889 InvalidateAllPages(); | 1902 InvalidateAllPages(); |
| 1903 |
| 1904 if (!current_find_text.empty()) |
| 1905 StartFind(current_find_text.c_str(), false); |
1890 } | 1906 } |
1891 | 1907 |
1892 void PDFiumEngine::RotateCounterclockwise() { | 1908 void PDFiumEngine::RotateCounterclockwise() { |
1893 current_rotation_ = (current_rotation_ - 1) % 4; | 1909 current_rotation_ = (current_rotation_ - 1) % 4; |
| 1910 |
| 1911 // Store the current find index so that we can resume finding at that |
| 1912 // particular index after we have recomputed the find results. |
| 1913 std::string current_find_text = current_find_text_; |
| 1914 resume_find_index_ = current_find_index_; |
| 1915 |
1894 InvalidateAllPages(); | 1916 InvalidateAllPages(); |
| 1917 |
| 1918 if (!current_find_text.empty()) |
| 1919 StartFind(current_find_text.c_str(), false); |
1895 } | 1920 } |
1896 | 1921 |
1897 void PDFiumEngine::InvalidateAllPages() { | 1922 void PDFiumEngine::InvalidateAllPages() { |
1898 selection_.clear(); | |
1899 find_results_.clear(); | |
1900 | |
1901 CancelPaints(); | 1923 CancelPaints(); |
| 1924 StopFind(); |
1902 LoadPageInfo(true); | 1925 LoadPageInfo(true); |
1903 UpdateTickMarks(); | |
1904 client_->Invalidate(pp::Rect(plugin_size_)); | 1926 client_->Invalidate(pp::Rect(plugin_size_)); |
1905 } | 1927 } |
1906 | 1928 |
1907 std::string PDFiumEngine::GetSelectedText() { | 1929 std::string PDFiumEngine::GetSelectedText() { |
1908 base::string16 result; | 1930 base::string16 result; |
1909 for (size_t i = 0; i < selection_.size(); ++i) { | 1931 for (size_t i = 0; i < selection_.size(); ++i) { |
1910 if (i > 0 && | 1932 if (i > 0 && |
1911 selection_[i - 1].page_index() > selection_[i].page_index()) { | 1933 selection_[i - 1].page_index() > selection_[i].page_index()) { |
1912 result = selection_[i].GetText() + result; | 1934 result = selection_[i].GetText() + result; |
1913 } else { | 1935 } else { |
(...skipping 1600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3514 double* height) { | 3536 double* height) { |
3515 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3537 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
3516 if (!doc) | 3538 if (!doc) |
3517 return false; | 3539 return false; |
3518 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3540 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
3519 FPDF_CloseDocument(doc); | 3541 FPDF_CloseDocument(doc); |
3520 return success; | 3542 return success; |
3521 } | 3543 } |
3522 | 3544 |
3523 } // namespace chrome_pdf | 3545 } // namespace chrome_pdf |
OLD | NEW |