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 #ifndef PDF_PDFIUM_PDFIUM_ENGINE_H_ | 5 #ifndef PDF_PDFIUM_PDFIUM_ENGINE_H_ |
6 #define PDF_PDFIUM_PDFIUM_ENGINE_H_ | 6 #define PDF_PDFIUM_PDFIUM_ENGINE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 129 |
130 private: | 130 private: |
131 // This helper class is used to detect the difference in selection between | 131 // This helper class is used to detect the difference in selection between |
132 // construction and destruction. At destruction, it invalidates all the | 132 // construction and destruction. At destruction, it invalidates all the |
133 // parts that are newly selected, along with all the parts that used to be | 133 // parts that are newly selected, along with all the parts that used to be |
134 // selected but are not anymore. | 134 // selected but are not anymore. |
135 class SelectionChangeInvalidator { | 135 class SelectionChangeInvalidator { |
136 public: | 136 public: |
137 explicit SelectionChangeInvalidator(PDFiumEngine* engine); | 137 explicit SelectionChangeInvalidator(PDFiumEngine* engine); |
138 ~SelectionChangeInvalidator(); | 138 ~SelectionChangeInvalidator(); |
| 139 |
139 private: | 140 private: |
140 // Sets the given container to the all the currently visible selection | 141 // Sets the given container to the all the currently visible selection |
141 // rectangles, in screen coordinates. | 142 // rectangles, in screen coordinates. |
142 void GetVisibleSelectionsScreenRects(std::vector<pp::Rect>* rects); | 143 void GetVisibleSelectionsScreenRects(std::vector<pp::Rect>* rects); |
143 | 144 |
144 PDFiumEngine* engine_; | 145 PDFiumEngine* engine_; |
145 // Screen rectangles that were selected on construction. | 146 // Screen rectangles that were selected on construction. |
146 std::vector<pp::Rect> old_selections_; | 147 std::vector<pp::Rect> old_selections_; |
147 // The origin at the time this object was constructed. | 148 // The origin at the time this object was constructed. |
148 pp::Point previous_origin_; | 149 pp::Point previous_origin_; |
(...skipping 26 matching lines...) Expand all Loading... |
175 ~FindTextIndex(); | 176 ~FindTextIndex(); |
176 | 177 |
177 bool valid() const { return valid_; } | 178 bool valid() const { return valid_; } |
178 void Invalidate(); | 179 void Invalidate(); |
179 | 180 |
180 size_t GetIndex() const; | 181 size_t GetIndex() const; |
181 void SetIndex(size_t index); | 182 void SetIndex(size_t index); |
182 size_t IncrementIndex(); | 183 size_t IncrementIndex(); |
183 | 184 |
184 private: | 185 private: |
185 bool valid_; // Whether |index_| is valid or not. | 186 bool valid_; // Whether |index_| is valid or not. |
186 size_t index_; // The current search result, 0-based. | 187 size_t index_; // The current search result, 0-based. |
187 | 188 |
188 DISALLOW_COPY_AND_ASSIGN(FindTextIndex); | 189 DISALLOW_COPY_AND_ASSIGN(FindTextIndex); |
189 }; | 190 }; |
190 | 191 |
191 friend class SelectionChangeInvalidator; | 192 friend class SelectionChangeInvalidator; |
192 | 193 |
193 struct FileAvail : public FX_FILEAVAIL { | 194 struct FileAvail : public FX_FILEAVAIL { |
194 DocumentLoader* loader; | 195 DocumentLoader* loader; |
195 }; | 196 }; |
196 | 197 |
197 struct DownloadHints : public FX_DOWNLOADHINTS { | 198 struct DownloadHints : public FX_DOWNLOADHINTS { |
198 DocumentLoader* loader; | 199 DocumentLoader* loader; |
199 }; | 200 }; |
200 | 201 |
201 // PDFium interface to get block of data. | 202 // PDFium interface to get block of data. |
202 static int GetBlock(void* param, unsigned long position, | 203 static int GetBlock(void* param, |
203 unsigned char* buffer, unsigned long size); | 204 unsigned long position, |
| 205 unsigned char* buffer, |
| 206 unsigned long size); |
204 | 207 |
205 // PDFium interface to check is block of data is available. | 208 // PDFium interface to check is block of data is available. |
206 static FPDF_BOOL IsDataAvail(FX_FILEAVAIL* param, | 209 static FPDF_BOOL IsDataAvail(FX_FILEAVAIL* param, size_t offset, size_t size); |
207 size_t offset, size_t size); | |
208 | 210 |
209 // PDFium interface to request download of the block of data. | 211 // PDFium interface to request download of the block of data. |
210 static void AddSegment(FX_DOWNLOADHINTS* param, | 212 static void AddSegment(FX_DOWNLOADHINTS* param, size_t offset, size_t size); |
211 size_t offset, size_t size); | |
212 | 213 |
213 // We finished getting the pdf file, so load it. This will complete | 214 // We finished getting the pdf file, so load it. This will complete |
214 // asynchronously (due to password fetching) and may be run multiple times. | 215 // asynchronously (due to password fetching) and may be run multiple times. |
215 void LoadDocument(); | 216 void LoadDocument(); |
216 | 217 |
217 // Try loading the document. Returns true if the document is successfully | 218 // Try loading the document. Returns true if the document is successfully |
218 // loaded or is already loaded otherwise it will return false. If there is a | 219 // loaded or is already loaded otherwise it will return false. If there is a |
219 // password, then |password| is non-empty. If the document could not be loaded | 220 // password, then |password| is non-empty. If the document could not be loaded |
220 // and needs a password, |needs_password| will be set to true. | 221 // and needs a password, |needs_password| will be set to true. |
221 bool TryLoadingDoc(const std::string& password, bool* needs_password); | 222 bool TryLoadingDoc(const std::string& password, bool* needs_password); |
222 | 223 |
223 // Asks the user for the document password and then continue loading the | 224 // Asks the user for the document password and then continue loading the |
224 // document. | 225 // document. |
225 void GetPasswordAndLoad(); | 226 void GetPasswordAndLoad(); |
226 | 227 |
227 // Called when the password has been retrieved. | 228 // Called when the password has been retrieved. |
228 void OnGetPasswordComplete(int32_t result, | 229 void OnGetPasswordComplete(int32_t result, const pp::Var& password); |
229 const pp::Var& password); | |
230 | 230 |
231 // Continues loading the document when the password has been retrieved, or if | 231 // Continues loading the document when the password has been retrieved, or if |
232 // there is no password. If there is no password, then |password| is empty. | 232 // there is no password. If there is no password, then |password| is empty. |
233 void ContinueLoadingDocument(const std::string& password); | 233 void ContinueLoadingDocument(const std::string& password); |
234 | 234 |
235 // Finishes loading the document. Recalculate the document size if there were | 235 // Finishes loading the document. Recalculate the document size if there were |
236 // pages that were not previously available. | 236 // pages that were not previously available. |
237 // Also notifies the client that the document has been loaded. | 237 // Also notifies the client that the document has been loaded. |
238 // This should only be called after |doc_| has been loaded and the document is | 238 // This should only be called after |doc_| has been loaded and the document is |
239 // fully downloaded. | 239 // fully downloaded. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 // Given a page index, returns the corresponding index in progressive_rects_, | 373 // Given a page index, returns the corresponding index in progressive_rects_, |
374 // or -1 if it doesn't exist. | 374 // or -1 if it doesn't exist. |
375 int GetProgressiveIndex(int page_index) const; | 375 int GetProgressiveIndex(int page_index) const; |
376 | 376 |
377 // Creates a FPDF_BITMAP from a rectangle in screen coordinates. | 377 // Creates a FPDF_BITMAP from a rectangle in screen coordinates. |
378 FPDF_BITMAP CreateBitmap(const pp::Rect& rect, | 378 FPDF_BITMAP CreateBitmap(const pp::Rect& rect, |
379 pp::ImageData* image_data) const; | 379 pp::ImageData* image_data) const; |
380 | 380 |
381 // Given a rectangle in screen coordinates, returns the coordinates in the | 381 // Given a rectangle in screen coordinates, returns the coordinates in the |
382 // units that PDFium rendering functions expect. | 382 // units that PDFium rendering functions expect. |
383 void GetPDFiumRect(int page_index, const pp::Rect& rect, int* start_x, | 383 void GetPDFiumRect(int page_index, |
384 int* start_y, int* size_x, int* size_y) const; | 384 const pp::Rect& rect, |
| 385 int* start_x, |
| 386 int* start_y, |
| 387 int* size_x, |
| 388 int* size_y) const; |
385 | 389 |
386 // Returns the rendering flags to pass to PDFium. | 390 // Returns the rendering flags to pass to PDFium. |
387 int GetRenderingFlags() const; | 391 int GetRenderingFlags() const; |
388 | 392 |
389 // Returns the currently visible rectangle in document coordinates. | 393 // Returns the currently visible rectangle in document coordinates. |
390 pp::Rect GetVisibleRect() const; | 394 pp::Rect GetVisibleRect() const; |
391 | 395 |
392 // Given a rectangle in document coordinates, returns the rectange into screen | 396 // Given a rectangle in document coordinates, returns the rectange into screen |
393 // coordinates (i.e. 0,0 is top left corner of plugin area). If it's not | 397 // coordinates (i.e. 0,0 is top left corner of plugin area). If it's not |
394 // visible, an empty rectangle is returned. | 398 // visible, an empty rectangle is returned. |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 FileAvail file_availability_; | 671 FileAvail file_availability_; |
668 // Interface structure to request data chunks from the document stream. | 672 // Interface structure to request data chunks from the document stream. |
669 DownloadHints download_hints_; | 673 DownloadHints download_hints_; |
670 // Pointer to the document availability interface. | 674 // Pointer to the document availability interface. |
671 FPDF_AVAIL fpdf_availability_; | 675 FPDF_AVAIL fpdf_availability_; |
672 | 676 |
673 pp::Size default_page_size_; | 677 pp::Size default_page_size_; |
674 | 678 |
675 // Used to manage timers that form fill API needs. The pair holds the timer | 679 // Used to manage timers that form fill API needs. The pair holds the timer |
676 // period, in ms, and the callback function. | 680 // period, in ms, and the callback function. |
677 std::map<int, std::pair<int, TimerCallback> > timers_; | 681 std::map<int, std::pair<int, TimerCallback>> timers_; |
678 int next_timer_id_; | 682 int next_timer_id_; |
679 | 683 |
680 // Holds the zero-based page index of the last page that the mouse clicked on. | 684 // Holds the zero-based page index of the last page that the mouse clicked on. |
681 int last_page_mouse_down_; | 685 int last_page_mouse_down_; |
682 | 686 |
683 // Holds the zero-based page index of the most visible page; refreshed by | 687 // Holds the zero-based page index of the most visible page; refreshed by |
684 // calling CalculateVisiblePages() | 688 // calling CalculateVisiblePages() |
685 int most_visible_page_; | 689 int most_visible_page_; |
686 | 690 |
687 // Holds the page index requested by PDFium while the scroll operation | 691 // Holds the page index requested by PDFium while the scroll operation |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 bool GetPDFPageSizeByIndex(const void* pdf_buffer, | 793 bool GetPDFPageSizeByIndex(const void* pdf_buffer, |
790 int pdf_buffer_size, | 794 int pdf_buffer_size, |
791 int page_number, | 795 int page_number, |
792 double* width, | 796 double* width, |
793 double* height) override; | 797 double* height) override; |
794 }; | 798 }; |
795 | 799 |
796 } // namespace chrome_pdf | 800 } // namespace chrome_pdf |
797 | 801 |
798 #endif // PDF_PDFIUM_PDFIUM_ENGINE_H_ | 802 #endif // PDF_PDFIUM_PDFIUM_ENGINE_H_ |
OLD | NEW |