1/*
2 * Copyright (C) 2018 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "InputMode.h"
28
29#include <wtf/NeverDestroyed.h>
30
31namespace WebCore {
32
33InputMode inputModeForAttributeValue(const AtomicString& value)
34{
35 if (equalIgnoringASCIICase(value, InputModeNames::none()))
36 return InputMode::None;
37 if (equalIgnoringASCIICase(value, InputModeNames::text()))
38 return InputMode::Text;
39 if (equalIgnoringASCIICase(value, InputModeNames::tel()))
40 return InputMode::Telephone;
41 if (equalIgnoringASCIICase(value, InputModeNames::url()))
42 return InputMode::Url;
43 if (equalIgnoringASCIICase(value, InputModeNames::email()))
44 return InputMode::Email;
45 if (equalIgnoringASCIICase(value, InputModeNames::numeric()))
46 return InputMode::Numeric;
47 if (equalIgnoringASCIICase(value, InputModeNames::decimal()))
48 return InputMode::Decimal;
49 if (equalIgnoringASCIICase(value, InputModeNames::search()))
50 return InputMode::Search;
51
52 return InputMode::Unspecified;
53}
54
55const AtomicString& stringForInputMode(InputMode mode)
56{
57 switch (mode) {
58 case InputMode::Unspecified:
59 return emptyAtom();
60 case InputMode::None:
61 return InputModeNames::none();
62 case InputMode::Text:
63 return InputModeNames::text();
64 case InputMode::Telephone:
65 return InputModeNames::tel();
66 case InputMode::Url:
67 return InputModeNames::url();
68 case InputMode::Email:
69 return InputModeNames::email();
70 case InputMode::Numeric:
71 return InputModeNames::numeric();
72 case InputMode::Decimal:
73 return InputModeNames::decimal();
74 case InputMode::Search:
75 return InputModeNames::search();
76 }
77
78 return emptyAtom();
79}
80
81namespace InputModeNames {
82
83const AtomicString& none()
84{
85 static NeverDestroyed<AtomicString> mode("none", AtomicString::ConstructFromLiteral);
86 return mode;
87}
88
89const AtomicString& text()
90{
91 static NeverDestroyed<AtomicString> mode("text", AtomicString::ConstructFromLiteral);
92 return mode;
93}
94
95const AtomicString& tel()
96{
97 static NeverDestroyed<AtomicString> mode("tel", AtomicString::ConstructFromLiteral);
98 return mode;
99}
100
101const AtomicString& url()
102{
103 static NeverDestroyed<AtomicString> mode("url", AtomicString::ConstructFromLiteral);
104 return mode;
105}
106
107const AtomicString& email()
108{
109 static NeverDestroyed<AtomicString> mode("email", AtomicString::ConstructFromLiteral);
110 return mode;
111}
112
113const AtomicString& numeric()
114{
115 static NeverDestroyed<AtomicString> mode("numeric", AtomicString::ConstructFromLiteral);
116 return mode;
117}
118
119const AtomicString& decimal()
120{
121 static NeverDestroyed<AtomicString> mode("decimal", AtomicString::ConstructFromLiteral);
122 return mode;
123}
124
125const AtomicString& search()
126{
127 static NeverDestroyed<AtomicString> mode("search", AtomicString::ConstructFromLiteral);
128 return mode;
129}
130
131} // namespace InputModeNames
132
133} // namespace WebCore
134