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

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 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT &&
1531 event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) {
1531 return false; 1532 return false;
1533 }
1532 1534
1533 SelectionChangeInvalidator selection_invalidator(this); 1535 SelectionChangeInvalidator selection_invalidator(this);
1534 selection_.clear(); 1536 selection_.clear();
1535 1537
1536 int page_index = -1; 1538 int page_index = -1;
1537 int char_index = -1; 1539 int char_index = -1;
1538 int form_type = FPDF_FORMFIELD_UNKNOWN; 1540 int form_type = FPDF_FORMFIELD_UNKNOWN;
1539 PDFiumPage::LinkTarget target; 1541 PDFiumPage::LinkTarget target;
1540 PDFiumPage::Area area = 1542 PDFiumPage::Area area =
1541 GetCharIndex(event, &page_index, &char_index, &form_type, &target); 1543 GetCharIndex(event, &page_index, &char_index, &form_type, &target);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 base::char16 cur = pages_[page_index]->GetCharAtIndex(end_index); 1615 base::char16 cur = pages_[page_index]->GetCharAtIndex(end_index);
1614 if (cur == '\n' || (click_count == 2 && (cur == ' ' || cur == '\t'))) 1616 if (cur == '\n' || (click_count == 2 && (cur == ' ' || cur == '\t')))
1615 break; 1617 break;
1616 } 1618 }
1617 1619
1618 selection_.push_back(PDFiumRange( 1620 selection_.push_back(PDFiumRange(
1619 pages_[page_index], start_index, end_index - start_index)); 1621 pages_[page_index], start_index, end_index - start_index));
1620 } 1622 }
1621 1623
1622 bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) { 1624 bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) {
1623 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT) 1625 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT &&
1626 event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_MIDDLE) {
1624 return false; 1627 return false;
1628 }
1625 1629
1626 int page_index = -1; 1630 int page_index = -1;
1627 int char_index = -1; 1631 int char_index = -1;
1628 int form_type = FPDF_FORMFIELD_UNKNOWN; 1632 int form_type = FPDF_FORMFIELD_UNKNOWN;
1629 PDFiumPage::LinkTarget target; 1633 PDFiumPage::LinkTarget target;
1630 PDFiumPage::Area area = 1634 PDFiumPage::Area area =
1631 GetCharIndex(event, &page_index, &char_index, &form_type, &target); 1635 GetCharIndex(event, &page_index, &char_index, &form_type, &target);
1632 1636
1633 // Open link on mouse up for same link for which mouse down happened earlier. 1637 // Open link on mouse up for same link for which mouse down happened earlier.
1634 if (mouse_down_state_.Matches(area, target)) { 1638 if (mouse_down_state_.Matches(area, target)) {
1635 if (area == PDFiumPage::WEBLINK_AREA) { 1639 if (area == PDFiumPage::WEBLINK_AREA) {
1636 bool open_in_new_tab = !!(event.GetModifiers() & kDefaultKeyModifier); 1640 bool open_in_new_tab = !!(event.GetModifiers() & kDefaultKeyModifier) ||
1641 !!(event.GetModifiers() & PP_INPUTEVENT_MODIFIER_MIDDLEBUTTONDOWN);
1637 client_->NavigateTo(target.url, open_in_new_tab); 1642 client_->NavigateTo(target.url, open_in_new_tab);
1638 client_->FormTextFieldFocusChange(false); 1643 client_->FormTextFieldFocusChange(false);
1639 return true; 1644 return true;
1640 } 1645 }
1641 } 1646 }
1642 1647
1643 if (page_index != -1) { 1648 if (page_index != -1) {
1644 double page_x, page_y; 1649 double page_x, page_y;
1645 pp::Point point = event.GetPosition(); 1650 pp::Point point = event.GetPosition();
1646 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); 1651 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y);
(...skipping 2013 matching lines...) Expand 10 before | Expand all | Expand 10 after
3660 memcpy(file_path, &path[0], path.size() + 1); 3665 memcpy(file_path, &path[0], path.size() + 1);
3661 return path.size() + 1; 3666 return path.size() + 1;
3662 } 3667 }
3663 3668
3664 FPDF_BOOL PDFiumEngine::Pause_NeedToPauseNow(IFSDK_PAUSE* param) { 3669 FPDF_BOOL PDFiumEngine::Pause_NeedToPauseNow(IFSDK_PAUSE* param) {
3665 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param); 3670 PDFiumEngine* engine = static_cast<PDFiumEngine*>(param);
3666 return (base::Time::Now() - engine->last_progressive_start_time_). 3671 return (base::Time::Now() - engine->last_progressive_start_time_).
3667 InMilliseconds() > engine->progressive_paint_timeout_; 3672 InMilliseconds() > engine->progressive_paint_timeout_;
3668 } 3673 }
3669 3674
3675 std::vector<pp::Rect> PDFiumEngine::GetLinkRects() {
3676 int page_index = GetMostVisiblePage();
3677
3678 if (page_index == -1)
Lei Zhang 2016/07/08 21:12:29 Really, anything less than 0 is out of bounds.
jaepark 2016/07/08 22:15:04 Done.
3679 return std::vector<pp::Rect>();
3680
3681 return pages_[page_index]->GetLinkRects();
3682 }
3683
3670 ScopedUnsupportedFeature::ScopedUnsupportedFeature(PDFiumEngine* engine) 3684 ScopedUnsupportedFeature::ScopedUnsupportedFeature(PDFiumEngine* engine)
3671 : engine_(engine), old_engine_(g_engine_for_unsupported) { 3685 : engine_(engine), old_engine_(g_engine_for_unsupported) {
3672 g_engine_for_unsupported = engine_; 3686 g_engine_for_unsupported = engine_;
3673 } 3687 }
3674 3688
3675 ScopedUnsupportedFeature::~ScopedUnsupportedFeature() { 3689 ScopedUnsupportedFeature::~ScopedUnsupportedFeature() {
3676 g_engine_for_unsupported = old_engine_; 3690 g_engine_for_unsupported = old_engine_;
3677 } 3691 }
3678 3692
3679 namespace { 3693 namespace {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
3894 FPDF_DOCUMENT doc = 3908 FPDF_DOCUMENT doc =
3895 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 3909 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
3896 if (!doc) 3910 if (!doc)
3897 return false; 3911 return false;
3898 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3912 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3899 FPDF_CloseDocument(doc); 3913 FPDF_CloseDocument(doc);
3900 return success; 3914 return success;
3901 } 3915 }
3902 3916
3903 } // namespace chrome_pdf 3917 } // namespace chrome_pdf
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698