Trace LatencyInfo flow event in Display::DrawAndSwap()
[chromium-blink-merge.git] / pdf / pdfium / pdfium_page.h
blob3cca04c67168992bcd39f377f4107f7e321b7d7a
1 // Copyright (c) 2010 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_PAGE_H_
6 #define PDF_PDFIUM_PDFIUM_PAGE_H_
8 #include <string>
9 #include <vector>
11 #include "base/strings/string16.h"
12 #include "ppapi/cpp/rect.h"
13 #include "third_party/pdfium/public/fpdf_doc.h"
14 #include "third_party/pdfium/public/fpdf_formfill.h"
15 #include "third_party/pdfium/public/fpdf_text.h"
17 namespace base {
18 class Value;
21 namespace chrome_pdf {
23 class PDFiumEngine;
25 // Wrapper around a page from the document.
26 class PDFiumPage {
27 public:
28 PDFiumPage(PDFiumEngine* engine,
29 int i,
30 const pp::Rect& r,
31 bool available);
32 ~PDFiumPage();
33 // Unloads the PDFium data for this page from memory.
34 void Unload();
35 // Gets the FPDF_PAGE for this page, loading and parsing it if necessary.
36 FPDF_PAGE GetPage();
37 // Get the FPDF_PAGE for printing.
38 FPDF_PAGE GetPrintPage();
39 // Close the printing page.
40 void ClosePrintPage();
42 // Returns FPDF_TEXTPAGE for the page, loading and parsing it if necessary.
43 FPDF_TEXTPAGE GetTextPage();
45 // Returns a DictionaryValue version of the page.
46 base::Value* GetAccessibleContentAsValue(int rotation);
48 enum Area {
49 NONSELECTABLE_AREA,
50 TEXT_AREA,
51 WEBLINK_AREA, // Area is a hyperlink.
52 DOCLINK_AREA, // Area is a link to a different part of the same document.
55 struct LinkTarget {
56 // We are using std::string here which have a copy contructor.
57 // That prevents us from using union here.
58 std::string url; // Valid for WEBLINK_AREA only.
59 int page; // Valid for DOCLINK_AREA only.
62 // Given a point in the document that's in this page, returns its character
63 // index if it's near a character, and also the type of text.
64 // Target is optional. It will be filled in for WEBLINK_AREA or
65 // DOCLINK_AREA only.
66 Area GetCharIndex(const pp::Point& point, int rotation, int* char_index,
67 int* form_type, LinkTarget* target);
69 // Gets the character at the given index.
70 base::char16 GetCharAtIndex(int index);
72 // Gets the number of characters in the page.
73 int GetCharCount();
75 // Converts from page coordinates to screen coordinates.
76 pp::Rect PageToScreen(const pp::Point& offset,
77 double zoom,
78 double left,
79 double top,
80 double right,
81 double bottom,
82 int rotation);
84 int index() const { return index_; }
85 pp::Rect rect() const { return rect_; }
86 void set_rect(const pp::Rect& r) { rect_ = r; }
87 bool available() const { return available_; }
88 void set_available(bool available) { available_ = available; }
89 void set_calculated_links(bool calculated_links) {
90 calculated_links_ = calculated_links;
93 private:
94 // Returns a link index if the given character index is over a link, or -1
95 // otherwise.
96 int GetLink(int char_index, LinkTarget* target);
97 // Returns the link indices if the given rect intersects a link rect, or an
98 // empty vector otherwise.
99 std::vector<int> GetLinks(pp::Rect text_area,
100 std::vector<LinkTarget>* targets);
101 // Calculate the locations of any links on the page.
102 void CalculateLinks();
103 // Returns link type and target associated with a link. Returns
104 // NONSELECTABLE_AREA if link detection failed.
105 Area GetLinkTarget(FPDF_LINK link, LinkTarget* target);
106 // Returns target associated with a destination.
107 Area GetDestinationTarget(FPDF_DEST destination, LinkTarget* target);
108 // Returns the text in the supplied box as a Value Node
109 base::Value* GetTextBoxAsValue(double page_height, double left, double top,
110 double right, double bottom, int rotation);
111 // Helper functions for JSON generation
112 base::Value* CreateTextNode(std::string text);
113 base::Value* CreateURLNode(std::string text, std::string url);
115 class ScopedLoadCounter {
116 public:
117 explicit ScopedLoadCounter(PDFiumPage* page);
118 ~ScopedLoadCounter();
120 private:
121 PDFiumPage* const page_;
124 struct Link {
125 Link();
126 ~Link();
128 std::string url;
129 // Bounding rectangles of characters.
130 std::vector<pp::Rect> rects;
133 PDFiumEngine* engine_;
134 FPDF_PAGE page_;
135 FPDF_TEXTPAGE text_page_;
136 int index_;
137 int loading_count_;
138 pp::Rect rect_;
139 bool calculated_links_;
140 std::vector<Link> links_;
141 bool available_;
144 } // namespace chrome_pdf
146 #endif // PDF_PDFIUM_PDFIUM_PAGE_H_