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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
ash / components / arc / mojom / ime_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_IME_MOJOM_TRAITS_H_
#define ASH_COMPONENTS_ARC_MOJOM_IME_MOJOM_TRAITS_H_
#include "ash/components/arc/mojom/ime.mojom-shared.h"
#include "ui/base/ime/text_input_type.h"
#include "ui/events/event.h"
namespace mojo {
template <>
struct EnumTraits<arc::mojom::TextInputType, ui::TextInputType> {
using MojoType = arc::mojom::TextInputType;
// The two enum types are similar, but intentionally made not identical.
// We cannot force them to be in sync. If we do, updates in ui::TextInputType
// must always be propagated to the mojom::TextInputType mojo definition in
// ARC container side, which is in a different repository than Chromium.
// We don't want such dependency.
//
// That's why we need a lengthy switch statement instead of static_cast
// guarded by a static assert on the two enums to be in sync.
static MojoType ToMojom(ui::TextInputType input) {
switch (input) {
case ui::TEXT_INPUT_TYPE_NONE:
return MojoType::NONE;
case ui::TEXT_INPUT_TYPE_TEXT:
return MojoType::TEXT;
case ui::TEXT_INPUT_TYPE_PASSWORD:
return MojoType::PASSWORD;
case ui::TEXT_INPUT_TYPE_SEARCH:
return MojoType::SEARCH;
case ui::TEXT_INPUT_TYPE_EMAIL:
return MojoType::EMAIL;
case ui::TEXT_INPUT_TYPE_NUMBER:
return MojoType::NUMBER;
case ui::TEXT_INPUT_TYPE_TELEPHONE:
return MojoType::TELEPHONE;
case ui::TEXT_INPUT_TYPE_URL:
return MojoType::URL;
case ui::TEXT_INPUT_TYPE_DATE:
return MojoType::DATE;
case ui::TEXT_INPUT_TYPE_DATE_TIME:
return MojoType::DATETIME;
case ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL:
return MojoType::DATETIME;
case ui::TEXT_INPUT_TYPE_MONTH:
return MojoType::DATE;
case ui::TEXT_INPUT_TYPE_TIME:
return MojoType::TIME;
case ui::TEXT_INPUT_TYPE_WEEK:
return MojoType::DATE;
case ui::TEXT_INPUT_TYPE_TEXT_AREA:
return MojoType::TEXT;
case ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE:
return MojoType::TEXT;
case ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD:
return MojoType::DATETIME;
case ui::TEXT_INPUT_TYPE_NULL:
return MojoType::NONE;
}
NOTREACHED();
}
static bool FromMojom(MojoType input, ui::TextInputType* out) {
switch (input) {
case MojoType::NONE:
*out = ui::TEXT_INPUT_TYPE_NONE;
return true;
case MojoType::TEXT:
*out = ui::TEXT_INPUT_TYPE_TEXT;
return true;
case MojoType::PASSWORD:
*out = ui::TEXT_INPUT_TYPE_PASSWORD;
return true;
case MojoType::SEARCH:
*out = ui::TEXT_INPUT_TYPE_SEARCH;
return true;
case MojoType::EMAIL:
*out = ui::TEXT_INPUT_TYPE_EMAIL;
return true;
case MojoType::NUMBER:
*out = ui::TEXT_INPUT_TYPE_NUMBER;
return true;
case MojoType::TELEPHONE:
*out = ui::TEXT_INPUT_TYPE_TELEPHONE;
return true;
case MojoType::URL:
*out = ui::TEXT_INPUT_TYPE_URL;
return true;
case MojoType::DATE:
*out = ui::TEXT_INPUT_TYPE_DATE;
return true;
case MojoType::TIME:
*out = ui::TEXT_INPUT_TYPE_TIME;
return true;
case MojoType::DATETIME:
*out = ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL;
return true;
case MojoType::ANDROID_NULL:
*out = ui::TEXT_INPUT_TYPE_NULL;
return true;
}
NOTREACHED();
}
};
using KeyEventUniquePtr = std::unique_ptr<ui::KeyEvent>;
template <>
struct StructTraits<arc::mojom::KeyEventDataDataView, KeyEventUniquePtr> {
static bool pressed(const KeyEventUniquePtr& key_event) {
return key_event->type() == ui::EventType::kKeyPressed;
}
static int32_t key_code(const KeyEventUniquePtr& key_event) {
return key_event->key_code();
}
static bool is_shift_down(const KeyEventUniquePtr& key_event) {
return key_event->IsShiftDown();
}
static bool is_control_down(const KeyEventUniquePtr& key_event) {
return key_event->IsControlDown();
}
static bool is_alt_down(const KeyEventUniquePtr& key_event) {
return key_event->IsAltDown();
}
static bool is_capslock_on(const KeyEventUniquePtr& key_event) {
return key_event->IsCapsLockOn();
}
static int32_t scan_code(const KeyEventUniquePtr& key_event) {
return key_event->scan_code();
}
static bool is_alt_gr_down(const KeyEventUniquePtr& key_event) {
return key_event->IsAltGrDown();
}
static bool is_repeat(const KeyEventUniquePtr& key_event) {
return key_event->is_repeat();
}
static bool Read(arc::mojom::KeyEventDataDataView data,
KeyEventUniquePtr* out);
};
} // namespace mojo
#endif // ASH_COMPONENTS_ARC_MOJOM_IME_MOJOM_TRAITS_H_