Chromium Code Reviews| Index: Source/web/WebViewImpl.cpp |
| diff --git a/Source/web/WebViewImpl.cpp b/Source/web/WebViewImpl.cpp |
| index 03eff0db2ed476a19c6ff94d34c04f0d759b7efc..502a118c8eca67b50a06ec6931c1f6a10cba058b 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" |
| @@ -60,6 +61,7 @@ |
| #include "core/frame/Settings.h" |
| #include "core/frame/SmartClip.h" |
| #include "core/frame/TopControls.h" |
| +#include "core/html/HTMLFormElement.h" |
| #include "core/html/HTMLInputElement.h" |
| #include "core/html/HTMLMediaElement.h" |
| #include "core/html/HTMLPlugInElement.h" |
| @@ -120,6 +122,7 @@ |
| #include "public/platform/WebCompositeAndReadbackAsyncCallback.h" |
| #include "public/platform/WebDragData.h" |
| #include "public/platform/WebFloatPoint.h" |
| +#include "public/platform/WebFocusType.h" |
|
kochi
2015/07/03 04:10:34
It's strange you already used "WebFocusType" in We
AKV
2015/07/26 15:56:34
Done.
|
| #include "public/platform/WebGestureCurve.h" |
| #include "public/platform/WebImage.h" |
| #include "public/platform/WebLayerTreeView.h" |
| @@ -2505,9 +2508,76 @@ 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; |
| + |
| + Node* nextNode = element; |
|
kochi
2015/07/03 04:10:34
Now FocusController::findFocusableElement() return
AKV
2015/07/26 15:56:34
Done.
|
| + while ((nextNode = page()->focusController().findFocusableElement(focusType, *nextNode))) { |
| + if (nextNode->isContentEditable() && nextNode->isDescendantOf(formOwner)) |
| + return toElement(nextNode); |
|
kochi
2015/07/03 04:10:34
If the pointer type is changed to Element*, you do
AKV
2015/07/26 15:56:34
Done.
|
| + if (!toElement(nextNode)->isFormControlElement()) |
|
kochi
2015/07/03 04:10:34
Ditto.
AKV
2015/07/26 15:56:34
Done.
|
| + continue; |
| + HTMLFormControlElement* formElement = toHTMLFormControlElement(nextNode); |
| + if (formElement->formOwner() != formOwner) |
| + continue; |
| + LayoutObject* layout = nextNode->layoutObject(); |
| + if (layout && layout->isTextControl()) { |
| + // TODO(ajith.v) Extend it for Select element, Radio button and Check boxes |
| + return toElement(nextNode); |
|
kochi
2015/07/03 04:10:34
Ditto.
AKV
2015/07/26 15:56:34
Done.
|
| + } |
| + } |
| + return nullptr; |
| +} |
| + |
| +bool WebViewImpl::isListeningToKeyboardEvents(Element* element) |
| +{ |
| + if (!element->isFormControlElement() && !element->isContentEditable()) |
| + return false; |
| + Node* node = element; |
| + do { |
| + if (node->hasEventListeners(EventTypeNames::keydown) || node->hasEventListeners(EventTypeNames::keypress) || node->hasEventListeners(EventTypeNames::keyup)) |
| + return true; |
| + } while ((node = node->parentNode())); |
| + 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()) |