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 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1284 return false; | 1284 return false; |
1285 | 1285 |
1286 SelectionChangeInvalidator selection_invalidator(this); | 1286 SelectionChangeInvalidator selection_invalidator(this); |
1287 selection_.clear(); | 1287 selection_.clear(); |
1288 | 1288 |
1289 int page_index = -1; | 1289 int page_index = -1; |
1290 int char_index = -1; | 1290 int char_index = -1; |
1291 PDFiumPage::LinkTarget target; | 1291 PDFiumPage::LinkTarget target; |
1292 PDFiumPage::Area area = GetCharIndex(event, &page_index, | 1292 PDFiumPage::Area area = GetCharIndex(event, &page_index, |
1293 &char_index, &target); | 1293 &char_index, &target); |
1294 if (area == PDFiumPage::WEBLINK_AREA) { | 1294 mouse_down_state_ = MouseDownState(area, target); |
1295 bool open_in_new_tab = !!(event.GetModifiers() & kDefaultKeyModifier); | 1295 |
1296 client_->NavigateTo(target.url, open_in_new_tab); | 1296 // Decide whether to open link or not based on user action in mouse up and |
1297 client_->FormTextFieldFocusChange(false); | 1297 // mouse move events. |
| 1298 if (area == PDFiumPage::WEBLINK_AREA) |
1298 return true; | 1299 return true; |
1299 } | |
1300 | 1300 |
1301 if (area == PDFiumPage::DOCLINK_AREA) { | 1301 if (area == PDFiumPage::DOCLINK_AREA) { |
1302 client_->ScrollToPage(target.page); | 1302 client_->ScrollToPage(target.page); |
1303 client_->FormTextFieldFocusChange(false); | 1303 client_->FormTextFieldFocusChange(false); |
1304 return true; | 1304 return true; |
1305 } | 1305 } |
1306 | 1306 |
1307 if (page_index != -1) { | 1307 if (page_index != -1) { |
1308 last_page_mouse_down_ = page_index; | 1308 last_page_mouse_down_ = page_index; |
1309 double page_x, page_y; | 1309 double page_x, page_y; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1367 selection_.push_back(PDFiumRange( | 1367 selection_.push_back(PDFiumRange( |
1368 pages_[page_index], start_index, end_index - start_index)); | 1368 pages_[page_index], start_index, end_index - start_index)); |
1369 } | 1369 } |
1370 | 1370 |
1371 bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) { | 1371 bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) { |
1372 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT) | 1372 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT) |
1373 return false; | 1373 return false; |
1374 | 1374 |
1375 int page_index = -1; | 1375 int page_index = -1; |
1376 int char_index = -1; | 1376 int char_index = -1; |
1377 GetCharIndex(event, &page_index, &char_index, NULL); | 1377 PDFiumPage::LinkTarget target; |
| 1378 PDFiumPage::Area area = |
| 1379 GetCharIndex(event, &page_index, &char_index, &target); |
| 1380 |
| 1381 // Open link on mouse up for same link for which mouse down happened earlier. |
| 1382 if (mouse_down_state_ == MouseDownState(area, target)) { |
| 1383 if (area == PDFiumPage::WEBLINK_AREA) { |
| 1384 bool open_in_new_tab = !!(event.GetModifiers() & kDefaultKeyModifier); |
| 1385 client_->NavigateTo(target.url, open_in_new_tab); |
| 1386 client_->FormTextFieldFocusChange(false); |
| 1387 return true; |
| 1388 } |
| 1389 } |
| 1390 |
1378 if (page_index != -1) { | 1391 if (page_index != -1) { |
1379 double page_x, page_y; | 1392 double page_x, page_y; |
1380 pp::Point point = event.GetPosition(); | 1393 pp::Point point = event.GetPosition(); |
1381 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); | 1394 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); |
1382 FORM_OnLButtonUp( | 1395 FORM_OnLButtonUp( |
1383 form_, pages_[page_index]->GetPage(), 0, page_x, page_y); | 1396 form_, pages_[page_index]->GetPage(), 0, page_x, page_y); |
1384 } | 1397 } |
1385 | 1398 |
1386 if (!selecting_) | 1399 if (!selecting_) |
1387 return false; | 1400 return false; |
1388 | 1401 |
1389 selecting_ = false; | 1402 selecting_ = false; |
1390 return true; | 1403 return true; |
1391 } | 1404 } |
1392 | 1405 |
1393 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { | 1406 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { |
1394 int page_index = -1; | 1407 int page_index = -1; |
1395 int char_index = -1; | 1408 int char_index = -1; |
1396 PDFiumPage::Area area = GetCharIndex(event, &page_index, &char_index, NULL); | 1409 PDFiumPage::LinkTarget target; |
| 1410 PDFiumPage::Area area = |
| 1411 GetCharIndex(event, &page_index, &char_index, &target); |
| 1412 |
| 1413 // Clear |mouse_down_state_| if mouse moves away from where the mouse down |
| 1414 // happened. |
| 1415 if (mouse_down_state_ != MouseDownState(area, target)) |
| 1416 mouse_down_state_ = MouseDownState(); |
| 1417 |
1397 if (!selecting_) { | 1418 if (!selecting_) { |
1398 PP_CursorType_Dev cursor; | 1419 PP_CursorType_Dev cursor; |
1399 switch (area) { | 1420 switch (area) { |
1400 case PDFiumPage::TEXT_AREA: | 1421 case PDFiumPage::TEXT_AREA: |
1401 cursor = PP_CURSORTYPE_IBEAM; | 1422 cursor = PP_CURSORTYPE_IBEAM; |
1402 break; | 1423 break; |
1403 case PDFiumPage::WEBLINK_AREA: | 1424 case PDFiumPage::WEBLINK_AREA: |
1404 case PDFiumPage::DOCLINK_AREA: | 1425 case PDFiumPage::DOCLINK_AREA: |
1405 cursor = PP_CURSORTYPE_HAND; | 1426 cursor = PP_CURSORTYPE_HAND; |
1406 break; | 1427 break; |
(...skipping 2022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3429 double* height) { | 3450 double* height) { |
3430 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3451 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
3431 if (!doc) | 3452 if (!doc) |
3432 return false; | 3453 return false; |
3433 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3454 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
3434 FPDF_CloseDocument(doc); | 3455 FPDF_CloseDocument(doc); |
3435 return success; | 3456 return success; |
3436 } | 3457 } |
3437 | 3458 |
3438 } // namespace chrome_pdf | 3459 } // namespace chrome_pdf |
OLD | NEW |