From b66bccb7845ae59cd45c84026b993c37511dac0a Mon Sep 17 00:00:00 2001 From: "zyaozhujun@chromium.org" Date: Fri, 9 Aug 2013 21:33:27 +0000 Subject: Swipe selection on Virtual Keyboard This is a swipe selection feature on virtual keyboard on ChromeOS. This feature will improve user experience on text editing on touch screen and make the modification of text and position-setting of cursor much easier. It requires to implement an API and a swipe gesture recognizer on virtual keyboard. How to trigger this? TEST = 1. Enable the virtual keyboard feature on ChromeOS. 2. To move the cursor horizontally, swipe horizontally from anywhere on the virtual keyboard. 3. To move the cursor vertically, swipe vertically from anywhere on the virtual keyboard. 4. To move the cursor on diagonal direction, swipe diagonal from anywhere on the virtual keyboard in the four directions, which means, upleft, upright, downleft, downright. 5. To move the cursor while selecting the text on the edit field, swipe from shift key as the start point to any directions you want. BUG=263426 Review URL: https://chromiumcodereview.appspot.com/20818002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216752 0039d316-1c4b-4281-b951-d872f2087c98 --- ui/keyboard/keyboard_util.cc | 39 ++++++ ui/keyboard/keyboard_util.h | 14 ++ ui/keyboard/resources/api_adapter.js | 5 + ui/keyboard/resources/elements/kb-key.html | 1 + ui/keyboard/resources/elements/kb-keyboard.html | 169 +++++++++++++++++++++++- 5 files changed, 225 insertions(+), 3 deletions(-) (limited to 'ui/keyboard') diff --git a/ui/keyboard/keyboard_util.cc b/ui/keyboard/keyboard_util.cc index 076eacf..1579068 100644 --- a/ui/keyboard/keyboard_util.cc +++ b/ui/keyboard/keyboard_util.cc @@ -64,6 +64,45 @@ bool InsertText(const base::string16& text, aura::RootWindow* root_window) { return true; } +// TODO(varunjain): It would be cleaner to have something in the +// ui::TextInputClient interface, say MoveCaretInDirection(). The code in +// here would get the ui::InputMethod from the root_window, and the +// ui::TextInputClient from that (see above in InsertText()). +bool MoveCursor(int swipe_direction, + int modifier_flags, + aura::RootWindow* root_window) { + if (!root_window) + return false; + ui::KeyboardCode codex = ui::VKEY_UNKNOWN; + ui::KeyboardCode codey = ui::VKEY_UNKNOWN; + if (swipe_direction & kCursorMoveRight) + codex = ui::VKEY_RIGHT; + else if (swipe_direction & kCursorMoveLeft) + codex = ui::VKEY_LEFT; + + if (swipe_direction & kCursorMoveUp) + codey = ui::VKEY_UP; + else if (swipe_direction & kCursorMoveDown) + codey = ui::VKEY_DOWN; + + // First deal with the x movement. + if (codex != ui::VKEY_UNKNOWN) { + ui::KeyEvent press_event(ui::ET_KEY_PRESSED, codex, modifier_flags, 0); + root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&press_event); + ui::KeyEvent release_event(ui::ET_KEY_RELEASED, codex, modifier_flags, 0); + root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&release_event); + } + + // Then deal with the y movement. + if (codey != ui::VKEY_UNKNOWN) { + ui::KeyEvent press_event(ui::ET_KEY_PRESSED, codey, modifier_flags, 0); + root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&press_event); + ui::KeyEvent release_event(ui::ET_KEY_RELEASED, codey, modifier_flags, 0); + root_window->AsRootWindowHostDelegate()->OnHostKeyEvent(&release_event); + } + return true; +} + const GritResourceMap* GetKeyboardExtensionResources(size_t* size) { // This looks a lot like the contents of a resource map; however it is // necessary to have a custom path for the extension path, so the resource diff --git a/ui/keyboard/keyboard_util.h b/ui/keyboard/keyboard_util.h index 0fc60ff..7d46433 100644 --- a/ui/keyboard/keyboard_util.h +++ b/ui/keyboard/keyboard_util.h @@ -17,6 +17,14 @@ struct GritResourceMap; namespace keyboard { +// Enumeration of swipe directions. +enum CursorMoveDirection { + kCursorMoveRight = 0x01, + kCursorMoveLeft = 0x02, + kCursorMoveUp = 0x04, + kCursorMoveDown = 0x08 +}; + // Returns true if the virtual keyboard is enabled. KEYBOARD_EXPORT bool IsKeyboardEnabled(); @@ -27,6 +35,12 @@ KEYBOARD_EXPORT bool IsKeyboardEnabled(); KEYBOARD_EXPORT bool InsertText(const base::string16& text, aura::RootWindow* root_window); +// Move cursor when swipe on the virtualkeyboard. Returns true if cursor was +// successfully moved according to |swipe_direction|. +KEYBOARD_EXPORT bool MoveCursor(int swipe_direction, + int modifier_flags, + aura::RootWindow* root_window); + // Get the list of keyboard resources. |size| is populated with the number of // resources in the returned array. KEYBOARD_EXPORT const GritResourceMap* GetKeyboardExtensionResources( diff --git a/ui/keyboard/resources/api_adapter.js b/ui/keyboard/resources/api_adapter.js index cd64f57..eb95e35 100644 --- a/ui/keyboard/resources/api_adapter.js +++ b/ui/keyboard/resources/api_adapter.js @@ -11,3 +11,8 @@ function logIfError() { function insertText(text) { chrome.experimental.input.virtualKeyboard.insertText(text, logIfError); } + +function MoveCursor(swipe_direction, swipe_flags) { + chrome.experimental.input.virtualKeyboard.moveCursor(swipe_direction, + swipe_flags); +} diff --git a/ui/keyboard/resources/elements/kb-key.html b/ui/keyboard/resources/elements/kb-key.html index b8bbd4d..fc366bb 100644 --- a/ui/keyboard/resources/elements/kb-key.html +++ b/ui/keyboard/resources/elements/kb-key.html @@ -40,6 +40,7 @@ detail.nextKeyset = this.keysetRules.dbl[NEXT_KEYSET - OFFSET]; } this.fire('enable-dbl', detail); + this.fire('enable-sel'); } }); diff --git a/ui/keyboard/resources/elements/kb-keyboard.html b/ui/keyboard/resources/elements/kb-keyboard.html index d21edf0..f4efb31 100644 --- a/ui/keyboard/resources/elements/kb-keyboard.html +++ b/ui/keyboard/resources/elements/kb-keyboard.html @@ -6,6 +6,7 @@