Commit 01a16bc2 authored by alekseys's avatar alekseys Committed by Commit bot

Convert Print Preview layout and color radio buttons to select elements.

BUG=397741

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

Cr-Commit-Position: refs/heads/master@{#293811}
parent 5e3eccc1
...@@ -13,10 +13,12 @@ ...@@ -13,10 +13,12 @@
<link rel="stylesheet" href="common/search_box.css"> <link rel="stylesheet" href="common/search_box.css">
<link rel="stylesheet" href="common/search_bubble.css"> <link rel="stylesheet" href="common/search_bubble.css">
<link rel="stylesheet" href="settings/destination_settings.css"> <link rel="stylesheet" href="settings/destination_settings.css">
<link rel="stylesheet" href="settings/color_settings.css">
<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="settings/media_size_settings.css">
<link rel="stylesheet" href="settings/layout_settings.css">
<link rel="stylesheet" href="settings/advanced_options_settings.css"> <link rel="stylesheet" href="settings/advanced_options_settings.css">
<link rel="stylesheet" href="settings/advanced_settings/advanced_settings.css"> <link rel="stylesheet" href="settings/advanced_settings/advanced_settings.css">
<link rel="stylesheet" href="settings/advanced_settings/advanced_settings_item.css"> <link rel="stylesheet" href="settings/advanced_settings/advanced_settings_item.css">
......
...@@ -1028,13 +1028,13 @@ cr.define('print_preview', function() { ...@@ -1028,13 +1028,13 @@ cr.define('print_preview', function() {
* @private * @private
*/ */
setLayoutSettingsForTest_: function(portrait) { setLayoutSettingsForTest_: function(portrait) {
var element = document.querySelector(portrait ? var combobox = document.querySelector('.layout-settings-select');
'.layout-settings-portrait-radio' : if (combobox.value == 'portrait') {
'.layout-settings-landscape-radio');
if (element.checked)
this.nativeLayer_.previewReadyForTest(); this.nativeLayer_.previewReadyForTest();
else } else {
element.click(); combobox.value = 'landscape';
this.layoutSettings_.onSelectChange_();
}
}, },
/** /**
......
/* 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. */
#color-settings .color-settings-select {
height: 28px;
margin: 10px 0;
}
...@@ -4,13 +4,9 @@ ...@@ -4,13 +4,9 @@
hidden> hidden>
<h1 i18n-content="optionColor"></h1> <h1 i18n-content="optionColor"></h1>
<div class="right-column"> <div class="right-column">
<div class="radio"><label> <select class="color-settings-select">
<input class="color-option" type="radio" name="color"> <option i18n-content="optionBw" value="bw" selected></option>
<span i18n-content="optionColor"></span> <option i18n-content="optionColor" value="color"></option>
</label></div> </select>
<div class="radio"><label>
<input class="bw-option" type="radio" name="color" checked>
<span i18n-content="optionBw"></span>
</label></div>
</div> </div>
</div> </div>
...@@ -39,36 +39,53 @@ cr.define('print_preview', function() { ...@@ -39,36 +39,53 @@ cr.define('print_preview', function() {
/** @override */ /** @override */
set isEnabled(isEnabled) { set isEnabled(isEnabled) {
this.getChildElement('.color-option').disabled = !isEnabled; this.select_.disabled = !isEnabled;
this.getChildElement('.bw-option').disabled = !isEnabled;
}, },
/** @override */ /** @override */
enterDocument: function() { enterDocument: function() {
print_preview.SettingsSection.prototype.enterDocument.call(this); print_preview.SettingsSection.prototype.enterDocument.call(this);
this.tracker.add( this.tracker.add(
this.getChildElement('.color-option'), this.select_, 'change', this.onSelectChange_.bind(this));
'click',
this.colorTicketItem_.updateValue.bind(this.colorTicketItem_, true));
this.tracker.add(
this.getChildElement('.bw-option'),
'click',
this.colorTicketItem_.updateValue.bind(this.colorTicketItem_, false));
this.tracker.add( this.tracker.add(
this.colorTicketItem_, this.colorTicketItem_,
print_preview.ticket_items.TicketItem.EventType.CHANGE, print_preview.ticket_items.TicketItem.EventType.CHANGE,
this.updateState_.bind(this)); this.updateState_.bind(this));
}, },
/**
* Called when the select element is changed. Updates the print ticket
* color selection.
* @private
*/
onSelectChange_: function() {
var select = this.select_;
var isColor = select.options[select.selectedIndex].value == 'color';
this.colorTicketItem_.updateValue(isColor);
},
/**
* @return {HTMLSelectElement} Select element containing the color options.
* @private
*/
get select_() {
return this.getChildElement('.color-settings-select');
},
/** /**
* Updates state of the widget. * Updates state of the widget.
* @private * @private
*/ */
updateState_: function() { updateState_: function() {
if (this.isAvailable()) { if (this.isAvailable()) {
var isColorEnabled = this.colorTicketItem_.getValue(); var select = this.select_;
this.getChildElement('.color-option').checked = isColorEnabled; var valueToSelect = this.colorTicketItem_.getValue() ? 'color' : 'bw';
this.getChildElement('.bw-option').checked = !isColorEnabled; for (var i = 0; i < select.options.length; i++) {
if (select.options[i].value == valueToSelect) {
select.selectedIndex = i;
break;
}
}
} }
this.updateUiStateInternal(); this.updateUiStateInternal();
} }
......
/* 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. */
#layout-settings .layout-settings-select {
height: 28px;
margin: 10px 0;
}
<div id="layout-settings" class="two-column layout-settings" hidden> <div id="layout-settings" class="two-column layout-settings" hidden>
<h1 i18n-content="layoutLabel"></h1> <h1 i18n-content="layoutLabel"></h1>
<div class="right-column"> <div class="right-column">
<div class="radio"><label> <select class="layout-settings-select">
<input class="layout-settings-portrait-radio" <option i18n-content="optionPortrait" value="portrait" selected></option>
type="radio" <option i18n-content="optionLandscape" value="landscape"></option>
name="layout" </select>
checked>
<span i18n-content="optionPortrait"></span>
</label></div>
<div class="radio"><label>
<input class="layout-settings-landscape-radio"
type="radio"
name="layout">
<span i18n-content="optionLandscape"></span>
</label></div>
</div> </div>
</div> </div>
...@@ -24,16 +24,6 @@ cr.define('print_preview', function() { ...@@ -24,16 +24,6 @@ cr.define('print_preview', function() {
this.landscapeTicketItem_ = landscapeTicketItem; this.landscapeTicketItem_ = landscapeTicketItem;
}; };
/**
* CSS classes used by the layout settings.
* @enum {string}
* @private
*/
LayoutSettings.Classes_ = {
LANDSCAPE_RADIO: 'layout-settings-landscape-radio',
PORTRAIT_RADIO: 'layout-settings-portrait-radio'
};
LayoutSettings.prototype = { LayoutSettings.prototype = {
__proto__: print_preview.SettingsSection.prototype, __proto__: print_preview.SettingsSection.prototype,
...@@ -49,21 +39,14 @@ cr.define('print_preview', function() { ...@@ -49,21 +39,14 @@ cr.define('print_preview', function() {
/** @override */ /** @override */
set isEnabled(isEnabled) { set isEnabled(isEnabled) {
this.landscapeRadioButton_.disabled = !isEnabled; this.select_.disabled = !isEnabled;
this.portraitRadioButton_.disabled = !isEnabled;
}, },
/** @override */ /** @override */
enterDocument: function() { enterDocument: function() {
print_preview.SettingsSection.prototype.enterDocument.call(this); print_preview.SettingsSection.prototype.enterDocument.call(this);
this.tracker.add( this.tracker.add(
this.portraitRadioButton_, this.select_, 'change', this.onSelectChange_.bind(this));
'click',
this.onLayoutButtonClick_.bind(this));
this.tracker.add(
this.landscapeRadioButton_,
'click',
this.onLayoutButtonClick_.bind(this));
this.tracker.add( this.tracker.add(
this.landscapeTicketItem_, this.landscapeTicketItem_,
print_preview.ticket_items.TicketItem.EventType.CHANGE, print_preview.ticket_items.TicketItem.EventType.CHANGE,
...@@ -71,30 +54,23 @@ cr.define('print_preview', function() { ...@@ -71,30 +54,23 @@ cr.define('print_preview', function() {
}, },
/** /**
* @return {HTMLInputElement} The portrait orientation radio button. * Called when the select element is changed. Updates the print ticket
* @private * layout selection.
*/
get portraitRadioButton_() {
return this.getElement().getElementsByClassName(
LayoutSettings.Classes_.PORTRAIT_RADIO)[0];
},
/**
* @return {HTMLInputElement} The landscape orientation radio button.
* @private * @private
*/ */
get landscapeRadioButton_() { onSelectChange_: function() {
return this.getElement().getElementsByClassName( var select = this.select_;
LayoutSettings.Classes_.LANDSCAPE_RADIO)[0]; var isLandscape =
select.options[select.selectedIndex].value == 'landscape';
this.landscapeTicketItem_.updateValue(isLandscape);
}, },
/** /**
* Called when one of the radio buttons is clicked. Updates the print ticket * @return {HTMLSelectElement} Select element containing the layout options.
* store.
* @private * @private
*/ */
onLayoutButtonClick_: function() { get select_() {
this.landscapeTicketItem_.updateValue(this.landscapeRadioButton_.checked); return this.getChildElement('.layout-settings-select');
}, },
/** /**
...@@ -104,9 +80,15 @@ cr.define('print_preview', function() { ...@@ -104,9 +80,15 @@ cr.define('print_preview', function() {
*/ */
onLandscapeTicketItemChange_: function() { onLandscapeTicketItemChange_: function() {
if (this.isAvailable()) { if (this.isAvailable()) {
var isLandscapeEnabled = this.landscapeTicketItem_.getValue(); var select = this.select_;
this.portraitRadioButton_.checked = !isLandscapeEnabled; var valueToSelect =
this.landscapeRadioButton_.checked = isLandscapeEnabled; this.landscapeTicketItem_.getValue() ? 'landscape' : 'portrait';
for (var i = 0; i < select.options.length; i++) {
if (select.options[i].value == valueToSelect) {
select.selectedIndex = i;
break;
}
}
} }
this.updateUiStateInternal(); this.updateUiStateInternal();
} }
......
...@@ -775,8 +775,9 @@ TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor', ...@@ -775,8 +775,9 @@ TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor',
this.nativeLayer_.dispatchEvent(capsSetEvent); this.nativeLayer_.dispatchEvent(capsSetEvent);
checkSectionVisible($('color-settings'), true); checkSectionVisible($('color-settings'), true);
expectTrue($('color-settings').querySelector('.color-option').checked); expectEquals(
expectFalse($('color-settings').querySelector('.bw-option').checked); 'color',
$('color-settings').querySelector('.color-settings-select').value);
}); });
// Test that the color settings, two options, both standard, defaults to // Test that the color settings, two options, both standard, defaults to
...@@ -797,8 +798,8 @@ TEST_F('PrintPreviewWebUITest', ...@@ -797,8 +798,8 @@ TEST_F('PrintPreviewWebUITest',
this.nativeLayer_.dispatchEvent(capsSetEvent); this.nativeLayer_.dispatchEvent(capsSetEvent);
checkSectionVisible($('color-settings'), true); checkSectionVisible($('color-settings'), true);
expectFalse($('color-settings').querySelector('.color-option').checked); expectEquals(
expectTrue($('color-settings').querySelector('.bw-option').checked); 'bw', $('color-settings').querySelector('.color-settings-select').value);
}); });
// Test that the color settings, two options, both custom, defaults to color. // Test that the color settings, two options, both custom, defaults to color.
...@@ -818,8 +819,9 @@ TEST_F('PrintPreviewWebUITest', ...@@ -818,8 +819,9 @@ TEST_F('PrintPreviewWebUITest',
this.nativeLayer_.dispatchEvent(capsSetEvent); this.nativeLayer_.dispatchEvent(capsSetEvent);
checkSectionVisible($('color-settings'), true); checkSectionVisible($('color-settings'), true);
expectTrue($('color-settings').querySelector('.color-option').checked); expectEquals(
expectFalse($('color-settings').querySelector('.bw-option').checked); 'color',
$('color-settings').querySelector('.color-settings-select').value);
}); });
// Test to verify that duplex settings are set according to the printer // Test to verify that duplex settings are set according to the printer
......
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