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 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1235 | 1235 |
1236 void PDFiumEngine::PrintEnd() { | 1236 void PDFiumEngine::PrintEnd() { |
1237 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); | 1237 FORM_DoDocumentAAction(form_, FPDFDOC_AACTION_DP); |
1238 } | 1238 } |
1239 | 1239 |
1240 PDFiumPage::Area PDFiumEngine::GetCharIndex( | 1240 PDFiumPage::Area PDFiumEngine::GetCharIndex( |
1241 const pp::MouseInputEvent& event, int* page_index, | 1241 const pp::MouseInputEvent& event, int* page_index, |
1242 int* char_index, PDFiumPage::LinkTarget* target) { | 1242 int* char_index, PDFiumPage::LinkTarget* target) { |
1243 // First figure out which page this is in. | 1243 // First figure out which page this is in. |
1244 pp::Point mouse_point = event.GetPosition(); | 1244 pp::Point mouse_point = event.GetPosition(); |
1245 pp::Point point( | 1245 return GetCharIndex(mouse_point, page_index, char_index, target); |
1246 static_cast<int>((mouse_point.x() + position_.x()) / current_zoom_), | |
1247 static_cast<int>((mouse_point.y() + position_.y()) / current_zoom_)); | |
1248 return GetCharIndex(point, page_index, char_index, target); | |
1249 } | 1246 } |
1250 | 1247 |
1251 PDFiumPage::Area PDFiumEngine::GetCharIndex( | 1248 PDFiumPage::Area PDFiumEngine::GetCharIndex( |
raymes
2014/09/08 01:25:38
It looks like this function expects |point| to be
Nikhil
2014/09/08 05:59:12
Done.
| |
1252 const pp::Point& point, | 1249 const pp::Point& point, |
1253 int* page_index, | 1250 int* page_index, |
1254 int* char_index, | 1251 int* char_index, |
1255 PDFiumPage::LinkTarget* target) { | 1252 PDFiumPage::LinkTarget* target) { |
1253 pp::Point test_point( | |
1254 static_cast<int>((point.x() + position_.x()) / current_zoom_), | |
1255 static_cast<int>((point.y() + position_.y()) / current_zoom_)); | |
1256 | |
1256 int page = -1; | 1257 int page = -1; |
1257 for (size_t i = 0; i < visible_pages_.size(); ++i) { | 1258 for (size_t i = 0; i < visible_pages_.size(); ++i) { |
1258 if (pages_[visible_pages_[i]]->rect().Contains(point)) { | 1259 if (pages_[visible_pages_[i]]->rect().Contains(test_point)) { |
1259 page = visible_pages_[i]; | 1260 page = visible_pages_[i]; |
1260 break; | 1261 break; |
1261 } | 1262 } |
1262 } | 1263 } |
1263 if (page == -1) | 1264 if (page == -1) |
1264 return PDFiumPage::NONSELECTABLE_AREA; | 1265 return PDFiumPage::NONSELECTABLE_AREA; |
1265 | 1266 |
1266 // If the page hasn't finished rendering, calling into the page sometimes | 1267 // If the page hasn't finished rendering, calling into the page sometimes |
1267 // leads to hangs. | 1268 // leads to hangs. |
1268 for (size_t i = 0; i < progressive_paints_.size(); ++i) { | 1269 for (size_t i = 0; i < progressive_paints_.size(); ++i) { |
1269 if (progressive_paints_[i].page_index == page) | 1270 if (progressive_paints_[i].page_index == page) |
1270 return PDFiumPage::NONSELECTABLE_AREA; | 1271 return PDFiumPage::NONSELECTABLE_AREA; |
1271 } | 1272 } |
1272 | 1273 |
1273 *page_index = page; | 1274 *page_index = page; |
1274 return pages_[page]->GetCharIndex(point, current_rotation_, char_index, | 1275 return pages_[page]->GetCharIndex( |
1275 target); | 1276 test_point, current_rotation_, char_index, target); |
1276 } | 1277 } |
1277 | 1278 |
1278 bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) { | 1279 bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) { |
1279 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT) | 1280 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT) |
1280 return false; | 1281 return false; |
1281 | 1282 |
1282 SelectionChangeInvalidator selection_invalidator(this); | 1283 SelectionChangeInvalidator selection_invalidator(this); |
1283 selection_.clear(); | 1284 selection_.clear(); |
1284 | 1285 |
1285 int page_index = -1; | 1286 int page_index = -1; |
(...skipping 2136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3422 double* height) { | 3423 double* height) { |
3423 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3424 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
3424 if (!doc) | 3425 if (!doc) |
3425 return false; | 3426 return false; |
3426 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3427 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
3427 FPDF_CloseDocument(doc); | 3428 FPDF_CloseDocument(doc); |
3428 return success; | 3429 return success; |
3429 } | 3430 } |
3430 | 3431 |
3431 } // namespace chrome_pdf | 3432 } // namespace chrome_pdf |
OLD | NEW |