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

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: Rebased the patch along with review comment fixes. Created 3 years, 7 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.GetDocument()->FocusedElement(); 58 Element* target = frame.GetDocument()->FocusedElement();
55 if (!target) 59 if (!target)
56 return; 60 return;
57 61
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 flags |= kWebTextInputFlagAutocapitalizeCharacters; 1140 flags |= kWebTextInputFlagAutocapitalizeCharacters;
1137 else if (autocapitalize == words) 1141 else if (autocapitalize == words)
1138 flags |= kWebTextInputFlagAutocapitalizeWords; 1142 flags |= kWebTextInputFlagAutocapitalizeWords;
1139 else if (autocapitalize == sentences) 1143 else if (autocapitalize == sentences)
1140 flags |= kWebTextInputFlagAutocapitalizeSentences; 1144 flags |= kWebTextInputFlagAutocapitalizeSentences;
1141 else 1145 else
1142 NOTREACHED(); 1146 NOTREACHED();
1143 } 1147 }
1144 } 1148 }
1145 1149
1150 if (IsListeningToKeyboardEvents(element))
1151 flags |= kWebTextInputFlagListeningToKeyboardEvents;
1152
1153 if (NextFocusableElementInForm(element, kWebFocusTypeForward))
1154 flags |= kWebTextInputFlagHaveNextFocusableElement;
1155
1156 if (NextFocusableElementInForm(element, kWebFocusTypeBackward))
1157 flags |= kWebTextInputFlagHavePreviousFocusableElement;
1158
1146 return flags; 1159 return flags;
1147 } 1160 }
1148 1161
1162 bool InputMethodController::IsListeningToKeyboardEvents(
Changwan Ryu 2017/04/27 16:34:54 I'm not sure if this makes much sense... There are
yosin_UTC9 2017/04/28 03:32:11 Agree with changewan@. This is too specific and co
AKVT 2017/05/03 14:35:12 Yes I am convinced here, as it has a very narrow c
1163 Element* element) const {
1164 if (!element->IsFormControlElement() &&
1165 !ToHTMLElement(element)->isContentEditableForBinding())
1166 return false;
1167 for (Node* node = element; node; node = node->parentNode()) {
1168 if (node->HasEventListeners(EventTypeNames::keydown) ||
1169 node->HasEventListeners(EventTypeNames::keypress) ||
1170 node->HasEventListeners(EventTypeNames::keyup))
1171 return true;
1172 }
1173 return false;
1174 }
1175
1176 Element* InputMethodController::NextFocusableElementInForm(
yosin_UTC9 2017/04/28 01:07:28 This function should be in FocusController instead
yosin_UTC9 2017/04/28 03:32:11 I think this function should be implemented on top
AKVT 2017/05/03 14:35:12 Done.
AKVT 2017/05/03 14:35:12 Done.
1177 Element* element,
1178 WebFocusType focusType) const {
1179 if (!element->IsFormControlElement() &&
1180 !ToHTMLElement(element)->isContentEditableForBinding())
1181 return nullptr;
1182
1183 HTMLFormElement* formOwner = nullptr;
1184 if (ToHTMLElement(element)->isContentEditableForBinding())
1185 formOwner = Traversal<HTMLFormElement>::FirstAncestor(*element);
1186 else
1187 formOwner = ToHTMLFormControlElement(element)->formOwner();
1188
1189 if (!formOwner)
1190 return nullptr;
1191
1192 Element* nextElement = element;
1193 for (nextElement =
1194 GetDocument().GetPage()->GetFocusController().FindFocusableElement(
1195 focusType, *nextElement);
1196 nextElement;
1197 nextElement =
1198 GetDocument().GetPage()->GetFocusController().FindFocusableElement(
1199 focusType, *nextElement)) {
1200 if (ToHTMLElement(nextElement)->isContentEditableForBinding() &&
1201 nextElement->IsDescendantOf(formOwner))
1202 return nextElement;
1203 if (!nextElement->IsFormControlElement())
1204 continue;
1205 HTMLFormControlElement* formElement = ToHTMLFormControlElement(nextElement);
1206 if (formElement->formOwner() != formOwner)
1207 continue;
1208 // Skip disabled or readonly editable elements.
1209 if (formElement->IsDisabledOrReadOnly())
1210 continue;
1211 LayoutObject* layout = nextElement->GetLayoutObject();
1212 if (layout && layout->IsTextControl()) {
1213 // TODO(ajith.v) Extend it for Select element, Radio button and Check
1214 // boxes
1215 return nextElement;
1216 }
1217 }
1218 return nullptr;
1219 }
1220
1149 WebTextInputMode InputMethodController::InputModeOfFocusedElement() const { 1221 WebTextInputMode InputMethodController::InputModeOfFocusedElement() const {
1150 if (!RuntimeEnabledFeatures::inputModeAttributeEnabled()) 1222 if (!RuntimeEnabledFeatures::inputModeAttributeEnabled())
1151 return kWebTextInputModeDefault; 1223 return kWebTextInputModeDefault;
1152 1224
1153 AtomicString mode = GetInputModeAttribute(GetDocument().FocusedElement()); 1225 AtomicString mode = GetInputModeAttribute(GetDocument().FocusedElement());
1154 1226
1155 if (mode.IsEmpty()) 1227 if (mode.IsEmpty())
1156 return kWebTextInputModeDefault; 1228 return kWebTextInputModeDefault;
1157 if (mode == InputModeNames::verbatim) 1229 if (mode == InputModeNames::verbatim)
1158 return kWebTextInputModeVerbatim; 1230 return kWebTextInputModeVerbatim;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 FinishComposingText(kKeepSelection); 1319 FinishComposingText(kKeepSelection);
1248 } 1320 }
1249 1321
1250 DEFINE_TRACE(InputMethodController) { 1322 DEFINE_TRACE(InputMethodController) {
1251 visitor->Trace(frame_); 1323 visitor->Trace(frame_);
1252 visitor->Trace(composition_range_); 1324 visitor->Trace(composition_range_);
1253 SynchronousMutationObserver::Trace(visitor); 1325 SynchronousMutationObserver::Trace(visitor);
1254 } 1326 }
1255 1327
1256 } // namespace blink 1328 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698