forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reland: Handle long press in PDF documents.
This Cl updates the touch handlers for PDF documents to better support long press. The long press context menu is suppressed and the wonder under the press is of sufficient time. BUG=chromium:490184 CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation PRIOR REVIEWS: > Review-Url: https://codereview.chromium.org/2855953003 > Revert Review-Url: https://codereview.chromium.org/2864603006 Review-Url: https://codereview.chromium.org/2861383003 Cr-Commit-Position: refs/heads/master@{#471915}
- Loading branch information
Showing
12 changed files
with
287 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
function sendTouchStart(touches) { | ||
var id = 0; | ||
let touchList = touches.map(function(xy) { | ||
var touchInit = { | ||
identifier: id++, | ||
target: viewer.plugin_, | ||
clientX: xy.x, | ||
clientY: xy.y, | ||
}; | ||
|
||
return new window.Touch(touchInit); | ||
}); | ||
|
||
viewer.plugin_.dispatchEvent(new TouchEvent('touchstart', { | ||
touches: touchList, | ||
targetTouches: touchList, | ||
changedtouches: touchList | ||
})); | ||
} | ||
|
||
function createContextMenuEvent() { | ||
return new MouseEvent('contextmenu', { | ||
cancelable: true, | ||
sourceCapabilities: new InputDeviceCapabilities({firesTouchEvents: true}) | ||
}); | ||
} | ||
|
||
var tests = [ | ||
// Test suppression of the context menu on single touch. | ||
function testContextMenuSingleTouch() { | ||
sendTouchStart([{x: 10, y: 10}]); | ||
|
||
let event = createContextMenuEvent(); | ||
// Dispatch event will be false if the event is cancellable and one of the | ||
// handlers called preventDefault. | ||
chrome.test.assertFalse(document.dispatchEvent(event), | ||
"Should have called preventDefault() for single touch."); | ||
chrome.test.succeed(); | ||
}, | ||
|
||
// Test allowing of context menu on double touch. | ||
function testContextMenuDoubleTouch() { | ||
sendTouchStart([{x: 10, y: 10}, {x: 15, y: 15}]); | ||
|
||
let event = createContextMenuEvent(); | ||
chrome.test.assertTrue(document.dispatchEvent(event), | ||
"Should not have called preventDefault() for double touch."); | ||
chrome.test.succeed(); | ||
}, | ||
|
||
// Test long press selects word. | ||
function testLongPressSelectsText() { | ||
var client = new PDFScriptingAPI(window, window); | ||
|
||
sendTouchStart([{x: 336, y: 163}]); | ||
window.setTimeout(function() { | ||
client.getSelectedText(chrome.test.callbackPass(function(selectedText) { | ||
chrome.test.assertEq('some', selectedText); | ||
})); | ||
chrome.test.succeed(); | ||
// 10k is the value for the action_timeout_ms_ in Chrome test_timeouts.cc | ||
}, 10000); | ||
} | ||
]; | ||
|
||
var scriptingAPI = new PDFScriptingAPI(window, window); | ||
scriptingAPI.setLoadCallback(function() { | ||
chrome.test.runTests(tests); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.