| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // See TextEvent.idl. | 131 // See TextEvent.idl. |
| 132 frame.eventHandler().handleTextInputEvent(text, 0, | 132 frame.eventHandler().handleTextInputEvent(text, 0, |
| 133 TextEventInputComposition); | 133 TextEventInputComposition); |
| 134 break; | 134 break; |
| 135 default: | 135 default: |
| 136 NOTREACHED(); | 136 NOTREACHED(); |
| 137 } | 137 } |
| 138 // TODO(chongz): Fire 'input' event. | 138 // TODO(chongz): Fire 'input' event. |
| 139 } | 139 } |
| 140 | 140 |
| 141 AtomicString getInputModeAttribute(Element* element) { |
| 142 if (!element) |
| 143 return AtomicString(); |
| 144 |
| 145 bool queryAttribute = false; |
| 146 if (isHTMLInputElement(*element)) { |
| 147 queryAttribute = toHTMLInputElement(*element).supportsInputModeAttribute(); |
| 148 } else if (isHTMLTextAreaElement(*element)) { |
| 149 queryAttribute = true; |
| 150 } else { |
| 151 element->document().updateStyleAndLayoutTree(); |
| 152 if (hasEditableStyle(*element)) |
| 153 queryAttribute = true; |
| 154 } |
| 155 |
| 156 if (!queryAttribute) |
| 157 return AtomicString(); |
| 158 |
| 159 // TODO(dtapuska): We may wish to restrict this to a yet to be proposed |
| 160 // <contenteditable> or <richtext> element Mozilla discussed at TPAC 2016. |
| 161 return element->fastGetAttribute(HTMLNames::inputmodeAttr).lower(); |
| 162 } |
| 163 |
| 141 } // anonymous namespace | 164 } // anonymous namespace |
| 142 | 165 |
| 143 InputMethodController* InputMethodController::create(LocalFrame& frame) { | 166 InputMethodController* InputMethodController::create(LocalFrame& frame) { |
| 144 return new InputMethodController(frame); | 167 return new InputMethodController(frame); |
| 145 } | 168 } |
| 146 | 169 |
| 147 InputMethodController::InputMethodController(LocalFrame& frame) | 170 InputMethodController::InputMethodController(LocalFrame& frame) |
| 148 : m_frame(&frame), m_isDirty(false), m_hasComposition(false) {} | 171 : m_frame(&frame), m_isDirty(false), m_hasComposition(false) {} |
| 149 | 172 |
| 150 bool InputMethodController::hasComposition() const { | 173 bool InputMethodController::hasComposition() const { |
| (...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 } | 1064 } |
| 1042 } | 1065 } |
| 1043 | 1066 |
| 1044 return flags; | 1067 return flags; |
| 1045 } | 1068 } |
| 1046 | 1069 |
| 1047 WebTextInputMode InputMethodController::inputModeOfFocusedElement() const { | 1070 WebTextInputMode InputMethodController::inputModeOfFocusedElement() const { |
| 1048 if (!RuntimeEnabledFeatures::inputModeAttributeEnabled()) | 1071 if (!RuntimeEnabledFeatures::inputModeAttributeEnabled()) |
| 1049 return kWebTextInputModeDefault; | 1072 return kWebTextInputModeDefault; |
| 1050 | 1073 |
| 1051 Element* element = frame().document()->focusedElement(); | 1074 AtomicString mode = |
| 1052 if (!element) | 1075 getInputModeAttribute(frame().document()->focusedElement()); |
| 1053 return kWebTextInputModeDefault; | |
| 1054 | |
| 1055 AtomicString mode; | |
| 1056 if (isHTMLInputElement(*element)) { | |
| 1057 const HTMLInputElement& input = toHTMLInputElement(*element); | |
| 1058 if (input.supportsInputModeAttribute()) | |
| 1059 mode = input.fastGetAttribute(HTMLNames::inputmodeAttr).lower(); | |
| 1060 } | |
| 1061 if (isHTMLTextAreaElement(*element)) { | |
| 1062 const HTMLTextAreaElement& textarea = toHTMLTextAreaElement(*element); | |
| 1063 mode = textarea.fastGetAttribute(HTMLNames::inputmodeAttr).lower(); | |
| 1064 } | |
| 1065 | 1076 |
| 1066 if (mode.isEmpty()) | 1077 if (mode.isEmpty()) |
| 1067 return kWebTextInputModeDefault; | 1078 return kWebTextInputModeDefault; |
| 1068 if (mode == InputModeNames::verbatim) | 1079 if (mode == InputModeNames::verbatim) |
| 1069 return kWebTextInputModeVerbatim; | 1080 return kWebTextInputModeVerbatim; |
| 1070 if (mode == InputModeNames::latin) | 1081 if (mode == InputModeNames::latin) |
| 1071 return kWebTextInputModeLatin; | 1082 return kWebTextInputModeLatin; |
| 1072 if (mode == InputModeNames::latin_name) | 1083 if (mode == InputModeNames::latin_name) |
| 1073 return kWebTextInputModeLatinName; | 1084 return kWebTextInputModeLatinName; |
| 1074 if (mode == InputModeNames::latin_prose) | 1085 if (mode == InputModeNames::latin_prose) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 | 1165 |
| 1155 return WebTextInputTypeNone; | 1166 return WebTextInputTypeNone; |
| 1156 } | 1167 } |
| 1157 | 1168 |
| 1158 DEFINE_TRACE(InputMethodController) { | 1169 DEFINE_TRACE(InputMethodController) { |
| 1159 visitor->trace(m_frame); | 1170 visitor->trace(m_frame); |
| 1160 visitor->trace(m_compositionRange); | 1171 visitor->trace(m_compositionRange); |
| 1161 } | 1172 } |
| 1162 | 1173 |
| 1163 } // namespace blink | 1174 } // namespace blink |
| OLD | NEW |