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

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

Issue 553433002: PDF Viewer - Links should open on mouse up (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback (Store mouse down info) Created 6 years, 3 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 | « pdf/pdfium/pdfium_engine.h ('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 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 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 return false; 1280 return false;
1281 1281
1282 SelectionChangeInvalidator selection_invalidator(this); 1282 SelectionChangeInvalidator selection_invalidator(this);
1283 selection_.clear(); 1283 selection_.clear();
1284 1284
1285 int page_index = -1; 1285 int page_index = -1;
1286 int char_index = -1; 1286 int char_index = -1;
1287 PDFiumPage::LinkTarget target; 1287 PDFiumPage::LinkTarget target;
1288 PDFiumPage::Area area = GetCharIndex(event, &page_index, 1288 PDFiumPage::Area area = GetCharIndex(event, &page_index,
1289 &char_index, &target); 1289 &char_index, &target);
1290 if (area == PDFiumPage::WEBLINK_AREA) { 1290 mouse_down_state_ = MouseDownState(area, target);
1291 bool open_in_new_tab = !!(event.GetModifiers() & kDefaultKeyModifier); 1291
1292 client_->NavigateTo(target.url, open_in_new_tab); 1292 // Decide whether to open link or not based on user action in mouse up and
1293 client_->FormTextFieldFocusChange(false); 1293 // mouse move events.
1294 if (area == PDFiumPage::WEBLINK_AREA)
1294 return true; 1295 return true;
1295 }
1296 1296
1297 if (area == PDFiumPage::DOCLINK_AREA) { 1297 if (area == PDFiumPage::DOCLINK_AREA) {
1298 client_->ScrollToPage(target.page); 1298 client_->ScrollToPage(target.page);
1299 client_->FormTextFieldFocusChange(false); 1299 client_->FormTextFieldFocusChange(false);
1300 return true; 1300 return true;
1301 } 1301 }
1302 1302
1303 if (page_index != -1) { 1303 if (page_index != -1) {
1304 last_page_mouse_down_ = page_index; 1304 last_page_mouse_down_ = page_index;
1305 double page_x, page_y; 1305 double page_x, page_y;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1363 selection_.push_back(PDFiumRange( 1363 selection_.push_back(PDFiumRange(
1364 pages_[page_index], start_index, end_index - start_index)); 1364 pages_[page_index], start_index, end_index - start_index));
1365 } 1365 }
1366 1366
1367 bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) { 1367 bool PDFiumEngine::OnMouseUp(const pp::MouseInputEvent& event) {
1368 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT) 1368 if (event.GetButton() != PP_INPUTEVENT_MOUSEBUTTON_LEFT)
1369 return false; 1369 return false;
1370 1370
1371 int page_index = -1; 1371 int page_index = -1;
1372 int char_index = -1; 1372 int char_index = -1;
1373 GetCharIndex(event, &page_index, &char_index, NULL); 1373 PDFiumPage::LinkTarget target;
1374 PDFiumPage::Area area =
1375 GetCharIndex(event, &page_index, &char_index, &target);
1376
1377 // Open link on mouse up for same link for which mouse down happened earlier.
1378 if (mouse_down_state_ == MouseDownState(area, target)) {
1379 if (area == PDFiumPage::WEBLINK_AREA) {
1380 bool open_in_new_tab = !!(event.GetModifiers() & kDefaultKeyModifier);
1381 client_->NavigateTo(target.url, open_in_new_tab);
1382 client_->FormTextFieldFocusChange(false);
1383 return true;
1384 }
1385 }
1386
1374 if (page_index != -1) { 1387 if (page_index != -1) {
1375 double page_x, page_y; 1388 double page_x, page_y;
1376 pp::Point point = event.GetPosition(); 1389 pp::Point point = event.GetPosition();
1377 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y); 1390 DeviceToPage(page_index, point.x(), point.y(), &page_x, &page_y);
1378 FORM_OnLButtonUp( 1391 FORM_OnLButtonUp(
1379 form_, pages_[page_index]->GetPage(), 0, page_x, page_y); 1392 form_, pages_[page_index]->GetPage(), 0, page_x, page_y);
1380 } 1393 }
1381 1394
1382 if (!selecting_) 1395 if (!selecting_)
1383 return false; 1396 return false;
1384 1397
1385 selecting_ = false; 1398 selecting_ = false;
1386 return true; 1399 return true;
1387 } 1400 }
1388 1401
1389 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) { 1402 bool PDFiumEngine::OnMouseMove(const pp::MouseInputEvent& event) {
1390 int page_index = -1; 1403 int page_index = -1;
1391 int char_index = -1; 1404 int char_index = -1;
1392 PDFiumPage::Area area = GetCharIndex(event, &page_index, &char_index, NULL); 1405 PDFiumPage::LinkTarget target;
1406 PDFiumPage::Area area =
1407 GetCharIndex(event, &page_index, &char_index, &target);
1408
1409 if (mouse_down_state_ != MouseDownState(area, target))
1410 mouse_down_state_ = MouseDownState();
raymes 2014/09/11 01:23:01 nit: Maybe just add a note of what's happening her
Nikhil 2014/09/12 07:44:12 Done.
1411
1393 if (!selecting_) { 1412 if (!selecting_) {
1394 PP_CursorType_Dev cursor; 1413 PP_CursorType_Dev cursor;
1395 switch (area) { 1414 switch (area) {
1396 case PDFiumPage::TEXT_AREA: 1415 case PDFiumPage::TEXT_AREA:
1397 cursor = PP_CURSORTYPE_IBEAM; 1416 cursor = PP_CURSORTYPE_IBEAM;
1398 break; 1417 break;
1399 case PDFiumPage::WEBLINK_AREA: 1418 case PDFiumPage::WEBLINK_AREA:
1400 case PDFiumPage::DOCLINK_AREA: 1419 case PDFiumPage::DOCLINK_AREA:
1401 cursor = PP_CURSORTYPE_HAND; 1420 cursor = PP_CURSORTYPE_HAND;
1402 break; 1421 break;
(...skipping 2019 matching lines...) Expand 10 before | Expand all | Expand 10 after
3422 double* height) { 3441 double* height) {
3423 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 3442 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
3424 if (!doc) 3443 if (!doc)
3425 return false; 3444 return false;
3426 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3445 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3427 FPDF_CloseDocument(doc); 3446 FPDF_CloseDocument(doc);
3428 return success; 3447 return success;
3429 } 3448 }
3430 3449
3431 } // namespace chrome_pdf 3450 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698