summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/resources/print_preview/ui/scaling_settings.js
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/chrome/browser/resources/print_preview/ui/scaling_settings.js')
-rw-r--r--chromium/chrome/browser/resources/print_preview/ui/scaling_settings.js126
1 files changed, 60 insertions, 66 deletions
diff --git a/chromium/chrome/browser/resources/print_preview/ui/scaling_settings.js b/chromium/chrome/browser/resources/print_preview/ui/scaling_settings.js
index 909562b33d3..500637a9ab2 100644
--- a/chromium/chrome/browser/resources/print_preview/ui/scaling_settings.js
+++ b/chromium/chrome/browser/resources/print_preview/ui/scaling_settings.js
@@ -4,20 +4,10 @@
cr.exportPath('print_preview');
-/** @enum {number} */
-const ScalingValue = {
- DEFAULT: 0,
- FIT_TO_PAGE: 1,
- CUSTOM: 2,
-};
-
/*
- * When fit to page is available, the checkbox and input interact as follows:
- * 1. When checkbox is checked, the fit to page scaling value is displayed in
- * the input. The error message is cleared if it was present.
- * 2. When checkbox is unchecked, the most recent valid scale value is restored.
- * 3. If the input is modified while the checkbox is checked, the checkbox will
- * be unchecked automatically, regardless of the validity of the new value.
+ * Fit to page and fit to paper options will only be displayed for PDF
+ * documents. If the custom option is selected, an additional input field will
+ * appear to enter the custom scale factor.
*/
Polymer({
is: 'print-preview-scaling-settings',
@@ -30,6 +20,8 @@ Polymer({
observer: 'onDisabledChanged_',
},
+ isPdf: Boolean,
+
/** @private {string} */
currentValue_: {
type: String,
@@ -39,8 +31,8 @@ Polymer({
/** @private {boolean} */
customSelected_: {
type: Boolean,
- computed: 'computeCustomSelected_(settings.customScaling.*, ' +
- 'settings.fitToPage.*)',
+ computed: 'computeCustomSelected_(settingKey_, ' +
+ 'settings.scalingType.*, settings.scalingTypePdf.*)',
},
/** @private {boolean} */
@@ -52,14 +44,23 @@ Polymer({
value: false,
},
+ /** @private {string} */
+ settingKey_: {
+ type: String,
+ computed: 'computeSettingKey_(isPdf)',
+ },
+
/** Mirroring the enum so that it can be used from HTML bindings. */
- ScalingValue: Object,
+ ScalingValue: {
+ type: Object,
+ value: print_preview.ScalingType,
+ },
},
observers: [
- 'onFitToPageSettingChange_(settings.fitToPage.value)',
+ 'onScalingTypeSettingChanged_(settingKey_, settings.scalingType.value, ' +
+ 'settings.scalingTypePdf.value)',
'onScalingSettingChanged_(settings.scaling.value)',
- 'onCustomScalingSettingChanged_(settings.customScaling.value)',
],
/** @private {string} */
@@ -81,28 +82,26 @@ Polymer({
*/
userSelectedCustomScaling_: false,
- /** @override */
- ready: function() {
- this.ScalingValue = ScalingValue;
- },
-
onProcessSelectChange: function(value) {
- if (value === ScalingValue.FIT_TO_PAGE.toString()) {
- this.setSetting('fitToPage', true);
- return;
- }
-
- const fitToPageAvailable = this.getSetting('fitToPage').available;
- if (fitToPageAvailable) {
- this.setSetting('fitToPage', false);
- }
- const isCustom = value === ScalingValue.CUSTOM.toString();
+ const isCustom = value === print_preview.ScalingType.CUSTOM.toString();
if (isCustom && !this.customScalingSettingSet_) {
this.userSelectedCustomScaling_ = true;
} else {
this.customScalingSettingSet_ = false;
}
- this.setSetting('customScaling', isCustom);
+
+ const valueAsNumber = parseInt(value, 10);
+ if (isCustom || value === print_preview.ScalingType.DEFAULT.toString()) {
+ this.setSetting('scalingType', valueAsNumber);
+ }
+ if (this.isPdf ||
+ this.getSetting('scalingTypePdf').value ===
+ print_preview.ScalingType.DEFAULT ||
+ this.getSetting('scalingTypePdf').value ===
+ print_preview.ScalingType.CUSTOM) {
+ this.setSetting('scalingTypePdf', valueAsNumber);
+ }
+
if (isCustom) {
this.setSetting('scaling', this.currentValue_);
}
@@ -117,48 +116,35 @@ Polymer({
}
},
- /** @private */
- onFitToPageSettingChange_: function() {
- if (!this.getSettingValue('fitToPage') ||
- !this.getSetting('fitToPage').available) {
- return;
- }
-
- this.updateScalingToValid_();
- this.selectedValue = ScalingValue.FIT_TO_PAGE.toString();
+ /**
+ * Updates the input string when scaling setting is set.
+ * @private
+ */
+ onScalingSettingChanged_: function() {
+ const value = /** @type {string} */ (this.getSetting('scaling').value);
+ this.lastValidScaling_ = value;
+ this.currentValue_ = value;
},
/** @private */
- onCustomScalingSettingChanged_: function() {
- if (this.getSettingValue('fitToPage') &&
- this.getSetting('fitToPage').available) {
+ onScalingTypeSettingChanged_: function() {
+ if (!this.settingKey_) {
return;
}
- const isCustom =
- /** @type {boolean} */ (this.getSetting('customScaling').value);
- if (!isCustom) {
+ const value = /** @type {!print_preview.ScalingType} */
+ (this.getSettingValue(this.settingKey_));
+ if (value !== print_preview.ScalingType.CUSTOM) {
this.updateScalingToValid_();
} else {
this.customScalingSettingSet_ = true;
}
- this.selectedValue = isCustom ? ScalingValue.CUSTOM.toString() :
- ScalingValue.DEFAULT.toString();
- },
-
- /**
- * Updates the input string when scaling setting is set.
- * @private
- */
- onScalingSettingChanged_: function() {
- const value = /** @type {string} */ (this.getSetting('scaling').value);
- this.lastValidScaling_ = value;
- this.currentValue_ = value;
+ this.selectedValue = value.toString();
},
/**
- * Updates scaling and fit to page settings based on the validity and current
- * value of the scaling input.
+ * Updates scaling settings based on the validity and current value of the
+ * scaling input.
* @private
*/
onInputChanged_: function() {
@@ -188,9 +174,17 @@ Polymer({
* @private
*/
computeCustomSelected_: function() {
- return /** @type {boolean} */ (this.getSettingValue('customScaling')) &&
- (!this.getSetting('fitToPage').available ||
- !(/** @type {boolean} */ (this.getSettingValue('fitToPage'))));
+ return !!this.settingKey_ &&
+ this.getSettingValue(this.settingKey_) ===
+ print_preview.ScalingType.CUSTOM;
+ },
+
+ /**
+ * @return {string} The key of the appropriate scaling setting.
+ * @private
+ */
+ computeSettingKey_: function() {
+ return this.isPdf ? 'scalingTypePdf' : 'scalingType';
},
/** @private */