Commit b439d993 authored by Jesse Schettler's avatar Jesse Schettler Committed by Commit Bot

scanning: Display scanned images

Display scanned images when a scan is complete.

Bug: 1059779
Change-Id: I1341ece7bc7043ad34ba527dcbdec111563e23a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2545293
Commit-Queue: Jesse Schettler <jschettler@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828912}
parent bcd86748
...@@ -326,6 +326,8 @@ export function scanningAppTest() { ...@@ -326,6 +326,8 @@ export function scanningAppTest() {
let progressText; let progressText;
/** @type {!HTMLElement} */ /** @type {!HTMLElement} */
let progressBar; let progressBar;
/** @type {!HTMLElement} */
let scannedImages;
return initializeScanningApp(expectedScanners, capabilities) return initializeScanningApp(expectedScanners, capabilities)
.then(() => { .then(() => {
...@@ -345,6 +347,7 @@ export function scanningAppTest() { ...@@ -345,6 +347,7 @@ export function scanningAppTest() {
scanProgress = scanningApp.$$('#scanPreview').$$('#scanProgress'); scanProgress = scanningApp.$$('#scanPreview').$$('#scanProgress');
progressText = scanningApp.$$('#scanPreview').$$('#progressText'); progressText = scanningApp.$$('#scanPreview').$$('#progressText');
progressBar = scanningApp.$$('#scanPreview').$$('paper-progress'); progressBar = scanningApp.$$('#scanPreview').$$('paper-progress');
scannedImages = scanningApp.$$('#scanPreview').$$('#scannedImages');
return fakeScanService_.whenCalled('getScannerCapabilities'); return fakeScanService_.whenCalled('getScannerCapabilities');
}) })
.then(() => { .then(() => {
...@@ -441,6 +444,8 @@ export function scanningAppTest() { ...@@ -441,6 +444,8 @@ export function scanningAppTest() {
return fakeScanService_.simulateScanComplete(true); return fakeScanService_.simulateScanComplete(true);
}) })
.then(() => { .then(() => {
assertTrue(isVisible(scannedImages));
assertEquals(2, scannedImages.querySelectorAll('img').length);
assertTrue(isVisible( assertTrue(isVisible(
/** @type {!HTMLElement} */ ( /** @type {!HTMLElement} */ (
scanningApp.$$('scan-done-section')))); scanningApp.$$('scan-done-section'))));
...@@ -470,6 +475,8 @@ export function scanningAppTest() { ...@@ -470,6 +475,8 @@ export function scanningAppTest() {
assertFalse(isVisible( assertFalse(isVisible(
/** @type {!HTMLElement} */ ( /** @type {!HTMLElement} */ (
scanningApp.$$('scan-done-section')))); scanningApp.$$('scan-done-section'))));
assertFalse(isVisible(scannedImages));
assertEquals(0, scannedImages.querySelectorAll('img').length);
}); });
}); });
......
...@@ -38,6 +38,6 @@ Polymer({ ...@@ -38,6 +38,6 @@ Polymer({
/** @private */ /** @private */
onDoneClick_() { onDoneClick_() {
this.fire('change-app-state', AppState.READY); this.fire('done-click');
}, },
}); });
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#helperText { #helperText {
@apply --scanning-helper-text-font; @apply --scanning-helper-text-font;
color: var(--scanning-helper-text-color); color: var(--scanning-helper-text-color);
margin: auto;
text-align: center; text-align: center;
width: 60%; width: 60%;
} }
...@@ -17,19 +18,30 @@ ...@@ -17,19 +18,30 @@
} }
#scanProgress { #scanProgress {
margin: auto;
text-align: center; text-align: center;
width: 60%; width: 60%;
} }
.preview { .preview {
align-items: center;
border: 1px solid var(--google-grey-200); border: 1px solid var(--google-grey-200);
border-radius: 4px; border-radius: 4px;
display: flex; display: flex;
/* TODO(michaelcheco): Replace with correct height for /* TODO(michaelcheco): Replace with correct height for
* preview container. */ * preview container. */
height: 420px; height: 420px;
justify-content: center; overflow-y: scroll;
}
/* TODO(jschettler): Check with UX about adding a border around each image. */
.scanned-image {
border-radius: 4px;
width: 100%;
}
/* Add top margin to all but the first scanned image. */
.scanned-image:nth-of-type(n+2) {
margin-top: 8px;
} }
paper-progress { paper-progress {
...@@ -49,4 +61,9 @@ ...@@ -49,4 +61,9 @@
<span id="progressText">[[getProgressTextString_(pageNumber)]]</span> <span id="progressText">[[getProgressTextString_(pageNumber)]]</span>
<paper-progress value="[[progressPercent]]"></paper-progress> <paper-progress value="[[progressPercent]]"></paper-progress>
</div> </div>
<div id="scannedImages" hidden$="[[!shouldShowScannedImages_(appState)]]">
<template is="dom-repeat" items="[[objectUrls]]" as="url">
<img class="scanned-image" src="[[url]]">
</template>
</div>
</div> </div>
...@@ -27,6 +27,12 @@ Polymer({ ...@@ -27,6 +27,12 @@ Polymer({
/** @type {!AppState} */ /** @type {!AppState} */
appState: Number, appState: Number,
/**
* The object URLs of the scanned images.
* @type {!Array<string>}
*/
objectUrls: Array,
/** @type {number} */ /** @type {number} */
pageNumber: Number, pageNumber: Number,
...@@ -69,4 +75,12 @@ Polymer({ ...@@ -69,4 +75,12 @@ Polymer({
shouldHideProgress_() { shouldHideProgress_() {
return this.appState !== AppState.SCANNING; return this.appState !== AppState.SCANNING;
}, },
/**
* @return {boolean}
* @private
*/
shouldShowScannedImages_() {
return this.appState === AppState.DONE && this.objectUrls.length > 0;
},
}); });
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
<div class="panel-container"> <div class="panel-container">
<div class="left-panel"> <div class="left-panel">
<scan-preview id="scanPreview" app-state="[[appState_]]" <scan-preview id="scanPreview" app-state="[[appState_]]"
page-number="[[pageNumber_]]" object-urls="[[objectUrls_]]" page-number="[[pageNumber_]]"
progress-percent="[[progressPercent_]]"></scan-preview> progress-percent="[[progressPercent_]]"></scan-preview>
</div> </div>
<div class="right-panel"> <div class="right-panel">
...@@ -140,7 +140,7 @@ ...@@ -140,7 +140,7 @@
</template> </template>
<template is="dom-if" if="[[showDoneSection_]]"> <template is="dom-if" if="[[showDoneSection_]]">
<scan-done-section page-number="[[pageNumber_]]" <scan-done-section page-number="[[pageNumber_]]"
on-change-app-state="onChangeAppState_"></scan-done-section> on-done-click="onDoneClick_"></scan-done-section>
</template> </template>
</div> </div>
</div> </div>
......
...@@ -104,7 +104,10 @@ Polymer({ ...@@ -104,7 +104,10 @@ Polymer({
observer: 'onAppStateChange_', observer: 'onAppStateChange_',
}, },
/** @private {!Array<string>} */ /**
* The object URLs of the scanned images.
* @private {!Array<string>}
*/
objectUrls_: { objectUrls_: {
type: Array, type: Array,
value: () => [], value: () => [],
...@@ -207,6 +210,7 @@ Polymer({ ...@@ -207,6 +210,7 @@ Polymer({
* @param {number} progressPercent * @param {number} progressPercent
*/ */
onPageProgress(pageNumber, progressPercent) { onPageProgress(pageNumber, progressPercent) {
assert(this.appState_ === AppState.SCANNING);
this.pageNumber_ = pageNumber; this.pageNumber_ = pageNumber;
this.progressPercent_ = progressPercent; this.progressPercent_ = progressPercent;
}, },
...@@ -216,8 +220,7 @@ Polymer({ ...@@ -216,8 +220,7 @@ Polymer({
* @param {!Array<number>} pageData * @param {!Array<number>} pageData
*/ */
onPageComplete(pageData) { onPageComplete(pageData) {
// TODO(jschettler): Display the scanned images in the preview area when the assert(this.appState_ === AppState.SCANNING);
// scan is complete.
const blob = new Blob([Uint8Array.from(pageData)], {'type': 'image/png'}); const blob = new Blob([Uint8Array.from(pageData)], {'type': 'image/png'});
this.push('objectUrls_', URL.createObjectURL(blob)); this.push('objectUrls_', URL.createObjectURL(blob));
}, },
...@@ -315,7 +318,6 @@ Polymer({ ...@@ -315,7 +318,6 @@ Polymer({
} }
this.statusText_ = ''; this.statusText_ = '';
this.objectUrls_ = [];
const settings = { const settings = {
'sourceName': this.selectedSource, 'sourceName': this.selectedSource,
...@@ -403,6 +405,17 @@ Polymer({ ...@@ -403,6 +405,17 @@ Polymer({
*/ */
onCancelComplete(success) {}, onCancelComplete(success) {},
/**
* Revokes and removes all of the object URLs.
* @private
*/
clearObjectUrls_() {
for (const url of this.objectUrls_) {
URL.revokeObjectURL(url);
}
this.objectUrls_ = [];
},
/** /**
* Sets the app state if the state transition is allowed. * Sets the app state if the state transition is allowed.
* @param {!AppState} newState * @param {!AppState} newState
...@@ -426,6 +439,7 @@ Polymer({ ...@@ -426,6 +439,7 @@ Polymer({
this.appState_ === AppState.GETTING_CAPS || this.appState_ === AppState.GETTING_CAPS ||
this.appState_ === AppState.SCANNING || this.appState_ === AppState.SCANNING ||
this.appState_ === AppState.DONE); this.appState_ === AppState.DONE);
this.clearObjectUrls_();
break; break;
case (AppState.SCANNING): case (AppState.SCANNING):
assert(this.appState_ === AppState.READY); assert(this.appState_ === AppState.READY);
...@@ -445,12 +459,4 @@ Polymer({ ...@@ -445,12 +459,4 @@ Polymer({
this.showCancelButton_ = this.appState_ === AppState.SCANNING; this.showCancelButton_ = this.appState_ === AppState.SCANNING;
this.showDoneSection_ = this.appState_ === AppState.DONE; this.showDoneSection_ = this.appState_ === AppState.DONE;
}, },
/**
* @param {!Event} event
* @private
*/
onChangeAppState_(event) {
this.setAppState_(event.detail);
}
}); });
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