summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorGeorge Mount <mount@google.com>2012-01-09 09:29:19 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-01-09 09:29:19 -0800
commiteeda08b1ca4b27f46c54656a420ab69b8eec870c (patch)
tree7f419c6c17a24fc09e944db7707c86969297840b /Source
parent422f9d3f7b0a4110e925506184ef381a816cdb92 (diff)
parent918301bd6deae5358d1def5459af872f486c9257 (diff)
downloadexternal_webkit-eeda08b1ca4b27f46c54656a420ab69b8eec870c.zip
external_webkit-eeda08b1ca4b27f46c54656a420ab69b8eec870c.tar.gz
external_webkit-eeda08b1ca4b27f46c54656a420ab69b8eec870c.tar.bz2
Merge "Fix delete key with ContentEditable fields."
Diffstat (limited to 'Source')
-rw-r--r--Source/WebKit/android/jni/WebViewCore.cpp58
-rw-r--r--Source/WebKit/android/jni/WebViewCore.h8
2 files changed, 64 insertions, 2 deletions
diff --git a/Source/WebKit/android/jni/WebViewCore.cpp b/Source/WebKit/android/jni/WebViewCore.cpp
index d2b6e6f..a448d8c 100644
--- a/Source/WebKit/android/jni/WebViewCore.cpp
+++ b/Source/WebKit/android/jni/WebViewCore.cpp
@@ -1525,8 +1525,12 @@ WTF::String WebViewCore::requestLabel(WebCore::Frame* frame,
static bool isContentEditable(const WebCore::Node* node)
{
- if (!node) return false;
- return node->document()->frame()->selection()->isContentEditable();
+ if (!node)
+ return false;
+ Frame* frame = node->document()->frame();
+ if (!frame)
+ return false;
+ return frame->selection()->isContentEditable();
}
// Returns true if the node is a textfield, textarea, or contentEditable
@@ -2863,6 +2867,47 @@ void WebViewCore::deleteSelection(int start, int end, int textGeneration)
m_shouldPaintCaret = true;
}
+void WebViewCore::deleteSurroundingText(int leftLength, int rightLength)
+{
+ WebCore::Node* focus = currentFocus();
+ if (!isTextInput(focus))
+ return;
+
+ Frame* frame = focus->document()->frame();
+ if (!frame)
+ return;
+ SelectionController* selection = frame->selection();
+ Position endPosition = selection->end();
+
+ Position deleteStart = endPosition;
+ int leftDelete = leftLength;
+ while (leftDelete > 0) {
+ leftDelete--;
+ deleteStart = deleteStart.previous(Character);
+ }
+ Position deleteEnd = endPosition;
+ int rightDelete = rightLength;
+ while (rightDelete > 0) {
+ rightDelete--;
+ deleteEnd = deleteEnd.next(Character);
+ }
+
+ // Select the text to delete.
+ VisibleSelection deletedText(deleteStart, deleteEnd);
+ selection->setSelection(deletedText);
+ // Prevent our editor client from passing a message to change the
+ // selection.
+ EditorClientAndroid* client = static_cast<EditorClientAndroid*>(
+ m_mainFrame->editor()->client());
+ client->setUiGeneratedSelectionChange(true);
+ WebCore::TypingCommand::deleteSelection(focus->document(), 0);
+ client->setUiGeneratedSelectionChange(false);
+
+ // set the new cursor position
+ VisibleSelection endCarat(deleteStart);
+ selection->setSelection(endCarat);
+}
+
void WebViewCore::replaceTextfieldText(int oldStart,
int oldEnd, const WTF::String& replace, int start, int end,
int textGeneration)
@@ -4004,6 +4049,13 @@ static void DeleteSelection(JNIEnv* env, jobject obj, jint nativeClass,
viewImpl->deleteSelection(start, end, textGeneration);
}
+static void DeleteSurroundingText(JNIEnv *env, jobject obj, jint nativeClass,
+ jint leftLength, jint rightLength)
+{
+ WebViewCore* viewImpl = reinterpret_cast<WebViewCore*>(nativeClass);
+ viewImpl->deleteSurroundingText(leftLength, rightLength);
+}
+
static void SetSelection(JNIEnv* env, jobject obj, jint nativeClass,
jint start, jint end)
{
@@ -4600,6 +4652,8 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = {
(void*) ModifySelection },
{ "nativeDeleteSelection", "(IIII)V",
(void*) DeleteSelection } ,
+ { "nativeDeleteSurroundingText", "(III)V",
+ (void*) DeleteSurroundingText } ,
{ "nativeReplaceTextfieldText", "(IIILjava/lang/String;III)V",
(void*) ReplaceTextfieldText } ,
{ "nativeMoveFocus", "(III)V",
diff --git a/Source/WebKit/android/jni/WebViewCore.h b/Source/WebKit/android/jni/WebViewCore.h
index a05c3ea..3d61f2c 100644
--- a/Source/WebKit/android/jni/WebViewCore.h
+++ b/Source/WebKit/android/jni/WebViewCore.h
@@ -358,6 +358,14 @@ namespace android {
void deleteSelection(int start, int end, int textGeneration);
/**
+ * Delete text near the cursor (assumed to be at selection end).
+ * leftLength and rightLength refer to the number of characters
+ * left and right of the cursor to delete. The cursor will be
+ * set to the beginning of the deleted text.
+ */
+ void deleteSurroundingText(int leftLength, int rightLength);
+
+ /**
* Set the selection of the currently focused textfield to (start, end).
* If start and end are out of order, swap them.
*/