Commit f69edcd5 authored by rbpotter's avatar rbpotter Committed by Commit Bot

PDF Viewer: Disable two up button in annotation mode

Two up mode is implemented in the plugin but not the ink controller,
and triggering it causes a crash if the plugin is not on the page.

Also fixing the following case:
1. Rotate PDF. Annotation is disabled.
2. Set 2 page view.
3. Rotate PDF back to upright.

Currently, annotation is re-enabled, despite still being in 2 page view.
After this CL, annotation remains disabled, until two page view is
turned off.

Bug: 1048812
Change-Id: I26c0cb43645c82905e1fe5b53398332573d8a774
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2411284Reviewed-by: default avatardpapad <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807496}
parent d8f713b1
...@@ -167,7 +167,10 @@ ...@@ -167,7 +167,10 @@
<div id="toolbar"> <div id="toolbar">
<div id="start"> <div id="start">
<cr-icon-button id="sidenavToggle" iron-icon="cr20:menu" <cr-icon-button id="sidenavToggle" iron-icon="cr20:menu"
disabled="[[annotationMode]]" on-click="onSidenavToggleClick_"> <if expr="chromeos">
disabled="[[annotationMode]]"
</if>
on-click="onSidenavToggleClick_">
</cr-icon-button> </cr-icon-button>
<span id="title">[[docTitle]]</span> <span id="title">[[docTitle]]</span>
</div> </div>
...@@ -193,8 +196,11 @@ ...@@ -193,8 +196,11 @@
on-click="onFitToButtonClick_"> on-click="onFitToButtonClick_">
</cr-icon-button> </cr-icon-button>
<cr-icon-button iron-icon="pdf:rotate-left" <cr-icon-button iron-icon="pdf:rotate-left"
disabled="[[annotationMode]]" aria-label$="$i18n{tooltipRotateCCW}" <if expr="chromeos">
title="$i18n{tooltipRotateCCW}" on-click="onRotateClick_"> disabled="[[annotationMode]]"
</if>
aria-label$="$i18n{tooltipRotateCCW}" title="$i18n{tooltipRotateCCW}"
on-click="onRotateClick_">
</cr-icon-button> </cr-icon-button>
</div> </div>
<div id="end"> <div id="end">
...@@ -224,8 +230,10 @@ ...@@ -224,8 +230,10 @@
<cr-action-menu> <cr-action-menu>
<button id="two-page-view-button" <button id="two-page-view-button"
class="dropdown-item" on-click="toggleTwoPageViewClick_" class="dropdown-item" on-click="toggleTwoPageViewClick_" role="checkbox"
role="checkbox" <if expr="chromeos">
disabled="[[annotationMode]]"
</if>
aria-checked="[[getTwoPageViewAriaChecked_(twoUpViewEnabled_)]]"> aria-checked="[[getTwoPageViewAriaChecked_(twoUpViewEnabled_)]]">
<span class="check-container"> <span class="check-container">
<iron-icon icon="pdf:check" hidden="[[!twoUpViewEnabled_]]"></iron-icon> <iron-icon icon="pdf:check" hidden="[[!twoUpViewEnabled_]]"></iron-icon>
......
...@@ -37,12 +37,12 @@ export class ViewerPdfToolbarNewElement extends PolymerElement { ...@@ -37,12 +37,12 @@ export class ViewerPdfToolbarNewElement extends PolymerElement {
return { return {
// <if expr="chromeos"> // <if expr="chromeos">
annotationAvailable: Boolean, annotationAvailable: Boolean,
// </if>
annotationMode: { annotationMode: {
type: Boolean, type: Boolean,
value: false, value: false,
reflectToAttribute: true, reflectToAttribute: true,
}, },
// </if>
docTitle: String, docTitle: String,
docLength: Number, docLength: Number,
hasEdits: Boolean, hasEdits: Boolean,
......
...@@ -105,7 +105,7 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -105,7 +105,7 @@ export class PDFViewerElement extends PDFViewerBaseElement {
annotationAvailable_: { annotationAvailable_: {
type: Boolean, type: Boolean,
computed: 'computeAnnotationAvailable_(' + computed: 'computeAnnotationAvailable_(' +
'hadPassword_, rotated_, canSerializeDocument_)', 'hadPassword_, rotated_, canSerializeDocument_, twoUpViewEnabled_)',
}, },
annotationMode_: { annotationMode_: {
...@@ -140,6 +140,8 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -140,6 +140,8 @@ export class PDFViewerElement extends PDFViewerBaseElement {
title_: String, title_: String,
twoUpViewEnabled_: Boolean,
isFormFieldFocused_: Boolean, isFormFieldFocused_: Boolean,
pdfViewerUpdateEnabled_: Boolean, pdfViewerUpdateEnabled_: Boolean,
...@@ -194,6 +196,9 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -194,6 +196,9 @@ export class PDFViewerElement extends PDFViewerBaseElement {
/** @private {string} */ /** @private {string} */
this.title_ = ''; this.title_ = '';
/** @private {boolean} */
this.twoUpViewEnabled_ = false;
/** @private {boolean} */ /** @private {boolean} */
this.isFormFieldFocused_ = false; this.isFormFieldFocused_ = false;
...@@ -620,13 +625,12 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -620,13 +625,12 @@ export class PDFViewerElement extends PDFViewerBaseElement {
* @private * @private
*/ */
onTwoUpViewChanged_(e) { onTwoUpViewChanged_(e) {
const twoUpViewEnabled = e.detail; this.twoUpViewEnabled_ = e.detail;
this.currentController.setTwoUpView(twoUpViewEnabled); this.currentController.setTwoUpView(this.twoUpViewEnabled_);
if (!this.pdfViewerUpdateEnabled_) { if (!this.pdfViewerUpdateEnabled_) {
this.toolbarManager_.forceHideTopToolbar(); this.toolbarManager_.forceHideTopToolbar();
} }
this.getToolbar_().annotationAvailable = !twoUpViewEnabled; PDFMetrics.recordTwoUpViewEnabled(this.twoUpViewEnabled_);
PDFMetrics.recordTwoUpViewEnabled(twoUpViewEnabled);
} }
/** /**
...@@ -1042,7 +1046,8 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -1042,7 +1046,8 @@ export class PDFViewerElement extends PDFViewerBaseElement {
* @private * @private
*/ */
computeAnnotationAvailable_() { computeAnnotationAvailable_() {
return this.canSerializeDocument_ && !this.rotated_ && !this.hadPassword_; return this.canSerializeDocument_ && !this.rotated_ && !this.hadPassword_ &&
!this.twoUpViewEnabled_;
} }
/** @override */ /** @override */
......
...@@ -386,9 +386,12 @@ chrome.test.runTests([ ...@@ -386,9 +386,12 @@ chrome.test.runTests([
}, },
function testHidingAnnotationsExitsAnnotationsMode() { function testHidingAnnotationsExitsAnnotationsMode() {
testAsync(async () => { testAsync(async () => {
document.body.innerHTML = '';
const toolbar = document.createElement('viewer-pdf-toolbar-new'); const toolbar = document.createElement('viewer-pdf-toolbar-new');
document.body.appendChild(toolbar); document.body.appendChild(toolbar);
toolbar.toggleAnnotation(); toolbar.toggleAnnotation();
// This is normally done by the parent in response to the event fired by
// toggleAnnotation().
toolbar.annotationMode = true; toolbar.annotationMode = true;
await toolbar.addEventListener('display-annotations-changed', async e => { await toolbar.addEventListener('display-annotations-changed', async e => {
...@@ -400,6 +403,7 @@ chrome.test.runTests([ ...@@ -400,6 +403,7 @@ chrome.test.runTests([
}); });
}, },
function testEnteringAnnotationsModeShowsAnnotations() { function testEnteringAnnotationsModeShowsAnnotations() {
document.body.innerHTML = '';
const toolbar = document.createElement('viewer-pdf-toolbar-new'); const toolbar = document.createElement('viewer-pdf-toolbar-new');
document.body.appendChild(toolbar); document.body.appendChild(toolbar);
chrome.test.assertFalse(toolbar.annotationMode); chrome.test.assertFalse(toolbar.annotationMode);
...@@ -412,5 +416,19 @@ chrome.test.runTests([ ...@@ -412,5 +416,19 @@ chrome.test.runTests([
chrome.test.succeed(); chrome.test.succeed();
}); });
toolbar.toggleAnnotation(); toolbar.toggleAnnotation();
},
function testEnteringAnnotationsModeDisablesTwoUp() {
document.body.innerHTML = '';
const toolbar = document.createElement('viewer-pdf-toolbar-new');
document.body.appendChild(toolbar);
chrome.test.assertFalse(toolbar.annotationMode);
toolbar.toggleAnnotation();
// This is normally done by the parent in response to the event fired by
// toggleAnnotation().
toolbar.annotationMode = true;
chrome.test.assertTrue(
toolbar.shadowRoot.querySelector('#two-page-view-button').disabled);
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