diff options
author | George Mount <mount@google.com> | 2012-02-16 14:12:59 -0800 |
---|---|---|
committer | George Mount <mount@google.com> | 2012-02-22 11:24:33 -0800 |
commit | 8b454995ee6b2833d6730c611f979974c5aabdfa (patch) | |
tree | e203f6f3ff14fb30e69261b1b2fa650d0cb42807 /Source/WebKit | |
parent | 67e33c4976d10fa2cb6fc55455dc4ba1acf4395e (diff) | |
download | external_webkit-8b454995ee6b2833d6730c611f979974c5aabdfa.zip external_webkit-8b454995ee6b2833d6730c611f979974c5aabdfa.tar.gz external_webkit-8b454995ee6b2833d6730c611f979974c5aabdfa.tar.bz2 |
Get input type for text field so that autocorrect works.
Bug 5987568
Get the input type and other necessary information for setting
up the IME.
Framework Change: Ic8c14687a70727148dfc8115c46f09530ca0c0f6
Change-Id: I7eceafdbede8b7b463590a2e875a237241479ad1
Diffstat (limited to 'Source/WebKit')
-rw-r--r-- | Source/WebKit/android/jni/WebViewCore.cpp | 56 | ||||
-rw-r--r-- | Source/WebKit/android/jni/WebViewCore.h | 25 |
2 files changed, 79 insertions, 2 deletions
diff --git a/Source/WebKit/android/jni/WebViewCore.cpp b/Source/WebKit/android/jni/WebViewCore.cpp index c53f3fb..59ef96c 100644 --- a/Source/WebKit/android/jni/WebViewCore.cpp +++ b/Source/WebKit/android/jni/WebViewCore.cpp @@ -80,6 +80,7 @@ #include "HitTestRequest.h" #include "HitTestResult.h" #include "InlineTextBox.h" +#include "KeyboardEvent.h" #include "MemoryUsage.h" #include "NamedNodeMap.h" #include "Navigator.h" @@ -443,7 +444,7 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m #endif m_javaGlue->m_setWebTextViewAutoFillable = GetJMethod(env, clazz, "setWebTextViewAutoFillable", "(ILjava/lang/String;)V"); m_javaGlue->m_selectAt = GetJMethod(env, clazz, "selectAt", "(II)V"); - m_javaGlue->m_initEditField = GetJMethod(env, clazz, "initEditField", "(ILjava/lang/String;II)V"); + m_javaGlue->m_initEditField = GetJMethod(env, clazz, "initEditField", "(ILjava/lang/String;IZZLjava/lang/String;II)V"); m_javaGlue->m_updateMatchCount = GetJMethod(env, clazz, "updateMatchCount", "(IILjava/lang/String;)V"); env->DeleteLocalRef(clazz); @@ -3504,6 +3505,46 @@ bool WebViewCore::handleMouseClick(WebCore::Frame* framePtr, WebCore::Node* node return handled; } +WebViewCore::InputType WebViewCore::getInputType(Node* node) +{ + WebCore::RenderObject* renderer = node->renderer(); + if (!renderer) + return WebViewCore::NONE; + if (renderer->isTextArea()) + return WebViewCore::TEXT_AREA; + + if (node->hasTagName(WebCore::HTMLNames::inputTag)) { + HTMLInputElement* htmlInput = static_cast<HTMLInputElement*>(node); + if (htmlInput->isPasswordField()) + return WebViewCore::PASSWORD; + if (htmlInput->isSearchField()) + return WebViewCore::SEARCH; + if (htmlInput->isEmailField()) + return WebViewCore::EMAIL; + if (htmlInput->isNumberField()) + return WebViewCore::NUMBER; + if (htmlInput->isTelephoneField()) + return WebViewCore::TELEPHONE; + if (htmlInput->isTextField()) + return WebViewCore::NORMAL_TEXT_FIELD; + } + + if (node->isContentEditable()) + return WebViewCore::TEXT_AREA; + + return WebViewCore::NONE; +} + +bool WebViewCore::isSpellCheckEnabled(Node* node) +{ + bool isEnabled = true; + if (node->isElementNode()) { + WebCore::Element* element = static_cast<WebCore::Element*>(node); + isEnabled = element->isSpellCheckingEnabled(); + } + return isEnabled; +} + void WebViewCore::initEditField(Node* node) { String text = getInputText(node); @@ -3515,9 +3556,20 @@ void WebViewCore::initEditField(Node* node) if (!javaObject.get()) return; m_textGeneration = 0; + InputType inputType = getInputType(node); + Document* document = node->document(); + PlatformKeyboardEvent tab(AKEYCODE_TAB, 0, 0, false, false, false, false); + PassRefPtr<KeyboardEvent> tabEvent = + KeyboardEvent::create(tab, document->defaultView()); + Node* nextFocus = document->nextFocusableNode(node, tabEvent.get()); + bool isNextText = isTextInput(nextFocus); + bool spellCheckEnabled = isSpellCheckEnabled(node); + String label = requestLabel(document->frame(), node); jstring fieldText = wtfStringToJstring(env, text, true); + jstring labelText = wtfStringToJstring(env, text, false); env->CallVoidMethod(javaObject.get(), m_javaGlue->m_initEditField, - reinterpret_cast<int>(node), fieldText, start, end); + reinterpret_cast<int>(node), fieldText, inputType, + spellCheckEnabled, isNextText, labelText, start, end); checkException(env); } diff --git a/Source/WebKit/android/jni/WebViewCore.h b/Source/WebKit/android/jni/WebViewCore.h index 315b024..785b659 100644 --- a/Source/WebKit/android/jni/WebViewCore.h +++ b/Source/WebKit/android/jni/WebViewCore.h @@ -641,6 +641,18 @@ namespace android { // internal functions private: + enum InputType { + NONE = -1, + NORMAL_TEXT_FIELD = 0, + TEXT_AREA = 1, + PASSWORD = 2, + SEARCH = 3, + EMAIL = 4, + NUMBER = 5, + TELEPHONE = 6, + URL = 7, + }; + #ifndef DISABLE_NAVCACHE CacheBuilder& cacheBuilder(); #endif @@ -686,6 +698,19 @@ namespace android { * current contents and selection. */ void initEditField(Node* node); + + /** + * Gets the input type a Node. NONE is returned if it isn't an + * input field. + */ + InputType getInputType(Node* node); + + /** + * If node is an input field, the spellcheck value for the + * field is returned. Otherwise true is returned. + */ + static bool isSpellCheckEnabled(Node* node); + /** * Returns the offsets of the selection area for both normal text * fields and content editable fields. start and end are modified |