Commit 5abec95c authored by dpapad's avatar dpapad Committed by Commit Bot

PDF Viewer update: Change single/two-page to a checkmark toggle.

Fixed: 1123224
Change-Id: Ifa40c81d5514ad903e6065f95109a43caa0a2dc5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2384911Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Auto-Submit: dpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803236}
parent ae02f54b
...@@ -39,7 +39,6 @@ void AddCommonStrings(base::Value* dict) { ...@@ -39,7 +39,6 @@ void AddCommonStrings(base::Value* dict) {
{"tooltipFitToWidth", IDS_PDF_TOOLTIP_FIT_WIDTH}, {"tooltipFitToWidth", IDS_PDF_TOOLTIP_FIT_WIDTH},
{"tooltipZoomIn", IDS_PDF_TOOLTIP_ZOOM_IN}, {"tooltipZoomIn", IDS_PDF_TOOLTIP_ZOOM_IN},
{"tooltipZoomOut", IDS_PDF_TOOLTIP_ZOOM_OUT}, {"tooltipZoomOut", IDS_PDF_TOOLTIP_ZOOM_OUT},
{"twoUpViewDisable", IDS_PDF_TWO_UP_VIEW_DISABLE},
{"twoUpViewEnable", IDS_PDF_TWO_UP_VIEW_ENABLE}, {"twoUpViewEnable", IDS_PDF_TWO_UP_VIEW_ENABLE},
}; };
for (const auto& resource : kPdfResources) for (const auto& resource : kPdfResources)
......
...@@ -130,10 +130,6 @@ ...@@ -130,10 +130,6 @@
margin-inline-end: 12px; margin-inline-end: 12px;
width: 16px; width: 16px;
} }
#show-annotations-button {
border-top: var(--cr-separator-line);
}
</style> </style>
<!-- TODO(dpapad): Add aria-label and title for all buttons --> <!-- TODO(dpapad): Add aria-label and title for all buttons -->
<div id="toolbar"> <div id="toolbar">
...@@ -195,18 +191,9 @@ ...@@ -195,18 +191,9 @@
</paper-progress> </paper-progress>
<cr-action-menu> <cr-action-menu>
<button id="single-page-view-button"
class="dropdown-item" on-click="onSinglePageViewClick_"
role="radio"
aria-checked="[[getSinglePageAriaChecked_(twoUpViewEnabled_)]]">
<span class="check-container">
<iron-icon icon="pdf:check" hidden="[[twoUpViewEnabled_]]"></iron-icon>
</span>
$i18n{twoUpViewDisable}
</button>
<button id="two-page-view-button" <button id="two-page-view-button"
class="dropdown-item" on-click="onTwoPageViewClick_" class="dropdown-item" on-click="toggleTwoPageViewClick_"
role="radio" role="checkbox"
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>
......
...@@ -216,16 +216,10 @@ export class ViewerPdfToolbarNewElement extends PolymerElement { ...@@ -216,16 +216,10 @@ export class ViewerPdfToolbarNewElement extends PolymerElement {
} }
/** @private */ /** @private */
onSinglePageViewClick_() { toggleTwoPageViewClick_() {
this.twoUpViewEnabled_ = false; this.twoUpViewEnabled_ = !this.twoUpViewEnabled_;
this.dispatchEvent(new CustomEvent('two-up-view-changed', {detail: false})); this.dispatchEvent(new CustomEvent(
this.getMenu_().close(); 'two-up-view-changed', {detail: this.twoUpViewEnabled_}));
}
/** @private */
onTwoPageViewClick_() {
this.twoUpViewEnabled_ = true;
this.dispatchEvent(new CustomEvent('two-up-view-changed', {detail: true}));
this.getMenu_().close(); this.getMenu_().close();
} }
......
...@@ -26,6 +26,16 @@ function getCrIconButtons(toolbar, parentId) { ...@@ -26,6 +26,16 @@ function getCrIconButtons(toolbar, parentId) {
toolbar.shadowRoot.querySelectorAll(`#${parentId} cr-icon-button`)); toolbar.shadowRoot.querySelectorAll(`#${parentId} cr-icon-button`));
} }
/**
* @param {!HTMLElement} button
* @param {boolean} enabled
*/
function assertCheckboxMenuButton(button, enabled) {
chrome.test.assertEq(
enabled ? 'true' : 'false', button.getAttribute('aria-checked'));
chrome.test.assertEq(enabled, !button.querySelector('iron-icon').hidden);
}
// Unit tests for the viewer-pdf-toolbar-new element. // Unit tests for the viewer-pdf-toolbar-new element.
const tests = [ const tests = [
/** /**
...@@ -169,69 +179,50 @@ const tests = [ ...@@ -169,69 +179,50 @@ const tests = [
chrome.test.succeed(); chrome.test.succeed();
}, },
function testSinglePageView() { function testTwoPageViewToggle() {
const toolbar = createToolbar();
const singlePageViewButton =
toolbar.shadowRoot.querySelector('#single-page-view-button');
const twoPageViewButton =
toolbar.shadowRoot.querySelector('#two-page-view-button');
toolbar.addEventListener('two-up-view-changed', function(e) {
chrome.test.assertEq(false, e.detail);
chrome.test.assertEq(
'true', singlePageViewButton.getAttribute('aria-checked'));
chrome.test.assertFalse(
singlePageViewButton.querySelector('iron-icon').hidden);
chrome.test.assertEq(
'false', twoPageViewButton.getAttribute('aria-checked'));
chrome.test.assertTrue(
twoPageViewButton.querySelector('iron-icon').hidden);
chrome.test.succeed();
});
singlePageViewButton.click();
},
function testTwoPageView() {
const toolbar = createToolbar(); const toolbar = createToolbar();
const singlePageViewButton = const button = /** @type {!HTMLElement} */ (
toolbar.shadowRoot.querySelector('#single-page-view-button'); toolbar.shadowRoot.querySelector('#two-page-view-button'));
const twoPageViewButton = assertCheckboxMenuButton(button, false);
toolbar.shadowRoot.querySelector('#two-page-view-button');
let whenChanged = eventToPromise('two-up-view-changed', toolbar);
toolbar.addEventListener('two-up-view-changed', function(e) { button.click();
chrome.test.assertEq(true, e.detail); whenChanged
chrome.test.assertEq( .then(e => {
'true', twoPageViewButton.getAttribute('aria-checked')); chrome.test.assertEq(true, e.detail);
chrome.test.assertFalse( assertCheckboxMenuButton(button, true);
twoPageViewButton.querySelector('iron-icon').hidden); whenChanged = eventToPromise('two-up-view-changed', toolbar);
chrome.test.assertEq( button.click();
'false', singlePageViewButton.getAttribute('aria-checked')); return whenChanged;
chrome.test.assertTrue( })
singlePageViewButton.querySelector('iron-icon').hidden); .then(e => {
chrome.test.succeed(); chrome.test.assertEq(false, e.detail);
}); assertCheckboxMenuButton(button, false);
twoPageViewButton.click(); chrome.test.succeed();
});
}, },
function testShowAnnotationsToggle() { function testShowAnnotationsToggle() {
const toolbar = createToolbar(); const toolbar = createToolbar();
const button = /** @type {!HTMLElement} */ (
const showAnnotationsButton = toolbar.shadowRoot.querySelector('#show-annotations-button'));
toolbar.shadowRoot.querySelector('#show-annotations-button'); assertCheckboxMenuButton(button, true);
chrome.test.assertEq(
'true', showAnnotationsButton.getAttribute('aria-checked')); let whenChanged = eventToPromise('display-annotations-changed', toolbar);
chrome.test.assertFalse( button.click();
showAnnotationsButton.querySelector('iron-icon').hidden); whenChanged
.then(e => {
toolbar.addEventListener('display-annotations-changed', (e) => { chrome.test.assertEq(false, e.detail);
chrome.test.assertEq(false, e.detail); assertCheckboxMenuButton(button, false);
chrome.test.assertEq( whenChanged = eventToPromise('display-annotations-changed', toolbar);
'false', showAnnotationsButton.getAttribute('aria-checked')); button.click();
chrome.test.assertTrue( return whenChanged;
showAnnotationsButton.querySelector('iron-icon').hidden); })
chrome.test.succeed(); .then(e => {
}); chrome.test.assertEq(true, e.detail);
showAnnotationsButton.click(); assertCheckboxMenuButton(button, true);
chrome.test.succeed();
});
}, },
function testSidenavToggleButton() { function testSidenavToggleButton() {
......
...@@ -58,9 +58,6 @@ ...@@ -58,9 +58,6 @@
<message name="IDS_PDF_TWO_UP_VIEW_ENABLE" desc="Button text for the button which enables displaying two pages of a PDF on the screen horizontally"> <message name="IDS_PDF_TWO_UP_VIEW_ENABLE" desc="Button text for the button which enables displaying two pages of a PDF on the screen horizontally">
Two page view Two page view
</message> </message>
<message name="IDS_PDF_TWO_UP_VIEW_DISABLE" desc="Button text for the button which stops displaying two pages of a PDF on the screen horizontally">
Single page view
</message>
<message name="IDS_PDF_ANNOTATIONS_SHOW_TOGGLE" desc="Button text for toggling showing annotations on the PDF document"> <message name="IDS_PDF_ANNOTATIONS_SHOW_TOGGLE" desc="Button text for toggling showing annotations on the PDF document">
Show annotations Show annotations
</message> </message>
......
c947bd9cda772b4f1933139637fe856acf4b094b
\ No newline at end of file
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