Commit f5cf4419 authored by Gavin Williams's avatar Gavin Williams Committed by Commit Bot

Incorporate existing features into new print preview dropdown

- Show the 3 default print preview destinations Save to PDF,
  Save to Google Drive, and See More...

- Add the existing icons to inside the dropdown using |destinationIcon|

Bug: 1059607
Change-Id: Icef448773ac3f350c0fd3bf5eb8b63c8d567cb48
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2194789
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Auto-Submit: Gavin Williams <gavinwill@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774642}
parent 8816e524
...@@ -98,7 +98,12 @@ ...@@ -98,7 +98,12 @@
} }
</style> </style>
<cr-input id="dropdownInput" on-keydown="onKeyDown_" <cr-input id="dropdownInput" on-keydown="onKeyDown_"
value="[[value.displayName]]" readonly> value="[[value.displayName]]" disabled="[[disabled]]">
<div id="pre-input-overlay" slot="prefix">
<div id="pre-input-box">
<iron-icon icon="[[destinationIcon]]"></iron-icon>
</div>
</div>
<div id="input-overlay" slot="suffix"> <div id="input-overlay" slot="suffix">
<div id="input-box"> <div id="input-box">
<iron-icon id="dropdown-icon" icon="cr:arrow-drop-down"></iron-icon> <iron-icon id="dropdown-icon" icon="cr:arrow-drop-down"></iron-icon>
...@@ -115,6 +120,22 @@ ...@@ -115,6 +120,22 @@
[[item.displayName]] [[item.displayName]]
</button> </button>
</template> </template>
<button class="list-item" on-click="onSelect_" tabindex="-1"
value="[[pdfDestinationKey]]" hidden$="[[pdfPrinterDisabled]]">
$i18n{printToPDF}
</button>
<button class="list-item" on-click="onSelect_" tabindex="-1"
value="[[driveDestinationKey]]" hidden$="[[!driveDestinationKey]]">
$i18n{printToGoogleDrive}
</button>
<button class="list-item" on-click="onSelect_" tabindex="-1"
value="noDestinations" hidden$="[[!noDestinations]]">
$i18n{noDestinationsMessage}
</button>
<button class="list-item" on-click="onSelect_" tabindex="-1"
value="seeMore" aria-label$="[[i18n(seeMoreDestinationsLabel)]]">
$i18n{seeMore}
</button>
</div> </div>
</iron-dropdown> </iron-dropdown>
</div> </div>
......
...@@ -28,6 +28,22 @@ Polymer({ ...@@ -28,6 +28,22 @@ Polymer({
type: Array, type: Array,
observer: 'enqueueDropdownRefit_', observer: 'enqueueDropdownRefit_',
}, },
/** @type {boolean} */
disabled: {
type: Boolean,
value: false,
},
driveDestinationKey: String,
noDestinations: Boolean,
pdfPrinterDisabled: Boolean,
pdfDestinationKey: String,
destinationIcon: String,
}, },
listeners: { listeners: {
...@@ -62,6 +78,10 @@ Polymer({ ...@@ -62,6 +78,10 @@ Polymer({
/** @private */ /** @private */
openDropdown_() { openDropdown_() {
if (this.disabled) {
return;
}
this.$$('iron-dropdown').open(); this.$$('iron-dropdown').open();
this.opened_ = true; this.opened_ = true;
}, },
......
...@@ -34,7 +34,13 @@ ...@@ -34,7 +34,13 @@
</template> </template>
<template is="dom-if" if="[[printerStatusFlagEnabled_]]"> <template is="dom-if" if="[[printerStatusFlagEnabled_]]">
<print-preview-destination-dropdown-cros id="dropdown" <print-preview-destination-dropdown-cros id="dropdown"
value="[[destination]]" item-list="[[recentDestinationList]]" value="[[destination]]" hidden$="[[!loaded]]"
item-list="[[recentDestinationList]]"
pdf-destination-key="[[pdfDestinationKey_]]"
drive-destination-key="[[driveDestinationKey]]"
no-destinations="[[noDestinations]]"
pdf-printer-disabled="[[pdfPrinterDisabled]]"
destination-icon="[[destinationIcon_]]" disabled="[[disabled]]"
on-dropdown-value-selected="onDropdownValueSelected_"> on-dropdown-value-selected="onDropdownValueSelected_">
</print-preview-destination-dropdown-cros> </print-preview-destination-dropdown-cros>
</template> </template>
......
...@@ -75,7 +75,13 @@ Polymer({ ...@@ -75,7 +75,13 @@ Polymer({
backgroundImages_: { backgroundImages_: {
type: String, type: String,
computed: computed:
'computeBackgroundImages_(selectedValue, destination, noDestinations, dark)', 'computeBackgroundImages_(destinationIcon_, dark, noDestinations)',
},
/** @private {string} */
destinationIcon_: {
type: String,
computed: 'computeDestinationIcon_(selectedValue, destination)',
}, },
/** @private */ /** @private */
...@@ -126,7 +132,7 @@ Polymer({ ...@@ -126,7 +132,7 @@ Polymer({
* @return {string} The iconset and icon for the current selection. * @return {string} The iconset and icon for the current selection.
* @private * @private
*/ */
getDestinationIcon_() { computeDestinationIcon_() {
if (!this.selectedValue) { if (!this.selectedValue) {
return ''; return '';
} }
...@@ -166,8 +172,7 @@ Polymer({ ...@@ -166,8 +172,7 @@ Polymer({
* @private * @private
*/ */
computeBackgroundImages_() { computeBackgroundImages_() {
const icon = this.getDestinationIcon_(); if (!this.destinationIcon_) {
if (!icon) {
return ''; return '';
} }
...@@ -175,7 +180,7 @@ Polymer({ ...@@ -175,7 +180,7 @@ Polymer({
if (this.noDestinations) { if (this.noDestinations) {
iconSetAndIcon = ['cr', 'error']; iconSetAndIcon = ['cr', 'error'];
} }
iconSetAndIcon = iconSetAndIcon || icon.split(':'); iconSetAndIcon = iconSetAndIcon || this.destinationIcon_.split(':');
const iconset = /** @type {!IronIconsetSvgElement} */ ( const iconset = /** @type {!IronIconsetSvgElement} */ (
this.meta_.byKey(iconSetAndIcon[0])); this.meta_.byKey(iconSetAndIcon[0]));
return getSelectDropdownBackground(iconset, iconSetAndIcon[1], this); return getSelectDropdownBackground(iconset, iconSetAndIcon[1], this);
......
...@@ -21,6 +21,7 @@ destination_dropdown_cros_test.TestNames = { ...@@ -21,6 +21,7 @@ destination_dropdown_cros_test.TestNames = {
SelectedAfterUpDown: 'selected after keyboard press up and down', SelectedAfterUpDown: 'selected after keyboard press up and down',
EnterOpensCloses: 'enter opens and closes dropdown', EnterOpensCloses: 'enter opens and closes dropdown',
SelectedFollowsMouse: 'selected follows mouse', SelectedFollowsMouse: 'selected follows mouse',
Disabled: 'disabled',
}; };
suite(destination_dropdown_cros_test.suiteName, function() { suite(destination_dropdown_cros_test.suiteName, function() {
...@@ -92,6 +93,7 @@ suite(destination_dropdown_cros_test.suiteName, function() { ...@@ -92,6 +93,7 @@ suite(destination_dropdown_cros_test.suiteName, function() {
/** @type {!PrintPreviewDestinationDropdownCrosElement} */ /** @type {!PrintPreviewDestinationDropdownCrosElement} */
(document.createElement('print-preview-destination-dropdown-cros')); (document.createElement('print-preview-destination-dropdown-cros'));
document.body.appendChild(dropdown); document.body.appendChild(dropdown);
dropdown.noDestinations = false;
}); });
test( test(
...@@ -103,7 +105,7 @@ suite(destination_dropdown_cros_test.suiteName, function() { ...@@ -103,7 +105,7 @@ suite(destination_dropdown_cros_test.suiteName, function() {
]); ]);
const itemList = getList(); const itemList = getList();
assertEquals(3, itemList.length); assertEquals(7, itemList.length);
assertEquals('One', itemList[0].textContent.trim()); assertEquals('One', itemList[0].textContent.trim());
assertEquals('Two', itemList[1].textContent.trim()); assertEquals('Two', itemList[1].textContent.trim());
assertEquals('Three', itemList[2].textContent.trim()); assertEquals('Three', itemList[2].textContent.trim());
...@@ -155,30 +157,29 @@ suite(destination_dropdown_cros_test.suiteName, function() { ...@@ -155,30 +157,29 @@ suite(destination_dropdown_cros_test.suiteName, function() {
test( test(
assert(destination_dropdown_cros_test.TestNames.SelectedAfterUpDown), assert(destination_dropdown_cros_test.TestNames.SelectedAfterUpDown),
function() { function() {
setItemList([ setItemList([createDestination('One')]);
createDestination('One'), createDestination('Two'),
createDestination('Three')
]);
pointerDown(dropdown.$$('#dropdownInput')); pointerDown(dropdown.$$('#dropdownInput'));
down(); down();
assertEquals('One', getSelectedElementText()); assertEquals('One', getSelectedElementText());
down(); down();
assertEquals('Two', getSelectedElementText()); assertEquals('Save as PDF', getSelectedElementText());
down(); down();
assertEquals('Three', getSelectedElementText()); assertEquals('Save to Google Drive', getSelectedElementText());
down();
assertEquals('See more…', getSelectedElementText());
down(); down();
assertEquals('One', getSelectedElementText()); assertEquals('One', getSelectedElementText());
up(); up();
assertEquals('Three', getSelectedElementText()); assertEquals('See more…', getSelectedElementText());
up(); up();
assertEquals('Two', getSelectedElementText()); assertEquals('Save to Google Drive', getSelectedElementText());
up(); up();
assertEquals('One', getSelectedElementText()); assertEquals('Save as PDF', getSelectedElementText());
up(); up();
assertEquals('Three', getSelectedElementText()); assertEquals('One', getSelectedElementText());
}); });
test( test(
...@@ -217,4 +218,16 @@ suite(destination_dropdown_cros_test.suiteName, function() { ...@@ -217,4 +218,16 @@ suite(destination_dropdown_cros_test.suiteName, function() {
move(getList()[0], {x: 0, y: 0}, {x: 0, y: 0}, 1); move(getList()[0], {x: 0, y: 0}, {x: 0, y: 0}, 1);
assertEquals('One', getSelectedElementText()); assertEquals('One', getSelectedElementText());
}); });
test(assert(destination_dropdown_cros_test.TestNames.Disabled), function() {
setItemList([createDestination('One')]);
dropdown.disabled = true;
pointerDown(dropdown.$$('#dropdownInput'));
assertFalse(dropdown.$$('iron-dropdown').opened);
dropdown.disabled = false;
pointerDown(dropdown.$$('#dropdownInput'));
assertTrue(dropdown.$$('iron-dropdown').opened);
});
}); });
...@@ -1172,6 +1172,10 @@ TEST_F( ...@@ -1172,6 +1172,10 @@ TEST_F(
destination_dropdown_cros_test.TestNames.SelectedFollowsMouse); destination_dropdown_cros_test.TestNames.SelectedFollowsMouse);
}); });
TEST_F('PrintPreviewDestinationDropdownCrosTest', 'Disabled', function() {
this.runMochaTest(destination_dropdown_cros_test.TestNames.Disabled);
});
GEN('#else'); GEN('#else');
// eslint-disable-next-line no-var // eslint-disable-next-line no-var
var PrintPreviewDestinationSelectTest = class extends PrintPreviewTest { var PrintPreviewDestinationSelectTest = class extends PrintPreviewTest {
......
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