diff options
author | n.bansal <n.bansal@samsung.com> | 2014-09-12 02:46:31 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-12 09:50:00 +0000 |
commit | 408ab9799677a63fb8b83076f847e9f5302be813 (patch) | |
tree | 22b133e38fdd63974cee1739f4a886bbe04f58d2 /pdf | |
parent | e163ac2ad78d8047bcae08d581d5921e5685f086 (diff) | |
download | chromium_src-408ab9799677a63fb8b83076f847e9f5302be813.zip chromium_src-408ab9799677a63fb8b83076f847e9f5302be813.tar.gz chromium_src-408ab9799677a63fb8b83076f847e9f5302be813.tar.bz2 |
PDF links should open on mouse up
Currently links in pdf open on mouse down. This doesn't
give user any chance to cancel the action by moving the mouse
without releasing the click.
This patch adds the fix to make sure pdf opens link on mouse up
and not on mouse down.
BUG=409753
Review URL: https://codereview.chromium.org/553433002
Cr-Commit-Position: refs/heads/master@{#294564}
Diffstat (limited to 'pdf')
-rw-r--r-- | pdf/pdfium/pdfium_engine.cc | 35 | ||||
-rw-r--r-- | pdf/pdfium/pdfium_engine.h | 18 |
2 files changed, 46 insertions, 7 deletions
diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc index f0fe1b2..28fca44 100644 --- a/pdf/pdfium/pdfium_engine.cc +++ b/pdf/pdfium/pdfium_engine.cc @@ -1291,12 +1291,12 @@ bool PDFiumEngine::OnMouseDown(const pp::MouseInputEvent& event) { PDFiumPage::LinkTarget target; PDFiumPage::Area area = GetCharIndex(event, &page_index, &char_index, &target); - if (area == PDFiumPage::WEBLINK_AREA) { - bool open_in_new_tab = !!(event.GetModifiers() & kDefaultKeyModifier); - client_->NavigateTo(target.url, open_in_new_tab); - client_->FormTextFieldFocusChange(false); + mouse_down_state_ = MouseDownState(area, target); + + // Decide whether to open link or not based on user action in mouse up and + // mouse move events. + if (area == PDFiumPage::WEBLINK_AREA) return true; - } if (area == PDFiumPage::DOCLINK_AREA) { client_->ScrollToPage(target.page); @@ -1374,7 +1374,20 @@ bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) { int page_index = -1; int char_index = -1; - GetCharIndex(event, &page_index, &char_index, NULL); + PDFiumPage::LinkTarget target; + PDFiumPage::Area area = + GetCharIndex(event, &page_index, &char_index, &target); + + // Open link on mouse up for same link for which mouse down happened earlier. + if (mouse_down_state_ == MouseDownState(area, target)) { + if (area == PDFiumPage::WEBLINK_AREA) { + bool open_in_new_tab = !!(event.GetModifiers() & kDefaultKeyModifier); + client_->NavigateTo(target.url, open_in_new_tab); + client_->FormTextFieldFocusChange(false); + return true; + } + } + if (page_index != -1) { double page_x, page_y; pp::Point point = event.GetPosition(); @@ -1393,7 +1406,15 @@ bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) { bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { int page_index = -1; int char_index = -1; - PDFiumPage::Area area = GetCharIndex(event, &page_index, &char_index, NULL); + PDFiumPage::LinkTarget target; + PDFiumPage::Area area = + GetCharIndex(event, &page_index, &char_index, &target); + + // Clear |mouse_down_state_| if mouse moves away from where the mouse down + // happened. + if (mouse_down_state_ != MouseDownState(area, target)) + mouse_down_state_ = MouseDownState(); + if (!selecting_) { PP_CursorType_Dev cursor; switch (area) { diff --git a/pdf/pdfium/pdfium_engine.h b/pdf/pdfium/pdfium_engine.h index a320ba1..6c8368a 100644 --- a/pdf/pdfium/pdfium_engine.h +++ b/pdf/pdfium/pdfium_engine.h @@ -509,6 +509,24 @@ class PDFiumEngine : public PDFEngine, // True if we're in the middle of selection. bool selecting_; + // Used to store mouse down state to handle it in other mouse event handlers. + struct MouseDownState { + MouseDownState() {}; + MouseDownState(PDFiumPage::Area area, PDFiumPage::LinkTarget target) + : area_(area), target_(target) {}; + PDFiumPage::Area area_; + PDFiumPage::LinkTarget target_; + + bool operator==(const MouseDownState& rhs) const { + return (area_ == rhs.area_) && (target_.url == rhs.target_.url); + } + + bool operator!=(const MouseDownState rhs) const { + return (area_ != rhs.area_) || (target_.url != rhs.target_.url); + } + }; + MouseDownState mouse_down_state_; + // Used for searching. typedef std::vector<PDFiumRange> FindResults; FindResults find_results_; |