Title: [91892] trunk/Source/WebKit/chromium
Revision
91892
Author
[email protected]
Date
2011-07-27 19:57:21 -0700 (Wed, 27 Jul 2011)

Log Message

Add more text input types for chromium
https://bugs.webkit.org/show_bug.cgi?id=64937

Patch by Peng Huang <[email protected]> on 2011-07-27
Reviewed by Darin Fisher.

* public/WebTextInputType.h:
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::textInputType):

Modified Paths

Diff

Modified: trunk/Source/WebKit/chromium/ChangeLog (91891 => 91892)


--- trunk/Source/WebKit/chromium/ChangeLog	2011-07-28 02:31:39 UTC (rev 91891)
+++ trunk/Source/WebKit/chromium/ChangeLog	2011-07-28 02:57:21 UTC (rev 91892)
@@ -1,3 +1,14 @@
+2011-07-27  Peng Huang  <[email protected]>
+
+        Add more text input types for chromium
+        https://bugs.webkit.org/show_bug.cgi?id=64937
+
+        Reviewed by Darin Fisher.
+
+        * public/WebTextInputType.h:
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::textInputType):
+
 2011-07-27  Ryosuke Niwa  <[email protected]>
 
         Add sfntly library to the Chromium DEPS file.

Modified: trunk/Source/WebKit/chromium/public/WebTextInputType.h (91891 => 91892)


--- trunk/Source/WebKit/chromium/public/WebTextInputType.h	2011-07-28 02:31:39 UTC (rev 91891)
+++ trunk/Source/WebKit/chromium/public/WebTextInputType.h	2011-07-28 02:57:21 UTC (rev 91892)
@@ -40,12 +40,14 @@
     // Input caret is in a normal editable node, any input method can be used.
     WebTextInputTypeText,
 
-    // Input caret is in a password box, an input method may be used only if
-    // it's suitable for password input.
+    // Input caret is in a specific input field, and input method may be used
+    // only if it's suitable for the specific input field.
     WebTextInputTypePassword,
-
-    // FIXME: Add more text input types when necessary, eg. Number,
-    // Date, Email, URL, etc.
+    WebTextInputTypeSearch,
+    WebTextInputTypeEmail,
+    WebTextInputTypeNumber,
+    WebTextInputTypeTelephone,
+    WebTextInputTypeURL,
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (91891 => 91892)


--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2011-07-28 02:31:39 UTC (rev 91891)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2011-07-28 02:57:21 UTC (rev 91892)
@@ -66,6 +66,7 @@
 #include "HTMLInputElement.h"
 #include "HTMLMediaElement.h"
 #include "HTMLNames.h"
+#include "HTMLTextAreaElement.h"
 #include "HitTestResult.h"
 #include "Image.h"
 #include "ImageBuffer.h"
@@ -1453,31 +1454,49 @@
 
 WebTextInputType WebViewImpl::textInputType()
 {
-    WebTextInputType type = WebTextInputTypeNone;
-    const Frame* focused = focusedWebCoreFrame();
-    if (!focused)
-        return type;
+    Node* node = focusedWebCoreNode();
+    if (!node)
+        return WebTextInputTypeNone;
 
-    const Editor* editor = focused->editor();
-    if (!editor || !editor->canEdit())
-        return type;
+    if (node->nodeType() == Node::ELEMENT_NODE) {
+        Element* element = static_cast<Element*>(node);
+        if (element->hasLocalName(HTMLNames::inputTag)) {
+            HTMLInputElement* input = static_cast<HTMLInputElement*>(element);
 
-    FrameSelection* selection = focused->selection();
-    if (!selection)
-        return type;
+            if (input->readOnly() || input->disabled())
+                return WebTextInputTypeNone;
 
-    Node* node = selection->start().containerNode();
-    if (!node)
-        return type;
+            if (input->isPasswordField())
+                return WebTextInputTypePassword;
+            if (input->isSearchField())
+                return WebTextInputTypeSearch;
+            if (input->isEmailField())
+                return WebTextInputTypeEmail;
+            if (input->isNumberField())
+                return WebTextInputTypeNumber;
+            if (input->isTelephoneField())
+                return WebTextInputTypeTelephone;
+            if (input->isURLField())
+                return WebTextInputTypeURL;
+            if (input->isTextField())
+                return WebTextInputTypeText;
+            return WebTextInputTypeNone;
+        }
 
-    // FIXME: Support more text input types when necessary, eg. Number,
-    // Date, Email, URL, etc.
-    if (selection->isInPasswordField())
-        type = WebTextInputTypePassword;
-    else if (node->shouldUseInputMethod())
-        type = WebTextInputTypeText;
+        if (element->hasLocalName(HTMLNames::textareaTag)) {
+            HTMLTextAreaElement* textarea = static_cast<HTMLTextAreaElement*>(element);
 
-    return type;
+            if (textarea->readOnly() || textarea->disabled())
+                return WebTextInputTypeNone;
+            return WebTextInputTypeText;
+        }
+    }
+
+    // For other situations.
+    if (node->shouldUseInputMethod())
+        return WebTextInputTypeText;
+
+    return WebTextInputTypeNone;
 }
 
 WebRect WebViewImpl::caretOrSelectionBounds()
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to