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 = {
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
* pdf/out_of_process_instance.h.
......
......@@ -18,7 +18,7 @@ import './shared-css.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 {FittingType, TwoUpViewAction} from '../constants.js';
import {FittingType} from '../constants.js';
// <if expr="chromeos">
import {InkController} from '../ink_controller.js';
// </if>
......@@ -184,15 +184,13 @@ export class ViewerPdfToolbarNewElement extends PolymerElement {
/** @private */
onSinglePageViewClick_() {
this.twoUpViewEnabled_ = false;
this.dispatchEvent(new CustomEvent(
'two-up-view-changed', {detail: TwoUpViewAction.TWO_UP_VIEW_DISABLE}));
this.dispatchEvent(new CustomEvent('two-up-view-changed', {detail: false}));
}
/** @private */
onTwoPageViewClick_() {
this.twoUpViewEnabled_ = true;
this.dispatchEvent(new CustomEvent(
'two-up-view-changed', {detail: TwoUpViewAction.TWO_UP_VIEW_ENABLE}));
this.dispatchEvent(new CustomEvent('two-up-view-changed', {detail: true}));
}
/** @private */
......
......@@ -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 {FittingType, TwoUpViewAction} from './constants.js';
import {FittingType} from './constants.js';
// Handles events specific to the PDF viewer and logs the corresponding metrics.
export class PDFMetrics {
......@@ -22,12 +22,11 @@ export class PDFMetrics {
/**
* 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(
twoUpViewAction === TwoUpViewAction.TWO_UP_VIEW_ENABLE ?
PDFMetrics.UserAction.TWO_UP_VIEW_ENABLE :
enabled ? PDFMetrics.UserAction.TWO_UP_VIEW_ENABLE :
PDFMetrics.UserAction.TWO_UP_VIEW_DISABLE);
}
......
......@@ -22,7 +22,7 @@ import {html} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.
import {Bookmark} from './bookmark_type.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';
// <if expr="chromeos">
import {InkController} from './ink_controller.js';
......@@ -559,19 +559,17 @@ export class PDFViewerElement extends PDFViewerBaseElement {
/**
* Changes two up view mode for the controller. Controller will trigger
* layout update later, which will update the viewport accordingly.
* @param {!CustomEvent<!TwoUpViewAction>} e
* @param {!CustomEvent<boolean>} e
* @private
*/
onTwoUpViewChanged_(e) {
this.currentController.setTwoUpView(
e.detail === TwoUpViewAction.TWO_UP_VIEW_ENABLE);
const twoUpViewEnabled = e.detail;
this.currentController.setTwoUpView(twoUpViewEnabled);
if (!this.pdfViewerUpdateEnabled_) {
this.toolbarManager_.forceHideTopToolbar();
}
this.getToolbar_().annotationAvailable =
(e.detail !== TwoUpViewAction.TWO_UP_VIEW_ENABLE);
PDFMetrics.recordTwoUpView(e.detail);
this.getToolbar_().annotationAvailable = !twoUpViewEnabled;
PDFMetrics.recordTwoUpViewEnabled(twoUpViewEnabled);
}
/**
......
......@@ -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 {FittingType, TwoUpViewAction} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/constants.js';
import {FittingType} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/constants.js';
import {PDFMetrics} from 'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/metrics.js';
chrome.test.runTests(function() {
......@@ -87,11 +87,11 @@ chrome.test.runTests(function() {
chrome.metricsPrivate = new MockMetricsPrivate();
PDFMetrics.record(PDFMetrics.UserAction.DOCUMENT_OPENED);
PDFMetrics.recordTwoUpView(TwoUpViewAction.TWO_UP_VIEW_ENABLE);
PDFMetrics.recordTwoUpView(TwoUpViewAction.TWO_UP_VIEW_DISABLE);
PDFMetrics.recordTwoUpView(TwoUpViewAction.TWO_UP_VIEW_ENABLE);
PDFMetrics.recordTwoUpView(TwoUpViewAction.TWO_UP_VIEW_DISABLE);
PDFMetrics.recordTwoUpView(TwoUpViewAction.TWO_UP_VIEW_ENABLE);
PDFMetrics.recordTwoUpViewEnabled(true);
PDFMetrics.recordTwoUpViewEnabled(false);
PDFMetrics.recordTwoUpViewEnabled(true);
PDFMetrics.recordTwoUpViewEnabled(false);
PDFMetrics.recordTwoUpViewEnabled(true);
chrome.test.assertEq(
{
......
......@@ -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 {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';
/** @return {!ViewerPdfToolbarNewElement} */
......@@ -155,7 +155,7 @@ const tests = [
toolbar.shadowRoot.querySelector('#two-page-view-button');
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(
singlePageViewButton.querySelector('iron-icon').hidden);
chrome.test.assertTrue(
......@@ -173,7 +173,7 @@ const tests = [
toolbar.shadowRoot.querySelector('#two-page-view-button');
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(
twoPageViewButton.querySelector('iron-icon').hidden);
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