Commit 755bd92c authored by alekseys@chromium.org's avatar alekseys@chromium.org

Add media size select element and ticket item. Do not expose in the UI yet.

BUG=239879

Review URL: https://codereview.chromium.org/253163002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267090 0039d316-1c4b-4281-b951-d872f2087c98
parent 3b3a5b90
...@@ -8420,6 +8420,9 @@ The following plug-in is unresponsive: <ph name="PLUGIN_NAME">$1 ...@@ -8420,6 +8420,9 @@ The following plug-in is unresponsive: <ph name="PLUGIN_NAME">$1
<message name="IDS_PRINT_PREVIEW_RIGHT_MARGIN_LABEL" desc="ARIA label used by screen reader to explain the purpose of the right margin textbox."> <message name="IDS_PRINT_PREVIEW_RIGHT_MARGIN_LABEL" desc="ARIA label used by screen reader to explain the purpose of the right margin textbox.">
Right margin Right margin
</message> </message>
<message name="IDS_PRINT_PREVIEW_MEDIA_SIZE_LABEL" desc="Media size option label. Provides user the option to change the size of the printed page.">
Paper size
</message>
<message name="IDS_PRINT_PREVIEW_NATIVE_DIALOG" desc="Option offering the user to open the native print dialog, displayed when the PDF viewer is missing or when print preview fails."> <message name="IDS_PRINT_PREVIEW_NATIVE_DIALOG" desc="Option offering the user to open the native print dialog, displayed when the PDF viewer is missing or when print preview fails.">
Print using system dialog… Print using system dialog…
</message> </message>
......
...@@ -40,6 +40,7 @@ cr.define('print_preview', function() { ...@@ -40,6 +40,7 @@ cr.define('print_preview', function() {
SELECTED_DESTINATION_CAPABILITIES: 'selectedDestinationCapabilities', SELECTED_DESTINATION_CAPABILITIES: 'selectedDestinationCapabilities',
SELECTED_DESTINATION_NAME: 'selectedDestinationName', SELECTED_DESTINATION_NAME: 'selectedDestinationName',
IS_GCP_PROMO_DISMISSED: 'isGcpPromoDismissed', IS_GCP_PROMO_DISMISSED: 'isGcpPromoDismissed',
MEDIA_SIZE: 'mediaSize',
MARGINS_TYPE: 'marginsType', MARGINS_TYPE: 'marginsType',
CUSTOM_MARGINS: 'customMargins', CUSTOM_MARGINS: 'customMargins',
IS_COLOR_ENABLED: 'isColorEnabled', IS_COLOR_ENABLED: 'isColorEnabled',
......
...@@ -117,6 +117,14 @@ cr.define('print_preview', function() { ...@@ -117,6 +117,14 @@ cr.define('print_preview', function() {
this.marginsType_ = new print_preview.ticket_items.MarginsType( this.marginsType_ = new print_preview.ticket_items.MarginsType(
this.appState_, this.documentInfo_, this.customMargins_); this.appState_, this.documentInfo_, this.customMargins_);
/**
* Media size ticket item.
* @type {!print_preview.ticket_items.MediaSize}
* @private
*/
this.mediaSize_ = new print_preview.ticket_items.MediaSize(
this.appState_, this.destinationStore_);
/** /**
* Landscape ticket item. * Landscape ticket item.
* @type {!print_preview.ticket_items.Landscape} * @type {!print_preview.ticket_items.Landscape}
...@@ -230,6 +238,10 @@ cr.define('print_preview', function() { ...@@ -230,6 +238,10 @@ cr.define('print_preview', function() {
return this.headerFooter_; return this.headerFooter_;
}, },
get mediaSize() {
return this.mediaSize_;
},
get landscape() { get landscape() {
return this.landscape_; return this.landscape_;
}, },
...@@ -280,6 +292,10 @@ cr.define('print_preview', function() { ...@@ -280,6 +292,10 @@ cr.define('print_preview', function() {
this.duplex_.updateValue(this.appState_.getField( this.duplex_.updateValue(this.appState_.getField(
print_preview.AppState.Field.IS_DUPLEX_ENABLED)); print_preview.AppState.Field.IS_DUPLEX_ENABLED));
} }
if (this.appState_.hasField(print_preview.AppState.Field.MEDIA_SIZE)) {
this.mediaSize_.updateValue(this.appState_.getField(
print_preview.AppState.Field.MEDIA_SIZE));
}
if (this.appState_.hasField( if (this.appState_.hasField(
print_preview.AppState.Field.IS_LANDSCAPE_ENABLED)) { print_preview.AppState.Field.IS_LANDSCAPE_ENABLED)) {
this.landscape_.updateValue(this.appState_.getField( this.landscape_.updateValue(this.appState_.getField(
...@@ -375,6 +391,15 @@ cr.define('print_preview', function() { ...@@ -375,6 +391,15 @@ cr.define('print_preview', function() {
cjt.print.duplex = cjt.print.duplex =
{type: this.duplex.getValue() ? 'LONG_EDGE' : 'NO_DUPLEX'}; {type: this.duplex.getValue() ? 'LONG_EDGE' : 'NO_DUPLEX'};
} }
if (this.mediaSize.isCapabilityAvailable()) {
var value = this.mediaSize.getValue();
cjt.print.media_size = {
width_microns: value.width_microns,
height_microns: value.height_microns,
is_continuous_feed: value.is_continuous_feed,
vendor_id: value.vendor_id
};
}
if (this.landscape.isCapabilityAvailable() && if (this.landscape.isCapabilityAvailable() &&
this.landscape.isUserEdited()) { this.landscape.isUserEdited()) {
cjt.print.page_orientation = cjt.print.page_orientation =
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('print_preview.ticket_items', function() {
'use strict';
/**
* Media size ticket item.
* @param {!print_preview.AppState} appState App state used to persist media
* size selection.
* @param {!print_preview.DestinationStore} destinationStore Destination store
* used to determine if a destination has the media size capability.
* @constructor
* @extends {print_preview.ticket_items.TicketItem}
*/
function MediaSize(appState, destinationStore) {
print_preview.ticket_items.TicketItem.call(
this,
appState,
print_preview.AppState.Field.MEDIA_SIZE,
destinationStore);
};
MediaSize.prototype = {
__proto__: print_preview.ticket_items.TicketItem.prototype,
/** @override */
wouldValueBeValid: function(value) {
if (!this.isCapabilityAvailable()) {
return false;
}
return this.capability.option.some(function(option) {
return option.width_microns == value.width_microns &&
option.height_microns == value.height_microns &&
option.is_continuous_feed == value.is_continuous_feed &&
option.vendor_id == value.vendor_id;
});
},
/** @override */
isCapabilityAvailable: function() {
// TODO(alekseys): Turn it on when the feature is ready (crbug/239879).
return false && !!this.capability;
},
/** @return {Object} Media size capability of the selected destination. */
get capability() {
var destination = this.getSelectedDestInternal();
return (destination &&
destination.capabilities &&
destination.capabilities.printer &&
destination.capabilities.printer.media_size) ||
null;
},
/** @override */
getDefaultValueInternal: function() {
var defaultOptions = this.capability.option.filter(function(option) {
return option.is_default;
});
return defaultOptions.length > 0 ? defaultOptions[0] : null;
},
/** @override */
getCapabilityNotAvailableValueInternal: function() {
return {};
}
};
// Export
return {
MediaSize: MediaSize
};
});
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<link rel="stylesheet" href="settings/copies_settings.css"> <link rel="stylesheet" href="settings/copies_settings.css">
<link rel="stylesheet" href="settings/page_settings.css"> <link rel="stylesheet" href="settings/page_settings.css">
<link rel="stylesheet" href="settings/margin_settings.css"> <link rel="stylesheet" href="settings/margin_settings.css">
<link rel="stylesheet" href="settings/media_size_settings.css">
<link rel="stylesheet" href="previewarea/preview_area.css"> <link rel="stylesheet" href="previewarea/preview_area.css">
<link rel="stylesheet" href="previewarea/margin_control_container.css"> <link rel="stylesheet" href="previewarea/margin_control_container.css">
<link rel="stylesheet" href="previewarea/margin_control.css"> <link rel="stylesheet" href="previewarea/margin_control.css">
...@@ -49,6 +50,7 @@ ...@@ -49,6 +50,7 @@
<include src="settings/destination_settings.html"/> <include src="settings/destination_settings.html"/>
<include src="settings/page_settings.html"/> <include src="settings/page_settings.html"/>
<include src="settings/copies_settings.html"/> <include src="settings/copies_settings.html"/>
<include src="settings/media_size_settings.html"/>
<include src="settings/layout_settings.html"/> <include src="settings/layout_settings.html"/>
<include src="settings/color_settings.html"/> <include src="settings/color_settings.html"/>
<include src="settings/margin_settings.html"/> <include src="settings/margin_settings.html"/>
......
...@@ -115,6 +115,15 @@ cr.define('print_preview', function() { ...@@ -115,6 +115,15 @@ cr.define('print_preview', function() {
this.printTicketStore_.copies, this.printTicketStore_.collate); this.printTicketStore_.copies, this.printTicketStore_.collate);
this.addChild(this.copiesSettings_); this.addChild(this.copiesSettings_);
/**
* Component that renders the media size settings.
* @type {!print_preview.MediaSizeSettings}
* @private
*/
this.mediaSizeSettings_ =
new print_preview.MediaSizeSettings(this.printTicketStore_.mediaSize);
this.addChild(this.mediaSizeSettings_);
/** /**
* Component that renders the layout settings. * Component that renders the layout settings.
* @type {!print_preview.LayoutSettings} * @type {!print_preview.LayoutSettings}
...@@ -382,6 +391,7 @@ cr.define('print_preview', function() { ...@@ -382,6 +391,7 @@ cr.define('print_preview', function() {
this.destinationSettings_.decorate($('destination-settings')); this.destinationSettings_.decorate($('destination-settings'));
this.pageSettings_.decorate($('page-settings')); this.pageSettings_.decorate($('page-settings'));
this.copiesSettings_.decorate($('copies-settings')); this.copiesSettings_.decorate($('copies-settings'));
this.mediaSizeSettings_.decorate($('media-size-settings'));
this.layoutSettings_.decorate($('layout-settings')); this.layoutSettings_.decorate($('layout-settings'));
this.colorSettings_.decorate($('color-settings')); this.colorSettings_.decorate($('color-settings'));
this.marginSettings_.decorate($('margin-settings')); this.marginSettings_.decorate($('margin-settings'));
...@@ -405,6 +415,7 @@ cr.define('print_preview', function() { ...@@ -405,6 +415,7 @@ cr.define('print_preview', function() {
this.destinationSettings_.isEnabled = isEnabled; this.destinationSettings_.isEnabled = isEnabled;
this.pageSettings_.isEnabled = isEnabled; this.pageSettings_.isEnabled = isEnabled;
this.copiesSettings_.isEnabled = isEnabled; this.copiesSettings_.isEnabled = isEnabled;
this.mediaSizeSettings_.isEnabled = isEnabled;
this.layoutSettings_.isEnabled = isEnabled; this.layoutSettings_.isEnabled = isEnabled;
this.colorSettings_.isEnabled = isEnabled; this.colorSettings_.isEnabled = isEnabled;
this.marginSettings_.isEnabled = isEnabled; this.marginSettings_.isEnabled = isEnabled;
...@@ -988,6 +999,7 @@ cr.define('print_preview', function() { ...@@ -988,6 +999,7 @@ cr.define('print_preview', function() {
<include src="data/ticket_items/copies.js"/> <include src="data/ticket_items/copies.js"/>
<include src="data/ticket_items/duplex.js"/> <include src="data/ticket_items/duplex.js"/>
<include src="data/ticket_items/header_footer.js"/> <include src="data/ticket_items/header_footer.js"/>
<include src="data/ticket_items/media_size.js"/>
<include src="data/ticket_items/landscape.js"/> <include src="data/ticket_items/landscape.js"/>
<include src="data/ticket_items/margins_type.js"/> <include src="data/ticket_items/margins_type.js"/>
<include src="data/ticket_items/page_range.js"/> <include src="data/ticket_items/page_range.js"/>
...@@ -1004,6 +1016,7 @@ cr.define('print_preview', function() { ...@@ -1004,6 +1016,7 @@ cr.define('print_preview', function() {
<include src="settings/page_settings.js"/> <include src="settings/page_settings.js"/>
<include src="settings/copies_settings.js"/> <include src="settings/copies_settings.js"/>
<include src="settings/media_size_settings.js"/>
<include src="settings/layout_settings.js"/> <include src="settings/layout_settings.js"/>
<include src="settings/color_settings.js"/> <include src="settings/color_settings.js"/>
<include src="settings/margin_settings.js"/> <include src="settings/margin_settings.js"/>
......
/* Copyright 2014 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. */
#media-size-settings .media-size-settings-select {
height: 28px;
margin: 10px 0;
}
<div id="media-size-settings" class="two-column visible media-size-settings" hidden>
<h1 i18n-content="mediaSizeLabel"></h1>
<div class="right-column">
<select class="media-size-settings-select"></select>
</div>
</div>
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('print_preview', function() {
'use strict';
/**
* Encapsulates all settings and logic related to the media size selection UI.
* @param {!print_preview.ticket_items.MediaSize} ticketItem Used to read and
* write the media size ticket item.
* @constructor
* @extends {print_preview.Component}
*/
function MediaSizeSettings(ticketItem) {
print_preview.Component.call(this);
/** @private {!print_preview.ticket_items.MediaSize} */
this.ticketItem_ = ticketItem;
};
MediaSizeSettings.prototype = {
__proto__: print_preview.Component.prototype,
/** @param {boolean} isEnabled Whether this component is enabled. */
set isEnabled(isEnabled) {
this.select_.disabled = !isEnabled;
},
/** @override */
enterDocument: function() {
print_preview.Component.prototype.enterDocument.call(this);
fadeOutOption(this.getElement(), true);
this.tracker.add(this.select_, 'change', this.onSelectChange_.bind(this));
this.tracker.add(
this.ticketItem_,
print_preview.ticket_items.TicketItem.EventType.CHANGE,
this.onTicketItemChange_.bind(this));
},
/**
* @return {HTMLSelectElement} Select element containing media size options.
* @private
*/
get select_() {
return this.getElement().getElementsByClassName(
'media-size-settings-select')[0];
},
/**
* Makes sure the content of the select element matches the capabilities of
* the destination.
* @private
*/
updateSelect_: function() {
var select = this.select_;
if (!this.ticketItem_.isCapabilityAvailable()) {
select.innerHtml = '';
return;
}
// Should the select content be updated?
var sameContent =
this.ticketItem_.capability.option.length == select.length &&
this.ticketItem_.capability.option.every(function(option, index) {
return select.options[index].value == JSON.stringify(option);
});
var indexToSelect = select.selectedIndex;
if (!sameContent) {
select.innerHtml = '';
// TODO: Better heuristics for the display name and options grouping.
this.ticketItem_.capability.option.forEach(function(option, index) {
var selectOption = document.createElement('option');
selectOption.text = option.custom_display_name || option.name;
selectOption.value = JSON.stringify(option);
select.add(selectOption);
if (option.is_default) {
indexToSelect = index;
}
});
} else {
var valueToSelect = JSON.stringify(this.ticketItem_.getValue());
for (var i = 0, option; option = select.options[i]; i++) {
if (option.value == valueToSelect) {
indexToSelect = i;
break;
}
}
}
select.selectedIndex = indexToSelect;
},
/**
* Called when the select element is changed. Updates the print ticket.
* @private
*/
onSelectChange_: function() {
var select = this.select_;
var mediaSize = JSON.parse(select.options[select.selectedIndex].value);
this.ticketItem_.updateValue(mediaSize);
},
/**
* Called when the print ticket store changes. Selects the corresponding
* select option.
* @private
*/
onTicketItemChange_: function() {
if (this.ticketItem_.isCapabilityAvailable()) {
this.updateSelect_();
fadeInOption(this.getElement());
} else {
fadeOutOption(this.getElement());
}
}
};
// Export
return {
MediaSizeSettings: MediaSizeSettings
};
});
...@@ -272,6 +272,8 @@ content::WebUIDataSource* CreatePrintPreviewUISource() { ...@@ -272,6 +272,8 @@ content::WebUIDataSource* CreatePrintPreviewUISource() {
source->AddLocalizedString("bottom", IDS_PRINT_PREVIEW_BOTTOM_MARGIN_LABEL); source->AddLocalizedString("bottom", IDS_PRINT_PREVIEW_BOTTOM_MARGIN_LABEL);
source->AddLocalizedString("left", IDS_PRINT_PREVIEW_LEFT_MARGIN_LABEL); source->AddLocalizedString("left", IDS_PRINT_PREVIEW_LEFT_MARGIN_LABEL);
source->AddLocalizedString("right", IDS_PRINT_PREVIEW_RIGHT_MARGIN_LABEL); source->AddLocalizedString("right", IDS_PRINT_PREVIEW_RIGHT_MARGIN_LABEL);
source->AddLocalizedString("mediaSizeLabel",
IDS_PRINT_PREVIEW_MEDIA_SIZE_LABEL);
source->AddLocalizedString("destinationSearchTitle", source->AddLocalizedString("destinationSearchTitle",
IDS_PRINT_PREVIEW_DESTINATION_SEARCH_TITLE); IDS_PRINT_PREVIEW_DESTINATION_SEARCH_TITLE);
source->AddLocalizedString("userInfo", IDS_PRINT_PREVIEW_USER_INFO); source->AddLocalizedString("userInfo", IDS_PRINT_PREVIEW_USER_INFO);
......
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