Print Preview: Making margin selection sticky (part 1/2).
This CL makes sticky default, minimum and no margins selections. Selecting custom margins is not remembered for now (will be addressed in a follow up CL). BUG=102446 TEST=See bug description. Review URL: http://codereview.chromium.org/8428005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108245 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
chrome/browser
resources
ui
printing
@@ -4,8 +4,8 @@
|
|||||||
<select id="margin-list">
|
<select id="margin-list">
|
||||||
<option i18n-content="defaultMargins" value="0" selected></option>
|
<option i18n-content="defaultMargins" value="0" selected></option>
|
||||||
<option i18n-content="noMargins" value="1"></option>
|
<option i18n-content="noMargins" value="1"></option>
|
||||||
<option i18n-content="minimumMargins" value="3"></option>
|
<option i18n-content="minimumMargins" value="2"></option>
|
||||||
<option i18n-content="customMargins" value="2"></option>
|
<option i18n-content="customMargins" value="3"></option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -151,13 +151,14 @@ cr.define('print_preview', function() {
|
|||||||
MarginSettings.POINTS_PER_INCH = 72;
|
MarginSettings.POINTS_PER_INCH = 72;
|
||||||
// Minimum allowed distance in points between top-bottom, left-right margins.
|
// Minimum allowed distance in points between top-bottom, left-right margins.
|
||||||
MarginSettings.MINIMUM_MARGINS_DISTANCE = 36;
|
MarginSettings.MINIMUM_MARGINS_DISTANCE = 36;
|
||||||
// Margin list values.
|
// Margin list values. Matches enum MarginType in
|
||||||
|
// printing/print_job_constants.h.
|
||||||
MarginSettings.MARGINS_VALUE_DEFAULT = 0;
|
MarginSettings.MARGINS_VALUE_DEFAULT = 0;
|
||||||
MarginSettings.MARGINS_VALUE_NO_MARGINS = 1;
|
MarginSettings.MARGINS_VALUE_NO_MARGINS = 1;
|
||||||
MarginSettings.MARGINS_VALUE_CUSTOM = 2;
|
MarginSettings.MARGINS_VALUE_MINIMUM = 2;
|
||||||
MarginSettings.MARGINS_VALUE_MINIMUM = 3;
|
MarginSettings.MARGINS_VALUE_CUSTOM = 3;
|
||||||
// Default Margins option index.
|
// Default Margins option index.
|
||||||
MarginSettings.DEFAULT_MARGINS_OPTION_INDEX = 0;
|
MarginSettings.OPTION_INDEX_DEFAULT = 0;
|
||||||
// Group name corresponding to the top margin.
|
// Group name corresponding to the top margin.
|
||||||
MarginSettings.TOP_GROUP = 'top';
|
MarginSettings.TOP_GROUP = 'top';
|
||||||
// Group name corresponding to the left margin.
|
// Group name corresponding to the left margin.
|
||||||
@@ -209,6 +210,16 @@ cr.define('print_preview', function() {
|
|||||||
return parseInt(val, 10);
|
return parseInt(val, 10);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current margin selection to |lastUsedMarginsType|.
|
||||||
|
* @param {number} lastUsedMarginsType An integer value identifying a margin
|
||||||
|
* type according to MarginType enum in printing/print_job_constants.h.
|
||||||
|
*/
|
||||||
|
setLastUsedMarginsType: function(lastUsedMarginsType) {
|
||||||
|
this.marginList_.selectedIndex =
|
||||||
|
this.getMarginOptionIndexByValue_(lastUsedMarginsType);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {number} The total width of the plugin in points.
|
* @return {number} The total width of the plugin in points.
|
||||||
*/
|
*/
|
||||||
@@ -225,6 +236,23 @@ cr.define('print_preview', function() {
|
|||||||
return this.pageHeight_ / pageInformation.height;
|
return this.pageHeight_ / pageInformation.height;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps margin type values to indices within |this.marginList_|.
|
||||||
|
* @param {number} marginTypeValue An integer value identifying a margin
|
||||||
|
* type according to MarginType enum in printing/print_job_constants.h.
|
||||||
|
* @return {number} The index within |this.marginList_| that corrsponds to
|
||||||
|
* |marginTypeValue|.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
getMarginOptionIndexByValue_: function(marginTypeValue) {
|
||||||
|
var options = this.marginList_.options;
|
||||||
|
for (var i = 0; i < options.length; i++) {
|
||||||
|
if (options[i].getAttribute('value') == marginTypeValue)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return MarginSettings.OPTION_INDEX_DEFAULT;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {boolean} True if default margins are selected.
|
* @return {boolean} True if default margins are selected.
|
||||||
*/
|
*/
|
||||||
@@ -596,7 +624,7 @@ cr.define('print_preview', function() {
|
|||||||
resetMarginsIfNeeded: function() {
|
resetMarginsIfNeeded: function() {
|
||||||
if (this.isCustomMarginsSelected()) {
|
if (this.isCustomMarginsSelected()) {
|
||||||
this.marginList_.options[
|
this.marginList_.options[
|
||||||
MarginSettings.DEFAULT_MARGINS_OPTION_INDEX].selected = true;
|
MarginSettings.OPTION_INDEX_DEFAULT].selected = true;
|
||||||
this.removeCustomMarginEventListeners_();
|
this.removeCustomMarginEventListeners_();
|
||||||
this.forceDisplayingMarginLines_ = true;
|
this.forceDisplayingMarginLines_ = true;
|
||||||
this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT;
|
this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT;
|
||||||
|
@@ -576,9 +576,13 @@ function fileSelectionCompleted() {
|
|||||||
* Set the default printer. If there is one, generate a print preview.
|
* Set the default printer. If there is one, generate a print preview.
|
||||||
* @param {string} printer Name of the default printer. Empty if none.
|
* @param {string} printer Name of the default printer. Empty if none.
|
||||||
* @param {string} cloudPrintData Cloud print related data to restore if
|
* @param {string} cloudPrintData Cloud print related data to restore if
|
||||||
* the default printer is a cloud printer.
|
* the default printer is a cloud printer.
|
||||||
|
* @param {number} lastUsedMarginsType Indicates the last used margins type
|
||||||
|
* (matches enum MarginType in printing/print_job_constants.h.
|
||||||
*/
|
*/
|
||||||
function setDefaultPrinter(printer_name, cloudPrintData) {
|
function setDefaultPrinter(printer_name, cloudPrintData, lastUsedMarginsType) {
|
||||||
|
// Setting the margin selection to the last used one.
|
||||||
|
marginSettings.setLastUsedMarginsType(lastUsedMarginsType);
|
||||||
// Add a placeholder value so the printer list looks valid.
|
// Add a placeholder value so the printer list looks valid.
|
||||||
addDestinationListOption('', '', true, true, true);
|
addDestinationListOption('', '', true, true, true);
|
||||||
if (printer_name) {
|
if (printer_name) {
|
||||||
|
@@ -202,6 +202,8 @@ std::string* PrintPreviewHandler::last_used_printer_cloud_print_data_ = NULL;
|
|||||||
std::string* PrintPreviewHandler::last_used_printer_name_ = NULL;
|
std::string* PrintPreviewHandler::last_used_printer_name_ = NULL;
|
||||||
printing::ColorModels PrintPreviewHandler::last_used_color_model_ =
|
printing::ColorModels PrintPreviewHandler::last_used_color_model_ =
|
||||||
printing::UNKNOWN_COLOR_MODEL;
|
printing::UNKNOWN_COLOR_MODEL;
|
||||||
|
printing::MarginType PrintPreviewHandler::last_used_margins_type_ =
|
||||||
|
printing::DEFAULT_MARGINS;
|
||||||
|
|
||||||
PrintPreviewHandler::PrintPreviewHandler()
|
PrintPreviewHandler::PrintPreviewHandler()
|
||||||
: print_backend_(printing::PrintBackend::CreateInstance(NULL)),
|
: print_backend_(printing::PrintBackend::CreateInstance(NULL)),
|
||||||
@@ -392,6 +394,12 @@ void PrintPreviewHandler::HandlePrint(const ListValue* args) {
|
|||||||
color_model = printing::GRAY;
|
color_model = printing::GRAY;
|
||||||
last_used_color_model_ = static_cast<printing::ColorModels>(color_model);
|
last_used_color_model_ = static_cast<printing::ColorModels>(color_model);
|
||||||
|
|
||||||
|
// Storing last used margin settings.
|
||||||
|
int margin_type;
|
||||||
|
if (!settings->GetInteger(printing::kSettingMarginsType, &margin_type))
|
||||||
|
margin_type = printing::DEFAULT_MARGINS;
|
||||||
|
last_used_margins_type_ = static_cast<printing::MarginType>(margin_type);
|
||||||
|
|
||||||
bool print_to_pdf = false;
|
bool print_to_pdf = false;
|
||||||
settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf);
|
settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf);
|
||||||
|
|
||||||
@@ -650,9 +658,12 @@ void PrintPreviewHandler::SendPrinterCapabilities(
|
|||||||
void PrintPreviewHandler::SendDefaultPrinter(
|
void PrintPreviewHandler::SendDefaultPrinter(
|
||||||
const StringValue& default_printer,
|
const StringValue& default_printer,
|
||||||
const StringValue& cloud_print_data) {
|
const StringValue& cloud_print_data) {
|
||||||
|
base::FundamentalValue margins_type(
|
||||||
|
PrintPreviewHandler::last_used_margins_type_);
|
||||||
web_ui_->CallJavascriptFunction("setDefaultPrinter",
|
web_ui_->CallJavascriptFunction("setDefaultPrinter",
|
||||||
default_printer,
|
default_printer,
|
||||||
cloud_print_data);
|
cloud_print_data,
|
||||||
|
margins_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintPreviewHandler::SetupPrinterList(const ListValue& printers) {
|
void PrintPreviewHandler::SetupPrinterList(const ListValue& printers) {
|
||||||
|
@@ -189,6 +189,7 @@ class PrintPreviewHandler : public WebUIMessageHandler,
|
|||||||
static std::string* last_used_printer_cloud_print_data_;
|
static std::string* last_used_printer_cloud_print_data_;
|
||||||
static std::string* last_used_printer_name_;
|
static std::string* last_used_printer_name_;
|
||||||
static printing::ColorModels last_used_color_model_;
|
static printing::ColorModels last_used_color_model_;
|
||||||
|
static printing::MarginType last_used_margins_type_;
|
||||||
|
|
||||||
// A count of how many requests received to regenerate preview data.
|
// A count of how many requests received to regenerate preview data.
|
||||||
// Initialized to 0 then incremented and emitted to a histogram.
|
// Initialized to 0 then incremented and emitted to a histogram.
|
||||||
|
@@ -118,8 +118,8 @@ enum ColorModels {
|
|||||||
enum MarginType {
|
enum MarginType {
|
||||||
DEFAULT_MARGINS, // Default varies depending on headers being enabled or not
|
DEFAULT_MARGINS, // Default varies depending on headers being enabled or not
|
||||||
NO_MARGINS,
|
NO_MARGINS,
|
||||||
CUSTOM_MARGINS,
|
|
||||||
PRINTABLE_AREA_MARGINS,
|
PRINTABLE_AREA_MARGINS,
|
||||||
|
CUSTOM_MARGINS,
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace printing
|
} // namespace printing
|
||||||
|
Reference in New Issue
Block a user