Commit 10f2faae authored by Jesse Schettler's avatar Jesse Schettler Committed by Commit Bot

scanning: Fix property annotations

The value of a select element is always a string, so the Polymer
properties bound to select element values are also strings. Fix the
annotations for these properties to indicate the correct types.

Bug: 1059779
Change-Id: I4ee229694f7925ac152d7de838779d36b9e9b56c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2481051
Commit-Queue: Jesse Schettler <jschettler@chromium.org>
Reviewed-by: default avatarJimmy Gong <jimmyxgong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818156}
parent b9a5f02a
......@@ -251,11 +251,13 @@ suite('ScanningAppTest', () => {
tokenToString(firstScannerId), scanningApp.selectedScannerId);
assertEquals(
firstCapabilities.sources[0].name, scanningApp.selectedSource);
assertEquals(FileType.PDF, scanningApp.selectedFileType);
assertEquals(FileType.PDF.toString(), scanningApp.selectedFileType);
assertEquals(
firstCapabilities.colorModes[0], scanningApp.selectedColorMode);
firstCapabilities.colorModes[0].toString(),
scanningApp.selectedColorMode);
assertEquals(
firstCapabilities.resolutions[0], scanningApp.selectedResolution);
firstCapabilities.resolutions[0].toString(),
scanningApp.selectedResolution);
// Before the scan button is clicked, the settings and scan button
// should be enabled, and there should be no scan status.
......
......@@ -30,9 +30,9 @@ Polymer({
value: () => [],
},
/** @type {chromeos.scanning.mojom.ColorMode|undefined} */
/** @type {?string} */
selectedColorMode: {
type: chromeos.scanning.mojom.ColorMode,
type: String,
notify: true,
},
},
......
......@@ -23,9 +23,9 @@ Polymer({
behaviors: [I18nBehavior, SelectBehavior],
properties: {
/** @type {chromeos.scanning.mojom.FileType|undefined} */
/** @type {?string} */
selectedFileType: {
type: chromeos.scanning.mojom.FileType,
type: String,
notify: true,
},
},
......
......@@ -30,9 +30,9 @@ Polymer({
value: () => [],
},
/** @type {number|undefined} */
/** @type {?string} */
selectedResolution: {
type: Number,
type: String,
notify: true,
},
},
......
......@@ -12,11 +12,12 @@ import './resolution_select.js';
import './scanner_select.js';
import './source_select.js';
import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {I18nBehavior} from 'chrome://resources/js/i18n_behavior.m.js';
import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {getScanService} from './mojo_interface_provider.js';
import {ScannerArr} from './scanning_app_types.js';
import {tokenToString} from './scanning_app_util.js';
import {colorModeFromString, tokenToString} from './scanning_app_util.js';
/**
* @fileoverview
......@@ -57,14 +58,14 @@ Polymer({
/** @type {?string} */
selectedSource: String,
/** @type {chromeos.scanning.mojom.FileType|undefined} */
selectedFileType: chromeos.scanning.mojom.FileType,
/** @type {?string} */
selectedFileType: String,
/** @type {chromeos.scanning.mojom.ColorMode|undefined} */
selectedColorMode: chromeos.scanning.mojom.ColorMode,
/** @type {?string} */
selectedColorMode: String,
/** @type {number|undefined} */
selectedResolution: Number,
/** @type {?string} */
selectedResolution: String,
/**
* @type {?string}
......@@ -117,11 +118,11 @@ Polymer({
// Set the first options as the selected options since they will be the
// first options in the dropdowns.
this.selectedSource = this.capabilities_.sources[0].name;
this.selectedColorMode = this.capabilities_.colorModes[0];
this.selectedResolution = this.capabilities_.resolutions[0];
this.selectedColorMode = this.capabilities_.colorModes[0].toString();
this.selectedResolution = this.capabilities_.resolutions[0].toString();
// PDF is the default file type.
this.selectedFileType = chromeos.scanning.mojom.FileType.kPdf;
this.selectedFileType = chromeos.scanning.mojom.FileType.kPdf.toString();
this.scanButtonDisabled_ = false;
},
......@@ -171,9 +172,8 @@ Polymer({
/** @private */
onScanClick_() {
if (!this.selectedScannerId || !this.selectedSource ||
this.selectedFileType === undefined ||
this.selectedColorMode === undefined ||
this.selectedResolution === undefined) {
!this.selectedFileType || !this.selectedColorMode ||
!this.selectedResolution) {
// TODO(jschettler): Replace status text with finalized i18n strings.
this.statusText_ = 'Failed to start scan.';
return;
......@@ -188,8 +188,8 @@ Polymer({
const settings = {
'sourceName': this.selectedSource,
'fileType': chromeos.scanning.mojom.FileType.kPng,
'colorMode': this.selectedColorMode,
'resolutionDpi': this.selectedResolution,
'colorMode': colorModeFromString(this.selectedColorMode),
'resolutionDpi': Number(this.selectedResolution),
};
this.scanService_
.scan(this.scannerIds_.get(this.selectedScannerId), settings)
......
......@@ -4,6 +4,26 @@
import {assertNotReached} from 'chrome://resources/js/assert.m.js';
/**
* Converts a chromeos.scanning.mojom.ColorMode string to the corresponding enum
* value.
* @param {!string} colorModeString
* @return {chromeos.scanning.mojom.ColorMode}
*/
export function colorModeFromString(colorModeString) {
switch (colorModeString) {
case chromeos.scanning.mojom.ColorMode.kBlackAndWhite.toString():
return chromeos.scanning.mojom.ColorMode.kBlackAndWhite;
case chromeos.scanning.mojom.ColorMode.kGrayscale.toString():
return chromeos.scanning.mojom.ColorMode.kGrayscale;
case chromeos.scanning.mojom.ColorMode.kColor.toString():
return chromeos.scanning.mojom.ColorMode.kColor;
default:
assertNotReached();
return chromeos.scanning.mojom.ColorMode.kColor;
}
}
/**
* Converts a chromeos.scanning.mojom.ColorMode to a string that can be
* displayed in the color mode dropdown.
......
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