Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Unified Diff: chrome/browser/resources/print_preview/search/destination_search.js

Issue 1144983002: Introduce concept of provisional destinations to print preview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/print_preview/search/destination_search.js
diff --git a/chrome/browser/resources/print_preview/search/destination_search.js b/chrome/browser/resources/print_preview/search/destination_search.js
index 601022408dffeaa331b6b3118fda27e490c768a7..da1a9238b346cead15a285cbbd5e616f0e03561f 100644
--- a/chrome/browser/resources/print_preview/search/destination_search.js
+++ b/chrome/browser/resources/print_preview/search/destination_search.js
@@ -66,6 +66,14 @@ cr.define('print_preview', function() {
this.registerPromoShownMetricRecorded_ = false;
/**
+ * Child overlay used for resolving a provisional destination. The overlay
+ * is shown when the user attempts to select a provisional destination.
+ * Set only when a destination is being resolved.
+ * @private {?print_preview.ProvisionalDestinationResolver}
+ */
+ this.provisionalDestinationResolver_ = null;
+
+ /**
* Search box used to search through the destination lists.
* @type {!print_preview.SearchBox}
* @private
@@ -153,6 +161,8 @@ cr.define('print_preview', function() {
// Collapse all destination lists
this.localList_.setIsShowAll(false);
this.cloudList_.setIsShowAll(false);
+ if (this.provisionalDestinationResolver_)
+ this.provisionalDestinationResolver_.cancel();
this.resetSearch_();
}
},
@@ -232,6 +242,11 @@ cr.define('print_preview', function() {
this.destinationStore_,
print_preview.DestinationStore.EventType.DESTINATION_SEARCH_DONE,
this.onDestinationSearchDone_.bind(this));
+ this.tracker.add(
+ this.destinationStore_,
+ print_preview.DestinationStore.EventType
+ .PROVISIONAL_DESTINATION_RESOLVED,
+ this.onDestinationsInserted_.bind(this));
this.tracker.add(
this.invitationStore_,
@@ -544,14 +559,69 @@ cr.define('print_preview', function() {
},
/**
- * Called when a destination is selected. Clears the search and hides the
- * widget.
+ * Handler for {@code print_preview.DestinationListItem.EventType.SELECT}
+ * event, which is called when a destinationi list item is selected.
* @param {Event} evt Contains the selected destination.
* @private
*/
onDestinationSelect_: function(evt) {
+ this.handleOnDestinationSelect_(evt.destination);
+ },
+
+ /**
+ * Called when a destination is selected. Clears the search and hides the
+ * widget. If The destination is provisional, it runs provisional
+ * destination resolver first.
+ * @param {!print_preview.Destination} destination The selected destination.
+ * @private
+ */
+ handleOnDestinationSelect_: function(destination) {
+ if (destination.isProvisional) {
+ assert(!this.provisionalDestinationResolver_,
+ 'Provisional destination resolver already exists.');
+ this.provisionalDestinationResolver_ =
+ print_preview.ProvisionalDestinationResolver.create(
+ this.destinationStore_, destination);
+ assert(!!this.provisionalDestinationResolver_,
+ 'Unable to create provisional destination resolver');
+
+ var lastFocusedElement = document.activeElement;
+ this.addChild(this.provisionalDestinationResolver_);
+ this.provisionalDestinationResolver_.run(this.getElement())
+ .then(
+ /**
+ * @param {!print_preview.Destination} resolvedDestination
+ * Destination to which the provisional destination was
+ * resolved.
+ */
+ function(resolvedDestination) {
+ this.handleOnDestinationSelect_(resolvedDestination);
+ }.bind(this))
+ .catch(
+ function() {
+ console.log('Failed to resolve provisional destination: ' +
+ destination.id);
+ })
+ .then(
+ function() {
+ this.removeChild(this.provisionalDestinationResolver_);
+ this.provisionalDestinationResolver_ = null;
+
+ // Restore focus to the previosly focused element if it's
+ // still shown in the search.
+ if (lastFocusedElement &&
+ this.getIsVisible() &&
+ getIsVisible(lastFocusedElement) &&
+ this.getElement().contains(lastFocusedElement)) {
+ lastFocusedElement.focus();
+ }
+ lastFocusedElement = null;
Aleksey Shlyapnikov 2015/06/08 23:00:54 Why do you need to reset this local var?
tbarzic 2015/06/09 18:21:59 removed
+ }.bind(this));
+ return;
+ }
+
this.setIsVisible(false);
- this.destinationStore_.selectDestination(evt.destination);
+ this.destinationStore_.selectDestination(destination);
this.metrics_.record(print_preview.Metrics.DestinationSearchBucket.
DESTINATION_CLOSED_CHANGED);
},

Powered by Google App Engine
This is Rietveld 408576698