diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-09-07 13:12:05 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-11-09 10:02:59 +0000 |
commit | 33fc33aa94d4add0878ec30dc818e34e1dd3cc2a (patch) | |
tree | f6af110909c79b2759136554f1143d8b0572af0a /chromium/chrome/browser/resources/pdf | |
parent | 7d2c5d177e9813077a621df8d18c0deda73099b3 (diff) |
BASELINE: Update Chromium to 104.0.5112.120
Change-Id: I5d2726c2ab018d75d055739b6ba64317904f05bb
Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/438935
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/chrome/browser/resources/pdf')
31 files changed, 376 insertions, 176 deletions
diff --git a/chromium/chrome/browser/resources/pdf/BUILD.gn b/chromium/chrome/browser/resources/pdf/BUILD.gn index 682e04f1b7a..55909353505 100644 --- a/chromium/chrome/browser/resources/pdf/BUILD.gn +++ b/chromium/chrome/browser/resources/pdf/BUILD.gn @@ -6,7 +6,7 @@ import("//chrome/common/features.gni") import("//pdf/features.gni") import("//tools/grit/grit_rule.gni") import("//tools/grit/preprocess_if_expr.gni") -import("//tools/polymer/html_to_js.gni") +import("//tools/polymer/css_to_wrapper.gni") import("//tools/polymer/html_to_wrapper.gni") import("//tools/typescript/ts_library.gni") import("//ui/webui/resources/tools/generate_grd.gni") @@ -37,7 +37,7 @@ preprocess_if_expr("preprocess_generated") { } html_to_wrapper("html_wrapper_files") { - in_files = html_files + in_files = html_files + shared_icons_html_files } # Preprocess and build a manifest file for the Print Preview HTML/CSS files, @@ -194,8 +194,8 @@ grit("resources") { output_dir = "$root_gen_dir/chrome" } -html_to_js("css_wrapper_files") { - js_files = css_wrapper_files +css_to_wrapper("css_wrapper_files") { + in_files = css_files } ts_library("build_ts") { diff --git a/chromium/chrome/browser/resources/pdf/constants.ts b/chromium/chrome/browser/resources/pdf/constants.ts index 925f2fc6dfb..0bd64431213 100644 --- a/chromium/chrome/browser/resources/pdf/constants.ts +++ b/chromium/chrome/browser/resources/pdf/constants.ts @@ -45,7 +45,7 @@ export type NamedDestinationMessageData = { /** * Enumeration of save message request types. Must match `SaveRequestType` in - * pdf/pdf_view_plugin_base.h. + * pdf/pdf_view_web_plugin.h. */ export enum SaveRequestType { ANNOTATION, diff --git a/chromium/chrome/browser/resources/pdf/controller.ts b/chromium/chrome/browser/resources/pdf/controller.ts index 5f22141bbd4..5eb37b7cdf7 100644 --- a/chromium/chrome/browser/resources/pdf/controller.ts +++ b/chromium/chrome/browser/resources/pdf/controller.ts @@ -339,10 +339,10 @@ export class PluginController implements ContentController { }); } - setReadOnly(enableReadOnly: boolean) { + setPresentationMode(enablePresentationMode: boolean) { this.postMessage_({ - type: 'setReadOnly', - enableReadOnly: enableReadOnly, + type: 'setPresentationMode', + enablePresentationMode, }); } @@ -423,6 +423,9 @@ export class PluginController implements ContentController { case 'gesture': this.viewport_.dispatchGesture(messageData.gesture); break; + case 'swipe': + this.viewport_.dispatchSwipe(messageData.direction); + break; case 'goToPage': this.viewport_.goToPage(messageData.page); break; diff --git a/chromium/chrome/browser/resources/pdf/elements/icons.ts b/chromium/chrome/browser/resources/pdf/elements/icons.ts deleted file mode 100644 index 500ccf6ebbc..00000000000 --- a/chromium/chrome/browser/resources/pdf/elements/icons.ts +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2019 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. - -import 'chrome://resources/polymer/v3_0/iron-iconset-svg/iron-iconset-svg.js'; - -import {html} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; - -const template = html`{__html_template__}`; -document.head.appendChild(template.content); diff --git a/chromium/chrome/browser/resources/pdf/elements/pdf-shared.css b/chromium/chrome/browser/resources/pdf/elements/pdf-shared.css new file mode 100644 index 00000000000..4476f7c2582 --- /dev/null +++ b/chromium/chrome/browser/resources/pdf/elements/pdf-shared.css @@ -0,0 +1,37 @@ +/* Copyright 2022 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. */ + +/* #css_wrapper_metadata_start + * #type=style + * #import=chrome://resources/cr_elements/shared_vars_css.m.js + * #css_wrapper_metadata_end */ + +cr-icon-button { + --cr-icon-button-fill-color: var(--pdf-toolbar-text-color); + --cr-icon-button-focus-outline-color: var(--google-grey-500); + margin: 0; +} + +cr-icon-button:hover { + background: rgba(255, 255, 255, 0.08); + border-radius: 50%; +} + +/* Dark mode styles copied from + ui/webui/resources/cr_elements/shared_vars_css.html. Unfortunately there + seems to be no great way to share styles with the + "prefers-color-scheme: dark" @media query selector. + TODO(crbug.com/1231199): Remove these overrides when the PDF viewer + supports light and dark modes. */ +cr-action-menu, +viewer-bookmark { + --cr-menu-background-color: var(--google-grey-900); + --cr-menu-shadow: rgba(0, 0, 0, .3) 0 1px 2px 0, + rgba(0, 0, 0, .15) 0 3px 6px 2px; + --cr-primary-text-color: var(--google-grey-200); + --cr-menu-background-focus-color: var(--google-grey-700); + --cr-menu-background-sheen: rgba(255, 255, 255, .06); + --cr-separator-line: var(--cr-separator-height) solid + rgba(255, 255, 255, .1); +} diff --git a/chromium/chrome/browser/resources/pdf/elements/shared-css.html b/chromium/chrome/browser/resources/pdf/elements/shared-css.html deleted file mode 100644 index eea91862210..00000000000 --- a/chromium/chrome/browser/resources/pdf/elements/shared-css.html +++ /dev/null @@ -1,33 +0,0 @@ -<template> - <style> - cr-icon-button { - --cr-icon-button-fill-color: var(--pdf-toolbar-text-color); - --cr-icon-button-focus-outline-color: var(--google-grey-500); - margin: 0; - } - - cr-icon-button:hover { - background: rgba(255, 255, 255, 0.08); - border-radius: 50%; - } - - /* Dark mode styles copied from - ui/webui/resources/cr_elements/shared_vars_css.html. Unfortunately there - seems to be no great way to share styles with the - "prefers-color-scheme: dark" @media query selector. - TODO(crbug.com/1231199): Remove these overrides when the PDF viewer - supports light and dark modes. */ - cr-action-menu, - viewer-bookmark { - --cr-menu-background-color: var(--google-grey-900); - --cr-menu-shadow: rgba(0, 0, 0, .3) 0 1px 2px 0, - rgba(0, 0, 0, .15) 0 3px 6px 2px; - --cr-primary-text-color: var(--google-grey-200); - --cr-menu-background-focus-color: var(--google-grey-700); - --cr-menu-background-sheen: rgba(255, 255, 255, .06); - --cr-separator-line: var(--cr-separator-height) solid - rgba(255, 255, 255, .1); - } - - </style> -</template> diff --git a/chromium/chrome/browser/resources/pdf/elements/shared-css.ts b/chromium/chrome/browser/resources/pdf/elements/shared-css.ts deleted file mode 100644 index 4836848cf2e..00000000000 --- a/chromium/chrome/browser/resources/pdf/elements/shared-css.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2020 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. - -import 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; - -import 'chrome://resources/cr_elements/shared_vars_css.m.js'; - -const template = document.createElement('template'); -template.innerHTML = ` -<dom-module id="pdf-shared">{__html_template__}</dom-module> -`; -document.body.appendChild(template.content.cloneNode(true)); diff --git a/chromium/chrome/browser/resources/pdf/elements/shared-vars.css b/chromium/chrome/browser/resources/pdf/elements/shared-vars.css new file mode 100644 index 00000000000..fa4f8efe3be --- /dev/null +++ b/chromium/chrome/browser/resources/pdf/elements/shared-vars.css @@ -0,0 +1,16 @@ +/* Copyright 2022 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. */ + +/* #css_wrapper_metadata_start + * #type=vars + * #import=chrome://resources/polymer/v3_0/paper-styles/color.js + * #css_wrapper_metadata_end */ + +html { + --iron-icon-height: 20px; + --iron-icon-width: 20px; + --viewer-icon-ink-color: rgb(189, 189, 189); + --viewer-pdf-toolbar-background-color: rgb(50, 54, 57); + --viewer-text-input-selection-color: rgba(255, 255, 255, 0.3); +} diff --git a/chromium/chrome/browser/resources/pdf/elements/shared-vars.html b/chromium/chrome/browser/resources/pdf/elements/shared-vars.html deleted file mode 100644 index 8d898bba5d3..00000000000 --- a/chromium/chrome/browser/resources/pdf/elements/shared-vars.html +++ /dev/null @@ -1,11 +0,0 @@ -<custom-style> - <style> - html { - --iron-icon-height: 20px; - --iron-icon-width: 20px; - --viewer-icon-ink-color: rgb(189, 189, 189); - --viewer-pdf-toolbar-background-color: rgb(50, 54, 57); - --viewer-text-input-selection-color: rgba(255, 255, 255, 0.3); - } - </style> -</custom-style> diff --git a/chromium/chrome/browser/resources/pdf/elements/shared-vars.ts b/chromium/chrome/browser/resources/pdf/elements/shared-vars.ts deleted file mode 100644 index 8ada5463357..00000000000 --- a/chromium/chrome/browser/resources/pdf/elements/shared-vars.ts +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2019 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. - -import 'chrome://resources/polymer/v3_0/paper-styles/color.js'; -import 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; - -const $_documentContainer = document.createElement('template'); -$_documentContainer.innerHTML = `{__html_template__}`; -document.head.appendChild($_documentContainer.content); diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-annotations-bar.ts b/chromium/chrome/browser/resources/pdf/elements/viewer-annotations-bar.ts index b10fb400215..d3c6eebd473 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-annotations-bar.ts +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-annotations-bar.ts @@ -4,8 +4,8 @@ import 'chrome://resources/cr_elements/cr_icon_button/cr_icon_button.m.js'; import 'chrome://resources/cr_elements/icons.m.js'; -import './icons.js'; -import './shared-css.js'; +import './icons.html.js'; +import './pdf-shared.css.js'; import './viewer-pen-options.js'; import './viewer-toolbar-dropdown.js'; diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-bookmark.ts b/chromium/chrome/browser/resources/pdf/elements/viewer-bookmark.ts index 6886caa4b53..3948c83753b 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-bookmark.ts +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-bookmark.ts @@ -6,7 +6,7 @@ import 'chrome://resources/cr_elements/cr_icon_button/cr_icon_button.m.js'; import 'chrome://resources/cr_elements/icons.m.js'; import 'chrome://resources/cr_elements/shared_vars_css.m.js'; import 'chrome://resources/polymer/v3_0/paper-styles/color.js'; -import './shared-css.js'; +import './pdf-shared.css.js'; import {CrIconButtonElement} from 'chrome://resources/cr_elements/cr_icon_button/cr_icon_button.m.js'; import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; @@ -18,16 +18,22 @@ import {getTemplate} from './viewer-bookmark.html.js'; /** Amount that each level of bookmarks is indented by (px). */ const BOOKMARK_INDENT: number = 20; +export enum ChangePageOrigin { + BOOKMARK = 'bookmark', + THUMBNAIL = 'thumbnail', + PAGE_SELECTOR = 'pageSelector', +} + export type ChangePageAndXyDetail = { page: number, x: number, y: number, - origin: string, + origin: ChangePageOrigin, }; export type ChangePageDetail = { page: number, - origin: 'bookmark'|'thumbnail'|'pageSelector', + origin: ChangePageOrigin, }; export type ChangeZoomDetail = { @@ -129,11 +135,12 @@ export class ViewerBookmarkElement extends PolymerElement { page: this.bookmark.page, x: this.bookmark.x, y: this.bookmark.y, - origin: 'bookmark', + origin: ChangePageOrigin.BOOKMARK, }); } else { this.fire_( - 'change-page', {page: this.bookmark.page, origin: 'bookmark'}); + 'change-page', + {page: this.bookmark.page, origin: ChangePageOrigin.BOOKMARK}); } } else if (this.bookmark.uri != null) { this.fire_('navigate', {uri: this.bookmark.uri, newtab: true}); diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-document-outline.ts b/chromium/chrome/browser/resources/pdf/elements/viewer-document-outline.ts index fac3830a830..bb999869b47 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-document-outline.ts +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-document-outline.ts @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import './shared-css.js'; +import './pdf-shared.css.js'; import './viewer-bookmark.js'; import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-download-controls.ts b/chromium/chrome/browser/resources/pdf/elements/viewer-download-controls.ts index 6f616c6ee69..857dafa6854 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-download-controls.ts +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-download-controls.ts @@ -5,8 +5,8 @@ import 'chrome://resources/cr_elements/cr_action_menu/cr_action_menu.js'; import 'chrome://resources/cr_elements/cr_icon_button/cr_icon_button.m.js'; import 'chrome://resources/cr_elements/icons.m.js'; -import './icons.js'; -import './shared-css.js'; +import './icons.html.js'; +import './pdf-shared.css.js'; import {AnchorAlignment, CrActionMenuElement} from 'chrome://resources/cr_elements/cr_action_menu/cr_action_menu.js'; import {CrIconButtonElement} from 'chrome://resources/cr_elements/cr_icon_button/cr_icon_button.m.js'; diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-page-selector.ts b/chromium/chrome/browser/resources/pdf/elements/viewer-page-selector.ts index fd380a1b7f0..275b0ad8817 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-page-selector.ts +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-page-selector.ts @@ -2,9 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import './shared-vars.js'; +import './shared-vars.css.js'; import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; + +import {ChangePageOrigin} from './viewer-bookmark.js'; import {getTemplate} from './viewer-page-selector.html.js'; export interface ViewerPageSelectorElement { @@ -48,7 +50,7 @@ export class ViewerPageSelectorElement extends PolymerElement { if (!isNaN(page) && page <= this.docLength && page > 0) { this.dispatchEvent(new CustomEvent('change-page', { - detail: {page: page - 1, origin: 'pageSelector'}, + detail: {page: page - 1, origin: ChangePageOrigin.PAGE_SELECTOR}, composed: true, })); } else { diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-pdf-sidenav.ts b/chromium/chrome/browser/resources/pdf/elements/viewer-pdf-sidenav.ts index 99f9ef48eb0..3d5fbf1a2c7 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-pdf-sidenav.ts +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-pdf-sidenav.ts @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import './shared-vars.js'; -import '../pdf_viewer_shared_style.js'; -import './icons.js'; +import './shared-vars.css.js'; +import '../pdf_viewer_shared_style.css.js'; +import './icons.html.js'; import './viewer-document-outline.js'; import './viewer-thumbnail-bar.js'; import 'chrome://resources/cr_elements/cr_icon_button/cr_icon_button.m.js'; diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-pen-options.ts b/chromium/chrome/browser/resources/pdf/elements/viewer-pen-options.ts index 9eab5cbc5b9..e8754f87572 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-pen-options.ts +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-pen-options.ts @@ -5,7 +5,9 @@ import 'chrome://resources/cr_elements/cr_icon_button/cr_icon_button.m.js'; import {CrIconButtonElement} from 'chrome://resources/cr_elements/cr_icon_button/cr_icon_button.m.js'; +import {assert} from 'chrome://resources/js/assert_ts.js'; import {beforeNextRender, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; + import {getTemplate} from './viewer-pen-options.html.js'; type Color = { @@ -122,7 +124,7 @@ export class ViewerPenOptionsElement extends PolymerElement { strings: any; private colors_: Color[]; private expanded_: boolean; - private expandAnimations_: Animation[] = []; + private expandAnimations_: Animation[]|null = null; private sizes_: Size[]; private sizeChanged_(e: Event) { @@ -140,6 +142,7 @@ export class ViewerPenOptionsElement extends PolymerElement { private updateExpandedStateAndFinishAnimations_() { this.updateExpandedState_(); + assert(this.expandAnimations_); for (const animation of this.expandAnimations_) { animation.finish(); } diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-thumbnail.ts b/chromium/chrome/browser/resources/pdf/elements/viewer-thumbnail.ts index 7c3151d8187..1525367394b 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-thumbnail.ts +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-thumbnail.ts @@ -2,10 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import './shared-css.js'; +import './pdf-shared.css.js'; import {assert} from 'chrome://resources/js/assert_ts.js'; import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; + +import {ChangePageOrigin} from './viewer-bookmark.js'; import {getTemplate} from './viewer-thumbnail.html.js'; // The maximum widths of thumbnails for each layout (px). @@ -174,7 +176,7 @@ export class ViewerThumbnailElement extends PolymerElement { private onClick_() { this.dispatchEvent(new CustomEvent('change-page', { - detail: {page: this.pageNumber - 1, origin: 'thumbnail'}, + detail: {page: this.pageNumber - 1, origin: ChangePageOrigin.THUMBNAIL}, bubbles: true, composed: true })); diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-toolbar.ts b/chromium/chrome/browser/resources/pdf/elements/viewer-toolbar.ts index dfdf58d22fd..c26950e11ca 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-toolbar.ts +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-toolbar.ts @@ -7,11 +7,11 @@ import 'chrome://resources/cr_elements/icons.m.js'; import 'chrome://resources/cr_elements/shared_vars_css.m.js'; import 'chrome://resources/polymer/v3_0/iron-icon/iron-icon.js'; import 'chrome://resources/polymer/v3_0/paper-progress/paper-progress.js'; -import './icons.js'; +import './icons.html.js'; import './viewer-download-controls.js'; import './viewer-page-selector.js'; -import './shared-css.js'; -import './shared-vars.js'; +import './pdf-shared.css.js'; +import './shared-vars.css.js'; // <if expr="enable_ink"> import './viewer-annotations-bar.js'; import './viewer-annotations-mode-dialog.js'; diff --git a/chromium/chrome/browser/resources/pdf/elements/viewer-zoom-toolbar.ts b/chromium/chrome/browser/resources/pdf/elements/viewer-zoom-toolbar.ts index ae40807fb34..a5cddb6dd0a 100644 --- a/chromium/chrome/browser/resources/pdf/elements/viewer-zoom-toolbar.ts +++ b/chromium/chrome/browser/resources/pdf/elements/viewer-zoom-toolbar.ts @@ -4,7 +4,7 @@ import 'chrome://resources/cr_elements/hidden_style_css.m.js'; import 'chrome://resources/cr_elements/icons.m.js'; -import './icons.js'; +import './icons.html.js'; import './viewer-zoom-button.js'; import {isRTL} from 'chrome://resources/js/util.m.js'; diff --git a/chromium/chrome/browser/resources/pdf/pdf.gni b/chromium/chrome/browser/resources/pdf/pdf.gni index f8ca4e08fa5..826acafa28e 100644 --- a/chromium/chrome/browser/resources/pdf/pdf.gni +++ b/chromium/chrome/browser/resources/pdf/pdf.gni @@ -44,7 +44,14 @@ foreach(f, pdf_html_files) { pdf_html_wrapper_files += [ f + ".ts" ] } -pdf_css_wrapper_files = [ "elements/shared-css.ts" ] +# Files that are passed as input to css_to_wrapper(). +pdf_css_files = [ "elements/pdf-shared.css" ] + +# Files that are generated by css_to_wrapper(). +pdf_css_wrapper_files = [] +foreach(f, pdf_css_files) { + pdf_css_wrapper_files += [ f + ".ts" ] +} # Files to pass directly to preprocess_if_expr() that are used only in PDF # Viewer. @@ -108,9 +115,11 @@ foreach(f, shared_web_component_files) { shared_html_files += [ string_replace(f, ".ts", ".html") ] } +shared_icons_html_files = [ "elements/icons.html" ] + # Files that are generated by html_to_wrapper(). shared_html_wrapper_files = [] -foreach(f, shared_html_files) { +foreach(f, shared_html_files + shared_icons_html_files) { shared_html_wrapper_files += [ f + ".ts" ] } @@ -128,17 +137,24 @@ shared_ts_files = [ "pdf_scripting_api.ts", "pdf_viewer_base.ts", "pdf_viewer_utils.ts", + "swipe_detector.ts", "viewport.ts", "viewport_scroller.ts", "zoom_manager.ts", ] + shared_web_component_files -shared_css_wrapper_files = [ - "elements/icons.ts", - "elements/shared-vars.ts", - "pdf_viewer_shared_style.ts", +# Files that are passed as input to css_to_wrapper(). +shared_css_files = [ + "elements/shared-vars.css", + "pdf_viewer_shared_style.css", ] +# Files that are generated by css_to_wrapper(). +shared_css_wrapper_files = [] +foreach(f, shared_css_files) { + shared_css_wrapper_files += [ f + ".ts" ] +} + # ------------------Shared files end-------------------------------------------- # Combined lists, to make consuming them in the BULID.gn easier. @@ -149,6 +165,8 @@ html_files = pdf_html_files + shared_html_files + print_preview_html_files html_wrapper_files = pdf_html_wrapper_files + shared_html_wrapper_files + print_preview_html_wrapper_files +css_files = pdf_css_files + shared_css_files + css_wrapper_files = pdf_css_wrapper_files + shared_css_wrapper_files print_preview_only_files = diff --git a/chromium/chrome/browser/resources/pdf/pdf_internal_plugin_wrapper.ts b/chromium/chrome/browser/resources/pdf/pdf_internal_plugin_wrapper.ts index 532bb089363..b1ea8eefe82 100644 --- a/chromium/chrome/browser/resources/pdf/pdf_internal_plugin_wrapper.ts +++ b/chromium/chrome/browser/resources/pdf/pdf_internal_plugin_wrapper.ts @@ -4,6 +4,7 @@ import {Point} from './constants.js'; import {GestureDetector, PinchEventDetail} from './gesture_detector.js'; +import {SwipeDetector, SwipeDirection} from './swipe_detector.js'; import {ViewportInterface, ViewportScroller} from './viewport_scroller.js'; interface InProcessPdfPluginElement extends HTMLEmbedElement { @@ -73,12 +74,11 @@ channel.port1.onmessage = e => { plugin.setAttribute('has-edits', ''); return; - case 'setReadOnly': - // TODO(crbug.com/702993): Rename the incoming message to reflect that - // this is only used by Presentation mode. - isPresentationMode = e.data.enableReadOnly; + case 'setPresentationMode': + isPresentationMode = e.data.enablePresentationMode; gestureDetector.setPresentationMode(isPresentationMode); + swipeDetector.setPresentationMode(isPresentationMode); if (isPresentationMode) { document.documentElement.className = 'fullscreen'; } else { @@ -163,6 +163,21 @@ for (const type of ['pinchstart', 'pinchupdate', 'pinchend', 'wheel']) { gestureDetector.getEventTarget().addEventListener(type, relayGesture); } +/** + * Relays swipe events to the parent frame. + * @param e The swipe event. + */ +function relaySwipe(e: Event): void { + const swipeEvent = e as CustomEvent<SwipeDirection>; + channel.port1.postMessage({ + type: 'swipe', + direction: swipeEvent.detail, + }); +} + +const swipeDetector = new SwipeDetector(plugin); +swipeDetector.getEventTarget().addEventListener('swipe', relaySwipe); + document.addEventListener('keydown', e => { // Only forward potential shortcut keys. switch (e.key) { diff --git a/chromium/chrome/browser/resources/pdf/pdf_scripting_api.ts b/chromium/chrome/browser/resources/pdf/pdf_scripting_api.ts index d78ee2d7406..930ba3edc90 100644 --- a/chromium/chrome/browser/resources/pdf/pdf_scripting_api.ts +++ b/chromium/chrome/browser/resources/pdf/pdf_scripting_api.ts @@ -33,7 +33,7 @@ export type SerializedKeyEvent = { * Turn a dictionary received from postMessage into a key event. * @param dict A dictionary representing the key event. */ -export function DeserializeKeyEvent(dict: SerializedKeyEvent): KeyboardEvent { +export function deserializeKeyEvent(dict: SerializedKeyEvent): KeyboardEvent { const e = new KeyboardEvent('keydown', { bubbles: true, cancelable: true, @@ -52,7 +52,7 @@ export function DeserializeKeyEvent(dict: SerializedKeyEvent): KeyboardEvent { * Turn a key event into a dictionary which can be sent over postMessage. * @return A dictionary representing the key event. */ -export function SerializeKeyEvent(event: KeyboardEvent): SerializedKeyEvent { +export function serializeKeyEvent(event: KeyboardEvent): SerializedKeyEvent { return { keyCode: event.keyCode, code: event.code, @@ -129,7 +129,7 @@ export class PDFScriptingAPI { } case 'sendKeyEvent': if (this.keyEventCallback_) { - this.keyEventCallback_(DeserializeKeyEvent(event.data.keyEvent)); + this.keyEventCallback_(deserializeKeyEvent(event.data.keyEvent)); } break; } @@ -267,7 +267,7 @@ export class PDFScriptingAPI { */ sendKeyEvent(keyEvent: KeyboardEvent) { this.sendMessage_( - {type: 'sendKeyEvent', keyEvent: SerializeKeyEvent(keyEvent)}); + {type: 'sendKeyEvent', keyEvent: serializeKeyEvent(keyEvent)}); } /** @@ -288,7 +288,7 @@ export class PDFScriptingAPI { * @param baseUrl the base URL of the PDF viewer * @return The iframe element containing the PDF viewer. */ -export function PDFCreateOutOfProcessPlugin( +export function pdfCreateOutOfProcessPlugin( src: string, baseUrl: string): PDFPlugin { const client = new PDFScriptingAPI(window, null); const iframe = window.document.createElement('iframe') as PDFPlugin; diff --git a/chromium/chrome/browser/resources/pdf/pdf_viewer.ts b/chromium/chrome/browser/resources/pdf/pdf_viewer.ts index 22f7a86817f..904704e95f1 100644 --- a/chromium/chrome/browser/resources/pdf/pdf_viewer.ts +++ b/chromium/chrome/browser/resources/pdf/pdf_viewer.ts @@ -10,8 +10,8 @@ import './elements/viewer-password-dialog.js'; import './elements/viewer-pdf-sidenav.js'; import './elements/viewer-properties-dialog.js'; import './elements/viewer-toolbar.js'; -import './elements/shared-vars.js'; -import './pdf_viewer_shared_style.js'; +import './elements/shared-vars.css.js'; +import './pdf_viewer_shared_style.css.js'; import 'chrome://resources/cr_elements/hidden_style_css.m.js'; import 'chrome://resources/cr_elements/shared_vars_css.m.js'; @@ -26,7 +26,7 @@ import {MessageData, PluginController} from './controller.js'; // <if expr="enable_ink"> import {ContentController} from './controller.js'; // </if> -import {ChangePageAndXyDetail, ChangePageDetail, NavigateDetail} from './elements/viewer-bookmark.js'; +import {ChangePageAndXyDetail, ChangePageDetail, ChangePageOrigin, NavigateDetail} from './elements/viewer-bookmark.js'; import {ViewerErrorDialogElement} from './elements/viewer-error-dialog.js'; import {ViewerPasswordDialogElement} from './elements/viewer-password-dialog.js'; import {ViewerPdfSidenavElement} from './elements/viewer-pdf-sidenav.js'; @@ -37,7 +37,7 @@ import {InkController, InkControllerEventType} from './ink_controller.js'; import {LocalStorageProxyImpl} from './local_storage_proxy.js'; import {record, UserAction} from './metrics.js'; import {NavigatorDelegateImpl, PdfNavigator, WindowOpenDisposition} from './navigator.js'; -import {DeserializeKeyEvent, LoadState} from './pdf_scripting_api.js'; +import {deserializeKeyEvent, LoadState} from './pdf_scripting_api.js'; import {getTemplate} from './pdf_viewer.html.js'; import {KeyEventData, PDFViewerBaseElement} from './pdf_viewer_base.js'; import {DestinationMessageData, DocumentDimensionsMessageData, hasCtrlModifier, shouldIgnoreKeyEvents} from './pdf_viewer_utils.js'; @@ -514,14 +514,15 @@ export class PDFViewerElement extends PDFViewerBaseElement { // Switch viewport's wheel behavior. this.viewport.setPresentationMode(true); - // Restrict the content to read only (e.g. disable forms and links). - this.pluginController_!.setReadOnly(true); + // Set presentation mode, which restricts the content to read only + // (e.g. disable forms and links). + this.pluginController_!.setPresentationMode(true); // Revert back to the normal state when exiting Presentation mode. eventToPromise('fullscreenchange', scroller).then(() => { assert(document.fullscreenElement === null); this.viewport.setPresentationMode(false); - this.pluginController_!.setReadOnly(false); + this.pluginController_!.setPresentationMode(false); // Ensure that directional keys still work after exiting. this.shadowRoot!.querySelector('embed')!.focus(); @@ -563,9 +564,10 @@ export class PDFViewerElement extends PDFViewerBaseElement { * @param message Message received from the plugin containing the x and y to * navigate to in screen coordinates. */ - private goToPageAndXY_(origin: string, page: number, message: Point) { + private goToPageAndXY_( + origin: ChangePageOrigin, page: number, message: Point) { this.viewport.goToPageAndXY(page, message.x, message.y); - if (origin === 'bookmark') { + if (origin === ChangePageOrigin.BOOKMARK) { record(UserAction.FOLLOW_BOOKMARK); } } @@ -749,7 +751,7 @@ export class PDFViewerElement extends PDFViewerBaseElement { case 'sendKeyEvent': const keyEventData = data as unknown as KeyEventData; const keyEvent = - DeserializeKeyEvent(keyEventData.keyEvent) as ExtendedKeyEvent; + deserializeKeyEvent(keyEventData.keyEvent) as ExtendedKeyEvent; keyEvent.fromPlugin = true; this.handleKeyEvent(keyEvent); return; @@ -908,11 +910,11 @@ export class PDFViewerElement extends PDFViewerBaseElement { private onChangePage_(e: CustomEvent<ChangePageDetail>) { this.viewport.goToPage(e.detail.page); - if (e.detail.origin === 'bookmark') { + if (e.detail.origin === ChangePageOrigin.BOOKMARK) { record(UserAction.FOLLOW_BOOKMARK); - } else if (e.detail.origin === 'pageSelector') { + } else if (e.detail.origin === ChangePageOrigin.PAGE_SELECTOR) { record(UserAction.PAGE_SELECTOR_NAVIGATE); - } else if (e.detail.origin === 'thumbnail') { + } else if (e.detail.origin === ChangePageOrigin.THUMBNAIL) { record(UserAction.THUMBNAIL_NAVIGATE); } } diff --git a/chromium/chrome/browser/resources/pdf/pdf_viewer_pp.ts b/chromium/chrome/browser/resources/pdf/pdf_viewer_pp.ts index 883cb8de2ed..4f479fa9d30 100644 --- a/chromium/chrome/browser/resources/pdf/pdf_viewer_pp.ts +++ b/chromium/chrome/browser/resources/pdf/pdf_viewer_pp.ts @@ -4,9 +4,9 @@ import './elements/viewer-error-dialog.js'; import './elements/viewer-page-indicator.js'; -import './elements/shared-vars.js'; +import './elements/shared-vars.css.js'; import './elements/viewer-zoom-toolbar.js'; -import './pdf_viewer_shared_style.js'; +import './pdf_viewer_shared_style.css.js'; import {assertNotReached} from 'chrome://resources/js/assert_ts.js'; import {isRTL} from 'chrome://resources/js/util.m.js'; @@ -16,7 +16,7 @@ import {ExtendedKeyEvent, FittingType} from './constants.js'; import {MessageData, PluginController, PrintPreviewParams} from './controller.js'; import {ViewerPageIndicatorElement} from './elements/viewer-page-indicator.js'; import {ViewerZoomToolbarElement} from './elements/viewer-zoom-toolbar.js'; -import {DeserializeKeyEvent, LoadState, SerializeKeyEvent} from './pdf_scripting_api.js'; +import {deserializeKeyEvent, LoadState, serializeKeyEvent} from './pdf_scripting_api.js'; import {KeyEventData, PDFViewerBaseElement} from './pdf_viewer_base.js'; import {getTemplate} from './pdf_viewer_pp.html.js'; import {DestinationMessageData, DocumentDimensionsMessageData, hasCtrlModifier, shouldIgnoreKeyEvents} from './pdf_viewer_utils.js'; @@ -98,7 +98,7 @@ export class PDFViewerPPElement extends PDFViewerBaseElement { // Give print preview a chance to handle the key event. if (!e.fromScriptingAPI) { this.sendScriptingMessage( - {type: 'sendKeyEvent', keyEvent: SerializeKeyEvent(e)}); + {type: 'sendKeyEvent', keyEvent: serializeKeyEvent(e)}); } else { // Show toolbar as a fallback. if (!(e.shiftKey || e.ctrlKey || e.altKey)) { @@ -215,7 +215,7 @@ export class PDFViewerPPElement extends PDFViewerBaseElement { return true; case 'sendKeyEvent': const keyEvent = - DeserializeKeyEvent((message.data as KeyEventData).keyEvent); + deserializeKeyEvent((message.data as KeyEventData).keyEvent); const extendedKeyEvent = keyEvent as ExtendedKeyEvent; extendedKeyEvent.fromScriptingAPI = true; this.handleKeyEvent(extendedKeyEvent); @@ -284,7 +284,7 @@ export class PDFViewerPPElement extends PDFViewerBaseElement { // TODO(crbug.com/1069370): Draw a focus rect around plugin. return; case 'sendKeyEvent': - const keyEvent = DeserializeKeyEvent((data as KeyEventData).keyEvent) as + const keyEvent = deserializeKeyEvent((data as KeyEventData).keyEvent) as ExtendedKeyEvent; keyEvent.fromPlugin = true; this.handleKeyEvent(keyEvent); diff --git a/chromium/chrome/browser/resources/pdf/pdf_viewer_shared_style.css b/chromium/chrome/browser/resources/pdf/pdf_viewer_shared_style.css new file mode 100644 index 00000000000..f6cf8d31d1d --- /dev/null +++ b/chromium/chrome/browser/resources/pdf/pdf_viewer_shared_style.css @@ -0,0 +1,26 @@ +/* Copyright 2022 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. */ + +/* #css_wrapper_metadata_start + * #type=style + * #css_wrapper_metadata_end */ + +#content { + height: 100%; + position: fixed; + width: 100%; + z-index: 1; +} + +#plugin { + display: block; + height: 100%; + position: absolute; + width: 100%; +} + +#sizer { + position: absolute; + z-index: 0; +} diff --git a/chromium/chrome/browser/resources/pdf/pdf_viewer_shared_style.html b/chromium/chrome/browser/resources/pdf/pdf_viewer_shared_style.html deleted file mode 100644 index 9cfc9097788..00000000000 --- a/chromium/chrome/browser/resources/pdf/pdf_viewer_shared_style.html +++ /dev/null @@ -1,22 +0,0 @@ -<template> - <style> - #content { - height: 100%; - position: fixed; - width: 100%; - z-index: 1; - } - - #plugin { - display: block; - height: 100%; - position: absolute; - width: 100%; - } - - #sizer { - position: absolute; - z-index: 0; - } - </style> -</template> diff --git a/chromium/chrome/browser/resources/pdf/pdf_viewer_shared_style.ts b/chromium/chrome/browser/resources/pdf/pdf_viewer_shared_style.ts deleted file mode 100644 index ee718ab8b3e..00000000000 --- a/chromium/chrome/browser/resources/pdf/pdf_viewer_shared_style.ts +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2020 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. - -import 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; - -const template = document.createElement('template'); -template.innerHTML = ` -<dom-module id="pdf-viewer-shared-style">{__html_template__}</dom-module> -`; -document.body.appendChild(template.content.cloneNode(true)); diff --git a/chromium/chrome/browser/resources/pdf/pdf_viewer_wrapper.ts b/chromium/chrome/browser/resources/pdf/pdf_viewer_wrapper.ts index 9dc18c5fbeb..00b7ac30264 100644 --- a/chromium/chrome/browser/resources/pdf/pdf_viewer_wrapper.ts +++ b/chromium/chrome/browser/resources/pdf/pdf_viewer_wrapper.ts @@ -11,7 +11,7 @@ export {Bookmark} from './bookmark_type.js'; export {BrowserApi, ZoomBehavior} from './browser_api.js'; export {FittingType, Point, SaveRequestType} from './constants.js'; export {PluginController} from './controller.js'; -export {ChangePageAndXyDetail, ChangePageDetail, ChangeZoomDetail, NavigateDetail, ViewerBookmarkElement} from './elements/viewer-bookmark.js'; +export {ChangePageAndXyDetail, ChangePageDetail, ChangePageOrigin, ChangeZoomDetail, NavigateDetail, ViewerBookmarkElement} from './elements/viewer-bookmark.js'; export {ViewerDocumentOutlineElement} from './elements/viewer-document-outline.js'; export {ViewerDownloadControlsElement} from './elements/viewer-download-controls.js'; // <if expr="enable_ink"> @@ -36,6 +36,7 @@ export {PDFScriptingAPI} from './pdf_scripting_api.js'; export {getFilenameFromURL, PDFViewerElement} from './pdf_viewer.js'; export {PDFViewerBaseElement} from './pdf_viewer_base.js'; export {shouldIgnoreKeyEvents} from './pdf_viewer_utils.js'; +export {SwipeDetector, SwipeDirection} from './swipe_detector.js'; export {DocumentDimensions, LayoutOptions, PAGE_SHADOW, Viewport} from './viewport.js'; export {ViewportInterface, ViewportScroller} from './viewport_scroller.js'; export {ZoomManager} from './zoom_manager.js'; diff --git a/chromium/chrome/browser/resources/pdf/swipe_detector.ts b/chromium/chrome/browser/resources/pdf/swipe_detector.ts new file mode 100644 index 00000000000..01a05ac165a --- /dev/null +++ b/chromium/chrome/browser/resources/pdf/swipe_detector.ts @@ -0,0 +1,139 @@ +// Copyright 2022 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. + +/** + * The longest period of time in milliseconds for a horizontal touch movement to + * be considered as a swipe. + */ +const SWIPE_TIMER_INTERVAL_MS: number = 200; + +/* The minimum travel distance on the x axis for a swipe. */ +const SWIPE_X_DIST_MIN: number = 150; + +/* The maximum travel distance on the y axis for a swipe. */ +const SWIPE_Y_DIST_MAX: number = 100; + +export type SwipeEvent = { + type: string, + detail: SwipeDirection, +}; + +/** Enumeration of swipe directions. */ +export enum SwipeDirection { + RIGHT_TO_LEFT = 0, + LEFT_TO_RIGHT = 1, +} + +// A class that listens for touch events and produces events when these +// touches form swipe gestures. +export class SwipeDetector { + private element_: HTMLElement; + private isPresentationMode_: boolean = false; + private swipeStartEvent_: TouchEvent|null = null; + + private elapsedTimeForTesting_: number|null = null; + + private eventTarget_: EventTarget = new EventTarget(); + + /** @param element The element to monitor for touch gestures. */ + constructor(element: HTMLElement) { + this.element_ = element; + + this.element_.addEventListener( + 'touchstart', (this.onTouchStart_.bind(this) as (p1: Event) => any), + {passive: true}); + + this.element_.addEventListener( + 'touchend', (this.onTouchEnd_.bind(this) as (p1: Event) => any), + {passive: true}); + this.element_.addEventListener( + 'touchcancel', () => this.onTouchCancel_(), {passive: true}); + } + + /** + * Public for tests. Allow manually setting the elapsed time for a swipe + * action. + */ + setElapsedTimerForTesting(time: number) { + this.elapsedTimeForTesting_ = time; + } + + setPresentationMode(enabled: boolean) { + this.isPresentationMode_ = enabled; + } + + getPresentationModeForTesting() { + return this.isPresentationMode_; + } + + getEventTarget(): EventTarget { + return this.eventTarget_; + } + + /** + * Call the relevant listeners with the given swipe |direction|. + * @param direction The direction of swipe action. + */ + private notify_(direction: SwipeDirection) { + this.eventTarget_.dispatchEvent( + new CustomEvent('swipe', {detail: direction})); + } + + /** The callback for touchstart events on the element. */ + private onTouchStart_(event: TouchEvent) { + if (!this.isPresentationMode_) { + return; + } + + // If more than 1 finger touch the screen or there is already an ongoing + // swipe detection process, there is no valid swipe event to keep track. + if (event.touches.length !== 1 || this.swipeStartEvent_) { + this.swipeStartEvent_ = null; + return; + } + + this.swipeStartEvent_ = event; + return; + } + + /** The callback for touchcancel events on the element. */ + private onTouchCancel_() { + if (!this.isPresentationMode_ || !this.swipeStartEvent_) { + return; + } + + this.swipeStartEvent_ = null; + } + + /** The callback for touchend events on the element. */ + private onTouchEnd_(event: TouchEvent) { + if (!this.isPresentationMode_ || !this.swipeStartEvent_) { + return; + } + + if (event.touches.length !== 0 || + this.swipeStartEvent_.touches.length !== 1) { + return; + } + + const elapsedTime = this.elapsedTimeForTesting_ ? + this.elapsedTimeForTesting_ : + event.timeStamp - this.swipeStartEvent_.timeStamp; + const swipeStartObj = this.swipeStartEvent_.changedTouches[0]; + const swipeEndObj = event.changedTouches[0]; + const distX = swipeEndObj.pageX - swipeStartObj.pageX; + const distY = swipeEndObj.pageY - swipeStartObj.pageY; + + // If this is a valid swipe, notify its direction to the viewer. + if (elapsedTime <= SWIPE_TIMER_INTERVAL_MS && + Math.abs(distX) >= SWIPE_X_DIST_MIN && + Math.abs(distY) <= SWIPE_Y_DIST_MAX) { + const direction = distX > 0 ? SwipeDirection.LEFT_TO_RIGHT : + SwipeDirection.RIGHT_TO_LEFT; + this.notify_(direction); + } + + this.swipeStartEvent_ = null; + } +} diff --git a/chromium/chrome/browser/resources/pdf/viewport.ts b/chromium/chrome/browser/resources/pdf/viewport.ts index d19314cc959..77c2878b6a1 100644 --- a/chromium/chrome/browser/resources/pdf/viewport.ts +++ b/chromium/chrome/browser/resources/pdf/viewport.ts @@ -9,6 +9,7 @@ import {hasKeyModifiers, isRTL} from 'chrome://resources/js/util.m.js'; import {ExtendedKeyEvent, FittingType, Point} from './constants.js'; import {Gesture, GestureDetector, PinchEventDetail} from './gesture_detector.js'; import {PdfPluginElement} from './internal_plugin.js'; +import {SwipeDetector, SwipeDirection} from './swipe_detector.js'; import {ViewportInterface} from './viewport_scroller.js'; import {InactiveZoomManager, ZoomManager} from './zoom_manager.js'; @@ -95,7 +96,9 @@ export class Viewport implements ViewportInterface { private keepContentCentered_: boolean = false; private tracker_: EventTracker = new EventTracker(); private gestureDetector_: GestureDetector; + private swipeDetector_: SwipeDetector; private sentPinchEvent_: boolean = false; + private fullscreenForTesting_: boolean = false; /** * @param container The element which contains the scrollable content. @@ -133,6 +136,11 @@ export class Viewport implements ViewportInterface { this.gestureDetector_.getEventTarget().addEventListener( 'wheel', e => this.onWheel_(e as CustomEvent<PinchEventDetail>)); + this.swipeDetector_ = new SwipeDetector(content); + + this.swipeDetector_.getEventTarget().addEventListener( + 'swipe', e => this.onSwipe_(e as CustomEvent<SwipeDirection>)); + // Set to a default zoom manager - used in tests. this.setZoomManager(new InactiveZoomManager(this.getZoom.bind(this), 1)); @@ -171,6 +179,7 @@ export class Viewport implements ViewportInterface { setPresentationMode(enabled: boolean) { assert((document.fullscreenElement !== null) === enabled); this.gestureDetector_.setPresentationMode(enabled); + this.swipeDetector_.setPresentationMode(enabled); } /** @@ -1327,6 +1336,14 @@ export class Viewport implements ViewportInterface { } /** + * Dispatches a swipe event of |direction| external to this viewport. + */ + dispatchSwipe(direction: SwipeDirection) { + this.swipeDetector_.getEventTarget().dispatchEvent( + new CustomEvent('swipe', {detail: direction})); + } + + /** * A callback that's called when an update to a pinch zoom is detected. */ private onPinchUpdate_(e: CustomEvent<PinchEventDetail>) { @@ -1408,7 +1425,7 @@ export class Viewport implements ViewportInterface { * A callback that's called when the start of a pinch zoom is detected. */ private onPinchStart_(e: CustomEvent<PinchEventDetail>) { - // Disable pinch gestures in Presentation mode. + // Disable pinch gestures in Presentation mode. if (document.fullscreenElement !== null) { return; } @@ -1442,6 +1459,28 @@ export class Viewport implements ViewportInterface { getGestureDetectorForTesting(): GestureDetector { return this.gestureDetector_; } + + /** + * A callback that's called when a left/right swipe is detected in + * Presentation mode. + */ + private onSwipe_(e: CustomEvent<SwipeDirection>) { + // Left and right swipes are enabled only in Presentation mode. + if (document.fullscreenElement === null && !this.fullscreenForTesting_) { + return; + } + + if ((e.detail === SwipeDirection.RIGHT_TO_LEFT && !isRTL()) || + (e.detail === SwipeDirection.LEFT_TO_RIGHT && isRTL())) { + this.goToNextPage(); + } else { + this.goToPreviousPage(); + } + } + + enableFullscreenForTesting() { + this.fullscreenForTesting_ = true; + } } /** |