Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/InputMethodController.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/InputMethodController.cpp b/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
| index 1d880e513e4a5ed8d765678f2a04352ee79b47ec..b13181a2d83da7366b0572feec4c6240b1ec61db 100644 |
| --- a/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
| +++ b/third_party/WebKit/Source/core/editing/InputMethodController.cpp |
| @@ -30,6 +30,7 @@ |
| #include "core/InputTypeNames.h" |
| #include "core/dom/Document.h" |
| #include "core/dom/Element.h" |
| +#include "core/dom/ElementTraversal.h" |
| #include "core/dom/Text.h" |
| #include "core/editing/EditingUtilities.h" |
| #include "core/editing/Editor.h" |
| @@ -39,12 +40,15 @@ |
| #include "core/editing/state_machines/ForwardCodePointStateMachine.h" |
| #include "core/events/CompositionEvent.h" |
| #include "core/frame/LocalFrame.h" |
| +#include "core/html/HTMLFormElement.h" |
| #include "core/html/HTMLInputElement.h" |
| #include "core/html/HTMLTextAreaElement.h" |
| #include "core/input/EventHandler.h" |
| #include "core/layout/LayoutObject.h" |
| #include "core/layout/LayoutTheme.h" |
| #include "core/page/ChromeClient.h" |
| +#include "core/page/FocusController.h" |
| +#include "core/page/Page.h" |
| namespace blink { |
| @@ -1143,9 +1147,77 @@ int InputMethodController::TextInputFlags() const { |
| } |
| } |
| + if (IsListeningToKeyboardEvents(element)) |
| + flags |= kWebTextInputFlagListeningToKeyboardEvents; |
| + |
| + if (NextFocusableElementInForm(element, kWebFocusTypeForward)) |
| + flags |= kWebTextInputFlagHaveNextFocusableElement; |
| + |
| + if (NextFocusableElementInForm(element, kWebFocusTypeBackward)) |
| + flags |= kWebTextInputFlagHavePreviousFocusableElement; |
| + |
| return flags; |
| } |
| +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
|
| + Element* element) const { |
| + if (!element->IsFormControlElement() && |
| + !ToHTMLElement(element)->isContentEditableForBinding()) |
| + return false; |
| + for (Node* node = element; node; node = node->parentNode()) { |
| + if (node->HasEventListeners(EventTypeNames::keydown) || |
| + node->HasEventListeners(EventTypeNames::keypress) || |
| + node->HasEventListeners(EventTypeNames::keyup)) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +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.
|
| + Element* element, |
| + WebFocusType focusType) const { |
| + if (!element->IsFormControlElement() && |
| + !ToHTMLElement(element)->isContentEditableForBinding()) |
| + return nullptr; |
| + |
| + HTMLFormElement* formOwner = nullptr; |
| + if (ToHTMLElement(element)->isContentEditableForBinding()) |
| + formOwner = Traversal<HTMLFormElement>::FirstAncestor(*element); |
| + else |
| + formOwner = ToHTMLFormControlElement(element)->formOwner(); |
| + |
| + if (!formOwner) |
| + return nullptr; |
| + |
| + Element* nextElement = element; |
| + for (nextElement = |
| + GetDocument().GetPage()->GetFocusController().FindFocusableElement( |
| + focusType, *nextElement); |
| + nextElement; |
| + nextElement = |
| + GetDocument().GetPage()->GetFocusController().FindFocusableElement( |
| + focusType, *nextElement)) { |
| + if (ToHTMLElement(nextElement)->isContentEditableForBinding() && |
| + 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->GetLayoutObject(); |
| + if (layout && layout->IsTextControl()) { |
| + // TODO(ajith.v) Extend it for Select element, Radio button and Check |
| + // boxes |
| + return nextElement; |
| + } |
| + } |
| + return nullptr; |
| +} |
| + |
| WebTextInputMode InputMethodController::InputModeOfFocusedElement() const { |
| if (!RuntimeEnabledFeatures::inputModeAttributeEnabled()) |
| return kWebTextInputModeDefault; |