Commit 50e3e4de authored by dpapad's avatar dpapad Committed by Chromium LUCI CQ

PDF Viewer: Presentation mode initial approach.

Upon entering Presentation mode:
 - Disable scrolling and hide scrollbars.
 - Disable zooming with ctrl+wheel and pinch gestures.
 - Force fit-to-height.
 - Next/previous page can be shown using the left/right keyboard
  arrows.

The following known issues
 - Zooming is still possible with ctrl+/-
 - Rotating is still possible via ctrl]/[
 - Using the scroll wheel does not update to the next/previous page

will be addressed in a follow up CL.

Bug: 1148478
Change-Id: I8b0e3b9ea6c3ed6738bc07f313935c7ea4d770a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2539741
Commit-Queue: dpapad <dpapad@chromium.org>
Reviewed-by: default avatarDaniel Hosseinian <dhoss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832284}
parent 980d0632
...@@ -164,6 +164,11 @@ export class GestureDetector { ...@@ -164,6 +164,11 @@ export class GestureDetector {
event.preventDefault(); event.preventDefault();
// Disable wheel gestures in Presentation mode.
if (document.fullscreenElement !== null) {
return;
}
const wheelScale = Math.exp(-event.deltaY / 100); const wheelScale = Math.exp(-event.deltaY / 100);
// Clamp scale changes from the wheel event as they can be // Clamp scale changes from the wheel event as they can be
// quite dramatic for non-synthetic ctrl-wheels. // quite dramatic for non-synthetic ctrl-wheels.
......
...@@ -121,6 +121,11 @@ ...@@ -121,6 +121,11 @@
overflow: auto; overflow: auto;
position: relative; position: relative;
} }
/* Hide scrollbars when in Presentation mode. */
#scroller:fullscreen {
overflow: hidden;
}
</style> </style>
<template is="dom-if" if="[[!pdfViewerUpdateEnabled_]]"> <template is="dom-if" if="[[!pdfViewerUpdateEnabled_]]">
......
...@@ -683,7 +683,11 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -683,7 +683,11 @@ export class PDFViewerElement extends PDFViewerBaseElement {
/** @private */ /** @private */
onFullscreenClick_() { onFullscreenClick_() {
assert(this.presentationModeEnabled_); assert(this.presentationModeEnabled_);
this.shadowRoot.querySelector('#main').requestFullscreen(); this.shadowRoot.querySelector('#scroller').requestFullscreen().then(() => {
this.forceFit(FittingType.FIT_TO_HEIGHT);
// Nothing else to do here. The viewport will be updated as a result of a
// 'resize' event callback.
});
} }
/** /**
......
...@@ -454,12 +454,20 @@ export class Viewport { ...@@ -454,12 +454,20 @@ export class Viewport {
* @private * @private
*/ */
resize_() { resize_() {
// Force fit-to-height when resizing happens as a result of entering full
// screen mode.
if (document.fullscreenElement !== null) {
this.fittingType_ = FittingType.FIT_TO_HEIGHT;
this.window_.dispatchEvent(
new CustomEvent('fitting-type-changed-for-testing'));
}
if (this.fittingType_ === FittingType.FIT_TO_PAGE) { if (this.fittingType_ === FittingType.FIT_TO_PAGE) {
this.fitToPageInternal_(false); this.fitToPageInternal_(false);
} else if (this.fittingType_ === FittingType.FIT_TO_WIDTH) { } else if (this.fittingType_ === FittingType.FIT_TO_WIDTH) {
this.fitToWidth(); this.fitToWidth();
} else if (this.fittingType_ === FittingType.FIT_TO_HEIGHT) { } else if (this.fittingType_ === FittingType.FIT_TO_HEIGHT) {
this.fitToHeightInternal_(false); this.fitToHeightInternal_(document.fullscreenElement !== null);
} else if (this.internalZoom_ === 0) { } else if (this.internalZoom_ === 0) {
this.fitToNone(); this.fitToNone();
} else { } else {
...@@ -1502,6 +1510,11 @@ export class Viewport { ...@@ -1502,6 +1510,11 @@ export class Viewport {
* @private * @private
*/ */
onPinchStart_(e) { onPinchStart_(e) {
// Disable pinch gestures in Presentation mode.
if (document.fullscreenElement !== null) {
return;
}
// We also use rAF for pinch start, so that if there is a pinch end event // We also use rAF for pinch start, so that if there is a pinch end event
// scheduled by rAF, this pinch start will be sent after. // scheduled by rAF, this pinch start will be sent after.
window.requestAnimationFrame(() => { window.requestAnimationFrame(() => {
......
...@@ -130,6 +130,7 @@ js_library("download_controls_test") { ...@@ -130,6 +130,7 @@ js_library("download_controls_test") {
js_library("fullscreen_test") { js_library("fullscreen_test") {
deps = [ deps = [
"../webui:test_util.m", "../webui:test_util.m",
"//chrome/browser/resources/pdf:constants",
"//chrome/browser/resources/pdf:pdf_viewer", "//chrome/browser/resources/pdf:pdf_viewer",
] ]
externs_list = [ "$externs_path/test.js" ] externs_list = [ "$externs_path/test.js" ]
......
...@@ -3,19 +3,35 @@ ...@@ -3,19 +3,35 @@
// found in the LICENSE file. // found in the LICENSE file.
import {eventToPromise} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/_test_resources/webui/test_util.m.js'; import {eventToPromise} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/_test_resources/webui/test_util.m.js';
import {FittingType} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/constants.js';
import {PDFViewerElement} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/pdf_viewer.js'; import {PDFViewerElement} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/pdf_viewer.js';
const tests = [ const tests = [
function testFullscreen() { async function testFullscreen() {
const viewer = /** @type {!PDFViewerElement} */ ( const viewer = /** @type {!PDFViewerElement} */ (
document.body.querySelector('pdf-viewer')); document.body.querySelector('pdf-viewer'));
const scroller = /** @type {!HTMLElement} */ (
viewer.shadowRoot.querySelector('#scroller'));
chrome.test.assertTrue(scroller !== null);
chrome.test.assertEq(FittingType.NONE, viewer.viewport.fittingType);
const whenFitToTypeChanged =
eventToPromise('fitting-type-changed-for-testing', scroller);
const whenFullscreenChange = eventToPromise('fullscreenchange', scroller);
const toolbar = viewer.shadowRoot.querySelector('viewer-pdf-toolbar-new'); const toolbar = viewer.shadowRoot.querySelector('viewer-pdf-toolbar-new');
toolbar.dispatchEvent(new CustomEvent('fullscreen-click')); toolbar.dispatchEvent(new CustomEvent('fullscreen-click'));
eventToPromise('fullscreenchange', viewer).then(e => { await whenFitToTypeChanged;
chrome.test.assertEq( await whenFullscreenChange;
viewer.shadowRoot.querySelector('#main'), e.composedPath()[0]);
chrome.test.succeed(); // Check that the scrollbars are hidden.
}); chrome.test.assertEq('hidden', window.getComputedStyle(scroller).overflow);
// Check that the `fittingType` has changed.
chrome.test.assertEq(
FittingType.FIT_TO_HEIGHT, viewer.viewport.fittingType);
chrome.test.succeed();
}, },
]; ];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment