summaryrefslogtreecommitdiffstats
path: root/WebKit/android/nav
diff options
context:
space:
mode:
authorLeon Scroggins <scroggo@google.com>2010-01-05 10:56:57 -0500
committerLeon Scroggins <scroggo@google.com>2010-01-06 10:14:48 -0500
commit62d9c8e597ebe68adce93008597730a41a1d716b (patch)
tree9b1a4b3a07b4c002b48cbce870ebcf902d0ea683 /WebKit/android/nav
parent3bacb88ba1ca0b7bbce5b16b832cc5acd411e1f9 (diff)
downloadexternal_webkit-62d9c8e597ebe68adce93008597730a41a1d716b.zip
external_webkit-62d9c8e597ebe68adce93008597730a41a1d716b.tar.gz
external_webkit-62d9c8e597ebe68adce93008597730a41a1d716b.tar.bz2
Store label information to be used for hint text.
Fix for http://b/issue?id=2331526 Requires a change to frameworks/base.
Diffstat (limited to 'WebKit/android/nav')
-rw-r--r--WebKit/android/nav/CacheBuilder.cpp24
-rw-r--r--WebKit/android/nav/CachedInput.cpp16
-rw-r--r--WebKit/android/nav/CachedInput.h4
-rw-r--r--WebKit/android/nav/WebView.cpp11
4 files changed, 49 insertions, 6 deletions
diff --git a/WebKit/android/nav/CacheBuilder.cpp b/WebKit/android/nav/CacheBuilder.cpp
index ce78c29..729296d 100644
--- a/WebKit/android/nav/CacheBuilder.cpp
+++ b/WebKit/android/nav/CacheBuilder.cpp
@@ -38,6 +38,7 @@
#include "HTMLAreaElement.h"
#include "HTMLImageElement.h"
#include "HTMLInputElement.h"
+#include "HTMLLabelElement.h"
#include "HTMLMapElement.h"
#include "HTMLNames.h"
#include "HTMLOptionElement.h"
@@ -45,6 +46,7 @@
#include "HTMLTextAreaElement.h"
#include "InlineTextBox.h"
#include "KURL.h"
+#include "NodeList.h"
#include "PluginView.h"
#include "RegisteredEventListener.h"
#include "RenderImage.h"
@@ -860,6 +862,23 @@ static bool checkForPluginViewThatWantsFocus(RenderObject* renderer) {
return false;
}
+// Code copied from AccessibilityRenderObject.cpp. If/when Webkit makes this
+// function public, we can use their version.
+static HTMLLabelElement* labelForElement(Element* element)
+{
+ RefPtr<NodeList> list = element->document()->getElementsByTagName("label");
+ unsigned len = list->length();
+ for (unsigned i = 0; i < len; i++) {
+ if (list->item(i)->hasTagName(HTMLNames::labelTag)) {
+ HTMLLabelElement* label = static_cast<HTMLLabelElement*>(list->item(i));
+ if (label->correspondingControl() == element)
+ return label;
+ }
+ }
+
+ return 0;
+}
+
// when new focus is found, push it's parent on a stack
// as long as more focii are found with the same (grand) parent, note it
// (which only requires retrieving the last parent on the stack)
@@ -1099,7 +1118,7 @@ void CacheBuilder::BuildFrame(Frame* root, Frame* frame,
goto keepTextNode;
}
if (node->hasTagName(WebCore::HTMLNames::inputTag)) {
- HTMLInputElement* input = (HTMLInputElement*) node;
+ HTMLInputElement* input = static_cast<HTMLInputElement*>(node);
HTMLInputElement::InputType inputType = input->inputType();
if (input->isTextField()) {
type = TEXT_INPUT_CACHEDNODETYPE;
@@ -1107,6 +1126,9 @@ void CacheBuilder::BuildFrame(Frame* root, Frame* frame,
cachedInput.setFormPointer(input->form());
cachedInput.setIsTextField(true);
cachedInput.setIsReadOnly(input->readOnly());
+ HTMLLabelElement* label = labelForElement(input);
+ if (label)
+ cachedInput.setLabel(label->innerHTML());
exported = input->value().threadsafeCopy();
cachedInput.setMaxLength(input->maxLength());
cachedInput.setInputType(inputType);
diff --git a/WebKit/android/nav/CachedInput.cpp b/WebKit/android/nav/CachedInput.cpp
index 52d2066..b145591 100644
--- a/WebKit/android/nav/CachedInput.cpp
+++ b/WebKit/android/nav/CachedInput.cpp
@@ -38,18 +38,24 @@ CachedInput* CachedInput::Debug::base() const {
return nav;
}
-void CachedInput::Debug::print() const
-{
- CachedInput* b = base();
+static void printWebCoreString(const char* label,
+ const WebCore::String& string) {
char scratch[256];
- size_t index = snprintf(scratch, sizeof(scratch), "// char* mName=\"");
- const UChar* ch = b->mName.characters();
+ size_t index = snprintf(scratch, sizeof(scratch), label);
+ const UChar* ch = string.characters();
while (ch && *ch && index < sizeof(scratch)) {
UChar c = *ch++;
if (c < ' ' || c >= 0x7f) c = ' ';
scratch[index++] = c;
}
DUMP_NAV_LOGD("%.*s\"\n", index, scratch);
+}
+
+void CachedInput::Debug::print() const
+{
+ CachedInput* b = base();
+ printWebCoreString("// char* mLabel=\"", b->mLabel);
+ printWebCoreString("// char* mName=\"", b->mName);
DUMP_NAV_LOGD("// void* mForm=%p;", b->mForm);
DUMP_NAV_LOGD("// int mMaxLength=%d;\n", b->mMaxLength);
DUMP_NAV_LOGD("// int mTextSize=%d;\n", b->mTextSize);
diff --git a/WebKit/android/nav/CachedInput.h b/WebKit/android/nav/CachedInput.h
index f3cf1fe..a75efe4 100644
--- a/WebKit/android/nav/CachedInput.h
+++ b/WebKit/android/nav/CachedInput.h
@@ -41,12 +41,14 @@ public:
void* formPointer() const { return mForm; }
void init() {
bzero(this, sizeof(CachedInput));
+ mLabel = WebCore::String();
mName = WebCore::String();
}
WebCore::HTMLInputElement::InputType inputType() const { return mInputType; }
bool isReadOnly() const { return mIsReadOnly; }
bool isRtlText() const { return mIsRtlText; }
bool isTextField() const { return mIsTextField; }
+ const WebCore::String& label() const { return mLabel; }
int maxLength() const { return mMaxLength; };
const WebCore::String& name() const { return mName; }
void setFormPointer(void* form) { mForm = form; }
@@ -54,12 +56,14 @@ public:
void setIsReadOnly(bool isReadOnly) { mIsReadOnly = isReadOnly; }
void setIsRtlText(bool isRtlText) { mIsRtlText = isRtlText; }
void setIsTextField(bool isTextField) { mIsTextField = isTextField; }
+ void setLabel(const WebCore::String& label) { mLabel = label; }
void setMaxLength(int maxLength) { mMaxLength = maxLength; }
void setName(const WebCore::String& name) { mName = name; }
void setTextSize(int textSize) { mTextSize = textSize; }
int textSize() const { return mTextSize; }
private:
void* mForm;
+ WebCore::String mLabel;
WebCore::String mName;
int mMaxLength;
int mTextSize;
diff --git a/WebKit/android/nav/WebView.cpp b/WebKit/android/nav/WebView.cpp
index c8d89de..fd6a1da 100644
--- a/WebKit/android/nav/WebView.cpp
+++ b/WebKit/android/nav/WebView.cpp
@@ -1775,6 +1775,15 @@ static bool nativeFocusCandidateIsTextInput(JNIEnv *env, jobject obj)
return node ? node->isTextInput() : false;
}
+static jobject nativeFocusCandidateLabel(JNIEnv *env, jobject obj)
+{
+ const CachedInput* input = getInputCandidate(env, obj);
+ if (!input)
+ return 0;
+ const WebCore::String& label = input->label();
+ return env->NewString((jchar*)label.characters(), label.length());
+}
+
static jint nativeFocusCandidateMaxLength(JNIEnv *env, jobject obj)
{
const CachedInput* input = getInputCandidate(env, obj);
@@ -2257,6 +2266,8 @@ static JNINativeMethod gJavaWebViewMethods[] = {
(void*) nativeFocusCandidateIsRtlText },
{ "nativeFocusCandidateIsTextInput", "()Z",
(void*) nativeFocusCandidateIsTextInput },
+ { "nativeFocusCandidateLabel", "()Ljava/lang/String;",
+ (void*) nativeFocusCandidateLabel },
{ "nativeFocusCandidateMaxLength", "()I",
(void*) nativeFocusCandidateMaxLength },
{ "nativeFocusCandidateName", "()Ljava/lang/String;",