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

Unified Diff: Source/web/WebViewImpl.cpp

Issue 939603002: Adding support for Smart GO NEXT feature in Android Chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: Source/web/WebViewImpl.cpp
diff --git a/Source/web/WebViewImpl.cpp b/Source/web/WebViewImpl.cpp
index 0058e054eb3038f1b91e0da696fe6666b71a7b88..cd056751413928f1c537fc243b8d86261e15a4e8 100644
--- a/Source/web/WebViewImpl.cpp
+++ b/Source/web/WebViewImpl.cpp
@@ -2432,9 +2432,106 @@ int WebViewImpl::textInputFlags()
else if (spellcheck == "off")
flags |= WebTextInputFlagSpellcheckOff;
+ if (wantEnterEvents(element)) {
+ flags |= WebTextInputFlagWantEnterEvents;
+ }
+
+ if (havePreviousInput(element)) {
+ flags |= WebTextInputFlagHavePreviousInput;
+ }
+
+ if (haveNextInput(element)) {
+ flags |= WebTextInputFlagHaveNextInput;
+ }
return flags;
}
+Element* WebViewImpl::haveNextInput(Element* element)
+{
+ if (!element->isFormControlElement())
+ return 0;
+
+ HTMLFormControlElement* formControlElement = toHTMLFormControlElement(element);
bcwhite 2015/02/24 17:06:23 80 character line limits
yosin_UTC9 2015/02/25 01:25:36 Blink coding style rule allows lines to over 80 ch
AKV 2015/04/08 18:38:12 Done.
+ Node* parentFormNode = reinterpret_cast<Node*>(formControlElement->formOwner());
yosin_UTC9 2015/02/25 01:25:36 We don't need to use |reinterpret_cast<Node*>|. |f
+ if (!parentFormNode)
+ return 0;
yosin_UTC9 2015/02/25 01:25:36 nit: better to use |nullptr|.
AKV 2015/04/08 18:38:12 Done.
+ Node* nextNode = static_cast<Node*>(element)->nextSibling();
yosin_UTC9 2015/02/25 01:25:36 nit: We don't need to cast to |Node| for |element|
+ // Find all children of parentForm and do the checks
+ // NodeList childNodes = static_cast<Node*>(parentFormElement)->childNodes();
+ while ((nextNode = NodeRenderingTraversal::next(nextNode, parentFormNode))) {
yosin_UTC9 2015/02/25 01:25:36 I think we should use tab order rather than render
AKV 2015/04/08 18:38:12 Done.
+ RenderObject* renderer = nextNode->renderer();
+ if (nextNode->isContentEditable() || (renderer && renderer->isTextControl())) {
+ if (nextNode->isElementNode()) {
+ return toElement(nextNode);
+ }
+ }
+ // TODO(AKV) Need to handle when form has an iframe/frame as its child.
+ }
+ return 0;
yosin_UTC9 2015/02/25 01:25:36 nit: better to use |nullptr|.
AKV 2015/04/08 18:38:12 Done.
+}
+
+Element* WebViewImpl::havePreviousInput(Element* element)
+{
+ if (!element->isFormControlElement())
+ return 0;
yosin_UTC9 2015/02/25 01:25:36 nit: better to use |nullptr|.
AKV 2015/04/08 18:38:12 Done.
AKV 2015/04/08 18:38:12 Done.
+
+ HTMLFormControlElement* formControlElement = toHTMLFormControlElement(element);
+ Node* parentFormNode = reinterpret_cast<Node*>(formControlElement->formOwner());
yosin_UTC9 2015/02/25 01:25:36 We don't need to use |reinterpret_cast<Node*>|. |f
AKV 2015/04/08 18:38:12 I wanted to use Node pointer to pass to FocusContr
+ if (!parentFormNode)
+ return 0;
+ Node* previousNode = static_cast<Node*>(element)->previousSibling();
+ while ((previousNode = NodeRenderingTraversal::previous(previousNode, parentFormNode))) {
+ RenderObject* renderer = previousNode->renderer();
+ if (previousNode->isContentEditable() || (renderer && renderer->isTextControl())) {
+ if (previousNode->isElementNode()) {
+ return toElement(previousNode);
+ }
+ }
+ // TODO(AKV) Need to handle when form has an iframe/frame as its child.
+ }
+ return 0;
+}
+
+bool WebViewImpl::wantEnterEvents(Element* element)
+{
+ if (!element->isFormControlElement())
+ return false;
+
+ if (element->hasEventListeners(EventTypeNames::keydown) || element->hasEventListeners(EventTypeNames::keypress) || element->hasEventListeners(EventTypeNames::keyup))
+ return true;
+
+ return false;
+}
+
+void WebViewImpl::advanceFocusToNextInputField(bool direction)
+{
+ Element* element = focusedElement();
+ if (!element)
+ return;
+
+ HTMLFormControlElement* formControlElement = toHTMLFormControlElement(element);
+ HTMLFormElement* parentFormElement = formControlElement->formOwner();
+ if (!parentFormElement) // There is no form element as parent, so navigation is not required.
+ return;
+
+ Element* nextElement = element;
+ FocusType focusType = FocusTypeNone;
+ if (direction) {
+ focusType = FocusTypeForward;
+ nextElement = haveNextInput(element);
+ } else {
+ nextElement = havePreviousInput(element);
+ focusType = FocusTypeBackward;
+ }
+
+ if (!nextElement)
+ return;
+
+ nextElement->scrollIntoViewIfNeeded(true /*centerIfNeeded*/);
+ nextElement->dispatchSimulatedClick(0, SendMouseUpDownEvents);
+ nextElement->focus(false, focusType);
+}
+
WebString WebViewImpl::inputModeOfFocusedElement()
{
if (!RuntimeEnabledFeatures::inputModeAttributeEnabled())
« no previous file with comments | « Source/web/WebViewImpl.h ('k') | public/web/WebTextInputType.h » ('j') | public/web/WebView.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698