Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: third_party/WebKit/Source/core/editing/InputMethodController.cpp

Issue 2839993002: [Android] Adding Smart GO/NEXT feature in Chrome (Closed)
Patch Set: Fixed WebViewTest build issues after restructure. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "core/editing/InputMethodController.h" 27 #include "core/editing/InputMethodController.h"
28 28
29 #include "core/InputModeNames.h" 29 #include "core/InputModeNames.h"
30 #include "core/InputTypeNames.h" 30 #include "core/InputTypeNames.h"
31 #include "core/dom/Document.h" 31 #include "core/dom/Document.h"
32 #include "core/dom/Element.h" 32 #include "core/dom/Element.h"
33 #include "core/dom/ElementTraversal.h"
33 #include "core/dom/Text.h" 34 #include "core/dom/Text.h"
34 #include "core/editing/EditingUtilities.h" 35 #include "core/editing/EditingUtilities.h"
35 #include "core/editing/Editor.h" 36 #include "core/editing/Editor.h"
36 #include "core/editing/commands/TypingCommand.h" 37 #include "core/editing/commands/TypingCommand.h"
37 #include "core/editing/markers/DocumentMarkerController.h" 38 #include "core/editing/markers/DocumentMarkerController.h"
38 #include "core/editing/state_machines/BackwardCodePointStateMachine.h" 39 #include "core/editing/state_machines/BackwardCodePointStateMachine.h"
39 #include "core/editing/state_machines/ForwardCodePointStateMachine.h" 40 #include "core/editing/state_machines/ForwardCodePointStateMachine.h"
40 #include "core/events/CompositionEvent.h" 41 #include "core/events/CompositionEvent.h"
41 #include "core/frame/LocalFrame.h" 42 #include "core/frame/LocalFrame.h"
43 #include "core/html/HTMLFormElement.h"
42 #include "core/html/HTMLInputElement.h" 44 #include "core/html/HTMLInputElement.h"
43 #include "core/html/HTMLTextAreaElement.h" 45 #include "core/html/HTMLTextAreaElement.h"
44 #include "core/input/EventHandler.h" 46 #include "core/input/EventHandler.h"
45 #include "core/layout/LayoutObject.h" 47 #include "core/layout/LayoutObject.h"
46 #include "core/layout/LayoutTheme.h" 48 #include "core/layout/LayoutTheme.h"
47 #include "core/page/ChromeClient.h" 49 #include "core/page/ChromeClient.h"
50 #include "core/page/FocusController.h"
51 #include "core/page/Page.h"
48 52
49 namespace blink { 53 namespace blink {
50 54
51 namespace { 55 namespace {
52 56
53 void dispatchCompositionUpdateEvent(LocalFrame& frame, const String& text) { 57 void dispatchCompositionUpdateEvent(LocalFrame& frame, const String& text) {
54 Element* target = frame.document()->focusedElement(); 58 Element* target = frame.document()->focusedElement();
55 if (!target) 59 if (!target)
56 return; 60 return;
57 61
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 flags |= WebTextInputFlagAutocapitalizeCharacters; 1106 flags |= WebTextInputFlagAutocapitalizeCharacters;
1103 else if (autocapitalize == words) 1107 else if (autocapitalize == words)
1104 flags |= WebTextInputFlagAutocapitalizeWords; 1108 flags |= WebTextInputFlagAutocapitalizeWords;
1105 else if (autocapitalize == sentences) 1109 else if (autocapitalize == sentences)
1106 flags |= WebTextInputFlagAutocapitalizeSentences; 1110 flags |= WebTextInputFlagAutocapitalizeSentences;
1107 else 1111 else
1108 NOTREACHED(); 1112 NOTREACHED();
1109 } 1113 }
1110 } 1114 }
1111 1115
1116 if (isListeningToKeyboardEvents(element))
1117 flags |= WebTextInputFlagListeningToKeyboardEvents;
1118
1119 if (nextFocusableElementInForm(element, WebFocusTypeForward))
1120 flags |= WebTextInputFlagHaveNextFocusableElement;
1121
1122 if (nextFocusableElementInForm(element, WebFocusTypeBackward))
1123 flags |= WebTextInputFlagHavePreviousFocusableElement;
1124
1112 return flags; 1125 return flags;
1113 } 1126 }
1114 1127
1128 bool InputMethodController::isListeningToKeyboardEvents(
1129 Element* element) const {
1130 if (!element->isFormControlElement() &&
1131 !toHTMLElement(element)->isContentEditableForBinding())
1132 return false;
1133 for (Node* node = element; node; node = node->parentNode()) {
1134 if (node->hasEventListeners(EventTypeNames::keydown) ||
1135 node->hasEventListeners(EventTypeNames::keypress) ||
1136 node->hasEventListeners(EventTypeNames::keyup))
1137 return true;
1138 }
1139 return false;
1140 }
1141
1142 Element* InputMethodController::nextFocusableElementInForm(
1143 Element* element,
1144 WebFocusType focusType) const {
1145 if (!element->isFormControlElement() &&
1146 !toHTMLElement(element)->isContentEditableForBinding())
1147 return nullptr;
1148
1149 HTMLFormElement* formOwner = nullptr;
1150 if (toHTMLElement(element)->isContentEditableForBinding())
1151 formOwner = Traversal<HTMLFormElement>::firstAncestor(*element);
1152 else
1153 formOwner = toHTMLFormControlElement(element)->formOwner();
1154
1155 if (!formOwner)
1156 return nullptr;
1157
1158 Element* nextElement = element;
1159 for (nextElement = document().page()->focusController().findFocusableElement(
1160 focusType, *nextElement);
1161 nextElement;
1162 nextElement = document().page()->focusController().findFocusableElement(
1163 focusType, *nextElement)) {
1164 if (toHTMLElement(nextElement)->isContentEditableForBinding() &&
1165 nextElement->isDescendantOf(formOwner))
1166 return nextElement;
1167 if (!nextElement->isFormControlElement())
1168 continue;
1169 HTMLFormControlElement* formElement = toHTMLFormControlElement(nextElement);
1170 if (formElement->formOwner() != formOwner)
1171 continue;
1172 // Skip disabled or readonly editable elements.
1173 if (formElement->isDisabledOrReadOnly())
1174 continue;
1175 LayoutObject* layout = nextElement->layoutObject();
1176 if (layout && layout->isTextControl()) {
1177 // TODO(ajith.v) Extend it for Select element, Radio button and Check
1178 // boxes
1179 return nextElement;
1180 }
1181 }
1182 return nullptr;
1183 }
1184
1115 WebTextInputMode InputMethodController::inputModeOfFocusedElement() const { 1185 WebTextInputMode InputMethodController::inputModeOfFocusedElement() const {
1116 if (!RuntimeEnabledFeatures::inputModeAttributeEnabled()) 1186 if (!RuntimeEnabledFeatures::inputModeAttributeEnabled())
1117 return kWebTextInputModeDefault; 1187 return kWebTextInputModeDefault;
1118 1188
1119 AtomicString mode = getInputModeAttribute(document().focusedElement()); 1189 AtomicString mode = getInputModeAttribute(document().focusedElement());
1120 1190
1121 if (mode.isEmpty()) 1191 if (mode.isEmpty())
1122 return kWebTextInputModeDefault; 1192 return kWebTextInputModeDefault;
1123 if (mode == InputModeNames::verbatim) 1193 if (mode == InputModeNames::verbatim)
1124 return kWebTextInputModeVerbatim; 1194 return kWebTextInputModeVerbatim;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 finishComposingText(KeepSelection); 1286 finishComposingText(KeepSelection);
1217 } 1287 }
1218 1288
1219 DEFINE_TRACE(InputMethodController) { 1289 DEFINE_TRACE(InputMethodController) {
1220 visitor->trace(m_frame); 1290 visitor->trace(m_frame);
1221 visitor->trace(m_compositionRange); 1291 visitor->trace(m_compositionRange);
1222 SynchronousMutationObserver::trace(visitor); 1292 SynchronousMutationObserver::trace(visitor);
1223 } 1293 }
1224 1294
1225 } // namespace blink 1295 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698