Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/cloud_devices/common/printer_description.h" | 5 #include "components/cloud_devices/common/printer_description.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 } | 453 } |
| 454 | 454 |
| 455 Media::Media(MediaType type, int32 width_um, int32 height_um) | 455 Media::Media(MediaType type, int32 width_um, int32 height_um) |
| 456 : type(type), | 456 : type(type), |
| 457 width_um(width_um), | 457 width_um(width_um), |
| 458 height_um(height_um), | 458 height_um(height_um), |
| 459 is_continuous_feed(width_um <= 0 || height_um <= 0) { | 459 is_continuous_feed(width_um <= 0 || height_um <= 0) { |
| 460 } | 460 } |
| 461 | 461 |
| 462 Media::Media(const std::string& custom_display_name, | 462 Media::Media(const std::string& custom_display_name, |
| 463 const std::string& vendor_id, | |
| 463 int32 width_um, | 464 int32 width_um, |
| 464 int32 height_um) | 465 int32 height_um) |
| 465 : type(CUSTOM_MEDIA), | 466 : type(CUSTOM_MEDIA), |
| 466 width_um(width_um), | 467 width_um(width_um), |
| 467 height_um(height_um), | 468 height_um(height_um), |
| 468 is_continuous_feed(width_um <= 0 || height_um <= 0), | 469 is_continuous_feed(width_um <= 0 || height_um <= 0), |
| 469 custom_display_name(custom_display_name) { | 470 custom_display_name(custom_display_name), |
| 471 vendor_id(vendor_id) { | |
| 470 } | 472 } |
| 471 | 473 |
| 472 bool Media::MatchBySize() { | 474 bool Media::MatchBySize() { |
| 473 const MediaDefinition* media = FindMediaBySize(width_um, height_um); | 475 const MediaDefinition* media = FindMediaBySize(width_um, height_um); |
| 474 if (!media) | 476 if (!media) |
| 475 return false; | 477 return false; |
| 476 type = media->id; | 478 type = media->id; |
| 477 custom_display_name.clear(); | |
| 478 return true; | 479 return true; |
| 479 } | 480 } |
| 480 | 481 |
| 481 bool Media::IsValid() const { | 482 bool Media::IsValid() const { |
| 482 if (is_continuous_feed) { | 483 if (is_continuous_feed) { |
| 483 if (width_um <= 0 && height_um <= 0) | 484 if (width_um <= 0 && height_um <= 0) |
| 484 return false; | 485 return false; |
| 485 } else { | 486 } else { |
| 486 if (width_um <= 0 || height_um <= 0) | 487 if (width_um <= 0 || height_um <= 0) |
| 487 return false; | 488 return false; |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 std::string type_str; | 752 std::string type_str; |
| 752 if (dict.GetString(kKeyName, &type_str)) { | 753 if (dict.GetString(kKeyName, &type_str)) { |
| 753 if (!TypeFromString(kMediaDefinitions, type_str, &option->type)) | 754 if (!TypeFromString(kMediaDefinitions, type_str, &option->type)) |
| 754 return false; | 755 return false; |
| 755 } | 756 } |
| 756 | 757 |
| 757 dict.GetInteger(kMediaWidth, &option->width_um); | 758 dict.GetInteger(kMediaWidth, &option->width_um); |
| 758 dict.GetInteger(kMediaHeight, &option->height_um); | 759 dict.GetInteger(kMediaHeight, &option->height_um); |
| 759 dict.GetBoolean(kMediaIsContinuous, &option->is_continuous_feed); | 760 dict.GetBoolean(kMediaIsContinuous, &option->is_continuous_feed); |
| 760 dict.GetString(kCustomName, &option->custom_display_name); | 761 dict.GetString(kCustomName, &option->custom_display_name); |
| 762 dict.GetString(kKeyVendorId, &option->vendor_id); | |
| 761 return true; | 763 return true; |
| 762 } | 764 } |
| 763 | 765 |
| 764 static void Save(const Media& option, base::DictionaryValue* dict) { | 766 static void Save(const Media& option, base::DictionaryValue* dict) { |
| 765 if (option.type != CUSTOM_MEDIA) | 767 dict->SetString(kKeyName, TypeToString(kMediaDefinitions, option.type)); |
|
Vitaly Buka (NO REVIEWS)
2014/06/12 00:43:24
if (option.type != CUSTOM_MEDIA)
Aleksey Shlyapnikov
2014/06/12 00:50:05
Done.
| |
| 766 dict->SetString(kKeyName, TypeToString(kMediaDefinitions, option.type)); | |
| 767 if (!option.custom_display_name.empty() || option.type == CUSTOM_MEDIA) | 768 if (!option.custom_display_name.empty() || option.type == CUSTOM_MEDIA) |
| 768 dict->SetString(kCustomName, option.custom_display_name); | 769 dict->SetString(kCustomName, option.custom_display_name); |
| 770 if (!option.vendor_id.empty()) | |
| 771 dict->SetString(kKeyVendorId, option.vendor_id); | |
| 769 if (option.width_um > 0) | 772 if (option.width_um > 0) |
| 770 dict->SetInteger(kMediaWidth, option.width_um); | 773 dict->SetInteger(kMediaWidth, option.width_um); |
| 771 if (option.height_um > 0) | 774 if (option.height_um > 0) |
| 772 dict->SetInteger(kMediaHeight, option.height_um); | 775 dict->SetInteger(kMediaHeight, option.height_um); |
| 773 if (option.is_continuous_feed) | 776 if (option.is_continuous_feed) |
| 774 dict->SetBoolean(kMediaIsContinuous, true); | 777 dict->SetBoolean(kMediaIsContinuous, true); |
| 775 } | 778 } |
| 776 }; | 779 }; |
| 777 | 780 |
| 778 class CollateTraits : public NoValueValidation, | 781 class CollateTraits : public NoValueValidation, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 828 template class TicketItem<Margins, MarginsTraits>; | 831 template class TicketItem<Margins, MarginsTraits>; |
| 829 template class TicketItem<Dpi, DpiTraits>; | 832 template class TicketItem<Dpi, DpiTraits>; |
| 830 template class TicketItem<FitToPageType, FitToPageTraits>; | 833 template class TicketItem<FitToPageType, FitToPageTraits>; |
| 831 template class TicketItem<Media, MediaTraits>; | 834 template class TicketItem<Media, MediaTraits>; |
| 832 template class TicketItem<int32, CopiesTraits>; | 835 template class TicketItem<int32, CopiesTraits>; |
| 833 template class TicketItem<PageRange, PageRangeTraits>; | 836 template class TicketItem<PageRange, PageRangeTraits>; |
| 834 template class TicketItem<bool, CollateTraits>; | 837 template class TicketItem<bool, CollateTraits>; |
| 835 template class TicketItem<bool, ReverseTraits>; | 838 template class TicketItem<bool, ReverseTraits>; |
| 836 | 839 |
| 837 } // namespace cloud_devices | 840 } // namespace cloud_devices |
| OLD | NEW |