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

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
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 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE)
Lei Zhang 2016/07/14 00:03:39 Add a comment to explain why we return here.
jaepark 2016/07/14 00:59:40 Done.
1553 return false;
1554
1549 if (area == PDFiumPage::DOCLINK_AREA) { 1555 if (area == PDFiumPage::DOCLINK_AREA) {
Lei Zhang 2016/07/14 00:03:40 What about middle clicks on DOCLINK_AREAs? How do
jaepark 2016/07/14 00:59:40 I assume you mean ctrl + left (not shift + left) c
Lei Zhang 2016/07/14 01:25:04 Yes, I meant ctrl, though I just discovered what s
1550 client_->ScrollToPage(target.page); 1556 client_->ScrollToPage(target.page);
1551 client_->FormTextFieldFocusChange(false); 1557 client_->FormTextFieldFocusChange(false);
1552 return true; 1558 return true;
1553 } 1559 }
1554 1560
1555 if (page_index != -1) { 1561 if (page_index != -1) {
1556 last_page_mouse_down_ = page_index; 1562 last_page_mouse_down_ = page_index;
1557 double page_x, page_y; 1563 double page_x, page_y;
1558 pp::Point point = event.GetPosition(); 1564 pp::Point point = event.GetPosition();
1559 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); 1565 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 base::char16 cur = pages_[page_index]->GetCharAtIndex(end_index); 1619 base::char16 cur = pages_[page_index]->GetCharAtIndex(end_index);
1614 if (cur == '\n' || (click_count == 2 && (cur == ' ' || cur == '\t'))) 1620 if (cur == '\n' || (click_count == 2 && (cur == ' ' || cur == '\t')))
1615 break; 1621 break;
1616 } 1622 }
1617 1623
1618 selection_.push_back(PDFiumRange( 1624 selection_.push_back(PDFiumRange(
1619 pages_[page_index], start_index, end_index - start_index)); 1625 pages_[page_index], start_index, end_index - start_index));
1620 } 1626 }
1621 1627
1622 bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) { 1628 bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) {
1623 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT) 1629
1630 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT &&
1631 event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) {
1624 return false; 1632 return false;
1633 }
1625 1634
1626 int page_index = -1; 1635 int page_index = -1;
1627 int char_index = -1; 1636 int char_index = -1;
1628 int form_type = FPDF_FORMFIELD_UNKNOWN; 1637 int form_type = FPDF_FORMFIELD_UNKNOWN;
1629 PDFiumPage::LinkTarget target; 1638 PDFiumPage::LinkTarget target;
1630 PDFiumPage::Area area = 1639 PDFiumPage::Area area =
1631 GetCharIndex(event, &page_index, &char_index, &form_type, &target); 1640 GetCharIndex(event, &page_index, &char_index, &form_type, &target);
1632 1641
1633 // Open link on mouse up for same link for which mouse down happened earlier. 1642 // Open link on mouse up for same link for which mouse down happened earlier.
1634 if (mouse_down_state_.Matches(area, target)) { 1643 if (mouse_down_state_.Matches(area, target)) {
1635 if (area == PDFiumPage::WEBLINK_AREA) { 1644 if (area == PDFiumPage::WEBLINK_AREA) {
1636 bool open_in_new_tab = !!(event.GetModifiers() & kDefaultKeyModifier); 1645 bool open_in_new_tab = !!(event.GetModifiers() & kDefaultKeyModifier) ||
1646 !!(event.GetModifiers() & PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN);
1637 client_->NavigateTo(target.url, open_in_new_tab); 1647 client_->NavigateTo(target.url, open_in_new_tab);
1638 client_->FormTextFieldFocusChange(false); 1648 client_->FormTextFieldFocusChange(false);
1639 return true; 1649 return true;
1640 } 1650 }
1641 } 1651 }
1642 1652
1653 if (event.GetButton() == PP_INPUTEVENT_MOUSEBUTTON_MIDDLE)
1654 return false;
1655
1643 if (page_index != -1) { 1656 if (page_index != -1) {
1644 double page_x, page_y; 1657 double page_x, page_y;
1645 pp::Point point = event.GetPosition(); 1658 pp::Point point = event.GetPosition();
1646 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); 1659 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y);
1647 FORM_OnLButtonUp( 1660 FORM_OnLButtonUp(
1648 form_, pages_[page_index]->GetPage(), 0, page_x, page_y); 1661 form_, pages_[page_index]->GetPage(), 0, page_x, page_y);
1649 } 1662 }
1650 1663
1651 if (!selecting_) 1664 if (!selecting_)
1652 return false; 1665 return false;
(...skipping 2240 matching lines...) Expand 10 before | Expand all | Expand 10 after
3893 FPDF_DOCUMENT doc = 3906 FPDF_DOCUMENT doc =
3894 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 3907 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
3895 if (!doc) 3908 if (!doc)
3896 return false; 3909 return false;
3897 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3910 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3898 FPDF_CloseDocument(doc); 3911 FPDF_CloseDocument(doc);
3899 return success; 3912 return success;
3900 } 3913 }
3901 3914
3902 } // namespace chrome_pdf 3915 } // namespace chrome_pdf
OLDNEW
« chrome/browser/pdf/pdf_extension_test.cc ('K') | « 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