Chromium Code Reviews| Index: Source/web/WebViewImpl.cpp |
| diff --git a/Source/web/WebViewImpl.cpp b/Source/web/WebViewImpl.cpp |
| index 562484e7fd1a4d3ed832efc95f0109442bc1a05a..1a5c76d0a407ec7a908f50d88ddc03df13b3eec8 100644 |
| --- a/Source/web/WebViewImpl.cpp |
| +++ b/Source/web/WebViewImpl.cpp |
| @@ -37,6 +37,7 @@ |
| #include "core/clipboard/DataObject.h" |
| #include "core/dom/Document.h" |
| #include "core/dom/DocumentMarkerController.h" |
| +#include "core/dom/ElementTraversal.h" |
| #include "core/dom/Fullscreen.h" |
| #include "core/dom/LayoutTreeBuilderTraversal.h" |
| #include "core/dom/Text.h" |
| @@ -61,6 +62,7 @@ |
| #include "core/frame/SmartClip.h" |
| #include "core/frame/TopControls.h" |
| #include "core/frame/VisualViewport.h" |
| +#include "core/html/HTMLFormElement.h" |
| #include "core/html/HTMLInputElement.h" |
| #include "core/html/HTMLMediaElement.h" |
| #include "core/html/HTMLPlugInElement.h" |
| @@ -2519,9 +2521,83 @@ int WebViewImpl::textInputFlags() |
| } |
| } |
| + if (isListeningToKeyboardEvents(element)) |
| + flags |= WebTextInputFlagListeningToKeyboardEvents; |
| + |
| + if (nextFocusableElementInForm(element, WebFocusTypeForward)) |
| + flags |= WebTextInputFlagHaveNextFocusableElement; |
| + |
| + if (nextFocusableElementInForm(element, WebFocusTypeBackward)) |
| + flags |= WebTextInputFlagHavePreviousFocusableElement; |
| + |
| return flags; |
| } |
| +Element* WebViewImpl::nextFocusableElementInForm(Element* element, WebFocusType focusType) |
| +{ |
| + if (!element->isFormControlElement() && !element->isContentEditable()) |
| + return nullptr; |
| + |
| + HTMLFormElement* formOwner = nullptr; |
| + if (element->isContentEditable()) |
| + formOwner = Traversal<HTMLFormElement>::firstAncestor(*element); |
| + else |
| + formOwner = toHTMLFormControlElement(element)->formOwner(); |
| + |
| + if (!formOwner) |
| + return nullptr; |
| + |
| + Element* nextElement = element; |
| + while (nextElement) { |
| + nextElement = page()->focusController().findFocusableElement(focusType, *nextElement); |
| + if (!nextElement) |
| + return nullptr; |
|
kochi
2015/08/12 10:47:33
How about using for()?
for (Element* nextElement
AKV
2015/08/12 11:10:14
Done.
|
| + if (nextElement->isContentEditable() && nextElement->isDescendantOf(formOwner)) |
| + return nextElement; |
| + if (!nextElement->isFormControlElement()) |
| + continue; |
| + HTMLFormControlElement* formElement = toHTMLFormControlElement(nextElement); |
| + if (formElement->formOwner() != formOwner) |
| + continue; |
| + // Skip disabled or readonly editable elements. |
| + if (formElement->isDisabledOrReadOnly()) |
| + continue; |
| + LayoutObject* layout = nextElement->layoutObject(); |
| + if (layout && layout->isTextControl()) { |
| + // TODO(ajith.v) Extend it for Select element, Radio button and Check boxes |
| + return nextElement; |
| + } |
| + } |
| + return nullptr; |
| +} |
| + |
| +bool WebViewImpl::isListeningToKeyboardEvents(Element* element) |
| +{ |
| + if (!element->isFormControlElement() && !element->isContentEditable()) |
| + return false; |
| + Node* node = element; |
| + do { |
|
kochi
2015/08/12 10:47:33
Ditto.
for (Node* node = element; node; node = no
AKV
2015/08/12 11:10:14
Done.
|
| + if (node->hasEventListeners(EventTypeNames::keydown) || node->hasEventListeners(EventTypeNames::keypress) || node->hasEventListeners(EventTypeNames::keyup)) |
| + return true; |
| + node = node->parentNode(); |
| + } while (node); |
| + return false; |
| +} |
| + |
| +void WebViewImpl::advanceFocusInForm(WebFocusType focusType) |
| +{ |
| + Element* element = focusedElement(); |
| + if (!element) |
| + return; |
| + |
| + RefPtrWillBeRawPtr<Element> nextElement = nextFocusableElementInForm(element, focusType); |
| + if (!nextElement) |
| + return; |
| + |
| + nextElement->scrollIntoViewIfNeeded(true /*centerIfNeeded*/); |
| + nextElement->focus(false, focusType); |
| +} |
| + |
| WebString WebViewImpl::inputModeOfFocusedElement() |
| { |
| if (!RuntimeEnabledFeatures::inputModeAttributeEnabled()) |