Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1363)

Unified Diff: chrome/browser/ui/ash/event_rewriter.cc

Issue 11421055: Add power-user keyboard mode for ChromeOS with Search key acting as a typical Fn key. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: SkyNits Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/ash/event_rewriter.h ('k') | chrome/browser/ui/ash/event_rewriter_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/ash/event_rewriter.cc
diff --git a/chrome/browser/ui/ash/event_rewriter.cc b/chrome/browser/ui/ash/event_rewriter.cc
index 7c567a126d7d2796a9ba885f4cf0cd76f43e3f96..42b1b8e6d928b410dc41ab1c72bb1c6bf1488542 100644
--- a/chrome/browser/ui/ash/event_rewriter.cc
+++ b/chrome/browser/ui/ash/event_rewriter.cc
@@ -121,6 +121,12 @@ bool HasChromeOSKeyboard() {
switches::kHasChromeOSKeyboard);
}
+bool EventSourceIsChromebookKeyboard(ui::KeyEvent* /* event */) {
+ // TODO(danakj): Determine if the event came from a Chromebook internal
+ // keyboard.
+ return true;
+}
+
bool IsMod3UsedByCurrentInputMethod() {
// Since both German Neo2 XKB layout and Caps Lock depend on Mod3Mask,
// it's not possible to make both features work. For now, we don't remap
@@ -638,43 +644,86 @@ bool EventRewriter::RewriteNumPadKeys(ui::KeyEvent* event) {
bool EventRewriter::RewriteBackspaceAndArrowKeys(ui::KeyEvent* event) {
bool rewritten = false;
#if defined(OS_CHROMEOS)
+ // On a Chromebook keyboard, modifier keys can be used to access extended
+ // keyboard shortcuts. On other keyboards, keys such as delete and page up are
+ // already available, so we do not need to rewrite anything here.
+ if (!EventSourceIsChromebookKeyboard(event))
+ return rewritten;
+
+ const PrefService* pref_service =
+ pref_service_ ? pref_service_ : GetPrefService();
+ bool chromebook_function_key = CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableChromebookFunctionKey);
+
+ bool search_as_function_key = chromebook_function_key && pref_service &&
+ pref_service->GetBoolean(prefs::kLanguageSearchKeyActsAsFunctionKey);
+
XEvent* xev = event->native_event();
XKeyEvent* xkey = &(xev->xkey);
-
const KeySym keysym = XLookupKeysym(xkey, 0);
- if (keysym == XK_BackSpace && (xkey->state & Mod1Mask)) {
- // Remap Alt+Backspace to Delete.
- OverwriteEvent(event, delete_xkeycode_, xkey->state & ~Mod1Mask,
- ui::VKEY_DELETE, event->flags() & ~ui::EF_ALT_DOWN);
- rewritten = true;
- } else if (keysym == XK_Up &&
- (xkey->state & ControlMask) && (xkey->state & Mod1Mask)) {
- // Remap Ctrl+Alt+Up to Home.
- OverwriteEvent(event,
- home_xkeycode_,
- xkey->state & ~(Mod1Mask | ControlMask),
- ui::VKEY_HOME,
- event->flags() & ~(ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN));
- rewritten = true;
- } else if (keysym == XK_Up && (xkey->state & Mod1Mask)) {
- // Remap Alt+Up to Prior (aka PageUp).
- OverwriteEvent(event, prior_xkeycode_, xkey->state & ~Mod1Mask,
- ui::VKEY_PRIOR, event->flags() & ~ui::EF_ALT_DOWN);
- rewritten = true;
- } else if (keysym == XK_Down &&
- (xkey->state & ControlMask) && (xkey->state & Mod1Mask)) {
- // Remap Ctrl+Alt+Down to End.
- OverwriteEvent(event,
- end_xkeycode_,
- xkey->state & ~(Mod1Mask | ControlMask),
- ui::VKEY_END,
- event->flags() & ~(ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN));
- rewritten = true;
- } else if (keysym == XK_Down && (xkey->state & Mod1Mask)) {
- // Remap Alt+Down to Next (aka PageDown).
- OverwriteEvent(event, next_xkeycode_, xkey->state & ~Mod1Mask,
- ui::VKEY_NEXT, event->flags() & ~ui::EF_ALT_DOWN);
- rewritten = true;
+
+ if (!search_as_function_key) {
+ if (keysym == XK_BackSpace && (xkey->state & Mod1Mask)) {
+ // Without Search as Function key: Remap Alt+Backspace to Delete.
+ OverwriteEvent(event, delete_xkeycode_, xkey->state & ~Mod1Mask,
+ ui::VKEY_DELETE, event->flags() & ~ui::EF_ALT_DOWN);
+ rewritten = true;
+ } else if (keysym == XK_Up &&
+ (xkey->state & ControlMask) && (xkey->state & Mod1Mask)) {
+ // Without Search as Function key: Remap Ctrl+Alt+Up to Home.
+ OverwriteEvent(event,
+ home_xkeycode_,
+ xkey->state & ~(Mod1Mask | ControlMask),
+ ui::VKEY_HOME,
+ event->flags() & ~(ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN));
+ rewritten = true;
+ } else if (keysym == XK_Up && (xkey->state & Mod1Mask)) {
+ // Without Search as Function key: Remap Alt+Up to Prior (aka PageUp).
+ OverwriteEvent(event, prior_xkeycode_, xkey->state & ~Mod1Mask,
+ ui::VKEY_PRIOR, event->flags() & ~ui::EF_ALT_DOWN);
+ rewritten = true;
+ } else if (keysym == XK_Down &&
+ (xkey->state & ControlMask) && (xkey->state & Mod1Mask)) {
+ // Without Search as Function key: Remap Ctrl+Alt+Down to End.
+ OverwriteEvent(event,
+ end_xkeycode_,
+ xkey->state & ~(Mod1Mask | ControlMask),
+ ui::VKEY_END,
+ event->flags() & ~(ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN));
+ rewritten = true;
+ } else if (keysym == XK_Down && (xkey->state & Mod1Mask)) {
+ // Without Search as Function key: Remap Alt+Down to Next (aka PageDown).
+ OverwriteEvent(event, next_xkeycode_, xkey->state & ~Mod1Mask,
+ ui::VKEY_NEXT, event->flags() & ~ui::EF_ALT_DOWN);
+ rewritten = true;
+ }
+ } else {
+ if (keysym == XK_BackSpace && (xkey->state & Mod4Mask)) {
+ // With Search as Function key: Remap Search+Backspace to Delete.
+ OverwriteEvent(event, delete_xkeycode_, xkey->state & ~Mod4Mask,
+ ui::VKEY_DELETE, event->flags());
+ rewritten = true;
+ } else if (keysym == XK_Left && (xkey->state & Mod4Mask)) {
+ // With Search as Function key: Remap Search+Left to Home.
+ OverwriteEvent(event, home_xkeycode_, xkey->state & ~Mod4Mask,
+ ui::VKEY_HOME, event->flags());
+ rewritten = true;
+ } else if (keysym == XK_Up && (xkey->state & Mod4Mask)) {
+ // With Search as Function key: Remap Search+Up to Prior (aka PageUp).
+ OverwriteEvent(event, prior_xkeycode_, xkey->state & ~Mod4Mask,
+ ui::VKEY_PRIOR, event->flags());
+ rewritten = true;
+ } else if (keysym == XK_Right && (xkey->state & Mod4Mask)) {
+ // With Search as Function key: Remap Search+Right to End.
+ OverwriteEvent(event, end_xkeycode_, xkey->state & ~Mod4Mask,
+ ui::VKEY_END, event->flags());
+ rewritten = true;
+ } else if (keysym == XK_Down && (xkey->state & Mod4Mask)) {
+ // With Search as Function key: Remap Search+Down to Next (aka PageDown).
+ OverwriteEvent(event, next_xkeycode_, xkey->state & ~Mod4Mask,
+ ui::VKEY_NEXT, event->flags());
+ rewritten = true;
+ }
}
#else
// TODO(yusukes): Support Ash on other platforms if needed.
« no previous file with comments | « chrome/browser/ui/ash/event_rewriter.h ('k') | chrome/browser/ui/ash/event_rewriter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698