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

Print Preview: Apply advanced settings on enter key

Apply the advanced settings when the enter key is pressed, unless:
- Focus is on the search box, where enter normally means "search"
- Focus is on a select, where enter selects an item in the dropdown
- Focus is on a cr-button (e.g. cancel or apply), where enter activates
the button.

This matches the behavior to the behavior on the main Print Preview UI,
where enter is equivalent to clicking Print unless a control that
normally handles the key event is focused.

Bug: 974161
Change-Id: I4818996fb960bfc0c6ee3e92d2c132fc7f8dd466
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1661302
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarEsmael El-Moslimany <aee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#669831}
parent fe125c15
......@@ -52,10 +52,21 @@ Polymer({
onKeydown_: function(e) {
e.stopPropagation();
const searchInput = this.$.searchBox.getSearchInput();
if (e.key == 'Escape' &&
(e.composedPath()[0] !== searchInput || !searchInput.value.trim())) {
const eventInSearchBox = e.composedPath().includes(searchInput);
if (e.key == 'Escape' && (!eventInSearchBox || !searchInput.value.trim())) {
this.$.dialog.cancel();
e.preventDefault();
return;
}
if (e.key == 'Enter' && !eventInSearchBox) {
const activeElementTag = e.composedPath()[0].tagName;
if (['CR-BUTTON', 'SELECT'].includes(activeElementTag)) {
return;
}
this.onApplyButtonClick_();
e.preventDefault();
return;
}
},
......
......@@ -8,6 +8,7 @@ cr.define('advanced_dialog_test', function() {
AdvancedSettings1Option: 'advanced settings 1 option',
AdvancedSettings2Options: 'advanced settings 2 options',
AdvancedSettingsApply: 'advanced settings apply',
AdvancedSettingsApplyWithEnter: 'advanced settings apply with enter',
AdvancedSettingsClose: 'advanced settings close',
AdvancedSettingsFilter: 'advanced settings filter',
};
......@@ -129,6 +130,34 @@ cr.define('advanced_dialog_test', function() {
});
});
// Tests that the advanced settings dialog updates the settings value for
// vendor items if Enter is pressed on a cr-input.
test(assert(TestNames.AdvancedSettingsApplyWithEnter), function() {
setupDialog(3);
setItemValues();
const items = dialog.shadowRoot.querySelectorAll(
'print-preview-advanced-settings-item');
const typedItemInput = items[2].$$('cr-input'); // Watermark
// Simulate typing a value and then pressing enter.
typedItemInput.value = 'Hello World';
typedItemInput.dispatchEvent(
new CustomEvent('input', {composed: true, bubbles: true}));
const whenDialogClose = test_util.eventToPromise('close', dialog);
MockInteractions.keyEventOn(
typedItemInput, 'keydown', 'Enter', [], 'Enter');
return whenDialogClose.then(() => {
// Check that the setting has been set.
const setting = dialog.getSettingValue('vendorItems');
assertEquals(6, setting.printArea);
assertEquals(1, setting.paperType);
assertEquals('Hello World', setting.watermark);
});
});
// Tests that the advanced settings dialog does not update the settings
// value for vendor items when the close button is clicked.
test(assert(TestNames.AdvancedSettingsClose), function() {
......
......@@ -786,6 +786,13 @@ TEST_F('PrintPreviewAdvancedDialogTest', 'AdvancedSettingsApply', function() {
this.runMochaTest(advanced_dialog_test.TestNames.AdvancedSettingsApply);
});
TEST_F(
'PrintPreviewAdvancedDialogTest', 'AdvancedSettingsApplyWithEnter',
function() {
this.runMochaTest(
advanced_dialog_test.TestNames.AdvancedSettingsApplyWithEnter);
});
TEST_F('PrintPreviewAdvancedDialogTest', 'AdvancedSettingsClose', function() {
this.runMochaTest(advanced_dialog_test.TestNames.AdvancedSettingsClose);
});
......
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