1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78

ash / components / arc / mojom / print_mojom_traits.h [blame]

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_COMPONENTS_ARC_MOJOM_PRINT_MOJOM_TRAITS_H_
#define ASH_COMPONENTS_ARC_MOJOM_PRINT_MOJOM_TRAITS_H_

#include <string>
#include <vector>

#include "ash/components/arc/mojom/print_common.mojom.h"
#include "printing/backend/print_backend.h"
#include "printing/page_range.h"
#include "ui/gfx/geometry/size.h"

namespace mojo {

template <>
struct StructTraits<arc::mojom::PrintPageRangeDataView, printing::PageRange> {
  static uint32_t start(const printing::PageRange& r) { return r.from; }
  static uint32_t end(const printing::PageRange& r) { return r.to; }

  static bool Read(arc::mojom::PrintPageRangeDataView data,
                   printing::PageRange* out) {
    out->from = data.start();
    out->to = data.end();
    return true;
  }
};

template <>
struct StructTraits<arc::mojom::PrintResolutionDataView, gfx::Size> {
  static uint32_t horizontal_dpi(const gfx::Size& size) { return size.width(); }
  static uint32_t vertical_dpi(const gfx::Size& size) { return size.width(); }
  static std::string id(const gfx::Size& size);
  static std::string label(const gfx::Size& size) { return id(size); }

  static bool Read(arc::mojom::PrintResolutionDataView data, gfx::Size* out) {
    *out = gfx::Size(data.horizontal_dpi(), data.vertical_dpi());
    return true;
  }
};

// TODO(vkuzkokov): PrinterSemanticCapsAndDefaults has no margins, boolean
// duplex_capable, and unlabeled resolutions.
template <>
struct StructTraits<arc::mojom::PrinterCapabilitiesDataView,
                    printing::PrinterSemanticCapsAndDefaults> {
  static std::vector<arc::mojom::PrintMediaSizePtr> media_sizes(
      const printing::PrinterSemanticCapsAndDefaults& caps);

  static const std::vector<gfx::Size>& resolutions(
      const printing::PrinterSemanticCapsAndDefaults& caps) {
    return caps.dpis;
  }

  static arc::mojom::PrintMarginsPtr min_margins(
      const printing::PrinterSemanticCapsAndDefaults& caps);

  static arc::mojom::PrintColorMode color_modes(
      const printing::PrinterSemanticCapsAndDefaults& caps);

  static arc::mojom::PrintDuplexMode duplex_modes(
      const printing::PrinterSemanticCapsAndDefaults& caps);

  static arc::mojom::PrintAttributesPtr defaults(
      const printing::PrinterSemanticCapsAndDefaults& caps);

  static bool Read(arc::mojom::PrinterCapabilitiesDataView data,
                   printing::PrinterSemanticCapsAndDefaults* out) {
    // This is never used.
    NOTREACHED();
  }
};

}  // namespace mojo

#endif  // ASH_COMPONENTS_ARC_MOJOM_PRINT_MOJOM_TRAITS_H_