Commit fb42d854 authored by John Lee's avatar John Lee Committed by Commit Bot

PDF Viewer: Replace TwoUpViewAction enum with a boolean

Bug: 1084620
Change-Id: I6f09aad6cd13fd5c6edbb6015edc3d09a7cc5ff5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2333171
Commit-Queue: John Lee <johntlee@chromium.org>
Reviewed-by: default avatardpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794662}
parent b545f589
...@@ -19,15 +19,6 @@ export const FittingType = { ...@@ -19,15 +19,6 @@ export const FittingType = {
FIT_TO_HEIGHT: 'fit-to-height', FIT_TO_HEIGHT: 'fit-to-height',
}; };
/**
* Enumeration of two up view actions.
* @enum {string}
*/
export const TwoUpViewAction = {
TWO_UP_VIEW_ENABLE: 'two-up-view-enable',
TWO_UP_VIEW_DISABLE: 'two-up-view-disable',
};
/** /**
* Enumeration of save message request types. Must Match SaveRequestType in * Enumeration of save message request types. Must Match SaveRequestType in
* pdf/out_of_process_instance.h. * pdf/out_of_process_instance.h.
......
...@@ -18,7 +18,7 @@ import './shared-css.js'; ...@@ -18,7 +18,7 @@ import './shared-css.js';
import {AnchorAlignment} from 'chrome://resources/cr_elements/cr_action_menu/cr_action_menu.m.js'; import {AnchorAlignment} from 'chrome://resources/cr_elements/cr_action_menu/cr_action_menu.m.js';
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {FittingType, TwoUpViewAction} from '../constants.js'; import {FittingType} from '../constants.js';
// <if expr="chromeos"> // <if expr="chromeos">
import {InkController} from '../ink_controller.js'; import {InkController} from '../ink_controller.js';
// </if> // </if>
...@@ -184,15 +184,13 @@ export class ViewerPdfToolbarNewElement extends PolymerElement { ...@@ -184,15 +184,13 @@ export class ViewerPdfToolbarNewElement extends PolymerElement {
/** @private */ /** @private */
onSinglePageViewClick_() { onSinglePageViewClick_() {
this.twoUpViewEnabled_ = false; this.twoUpViewEnabled_ = false;
this.dispatchEvent(new CustomEvent( this.dispatchEvent(new CustomEvent('two-up-view-changed', {detail: false}));
'two-up-view-changed', {detail: TwoUpViewAction.TWO_UP_VIEW_DISABLE}));
} }
/** @private */ /** @private */
onTwoPageViewClick_() { onTwoPageViewClick_() {
this.twoUpViewEnabled_ = true; this.twoUpViewEnabled_ = true;
this.dispatchEvent(new CustomEvent( this.dispatchEvent(new CustomEvent('two-up-view-changed', {detail: true}));
'two-up-view-changed', {detail: TwoUpViewAction.TWO_UP_VIEW_ENABLE}));
} }
/** @private */ /** @private */
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import {FittingType, TwoUpViewAction} from './constants.js'; import {FittingType} from './constants.js';
// Handles events specific to the PDF viewer and logs the corresponding metrics. // Handles events specific to the PDF viewer and logs the corresponding metrics.
export class PDFMetrics { export class PDFMetrics {
...@@ -22,13 +22,12 @@ export class PDFMetrics { ...@@ -22,13 +22,12 @@ export class PDFMetrics {
/** /**
* Records when the two up view mode is enabled or disabled. * Records when the two up view mode is enabled or disabled.
* @param {TwoUpViewAction} twoUpViewAction the new TwoUpViewAction. * @param {boolean} enabled True when two up view mode is enabled.
*/ */
static recordTwoUpView(twoUpViewAction) { static recordTwoUpViewEnabled(enabled) {
PDFMetrics.record( PDFMetrics.record(
twoUpViewAction === TwoUpViewAction.TWO_UP_VIEW_ENABLE ? enabled ? PDFMetrics.UserAction.TWO_UP_VIEW_ENABLE :
PDFMetrics.UserAction.TWO_UP_VIEW_ENABLE : PDFMetrics.UserAction.TWO_UP_VIEW_DISABLE);
PDFMetrics.UserAction.TWO_UP_VIEW_DISABLE);
} }
/** /**
......
...@@ -22,7 +22,7 @@ import {html} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min. ...@@ -22,7 +22,7 @@ import {html} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.
import {Bookmark} from './bookmark_type.js'; import {Bookmark} from './bookmark_type.js';
import {BrowserApi} from './browser_api.js'; import {BrowserApi} from './browser_api.js';
import {FittingType, Point, SaveRequestType, TwoUpViewAction} from './constants.js'; import {FittingType, Point, SaveRequestType} from './constants.js';
import {ViewerPdfToolbarNewElement} from './elements/viewer-pdf-toolbar-new.js'; import {ViewerPdfToolbarNewElement} from './elements/viewer-pdf-toolbar-new.js';
// <if expr="chromeos"> // <if expr="chromeos">
import {InkController} from './ink_controller.js'; import {InkController} from './ink_controller.js';
...@@ -559,19 +559,17 @@ export class PDFViewerElement extends PDFViewerBaseElement { ...@@ -559,19 +559,17 @@ export class PDFViewerElement extends PDFViewerBaseElement {
/** /**
* Changes two up view mode for the controller. Controller will trigger * Changes two up view mode for the controller. Controller will trigger
* layout update later, which will update the viewport accordingly. * layout update later, which will update the viewport accordingly.
* @param {!CustomEvent<!TwoUpViewAction>} e * @param {!CustomEvent<boolean>} e
* @private * @private
*/ */
onTwoUpViewChanged_(e) { onTwoUpViewChanged_(e) {
this.currentController.setTwoUpView( const twoUpViewEnabled = e.detail;
e.detail === TwoUpViewAction.TWO_UP_VIEW_ENABLE); this.currentController.setTwoUpView(twoUpViewEnabled);
if (!this.pdfViewerUpdateEnabled_) { if (!this.pdfViewerUpdateEnabled_) {
this.toolbarManager_.forceHideTopToolbar(); this.toolbarManager_.forceHideTopToolbar();
} }
this.getToolbar_().annotationAvailable = this.getToolbar_().annotationAvailable = !twoUpViewEnabled;
(e.detail !== TwoUpViewAction.TWO_UP_VIEW_ENABLE); PDFMetrics.recordTwoUpViewEnabled(twoUpViewEnabled);
PDFMetrics.recordTwoUpView(e.detail);
} }
/** /**
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import {FittingType, TwoUpViewAction} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/constants.js'; import {FittingType} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/constants.js';
import {PDFMetrics} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/metrics.js'; import {PDFMetrics} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/metrics.js';
chrome.test.runTests(function() { chrome.test.runTests(function() {
...@@ -87,11 +87,11 @@ chrome.test.runTests(function() { ...@@ -87,11 +87,11 @@ chrome.test.runTests(function() {
chrome.metricsPrivate = new MockMetricsPrivate(); chrome.metricsPrivate = new MockMetricsPrivate();
PDFMetrics.record(PDFMetrics.UserAction.DOCUMENT_OPENED); PDFMetrics.record(PDFMetrics.UserAction.DOCUMENT_OPENED);
PDFMetrics.recordTwoUpView(TwoUpViewAction.TWO_UP_VIEW_ENABLE); PDFMetrics.recordTwoUpViewEnabled(true);
PDFMetrics.recordTwoUpView(TwoUpViewAction.TWO_UP_VIEW_DISABLE); PDFMetrics.recordTwoUpViewEnabled(false);
PDFMetrics.recordTwoUpView(TwoUpViewAction.TWO_UP_VIEW_ENABLE); PDFMetrics.recordTwoUpViewEnabled(true);
PDFMetrics.recordTwoUpView(TwoUpViewAction.TWO_UP_VIEW_DISABLE); PDFMetrics.recordTwoUpViewEnabled(false);
PDFMetrics.recordTwoUpView(TwoUpViewAction.TWO_UP_VIEW_ENABLE); PDFMetrics.recordTwoUpViewEnabled(true);
chrome.test.assertEq( chrome.test.assertEq(
{ {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import {FittingType, TwoUpViewAction} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/constants.js'; import {FittingType} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/constants.js';
import {ViewerPdfToolbarNewElement} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/elements/viewer-pdf-toolbar-new.js'; import {ViewerPdfToolbarNewElement} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/elements/viewer-pdf-toolbar-new.js';
/** @return {!ViewerPdfToolbarNewElement} */ /** @return {!ViewerPdfToolbarNewElement} */
...@@ -155,7 +155,7 @@ const tests = [ ...@@ -155,7 +155,7 @@ const tests = [
toolbar.shadowRoot.querySelector('#two-page-view-button'); toolbar.shadowRoot.querySelector('#two-page-view-button');
toolbar.addEventListener('two-up-view-changed', function(e) { toolbar.addEventListener('two-up-view-changed', function(e) {
chrome.test.assertEq(TwoUpViewAction.TWO_UP_VIEW_DISABLE, e.detail); chrome.test.assertEq(false, e.detail);
chrome.test.assertFalse( chrome.test.assertFalse(
singlePageViewButton.querySelector('iron-icon').hidden); singlePageViewButton.querySelector('iron-icon').hidden);
chrome.test.assertTrue( chrome.test.assertTrue(
...@@ -173,7 +173,7 @@ const tests = [ ...@@ -173,7 +173,7 @@ const tests = [
toolbar.shadowRoot.querySelector('#two-page-view-button'); toolbar.shadowRoot.querySelector('#two-page-view-button');
toolbar.addEventListener('two-up-view-changed', function(e) { toolbar.addEventListener('two-up-view-changed', function(e) {
chrome.test.assertEq(TwoUpViewAction.TWO_UP_VIEW_ENABLE, e.detail); chrome.test.assertEq(true, e.detail);
chrome.test.assertFalse( chrome.test.assertFalse(
twoPageViewButton.querySelector('iron-icon').hidden); twoPageViewButton.querySelector('iron-icon').hidden);
chrome.test.assertTrue( chrome.test.assertTrue(
......
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