Add ICU message format support
[chromium-blink-merge.git] / pdf / pdfium / pdfium_engine.h
blobc8ee6bdb4cb7030edfe5d57411fc4419d1c3e2e7
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
3 // found in the LICENSE file.
5 #ifndef PDF_PDFIUM_PDFIUM_ENGINE_H_
6 #define PDF_PDFIUM_PDFIUM_ENGINE_H_
8 #include <map>
9 #include <string>
10 #include <utility>
11 #include <vector>
13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/time.h"
15 #include "pdf/document_loader.h"
16 #include "pdf/pdf_engine.h"
17 #include "pdf/pdfium/pdfium_page.h"
18 #include "pdf/pdfium/pdfium_range.h"
19 #include "ppapi/cpp/completion_callback.h"
20 #include "ppapi/cpp/dev/buffer_dev.h"
21 #include "ppapi/cpp/image_data.h"
22 #include "ppapi/cpp/point.h"
23 #include "ppapi/cpp/var_array.h"
24 #include "third_party/pdfium/public/fpdf_dataavail.h"
25 #include "third_party/pdfium/public/fpdf_formfill.h"
26 #include "third_party/pdfium/public/fpdf_progressive.h"
27 #include "third_party/pdfium/public/fpdfview.h"
29 namespace pp {
30 class KeyboardInputEvent;
31 class MouseInputEvent;
32 class VarDictionary;
35 namespace chrome_pdf {
37 class ShadowMatrix;
39 class PDFiumEngine : public PDFEngine,
40 public DocumentLoader::Client,
41 public FPDF_FORMFILLINFO,
42 public IPDF_JSPLATFORM,
43 public IFSDK_PAUSE {
44 public:
45 explicit PDFiumEngine(PDFEngine::Client* client);
46 virtual ~PDFiumEngine();
48 // PDFEngine implementation.
49 virtual bool New(const char* url, const char* headers);
50 virtual void PageOffsetUpdated(const pp::Point& page_offset);
51 virtual void PluginSizeUpdated(const pp::Size& size);
52 virtual void ScrolledToXPosition(int position);
53 virtual void ScrolledToYPosition(int position);
54 virtual void PrePaint();
55 virtual void Paint(const pp::Rect& rect,
56 pp::ImageData* image_data,
57 std::vector<pp::Rect>* ready,
58 std::vector<pp::Rect>* pending);
59 virtual void PostPaint();
60 virtual bool HandleDocumentLoad(const pp::URLLoader& loader);
61 virtual bool HandleEvent(const pp::InputEvent& event);
62 virtual uint32_t QuerySupportedPrintOutputFormats();
63 virtual void PrintBegin();
64 virtual pp::Resource PrintPages(
65 const PP_PrintPageNumberRange_Dev* page_ranges,
66 uint32_t page_range_count,
67 const PP_PrintSettings_Dev& print_settings);
68 virtual void PrintEnd();
69 virtual void StartFind(const char* text, bool case_sensitive);
70 virtual bool SelectFindResult(bool forward);
71 virtual void StopFind();
72 virtual void ZoomUpdated(double new_zoom_level);
73 virtual void RotateClockwise();
74 virtual void RotateCounterclockwise();
75 virtual std::string GetSelectedText();
76 virtual std::string GetLinkAtPosition(const pp::Point& point);
77 virtual bool IsSelecting();
78 virtual bool HasPermission(DocumentPermission permission) const;
79 virtual void SelectAll();
80 virtual int GetNumberOfPages();
81 virtual pp::VarArray GetBookmarks();
82 virtual int GetNamedDestinationPage(const std::string& destination);
83 virtual int GetFirstVisiblePage();
84 virtual int GetMostVisiblePage();
85 virtual pp::Rect GetPageRect(int index);
86 virtual pp::Rect GetPageContentsRect(int index);
87 virtual pp::Rect GetPageScreenRect(int page_index) const;
88 virtual int GetVerticalScrollbarYPosition() { return position_.y(); }
89 virtual void PaintThumbnail(pp::ImageData* image_data, int index);
90 virtual void SetGrayscale(bool grayscale);
91 virtual void OnCallback(int id);
92 virtual std::string GetPageAsJSON(int index);
93 virtual bool GetPrintScaling();
94 virtual int GetCopiesToPrint();
95 virtual int GetDuplexType();
96 virtual bool GetPageSizeAndUniformity(pp::Size* size);
97 virtual void AppendBlankPages(int num_pages);
98 virtual void AppendPage(PDFEngine* engine, int index);
99 virtual pp::Point GetScrollPosition();
100 virtual void SetScrollPosition(const pp::Point& position);
101 virtual bool IsProgressiveLoad();
103 // DocumentLoader::Client implementation.
104 virtual pp::Instance* GetPluginInstance();
105 virtual pp::URLLoader CreateURLLoader();
106 virtual void OnPartialDocumentLoaded();
107 virtual void OnPendingRequestComplete();
108 virtual void OnNewDataAvailable();
109 virtual void OnDocumentComplete();
111 void UnsupportedFeature(int type);
113 std::string current_find_text() const { return current_find_text_; }
115 FPDF_DOCUMENT doc() { return doc_; }
116 FPDF_FORMHANDLE form() { return form_; }
118 private:
119 // This helper class is used to detect the difference in selection between
120 // construction and destruction. At destruction, it invalidates all the
121 // parts that are newly selected, along with all the parts that used to be
122 // selected but are not anymore.
123 class SelectionChangeInvalidator {
124 public:
125 explicit SelectionChangeInvalidator(PDFiumEngine* engine);
126 ~SelectionChangeInvalidator();
127 private:
128 // Sets the given container to the all the currently visible selection
129 // rectangles, in screen coordinates.
130 void GetVisibleSelectionsScreenRects(std::vector<pp::Rect>* rects);
132 PDFiumEngine* engine_;
133 // Screen rectangles that were selected on construction.
134 std::vector<pp::Rect> old_selections_;
135 // The origin at the time this object was constructed.
136 pp::Point previous_origin_;
139 // Used to store mouse down state to handle it in other mouse event handlers.
140 class MouseDownState {
141 public:
142 MouseDownState(const PDFiumPage::Area& area,
143 const PDFiumPage::LinkTarget& target);
144 ~MouseDownState();
146 void Set(const PDFiumPage::Area& area,
147 const PDFiumPage::LinkTarget& target);
148 void Reset();
149 bool Matches(const PDFiumPage::Area& area,
150 const PDFiumPage::LinkTarget& target) const;
152 private:
153 PDFiumPage::Area area_;
154 PDFiumPage::LinkTarget target_;
156 DISALLOW_COPY_AND_ASSIGN(MouseDownState);
159 // Used to store the state of a text search.
160 class FindTextIndex {
161 public:
162 FindTextIndex();
163 ~FindTextIndex();
165 bool valid() const { return valid_; }
166 void Invalidate();
168 size_t GetIndex() const;
169 void SetIndex(size_t index);
170 size_t IncrementIndex();
172 private:
173 bool valid_; // Whether |index_| is valid or not.
174 size_t index_; // The current search result, 0-based.
176 DISALLOW_COPY_AND_ASSIGN(FindTextIndex);
179 friend class SelectionChangeInvalidator;
181 struct FileAvail : public FX_FILEAVAIL {
182 DocumentLoader* loader;
185 struct DownloadHints : public FX_DOWNLOADHINTS {
186 DocumentLoader* loader;
189 // PDFium interface to get block of data.
190 static int GetBlock(void* param, unsigned long position,
191 unsigned char* buffer, unsigned long size);
193 // PDFium interface to check is block of data is available.
194 static FPDF_BOOL IsDataAvail(FX_FILEAVAIL* param,
195 size_t offset, size_t size);
197 // PDFium interface to request download of the block of data.
198 static void AddSegment(FX_DOWNLOADHINTS* param,
199 size_t offset, size_t size);
201 // We finished getting the pdf file, so load it. This will complete
202 // asynchronously (due to password fetching) and may be run multiple times.
203 void LoadDocument();
205 // Try loading the document. Returns true if the document is successfully
206 // loaded or is already loaded otherwise it will return false. If
207 // |with_password| is set to true, the document will be loaded with
208 // |password|. If the document could not be loaded and needs a password,
209 // |needs_password| will be set to true.
210 bool TryLoadingDoc(bool with_password,
211 const std::string& password,
212 bool* needs_password);
214 // Ask the user for the document password and then continue loading the
215 // document.
216 void GetPasswordAndLoad();
218 // Called when the password has been retrieved.
219 void OnGetPasswordComplete(int32_t result,
220 const pp::Var& password);
222 // Continues loading the document when the password has been retrieved, or if
223 // there is no password.
224 void ContinueLoadingDocument(bool has_password,
225 const std::string& password);
227 // Finish loading the document and notify the client that the document has
228 // been loaded. This should only be run after |doc_| has been loaded and the
229 // document is fully downloaded. If this has been run once, it will result in
230 // a no-op.
231 void FinishLoadingDocument();
233 // Loads information about the pages in the document and calculate the
234 // document size.
235 void LoadPageInfo(bool reload);
237 // Calculate which pages should be displayed right now.
238 void CalculateVisiblePages();
240 // Returns true iff the given page index is visible. CalculateVisiblePages
241 // must have been called first.
242 bool IsPageVisible(int index) const;
244 // Checks if a page is now available, and if so marks it as such and returns
245 // true. Otherwise, it will return false and will add the index to the given
246 // array if it's not already there.
247 bool CheckPageAvailable(int index, std::vector<int>* pending);
249 // Helper function to get a given page's size in pixels. This is not part of
250 // PDFiumPage because we might not have that structure when we need this.
251 pp::Size GetPageSize(int index);
253 void GetAllScreenRectsUnion(std::vector<PDFiumRange>* rect_range,
254 const pp::Point& offset_point,
255 std::vector<pp::Rect>* rect_vector);
257 void UpdateTickMarks();
259 // Called to continue searching so we don't block the main thread.
260 void ContinueFind(int32_t result);
262 // Inserts a find result into find_results_, which is sorted.
263 void AddFindResult(const PDFiumRange& result);
265 // Search a page using PDFium's methods. Doesn't work with unicode. This
266 // function is just kept arount in case PDFium code is fixed.
267 void SearchUsingPDFium(const base::string16& term,
268 bool case_sensitive,
269 bool first_search,
270 int character_to_start_searching_from,
271 int current_page);
273 // Search a page ourself using ICU.
274 void SearchUsingICU(const base::string16& term,
275 bool case_sensitive,
276 bool first_search,
277 int character_to_start_searching_from,
278 int current_page);
280 // Input event handlers.
281 bool OnMouseDown(const pp::MouseInputEvent& event);
282 bool OnMouseUp(const pp::MouseInputEvent& event);
283 bool OnMouseMove(const pp::MouseInputEvent& event);
284 bool OnKeyDown(const pp::KeyboardInputEvent& event);
285 bool OnKeyUp(const pp::KeyboardInputEvent& event);
286 bool OnChar(const pp::KeyboardInputEvent& event);
288 FPDF_DOCUMENT CreateSinglePageRasterPdf(
289 double source_page_width,
290 double source_page_height,
291 const PP_PrintSettings_Dev& print_settings,
292 PDFiumPage* page_to_print);
294 pp::Buffer_Dev PrintPagesAsRasterPDF(
295 const PP_PrintPageNumberRange_Dev* page_ranges,
296 uint32_t page_range_count,
297 const PP_PrintSettings_Dev& print_settings);
299 pp::Buffer_Dev PrintPagesAsPDF(const PP_PrintPageNumberRange_Dev* page_ranges,
300 uint32_t page_range_count,
301 const PP_PrintSettings_Dev& print_settings);
303 pp::Buffer_Dev GetFlattenedPrintData(const FPDF_DOCUMENT& doc);
304 void FitContentsToPrintableAreaIfRequired(
305 const FPDF_DOCUMENT& doc,
306 const PP_PrintSettings_Dev& print_settings);
307 void SaveSelectedFormForPrint();
309 // Given a mouse event, returns which page and character location it's closest
310 // to.
311 PDFiumPage::Area GetCharIndex(const pp::MouseInputEvent& event,
312 int* page_index,
313 int* char_index,
314 int* form_type,
315 PDFiumPage::LinkTarget* target);
316 PDFiumPage::Area GetCharIndex(const pp::Point& point,
317 int* page_index,
318 int* char_index,
319 int* form_type,
320 PDFiumPage::LinkTarget* target);
322 void OnSingleClick(int page_index, int char_index);
323 void OnMultipleClick(int click_count, int page_index, int char_index);
325 // Starts a progressive paint operation given a rectangle in screen
326 // coordinates. Returns the index in progressive_rects_.
327 int StartPaint(int page_index, const pp::Rect& dirty);
329 // Continues a paint operation that was started earlier. Returns true if the
330 // paint is done, or false if it needs to be continued.
331 bool ContinuePaint(int progressive_index, pp::ImageData* image_data);
333 // Called once PDFium is finished rendering a page so that we draw our
334 // borders, highlighting etc.
335 void FinishPaint(int progressive_index, pp::ImageData* image_data);
337 // Stops any paints that are in progress.
338 void CancelPaints();
340 // Invalidates all pages. Use this when some global parameter, such as page
341 // orientation, has changed.
342 void InvalidateAllPages();
344 // If the page is narrower than the document size, paint the extra space
345 // with the page background.
346 void FillPageSides(int progressive_index);
348 void PaintPageShadow(int progressive_index, pp::ImageData* image_data);
350 // Highlight visible find results and selections.
351 void DrawSelections(int progressive_index, pp::ImageData* image_data);
353 // Paints an page that hasn't finished downloading.
354 void PaintUnavailablePage(int page_index,
355 const pp::Rect& dirty,
356 pp::ImageData* image_data);
358 // Given a page index, returns the corresponding index in progressive_rects_,
359 // or -1 if it doesn't exist.
360 int GetProgressiveIndex(int page_index) const;
362 // Creates a FPDF_BITMAP from a rectangle in screen coordinates.
363 FPDF_BITMAP CreateBitmap(const pp::Rect& rect,
364 pp::ImageData* image_data) const;
366 // Given a rectangle in screen coordinates, returns the coordinates in the
367 // units that PDFium rendering functions expect.
368 void GetPDFiumRect(int page_index, const pp::Rect& rect, int* start_x,
369 int* start_y, int* size_x, int* size_y) const;
371 // Returns the rendering flags to pass to PDFium.
372 int GetRenderingFlags() const;
374 // Returns the currently visible rectangle in document coordinates.
375 pp::Rect GetVisibleRect() const;
377 // Given a rectangle in document coordinates, returns the rectange into screen
378 // coordinates (i.e. 0,0 is top left corner of plugin area). If it's not
379 // visible, an empty rectangle is returned.
380 pp::Rect GetScreenRect(const pp::Rect& rect) const;
382 // Highlights the given rectangle.
383 void Highlight(void* buffer,
384 int stride,
385 const pp::Rect& rect,
386 std::vector<pp::Rect>* highlighted_rects);
388 // Helper function to convert a device to page coordinates. If the page is
389 // not yet loaded, page_x and page_y will be set to 0.
390 void DeviceToPage(int page_index,
391 float device_x,
392 float device_y,
393 double* page_x,
394 double* page_y);
396 // Helper function to get the index of a given FPDF_PAGE. Returns -1 if not
397 // found.
398 int GetVisiblePageIndex(FPDF_PAGE page);
400 // Helper function to change the current page, running page open/close
401 // triggers as necessary.
402 void SetCurrentPage(int index);
404 // Transform |page| contents to fit in the selected printer paper size.
405 void TransformPDFPageForPrinting(FPDF_PAGE page,
406 const PP_PrintSettings_Dev& print_settings);
408 void DrawPageShadow(const pp::Rect& page_rect,
409 const pp::Rect& shadow_rect,
410 const pp::Rect& clip_rect,
411 pp::ImageData* image_data);
413 void GetRegion(const pp::Point& location,
414 pp::ImageData* image_data,
415 void** region,
416 int* stride) const;
418 // Called when the selection changes.
419 void OnSelectionChanged();
421 // Common code shared by RotateClockwise() and RotateCounterclockwise().
422 void RotateInternal();
424 // Setting selection status of document.
425 void SetSelecting(bool selecting);
427 // FPDF_FORMFILLINFO callbacks.
428 static void Form_Invalidate(FPDF_FORMFILLINFO* param,
429 FPDF_PAGE page,
430 double left,
431 double top,
432 double right,
433 double bottom);
434 static void Form_OutputSelectedRect(FPDF_FORMFILLINFO* param,
435 FPDF_PAGE page,
436 double left,
437 double top,
438 double right,
439 double bottom);
440 static void Form_SetCursor(FPDF_FORMFILLINFO* param, int cursor_type);
441 static int Form_SetTimer(FPDF_FORMFILLINFO* param,
442 int elapse,
443 TimerCallback timer_func);
444 static void Form_KillTimer(FPDF_FORMFILLINFO* param, int timer_id);
445 static FPDF_SYSTEMTIME Form_GetLocalTime(FPDF_FORMFILLINFO* param);
446 static void Form_OnChange(FPDF_FORMFILLINFO* param);
447 static FPDF_PAGE Form_GetPage(FPDF_FORMFILLINFO* param,
448 FPDF_DOCUMENT document,
449 int page_index);
450 static FPDF_PAGE Form_GetCurrentPage(FPDF_FORMFILLINFO* param,
451 FPDF_DOCUMENT document);
452 static int Form_GetRotation(FPDF_FORMFILLINFO* param, FPDF_PAGE page);
453 static void Form_ExecuteNamedAction(FPDF_FORMFILLINFO* param,
454 FPDF_BYTESTRING named_action);
455 static void Form_SetTextFieldFocus(FPDF_FORMFILLINFO* param,
456 FPDF_WIDESTRING value,
457 FPDF_DWORD valueLen,
458 FPDF_BOOL is_focus);
459 static void Form_DoURIAction(FPDF_FORMFILLINFO* param, FPDF_BYTESTRING uri);
460 static void Form_DoGoToAction(FPDF_FORMFILLINFO* param,
461 int page_index,
462 int zoom_mode,
463 float* position_array,
464 int size_of_array);
466 // IPDF_JSPLATFORM callbacks.
467 static int Form_Alert(IPDF_JSPLATFORM* param,
468 FPDF_WIDESTRING message,
469 FPDF_WIDESTRING title,
470 int type,
471 int icon);
472 static void Form_Beep(IPDF_JSPLATFORM* param, int type);
473 static int Form_Response(IPDF_JSPLATFORM* param,
474 FPDF_WIDESTRING question,
475 FPDF_WIDESTRING title,
476 FPDF_WIDESTRING default_response,
477 FPDF_WIDESTRING label,
478 FPDF_BOOL password,
479 void* response,
480 int length);
481 static int Form_GetFilePath(IPDF_JSPLATFORM* param,
482 void* file_path,
483 int length);
484 static void Form_Mail(IPDF_JSPLATFORM* param,
485 void* mail_data,
486 int length,
487 FPDF_BOOL ui,
488 FPDF_WIDESTRING to,
489 FPDF_WIDESTRING subject,
490 FPDF_WIDESTRING cc,
491 FPDF_WIDESTRING bcc,
492 FPDF_WIDESTRING message);
493 static void Form_Print(IPDF_JSPLATFORM* param,
494 FPDF_BOOL ui,
495 int start,
496 int end,
497 FPDF_BOOL silent,
498 FPDF_BOOL shrink_to_fit,
499 FPDF_BOOL print_as_image,
500 FPDF_BOOL reverse,
501 FPDF_BOOL annotations);
502 static void Form_SubmitForm(IPDF_JSPLATFORM* param,
503 void* form_data,
504 int length,
505 FPDF_WIDESTRING url);
506 static void Form_GotoPage(IPDF_JSPLATFORM* param, int page_number);
507 static int Form_Browse(IPDF_JSPLATFORM* param, void* file_path, int length);
509 #ifdef PDF_USE_XFA
510 static void Form_EmailTo(FPDF_FORMFILLINFO* param,
511 FPDF_FILEHANDLER* file_handler,
512 FPDF_WIDESTRING to,
513 FPDF_WIDESTRING subject,
514 FPDF_WIDESTRING cc,
515 FPDF_WIDESTRING bcc,
516 FPDF_WIDESTRING message);
517 static void Form_DisplayCaret(FPDF_FORMFILLINFO* param,
518 FPDF_PAGE page,
519 FPDF_BOOL visible,
520 double left,
521 double top,
522 double right,
523 double bottom);
524 static void Form_SetCurrentPage(FPDF_FORMFILLINFO* param,
525 FPDF_DOCUMENT document,
526 int page);
527 static int Form_GetCurrentPageIndex(FPDF_FORMFILLINFO* param,
528 FPDF_DOCUMENT document);
529 static void Form_GetPageViewRect(FPDF_FORMFILLINFO* param,
530 FPDF_PAGE page,
531 double* left,
532 double* top,
533 double* right,
534 double* bottom);
535 static int Form_GetPlatform(FPDF_FORMFILLINFO* param,
536 void* platform,
537 int length);
538 static FPDF_BOOL Form_PopupMenu(FPDF_FORMFILLINFO* param,
539 FPDF_PAGE page,
540 FPDF_WIDGET widget,
541 int menu_flag,
542 float x,
543 float y);
544 static FPDF_BOOL Form_PostRequestURL(FPDF_FORMFILLINFO* param,
545 FPDF_WIDESTRING url,
546 FPDF_WIDESTRING data,
547 FPDF_WIDESTRING content_type,
548 FPDF_WIDESTRING encode,
549 FPDF_WIDESTRING header,
550 FPDF_BSTR* response);
551 static FPDF_BOOL Form_PutRequestURL(FPDF_FORMFILLINFO* param,
552 FPDF_WIDESTRING url,
553 FPDF_WIDESTRING data,
554 FPDF_WIDESTRING encode);
555 static void Form_UploadTo(FPDF_FORMFILLINFO* param,
556 FPDF_FILEHANDLER* file_handler,
557 int file_flag,
558 FPDF_WIDESTRING dest);
559 static FPDF_LPFILEHANDLER Form_DownloadFromURL(FPDF_FORMFILLINFO* param,
560 FPDF_WIDESTRING url);
561 static FPDF_FILEHANDLER* Form_OpenFile(FPDF_FORMFILLINFO* param,
562 int file_flag,
563 FPDF_WIDESTRING url,
564 const char* mode);
565 static void Form_GotoURL(FPDF_FORMFILLINFO* param,
566 FPDF_DOCUMENT document,
567 FPDF_WIDESTRING url);
568 static int Form_GetLanguage(FPDF_FORMFILLINFO* param,
569 void* language,
570 int length);
571 #endif // PDF_USE_XFA
573 // IFSDK_PAUSE callbacks
574 static FPDF_BOOL Pause_NeedToPauseNow(IFSDK_PAUSE* param);
576 PDFEngine::Client* client_;
577 pp::Size document_size_; // Size of document in pixels.
579 // The scroll position in screen coordinates.
580 pp::Point position_;
581 // The offset of the page into the viewport.
582 pp::Point page_offset_;
583 // The plugin size in screen coordinates.
584 pp::Size plugin_size_;
585 double current_zoom_;
586 unsigned int current_rotation_;
588 DocumentLoader doc_loader_; // Main document's loader.
589 std::string url_;
590 std::string headers_;
591 pp::CompletionCallbackFactory<PDFiumEngine> find_factory_;
593 pp::CompletionCallbackFactory<PDFiumEngine> password_factory_;
594 int32_t password_tries_remaining_;
596 // The current text used for searching.
597 std::string current_find_text_;
599 // The PDFium wrapper object for the document.
600 FPDF_DOCUMENT doc_;
602 // The PDFium wrapper for form data. Used even if there are no form controls
603 // on the page.
604 FPDF_FORMHANDLE form_;
606 // The page(s) of the document. Store a vector of pointers so that when the
607 // vector is resized we don't close the pages that are used in pending
608 // paints.
609 std::vector<PDFiumPage*> pages_;
611 // The indexes of the pages currently visible.
612 std::vector<int> visible_pages_;
614 // The indexes of the pages pending download.
615 std::vector<int> pending_pages_;
617 // During handling of input events we don't want to unload any pages in
618 // callbacks to us from PDFium, since the current page can change while PDFium
619 // code still has a pointer to it.
620 bool defer_page_unload_;
621 std::vector<int> deferred_page_unloads_;
623 // Used for selection. There could be more than one range if selection spans
624 // more than one page.
625 std::vector<PDFiumRange> selection_;
626 // True if we're in the middle of selection.
627 bool selecting_;
629 MouseDownState mouse_down_state_;
631 // Used for searching.
632 typedef std::vector<PDFiumRange> FindResults;
633 FindResults find_results_;
634 // Which page to search next.
635 int next_page_to_search_;
636 // Where to stop searching.
637 int last_page_to_search_;
638 int last_character_index_to_search_; // -1 if search until end of page.
639 // Which result the user has currently selected.
640 FindTextIndex current_find_index_;
641 // Where to resume searching.
642 FindTextIndex resume_find_index_;
644 // Permissions bitfield.
645 unsigned long permissions_;
647 // Permissions security handler revision number. -1 for unknown.
648 int permissions_handler_revision_;
650 // Interface structure to provide access to document stream.
651 FPDF_FILEACCESS file_access_;
652 // Interface structure to check data availability in the document stream.
653 FileAvail file_availability_;
654 // Interface structure to request data chunks from the document stream.
655 DownloadHints download_hints_;
656 // Pointer to the document availability interface.
657 FPDF_AVAIL fpdf_availability_;
659 pp::Size default_page_size_;
661 // Used to manage timers that form fill API needs. The pair holds the timer
662 // period, in ms, and the callback function.
663 std::map<int, std::pair<int, TimerCallback> > timers_;
664 int next_timer_id_;
666 // Holds the page index of the last page that the mouse clicked on.
667 int last_page_mouse_down_;
669 // Holds the page index of the first visible page; refreshed by calling
670 // CalculateVisiblePages()
671 int first_visible_page_;
673 // Holds the page index of the most visible page; refreshed by calling
674 // CalculateVisiblePages()
675 int most_visible_page_;
677 // Set to true after FORM_DoDocumentJSAction/FORM_DoDocumentOpenAction have
678 // been called. Only after that can we call FORM_DoPageAAction.
679 bool called_do_document_action_;
681 // Records parts of form fields that need to be highlighted at next paint, in
682 // screen coordinates.
683 std::vector<pp::Rect> form_highlights_;
685 // Whether to render in grayscale or in color.
686 bool render_grayscale_;
688 // The link currently under the cursor.
689 std::string link_under_cursor_;
691 // Pending progressive paints.
692 struct ProgressivePaint {
693 pp::Rect rect; // In screen coordinates.
694 FPDF_BITMAP bitmap;
695 int page_index;
696 // Temporary used to figure out if in a series of Paint() calls whether this
697 // pending paint was updated or not.
698 bool painted_;
700 std::vector<ProgressivePaint> progressive_paints_;
702 // Keeps track of when we started the last progressive paint, so that in our
703 // callback we can determine if we need to pause.
704 base::Time last_progressive_start_time_;
706 // The timeout to use for the current progressive paint.
707 int progressive_paint_timeout_;
709 // Shadow matrix for generating the page shadow bitmap.
710 scoped_ptr<ShadowMatrix> page_shadow_;
712 // Set to true if the user is being prompted for their password. Will be set
713 // to false after the user finishes getting their password.
714 bool getting_password_;
716 DISALLOW_COPY_AND_ASSIGN(PDFiumEngine);
719 // Create a local variable of this when calling PDFium functions which can call
720 // our global callback when an unsupported feature is reached.
721 class ScopedUnsupportedFeature {
722 public:
723 explicit ScopedUnsupportedFeature(PDFiumEngine* engine);
724 ~ScopedUnsupportedFeature();
725 private:
726 PDFiumEngine* engine_;
727 PDFiumEngine* old_engine_;
730 class PDFiumEngineExports : public PDFEngineExports {
731 public:
732 PDFiumEngineExports() {}
733 #if defined(OS_WIN)
734 // See the definition of RenderPDFPageToDC in pdf.cc for details.
735 virtual bool RenderPDFPageToDC(const void* pdf_buffer,
736 int buffer_size,
737 int page_number,
738 const RenderingSettings& settings,
739 HDC dc);
740 #endif // OS_WIN
741 virtual bool RenderPDFPageToBitmap(const void* pdf_buffer,
742 int pdf_buffer_size,
743 int page_number,
744 const RenderingSettings& settings,
745 void* bitmap_buffer);
747 virtual bool GetPDFDocInfo(const void* pdf_buffer,
748 int buffer_size,
749 int* page_count,
750 double* max_page_width);
752 // See the definition of GetPDFPageSizeByIndex in pdf.cc for details.
753 virtual bool GetPDFPageSizeByIndex(const void* pdf_buffer,
754 int pdf_buffer_size, int page_number,
755 double* width, double* height);
758 } // namespace chrome_pdf
760 #endif // PDF_PDFIUM_PDFIUM_ENGINE_H_