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

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: Extended the navigation support on ContentEditable element inside form. Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/web/WebViewImpl.h ('k') | public/web/WebTextInputType.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/web/WebViewImpl.cpp
diff --git a/Source/web/WebViewImpl.cpp b/Source/web/WebViewImpl.cpp
index b1e7118cb1f524e3f2a50c6ef76f72406a734d44..e8c099462b4f0942ba50b9e1733dc0404612c27b 100644
--- a/Source/web/WebViewImpl.cpp
+++ b/Source/web/WebViewImpl.cpp
@@ -116,6 +116,7 @@
#include "public/platform/WebCompositeAndReadbackAsyncCallback.h"
#include "public/platform/WebDragData.h"
#include "public/platform/WebFloatPoint.h"
+#include "public/platform/WebFocusType.h"
#include "public/platform/WebGestureCurve.h"
#include "public/platform/WebImage.h"
#include "public/platform/WebLayerTreeView.h"
@@ -2519,9 +2520,82 @@ int WebViewImpl::textInputFlags()
}
}
+ if (isListeningToKeyboardEvents(*element))
+ flags |= WebTextInputFlagListeningToKeyboardEvents;
+
+ if (nextFocusableElement(element, WebFocusTypeForward))
+ flags |= WebTextInputFlagHaveNextFocusableElement;
+
+ if (nextFocusableElement(element, WebFocusTypeBackward))
+ flags |= WebTextInputFlagHavePreviousFocusableElement;
+
return flags;
}
+Element* WebViewImpl::nextFocusableElement(Element* element, WebFocusType focusType)
+{
+ if (!element->isFormControlElement() && !element->isContentEditable())
+ return nullptr;
+
+ HTMLFormElement* formOwner = nullptr;
+ if (element->isContentEditable()) {
+ // Check whether it's child of a form element
+ Element* parent = element;
tkent 2015/04/20 01:40:20 formOwner = Traversal<HTMLFormElement>::firstAnces
AKV 2015/04/20 19:46:49 Done. Thanks., this is very simple :)
+ while ((parent = parent->parentElement())) {
+ if (!isHTMLFormElement(parent))
+ continue;
+ formOwner = reinterpret_cast<HTMLFormElement*>(toHTMLElement(parent));
tkent 2015/04/20 01:40:20 Do not use reinterpret_cast<>.
AKV 2015/04/20 19:46:49 Done.
+ break;
+ }
+ } else {
+ HTMLFormControlElement* formControlElement = toHTMLFormControlElement(element);
tkent 2015/04/20 01:40:21 formOwner = toHTMLFormControlElement(element)->for
AKV 2015/04/20 19:46:49 Done.
+ formOwner = formControlElement->formOwner();
+ }
+
+ if (!formOwner)
+ return nullptr;
+
+ Node* nextNode = element;
+ while ((nextNode = page()->focusController().findFocusableNode(focusType, *nextNode))) {
+ if (nextNode->isContentEditable() && nextNode->isDescendantOf(reinterpret_cast<Node*>(formOwner)))
tkent 2015/04/20 01:40:21 Do not use reinterpret_cast<>.
AKV 2015/04/20 19:46:49 Done.
+ return toElement(nextNode);
+ if (!toElement(nextNode)->isFormControlElement())
+ continue;
+ HTMLFormControlElement* formElement = toHTMLFormControlElement(nextNode);
+ if (formElement->formOwner() != formOwner)
+ continue;
+ LayoutObject* layout = nextNode->layoutObject();
+ if (layout && layout->isTextControl()) {
+ // TODO(AKV) Extend it for Select element, Radio button and Check boxes
tkent 2015/04/20 01:40:21 Please use the username part of your @chromium.org
AKV 2015/04/20 19:46:49 Done.
+ return toElement(nextNode);
+ }
+ }
+ return nullptr;
+}
+
+bool WebViewImpl::isListeningToKeyboardEvents(const Element& element)
+{
+ if (!element.isFormControlElement())
tkent 2015/04/20 01:40:21 This returns a wrong result for contenteditable e
AKV 2015/04/20 19:46:49 Thanks. I corrected :)
+ return false;
+
+ return (element.hasEventListeners(EventTypeNames::keydown) || element.hasEventListeners(EventTypeNames::keypress) || element.hasEventListeners(EventTypeNames::keyup));
tkent 2015/04/20 01:40:20 I found this didn't work for the following case.
AKV 2015/04/20 19:46:49 Thanks. I just corrected using document listener a
+}
+
+void WebViewImpl::advanceFocusToNextFormControl(WebFocusType focusType)
tkent 2015/04/20 01:40:21 You clarified you'd like to handle contenteditable
AKV 2015/04/20 19:46:49 Done. Thanks
+{
+ Element* element = focusedElement();
+ if (!element)
+ return;
+
+ Element* nextElement = nextFocusableElement(element, focusType);
tkent 2015/04/20 01:40:21 You can make |nextElement| RefPtrWillBeRawPtr<Elem
AKV 2015/04/20 19:46:49 Done.
+ if (!nextElement)
+ return;
+
+ RefPtrWillBeRawPtr<Element> nextFocusElement = nextElement;
+ nextFocusElement->scrollIntoViewIfNeeded(true /*centerIfNeeded*/);
+ nextFocusElement->focus(false, focusType);
+}
+
WebString WebViewImpl::inputModeOfFocusedElement()
{
if (!RuntimeEnabledFeatures::inputModeAttributeEnabled())
« no previous file with comments | « Source/web/WebViewImpl.h ('k') | public/web/WebTextInputType.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698