Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 2127383002: Open hyperlinks in PDF in a new tab when middle mouse clicking. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Open hyperlinks in PDF in a new tab when middle mouse clicking. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/data/pdf/test-link.pdf ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 1509 matching lines...) Expand 10 before | Expand all | Expand 10 after
1520 &selection_rect_vector); 1520 &selection_rect_vector);
1521 pp::Point point = event.GetPosition(); 1521 pp::Point point = event.GetPosition();
1522 for (const auto& rect : selection_rect_vector) { 1522 for (const auto& rect : selection_rect_vector) {
1523 if (rect.Contains(point.x(), point.y())) 1523 if (rect.Contains(point.x(), point.y()))
1524 return false; 1524 return false;
1525 } 1525 }
1526 SelectionChangeInvalidator selection_invalidator(this); 1526 SelectionChangeInvalidator selection_invalidator(this);
1527 selection_.clear(); 1527 selection_.clear();
1528 return true; 1528 return true;
1529 } 1529 }
1530 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT) 1530
1531 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT &&
1532 event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) {
1531 return false; 1533 return false;
1534 }
1532 1535
1533 SelectionChangeInvalidator selection_invalidator(this); 1536 SelectionChangeInvalidator selection_invalidator(this);
1534 selection_.clear(); 1537 selection_.clear();
1535 1538
1536 int page_index = -1; 1539 int page_index = -1;
1537 int char_index = -1; 1540 int char_index = -1;
1538 int form_type = FPDF_FORMFIELD_UNKNOWN; 1541 int form_type = FPDF_FORMFIELD_UNKNOWN;
1539 PDFiumPage::LinkTarget target; 1542 PDFiumPage::LinkTarget target;
1540 PDFiumPage::Area area = 1543 PDFiumPage::Area area =
1541 GetCharIndex(event, &page_index, &char_index, &form_type, &target); 1544 GetCharIndex(event, &page_index, &char_index, &form_type, &target);
1542 mouse_down_state_.Set(area, target); 1545 mouse_down_state_.Set(area, target);
1543 1546
1544 // Decide whether to open link or not based on user action in mouse up and 1547 // Decide whether to open link or not based on user action in mouse up and
1545 // mouse move events. 1548 // mouse move events.
1546 if (area == PDFiumPage::WEBLINK_AREA) 1549 if (area == PDFiumPage::WEBLINK_AREA)
1547 return true; 1550 return true;
1548 1551
1552 // Prevent middle mouse button from selecting texts.
1553 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE)
1554 return false;
1555
1549 if (area == PDFiumPage::DOCLINK_AREA) { 1556 if (area == PDFiumPage::DOCLINK_AREA) {
1550 client_->ScrollToPage(target.page); 1557 client_->ScrollToPage(target.page);
1551 client_->FormTextFieldFocusChange(false); 1558 client_->FormTextFieldFocusChange(false);
1552 return true; 1559 return true;
1553 } 1560 }
1554 1561
1555 if (page_index != -1) { 1562 if (page_index != -1) {
1556 last_page_mouse_down_ = page_index; 1563 last_page_mouse_down_ = page_index;
1557 double page_x, page_y; 1564 double page_x, page_y;
1558 pp::Point point = event.GetPosition(); 1565 pp::Point point = event.GetPosition();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 base::char16 cur = pages_[page_index]->GetCharAtIndex(end_index); 1620 base::char16 cur = pages_[page_index]->GetCharAtIndex(end_index);
1614 if (cur == '\n' || (click_count == 2 && (cur == ' ' || cur == '\t'))) 1621 if (cur == '\n' || (click_count == 2 && (cur == ' ' || cur == '\t')))
1615 break; 1622 break;
1616 } 1623 }
1617 1624
1618 selection_.push_back(PDFiumRange( 1625 selection_.push_back(PDFiumRange(
1619 pages_[page_index], start_index, end_index - start_index)); 1626 pages_[page_index], start_index, end_index - start_index));
1620 } 1627 }
1621 1628
1622 bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) { 1629 bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) {
1623 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT) 1630
1631 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT &&
1632 event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) {
1624 return false; 1633 return false;
1634 }
1625 1635
1626 int page_index = -1; 1636 int page_index = -1;
1627 int char_index = -1; 1637 int char_index = -1;
1628 int form_type = FPDF_FORMFIELD_UNKNOWN; 1638 int form_type = FPDF_FORMFIELD_UNKNOWN;
1629 PDFiumPage::LinkTarget target; 1639 PDFiumPage::LinkTarget target;
1630 PDFiumPage::Area area = 1640 PDFiumPage::Area area =
1631 GetCharIndex(event, &page_index, &char_index, &form_type, &target); 1641 GetCharIndex(event, &page_index, &char_index, &form_type, &target);
1632 1642
1633 // Open link on mouse up for same link for which mouse down happened earlier. 1643 // Open link on mouse up for same link for which mouse down happened earlier.
1634 if (mouse_down_state_.Matches(area, target)) { 1644 if (mouse_down_state_.Matches(area, target)) {
1635 if (area == PDFiumPage::WEBLINK_AREA) { 1645 if (area == PDFiumPage::WEBLINK_AREA) {
1636 bool open_in_new_tab = !!(event.GetModifiers() & kDefaultKeyModifier); 1646 bool open_in_new_tab = !!(event.GetModifiers() & kDefaultKeyModifier) ||
1647 !!(event.GetModifiers() & PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN);
1637 client_->NavigateTo(target.url, open_in_new_tab); 1648 client_->NavigateTo(target.url, open_in_new_tab);
1638 client_->FormTextFieldFocusChange(false); 1649 client_->FormTextFieldFocusChange(false);
1639 return true; 1650 return true;
1640 } 1651 }
1641 } 1652 }
1642 1653
1654 // Prevent middle mouse button from selecting texts.
1655 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE)
1656 return false;
1657
1643 if (page_index != -1) { 1658 if (page_index != -1) {
1644 double page_x, page_y; 1659 double page_x, page_y;
1645 pp::Point point = event.GetPosition(); 1660 pp::Point point = event.GetPosition();
1646 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); 1661 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y);
1647 FORM_OnLButtonUp( 1662 FORM_OnLButtonUp(
1648 form_, pages_[page_index]->GetPage(), 0, page_x, page_y); 1663 form_, pages_[page_index]->GetPage(), 0, page_x, page_y);
1649 } 1664 }
1650 1665
1651 if (!selecting_) 1666 if (!selecting_)
1652 return false; 1667 return false;
(...skipping 2240 matching lines...) Expand 10 before | Expand all | Expand 10 after
3893 FPDF_DOCUMENT doc = 3908 FPDF_DOCUMENT doc =
3894 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 3909 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
3895 if (!doc) 3910 if (!doc)
3896 return false; 3911 return false;
3897 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3912 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3898 FPDF_CloseDocument(doc); 3913 FPDF_CloseDocument(doc);
3899 return success; 3914 return success;
3900 } 3915 }
3901 3916
3902 } // namespace chrome_pdf 3917 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « chrome/test/data/pdf/test-link.pdf ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698