File: rrect_f_mojom_traits.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (120 lines) | stat: -rw-r--r-- 3,860 bytes parent folder | download | duplicates (6)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// 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 UI_GFX_MOJOM_RRECT_F_MOJOM_TRAITS_H_
#define UI_GFX_MOJOM_RRECT_F_MOJOM_TRAITS_H_

#include "base/notreached.h"
#include "ui/gfx/geometry/mojom/geometry_mojom_traits.h"
#include "ui/gfx/geometry/rrect_f.h"
#include "ui/gfx/geometry/rrect_f_builder.h"
#include "ui/gfx/mojom/rrect_f.mojom-shared.h"

namespace mojo {

namespace {

gfx::mojom::RRectFType GfxRRectFTypeToMojo(gfx::RRectF::Type type) {
  switch (type) {
    case gfx::RRectF::Type::kEmpty:
      return gfx::mojom::RRectFType::kEmpty;
    case gfx::RRectF::Type::kRect:
      return gfx::mojom::RRectFType::kRect;
    case gfx::RRectF::Type::kSingle:
      return gfx::mojom::RRectFType::kSingle;
    case gfx::RRectF::Type::kSimple:
      return gfx::mojom::RRectFType::kSimple;
    case gfx::RRectF::Type::kOval:
      return gfx::mojom::RRectFType::kOval;
    case gfx::RRectF::Type::kComplex:
      return gfx::mojom::RRectFType::kComplex;
  }
  NOTREACHED();
}

gfx::RRectF::Type MojoRRectFTypeToGfx(gfx::mojom::RRectFType type) {
  switch (type) {
    case gfx::mojom::RRectFType::kEmpty:
      return gfx::RRectF::Type::kEmpty;
    case gfx::mojom::RRectFType::kRect:
      return gfx::RRectF::Type::kRect;
    case gfx::mojom::RRectFType::kSingle:
      return gfx::RRectF::Type::kSingle;
    case gfx::mojom::RRectFType::kSimple:
      return gfx::RRectF::Type::kSimple;
    case gfx::mojom::RRectFType::kOval:
      return gfx::RRectF::Type::kOval;
    case gfx::mojom::RRectFType::kComplex:
      return gfx::RRectF::Type::kComplex;
  }
  NOTREACHED();
}

}  // namespace

template <>
struct StructTraits<gfx::mojom::RRectFDataView, gfx::RRectF> {
  static gfx::mojom::RRectFType type(const gfx::RRectF& input) {
    return GfxRRectFTypeToMojo(input.GetType());
  }

  static gfx::RectF rect(const gfx::RRectF& input) { return input.rect(); }

  static gfx::Vector2dF upper_left(const gfx::RRectF& input) {
    return input.GetCornerRadii(gfx::RRectF::Corner::kUpperLeft);
  }

  static gfx::Vector2dF upper_right(const gfx::RRectF& input) {
    return input.GetCornerRadii(gfx::RRectF::Corner::kUpperRight);
  }

  static gfx::Vector2dF lower_right(const gfx::RRectF& input) {
    return input.GetCornerRadii(gfx::RRectF::Corner::kLowerRight);
  }

  static gfx::Vector2dF lower_left(const gfx::RRectF& input) {
    return input.GetCornerRadii(gfx::RRectF::Corner::kLowerLeft);
  }

  static bool Read(gfx::mojom::RRectFDataView data, gfx::RRectF* out) {
    gfx::RRectF::Type type(MojoRRectFTypeToGfx(data.type()));
    gfx::RectF rect;
    if (!data.ReadRect(&rect))
      return false;
    if (type <= gfx::RRectF::Type::kRect) {
      *out = gfx::RRectFBuilder().set_rect(rect).Build();
      return true;
    }
    gfx::Vector2dF upper_left;
    if (!data.ReadUpperLeft(&upper_left))
      return false;
    if (type <= gfx::RRectF::Type::kSimple) {
      *out = gfx::RRectFBuilder()
                 .set_rect(rect)
                 .set_radius(upper_left.x(), upper_left.y())
                 .Build();
      return true;
    }
    gfx::Vector2dF upper_right;
    gfx::Vector2dF lower_right;
    gfx::Vector2dF lower_left;
    if (!data.ReadUpperRight(&upper_right) ||
        !data.ReadLowerRight(&lower_right) ||
        !data.ReadLowerLeft(&lower_left)) {
      return false;
    }
    *out = gfx::RRectFBuilder()
               .set_rect(rect)
               .set_upper_left(upper_left.x(), upper_left.y())
               .set_upper_right(upper_right.x(), upper_right.y())
               .set_lower_right(lower_right.x(), lower_right.y())
               .set_lower_left(lower_left.x(), lower_left.y())
               .Build();
    return true;
  }
};

}  // namespace mojo

#endif  // UI_GFX_MOJOM_RRECT_F_MOJOM_TRAITS_H_