summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSvetoslav Ganov <svetoslavganov@google.com>2010-05-07 20:33:09 -0700
committerSvetoslav Ganov <svetoslavganov@google.com>2010-05-15 12:10:01 -0700
commit4cd028871582a7f15f06fa772e65aa2f76e4e0d5 (patch)
treebd2af1dc927972ed353de4199ec20ee6602db932
parent0d4eb282a9331db55cb204c779cd172dba8ccf50 (diff)
downloadexternal_webkit-4cd028871582a7f15f06fa772e65aa2f76e4e0d5.zip
external_webkit-4cd028871582a7f15f06fa772e65aa2f76e4e0d5.tar.gz
external_webkit-4cd028871582a7f15f06fa772e65aa2f76e4e0d5.tar.bz2
Adding a mechanism for injecting accessibility in WebViews with disabled JavaScript.
Change-Id: If0d8fc9cffcd00356dffe46af094b65488b3ff5a
-rw-r--r--WebKit/android/jni/WebViewCore.cpp65
-rw-r--r--WebKit/android/jni/WebViewCore.h12
2 files changed, 77 insertions, 0 deletions
diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp
index beb38cd..50611c7 100644
--- a/WebKit/android/jni/WebViewCore.cpp
+++ b/WebKit/android/jni/WebViewCore.cpp
@@ -37,6 +37,7 @@
#include "DatabaseTracker.h"
#include "Document.h"
#include "DOMWindow.h"
+#include "DOMSelection.h"
#include "Element.h"
#include "Editor.h"
#include "EditorClientAndroid.h"
@@ -78,6 +79,7 @@
#include "PluginView.h"
#include "Position.h"
#include "ProgressTracker.h"
+#include "Range.h"
#include "RenderBox.h"
#include "RenderLayer.h"
#include "RenderPart.h"
@@ -1679,6 +1681,51 @@ void WebViewCore::setSelection(int start, int end)
setFocusControllerActive(focusedFrame, true);
}
+String WebViewCore::modifySelection(const String& alter, const String& direction, const String& granularity)
+{
+ DOMSelection* selection = m_mainFrame->domWindow()->getSelection();
+
+ if (selection->rangeCount() == 0) {
+ Document* document = m_mainFrame->document();
+ HTMLElement* body = document->body();
+ ExceptionCode ec;
+
+ PassRefPtr<Range> rangeRef = document->createRange();
+ rangeRef->setStart(PassRefPtr<Node>(body), 0, ec);
+ if (ec) {
+ LOGE("Error setting range start. Error code: %d", ec);
+ return String();
+ }
+
+ rangeRef->setEnd(PassRefPtr<Node>(body), 0, ec);
+ if (ec) {
+ LOGE("Error setting range end. Error code: %d", ec);
+ return String();
+ }
+
+ selection->addRange(rangeRef.get());
+ }
+
+ if (equalIgnoringCase(direction, "forward")) {
+ selection->collapseToEnd();
+ } else if (equalIgnoringCase(direction, "backward")) {
+ selection->collapseToStart();
+ } else {
+ LOGE("Invalid direction: %s", direction.utf8().data());
+ return String();
+ }
+
+ // NOTE: The selection of WebKit misbehaves and I need to add some
+ // voodoo here to force it behave well. Rachel did something similar
+ // in JS and I want to make sure it is optimal before adding it here.
+
+ selection->modify(alter, direction, granularity);
+ String selection_string = selection->toString();
+ LOGD("Selection string: %s", selection_string.utf8().data());
+
+ return selection_string;
+}
+
void WebViewCore::deleteSelection(int start, int end, int textGeneration)
{
setSelection(start, end);
@@ -2658,6 +2705,22 @@ static void SetSelection(JNIEnv *env, jobject obj, jint start, jint end)
viewImpl->setSelection(start, end);
}
+static jstring ModifySelection(JNIEnv *env, jobject obj, jstring alter, jstring direction, jstring granularity)
+{
+#ifdef ANDROID_INSTRUMENT
+ TimeCounterAuto counter(TimeCounter::WebViewCoreTimeCounter);
+#endif
+ String alterString = to_string(env, alter);
+ String directionString = to_string(env, direction);
+ String granularityString = to_string(env, granularity);
+
+ WebViewCore* viewImpl = GET_NATIVE_VIEW(env, obj);
+ String selection_string = viewImpl->modifySelection(alterString,
+ directionString,
+ granularityString);
+
+ return WebCoreStringToJString(env, selection_string);
+}
static void ReplaceTextfieldText(JNIEnv *env, jobject obj,
jint oldStart, jint oldEnd, jstring replace, jint start, jint end,
@@ -3195,6 +3258,8 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = {
(void*) SetGlobalBounds },
{ "nativeSetSelection", "(II)V",
(void*) SetSelection } ,
+ { "nativeModifySelection", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
+ (void*) ModifySelection },
{ "nativeDeleteSelection", "(III)V",
(void*) DeleteSelection } ,
{ "nativeReplaceTextfieldText", "(IILjava/lang/String;III)V",
diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h
index 4ed17bf..36b805e 100644
--- a/WebKit/android/jni/WebViewCore.h
+++ b/WebKit/android/jni/WebViewCore.h
@@ -325,6 +325,18 @@ namespace android {
* If start and end are out of order, swap them.
*/
void setSelection(int start, int end);
+
+ /**
+ * Modifies the current selection.
+ *
+ * alter - Specifies how to alter the selection.
+ * direction - The direction in which to alter the selection.
+ * granularity - The granularity of the selection modification.
+ *
+ * returns - The selection as string.
+ */
+ String modifySelection(const String& alter, const String& direction, const String& granularity);
+
/**
* In the currently focused textfield, replace the characters from oldStart to oldEnd
* (if oldStart == oldEnd, this will be an insert at that position) with replace,