diff options
-rw-r--r-- | chrome/browser/resources/print_preview/data/destination_store.js | 5 | ||||
-rw-r--r-- | chrome/browser/resources/print_preview/native_layer.js | 1 | ||||
-rw-r--r-- | chrome/browser/resources/print_preview/settings/media_size_settings.js | 15 | ||||
-rw-r--r-- | chrome/browser/ui/webui/print_preview/print_preview_handler.cc | 2 | ||||
-rw-r--r-- | chrome/common/cloud_print/cloud_print_cdd_conversion.cc | 7 | ||||
-rw-r--r-- | components/cloud_devices/common/printer_description.cc | 8 | ||||
-rw-r--r-- | components/cloud_devices/common/printer_description.h | 2 | ||||
-rw-r--r-- | components/cloud_devices/common/printer_description_unittest.cc | 7 | ||||
-rw-r--r-- | printing/print_job_constants.cc | 3 | ||||
-rw-r--r-- | printing/print_job_constants.h | 1 | ||||
-rw-r--r-- | printing/print_settings.cc | 1 | ||||
-rw-r--r-- | printing/print_settings.h | 26 | ||||
-rw-r--r-- | printing/print_settings_initializer.cc | 19 | ||||
-rw-r--r-- | printing/printing_context.cc | 20 |
14 files changed, 87 insertions, 30 deletions
diff --git a/chrome/browser/resources/print_preview/data/destination_store.js b/chrome/browser/resources/print_preview/data/destination_store.js index 84e54d5..418c457 100644 --- a/chrome/browser/resources/print_preview/data/destination_store.js +++ b/chrome/browser/resources/print_preview/data/destination_store.js @@ -210,7 +210,10 @@ cr.define('print_preview', function() { 'NA_LEDGER': 'Tabloid' }; for (var i = 0, media; media = mediaSize.option[i]; i++) { - media.custom_display_name = mediaDisplayNames[media.name] || media.name; + media.custom_display_name = + media.custom_display_name || + mediaDisplayNames[media.name] || + media.name; } } return capabilities; diff --git a/chrome/browser/resources/print_preview/native_layer.js b/chrome/browser/resources/print_preview/native_layer.js index 0111ccd..2fd26d2 100644 --- a/chrome/browser/resources/print_preview/native_layer.js +++ b/chrome/browser/resources/print_preview/native_layer.js @@ -277,6 +277,7 @@ cr.define('print_preview', function() { var ticket = { 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), + 'mediaSize': printTicketStore.mediaSize.getValue(), 'pageCount': printTicketStore.pageRange.getPageNumberSet().size, 'landscape': printTicketStore.landscape.getValue(), 'color': this.getNativeColorModel_(destination, printTicketStore.color), diff --git a/chrome/browser/resources/print_preview/settings/media_size_settings.js b/chrome/browser/resources/print_preview/settings/media_size_settings.js index 507fd93..4451253 100644 --- a/chrome/browser/resources/print_preview/settings/media_size_settings.js +++ b/chrome/browser/resources/print_preview/settings/media_size_settings.js @@ -77,16 +77,17 @@ cr.define('print_preview', function() { 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; - } + } + // Try to select current ticket item. + 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; + this.onSelectChange_(); }, /** diff --git a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc index 6bd1ffb..f47fe27 100644 --- a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc +++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc @@ -330,7 +330,7 @@ scoped_ptr<base::DictionaryValue> GetPdfCapabilitiesOnFileThread( }; const gfx::Size default_media_size = GetDefaultPdfMediaSizeMicrons(); Media default_media( - "", default_media_size.width(), default_media_size.height()); + "", "", default_media_size.width(), default_media_size.height()); if (!default_media.MatchBySize() || std::find(kPdfMedia, kPdfMedia + arraysize(kPdfMedia), diff --git a/chrome/common/cloud_print/cloud_print_cdd_conversion.cc b/chrome/common/cloud_print/cloud_print_cdd_conversion.cc index 8c20950..b485cff 100644 --- a/chrome/common/cloud_print/cloud_print_cdd_conversion.cc +++ b/chrome/common/cloud_print/cloud_print_cdd_conversion.cc @@ -54,9 +54,9 @@ scoped_ptr<base::DictionaryValue> PrinterSemanticCapsAndDefaultsToCdd( } color.SaveTo(&description); -#if defined(OS_WIN) if (!semantic_info.papers.empty()) { Media default_media(semantic_info.default_paper.name, + "", semantic_info.default_paper.size_um.width(), semantic_info.default_paper.size_um.height()); default_media.MatchBySize(); @@ -67,7 +67,9 @@ scoped_ptr<base::DictionaryValue> PrinterSemanticCapsAndDefaultsToCdd( gfx::Size paper_size = semantic_info.papers[i].size_um; if (paper_size.width() > paper_size.height()) paper_size.SetSize(paper_size.height(), paper_size.width()); - Media new_media(semantic_info.papers[i].name, paper_size.width(), + Media new_media(semantic_info.papers[i].name, + "", + paper_size.width(), paper_size.height()); new_media.MatchBySize(); if (new_media.IsValid() && !media.Contains(new_media)) { @@ -110,7 +112,6 @@ scoped_ptr<base::DictionaryValue> PrinterSemanticCapsAndDefaultsToCdd( NOTREACHED(); } } -#endif OrientationCapability orientation; orientation.AddDefaultOption(PORTRAIT, true); diff --git a/components/cloud_devices/common/printer_description.cc b/components/cloud_devices/common/printer_description.cc index 2f70fa6..f8ebf6b 100644 --- a/components/cloud_devices/common/printer_description.cc +++ b/components/cloud_devices/common/printer_description.cc @@ -460,13 +460,15 @@ Media::Media(MediaType type, int32 width_um, int32 height_um) } Media::Media(const std::string& custom_display_name, + const std::string& vendor_id, int32 width_um, int32 height_um) : type(CUSTOM_MEDIA), width_um(width_um), height_um(height_um), is_continuous_feed(width_um <= 0 || height_um <= 0), - custom_display_name(custom_display_name) { + custom_display_name(custom_display_name), + vendor_id(vendor_id) { } bool Media::MatchBySize() { @@ -474,7 +476,6 @@ bool Media::MatchBySize() { if (!media) return false; type = media->id; - custom_display_name.clear(); return true; } @@ -758,6 +759,7 @@ class MediaTraits : public ItemsTraits<kOptionMediaSize> { dict.GetInteger(kMediaHeight, &option->height_um); dict.GetBoolean(kMediaIsContinuous, &option->is_continuous_feed); dict.GetString(kCustomName, &option->custom_display_name); + dict.GetString(kKeyVendorId, &option->vendor_id); return true; } @@ -766,6 +768,8 @@ class MediaTraits : public ItemsTraits<kOptionMediaSize> { dict->SetString(kKeyName, TypeToString(kMediaDefinitions, option.type)); if (!option.custom_display_name.empty() || option.type == CUSTOM_MEDIA) dict->SetString(kCustomName, option.custom_display_name); + if (!option.vendor_id.empty()) + dict->SetString(kKeyVendorId, option.vendor_id); if (option.width_um > 0) dict->SetInteger(kMediaWidth, option.width_um); if (option.height_um > 0) diff --git a/components/cloud_devices/common/printer_description.h b/components/cloud_devices/common/printer_description.h index d434fa6..c3ceee8 100644 --- a/components/cloud_devices/common/printer_description.h +++ b/components/cloud_devices/common/printer_description.h @@ -292,6 +292,7 @@ struct Media { Media(MediaType type, int32 width_um, int32 height_um); Media(const std::string& custom_display_name, + const std::string& vendor_id, int32 width_um, int32 height_um); @@ -306,6 +307,7 @@ struct Media { int32 height_um; bool is_continuous_feed; std::string custom_display_name; + std::string vendor_id; }; struct Interval { diff --git a/components/cloud_devices/common/printer_description_unittest.cc b/components/cloud_devices/common/printer_description_unittest.cc index 519409e..c1fb455 100644 --- a/components/cloud_devices/common/printer_description_unittest.cc +++ b/components/cloud_devices/common/printer_description_unittest.cc @@ -138,7 +138,8 @@ const char kCdd[] = " }, {" " 'width_microns': 1111," " 'is_continuous_feed': true," - " 'custom_display_name': 'FEED'" + " 'custom_display_name': 'Feed'," + " 'vendor_id': 'FEED'" " } ]" " }," " 'collate': {" @@ -364,7 +365,7 @@ TEST(PrinterDescriptionTest, CddSetAll) { media.AddDefaultOption(Media(NA_LETTER, 2222, 3333), true); media.AddOption(Media(ISO_A6, 4444, 5555)); media.AddOption(Media(JPN_YOU4, 6666, 7777)); - media.AddOption(Media("FEED", 1111, 0)); + media.AddOption(Media("Feed", "FEED", 1111, 0)); collate.set_default_value(false); reverse.set_default_value(true); @@ -463,7 +464,7 @@ TEST(PrinterDescriptionTest, CddGetAll) { EXPECT_TRUE(media.Contains(Media(NA_LETTER, 2222, 3333))); EXPECT_TRUE(media.Contains(Media(ISO_A6, 4444, 5555))); EXPECT_TRUE(media.Contains(Media(JPN_YOU4, 6666, 7777))); - EXPECT_TRUE(media.Contains(Media("FEED", 1111, 0))); + EXPECT_TRUE(media.Contains(Media("Feed", "FEED", 1111, 0))); EXPECT_EQ(Media(NA_LETTER, 2222, 3333), media.GetDefault()); EXPECT_FALSE(collate.default_value()); diff --git a/printing/print_job_constants.cc b/printing/print_job_constants.cc index 832f700..8ac5db4 100644 --- a/printing/print_job_constants.cc +++ b/printing/print_job_constants.cc @@ -86,6 +86,9 @@ const char kSettingMediaSizeHeightMicrons[] = "height_microns"; // Key that specifies the requested media width in microns. const char kSettingMediaSizeWidthMicrons[] = "width_microns"; +// Key that specifies the requested media platform specific vendor id. +const char kSettingMediaSizeVendorId[] = "vendor_id"; + // Key that specifies the bottom margin of the page. const char kSettingMarginBottom[] = "marginBottom"; diff --git a/printing/print_job_constants.h b/printing/print_job_constants.h index 2deca79..257cba6 100644 --- a/printing/print_job_constants.h +++ b/printing/print_job_constants.h @@ -35,6 +35,7 @@ PRINTING_EXPORT extern const char kSettingLandscape[]; PRINTING_EXPORT extern const char kSettingMediaSize[]; PRINTING_EXPORT extern const char kSettingMediaSizeHeightMicrons[]; PRINTING_EXPORT extern const char kSettingMediaSizeWidthMicrons[]; +PRINTING_EXPORT extern const char kSettingMediaSizeVendorId[]; PRINTING_EXPORT extern const char kSettingMarginBottom[]; PRINTING_EXPORT extern const char kSettingMarginLeft[]; PRINTING_EXPORT extern const char kSettingMarginRight[]; diff --git a/printing/print_settings.cc b/printing/print_settings.cc index f2dc425..b1c50c9 100644 --- a/printing/print_settings.cc +++ b/printing/print_settings.cc @@ -128,6 +128,7 @@ void PrintSettings::Clear() { url_ = base::string16(); display_header_footer_ = false; device_name_.clear(); + requested_media_ = RequestedMedia(); page_setup_device_units_.Clear(); dpi_ = 0; landscape_ = false; diff --git a/printing/print_settings.h b/printing/print_settings.h index b18d860..b942189 100644 --- a/printing/print_settings.h +++ b/printing/print_settings.h @@ -29,6 +29,19 @@ PRINTING_EXPORT void GetColorModelForMode(int color_mode, // OS-independent print settings. class PRINTING_EXPORT PrintSettings { public: + // Media properties requested by the user. Default instance represents + // default media selection. + struct RequestedMedia { + // Size of the media, in microns. + gfx::Size size_microns; + // Platform specific id to map it back to the particular media. + std::string vendor_id; + + bool IsDefault() const { + return size_microns.IsEmpty() && vendor_id.empty(); + } + }; + PrintSettings(); ~PrintSettings(); @@ -43,6 +56,16 @@ class PRINTING_EXPORT PrintSettings { void SetOrientation(bool landscape); bool landscape() const { return landscape_; } + // Updates user requested media. + void set_requested_media(const RequestedMedia& media) { + requested_media_ = media; + } + // Media properties requested by the user. Translated into device media by the + // platform specific layers. + const RequestedMedia& requested_media() const { + return requested_media_; + } + // Set printer printable area in in device units. // Some platforms already provide flipped area. Set |landscape_needs_flip| // to false on those platforms to avoid double flipping. @@ -174,6 +197,9 @@ class PRINTING_EXPORT PrintSettings { // Printer device name as opened by the OS. base::string16 device_name_; + // Media requested by the user. + RequestedMedia requested_media_; + // Page setup in device units. PageSetup page_setup_device_units_; diff --git a/printing/print_settings_initializer.cc b/printing/print_settings_initializer.cc index 565fc78..df6a32e 100644 --- a/printing/print_settings_initializer.cc +++ b/printing/print_settings_initializer.cc @@ -51,6 +51,25 @@ bool PrintSettingsInitializer::InitSettings( settings->set_should_print_backgrounds(backgrounds); settings->set_selection_only(selection_only); + PrintSettings::RequestedMedia requested_media; + const base::DictionaryValue* media_size_value = NULL; + if (job_settings.GetDictionary(kSettingMediaSize, &media_size_value)) { + int width_microns = 0; + int height_microns = 0; + if (media_size_value->GetInteger(kSettingMediaSizeWidthMicrons, + &width_microns) && + media_size_value->GetInteger(kSettingMediaSizeHeightMicrons, + &height_microns)) { + requested_media.size_microns = gfx::Size(width_microns, height_microns); + } + std::string vendor_id; + if (media_size_value->GetString(kSettingMediaSizeVendorId, &vendor_id) && + !vendor_id.empty()) { + requested_media.vendor_id = vendor_id; + } + } + settings->set_requested_media(requested_media); + int margin_type = DEFAULT_MARGINS; if (!job_settings.GetInteger(kSettingMarginsType, &margin_type) || (margin_type != DEFAULT_MARGINS && diff --git a/printing/printing_context.cc b/printing/printing_context.cc index 8d438d0..c7cd644 100644 --- a/printing/printing_context.cc +++ b/printing/printing_context.cc @@ -96,19 +96,13 @@ PrintingContext::Result PrintingContext::UpdatePrintSettings( is_cloud_dialog || print_with_privet)) { settings_.set_dpi(kDefaultPdfDpi); gfx::Size paper_size(GetPdfPaperSizeDeviceUnits()); - const base::DictionaryValue* media_size = NULL; - if (job_settings.GetDictionary(kSettingMediaSize, &media_size)) { - int width_microns = 0; - int height_microns = 0; - if (media_size->GetInteger(kSettingMediaSizeWidthMicrons, - &width_microns) && - media_size->GetInteger(kSettingMediaSizeHeightMicrons, - &height_microns)) { - float deviceMicronsPerDeviceUnit = - (kHundrethsMMPerInch * 10.0f) / settings_.device_units_per_inch(); - paper_size = gfx::Size(width_microns / deviceMicronsPerDeviceUnit, - height_microns / deviceMicronsPerDeviceUnit); - } + if (!settings_.requested_media().size_microns.IsEmpty()) { + float deviceMicronsPerDeviceUnit = + (kHundrethsMMPerInch * 10.0f) / settings_.device_units_per_inch(); + paper_size = gfx::Size(settings_.requested_media().size_microns.width() / + deviceMicronsPerDeviceUnit, + settings_.requested_media().size_microns.height() / + deviceMicronsPerDeviceUnit); } gfx::Rect paper_rect(0, 0, paper_size.width(), paper_size.height()); if (print_to_cloud || print_with_privet) { |