2
* Copyright (C) 2019 Igalia S.L.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
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.
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.
27
#include "InputMethodState.h"
29
#include "ArgumentCoders.h"
30
#include <WebCore/HTMLInputElement.h>
34
void InputMethodState::setPurposeOrHintForInputMode(WebCore::InputMode inputMode)
37
case WebCore::InputMode::None:
38
hints.add(InputMethodState::Hint::InhibitOnScreenKeyboard);
40
case WebCore::InputMode::Unspecified:
41
case WebCore::InputMode::Text:
42
purpose = Purpose::FreeForm;
44
case WebCore::InputMode::Telephone:
45
purpose = Purpose::Phone;
47
case WebCore::InputMode::Url:
48
purpose = Purpose::Url;
50
case WebCore::InputMode::Email:
51
purpose = Purpose::Email;
53
case WebCore::InputMode::Numeric:
54
purpose = Purpose::Digits;
56
case WebCore::InputMode::Decimal:
57
purpose = Purpose::Number;
59
case WebCore::InputMode::Search:
64
static bool inputElementHasDigitsPattern(WebCore::HTMLInputElement& element)
66
const auto& pattern = element.attributeWithoutSynchronization(WebCore::HTMLNames::patternAttr);
67
return pattern == "\\d*" || pattern == "[0-9]*";
70
void InputMethodState::setPurposeForInputElement(WebCore::HTMLInputElement& element)
72
if (element.isPasswordField())
73
purpose = Purpose::Password;
74
else if (element.isEmailField())
75
purpose = Purpose::Email;
76
else if (element.isTelephoneField())
77
purpose = Purpose::Phone;
78
else if (element.isNumberField())
79
purpose = inputElementHasDigitsPattern(element) ? Purpose::Digits : Purpose::Number;
80
else if (element.isURLField())
81
purpose = Purpose::Url;
82
else if (element.isText() && inputElementHasDigitsPattern(element))
83
purpose = Purpose::Digits;
86
void InputMethodState::addHintsForAutocapitalizeType(AutocapitalizeType autocapitalizeType)
88
switch (autocapitalizeType) {
89
case AutocapitalizeTypeDefault:
91
case AutocapitalizeTypeNone:
92
hints.add(InputMethodState::Hint::Lowercase);
94
case AutocapitalizeTypeWords:
95
hints.add(InputMethodState::Hint::UppercaseWords);
97
case AutocapitalizeTypeSentences:
98
hints.add(InputMethodState::Hint::UppercaseSentences);
100
case AutocapitalizeTypeAllCharacters:
101
hints.add(InputMethodState::Hint::UppercaseChars);
106
void InputMethodState::encode(IPC::Encoder& encoder) const
108
encoder.encodeEnum(purpose);
112
Optional<InputMethodState> InputMethodState::decode(IPC::Decoder& decoder)
114
InputMethodState state;
115
if (!decoder.decodeEnum(state.purpose))
117
if (!decoder.decode(state.hints))
122
} // namespace WebKit