summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-20 04:14:58 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-20 04:14:58 +0000
commit2b110f43bd2a5253066ff7c7c4c5c81ecf2bc8ce (patch)
treef7937bc4fd7fc41d04c2dca4c58a9f98bb18c173 /chrome/browser
parent9d0984aadf39ed588efe90334bff43559d536d11 (diff)
downloadchromium_src-2b110f43bd2a5253066ff7c7c4c5c81ecf2bc8ce.zip
chromium_src-2b110f43bd2a5253066ff7c7c4c5c81ecf2bc8ce.tar.gz
chromium_src-2b110f43bd2a5253066ff7c7c4c5c81ecf2bc8ce.tar.bz2
Make GTK accelerator setup code more compact.
Review URL: http://codereview.chromium.org/50042 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12184 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc41
1 files changed, 19 insertions, 22 deletions
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index 43b620e..4ff8a7a 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -80,22 +80,22 @@ gfx::Rect GetInitialWindowBounds(GtkWindow* window) {
return gfx::Rect(x, y, width, height);
}
-const guint kFocusLocationKey = GDK_l;
-const guint kFocusSearchKey = GDK_k;
-const guint kOpenFileKey = GDK_o;
+const struct AcceleratorMapping {
+ guint keyval;
+ int command_id;
+} kAcceleratorMap[] = {
+ { GDK_l, IDC_FOCUS_LOCATION },
+ { GDK_k, IDC_FOCUS_SEARCH },
+ { GDK_o, IDC_OPEN_FILE },
+};
static int GetCommandFromKeyval(guint accel_key) {
- switch (accel_key) {
- case kFocusLocationKey:
- return IDC_FOCUS_LOCATION;
- case kFocusSearchKey:
- return IDC_FOCUS_SEARCH;
- case kOpenFileKey:
- return IDC_OPEN_FILE;
- default:
- NOTREACHED();
- return 0;
+ for (size_t i = 0; i < arraysize(kAcceleratorMap); ++i) {
+ if (kAcceleratorMap[i].keyval == accel_key)
+ return kAcceleratorMap[i].command_id;
}
+ NOTREACHED();
+ return 0;
}
// Usually accelerators are checked before propagating the key event, but in our
@@ -475,15 +475,12 @@ void BrowserWindowGtk::ConnectAccelerators() {
// Drop the initial ref on |accel_group| so |window_| will own it.
g_object_unref(accel_group);
- gtk_accel_group_connect(
- accel_group, kFocusLocationKey, GDK_CONTROL_MASK, GtkAccelFlags(0),
- g_cclosure_new(G_CALLBACK(OnAccelerator), this, NULL));
- gtk_accel_group_connect(
- accel_group, kFocusSearchKey, GDK_CONTROL_MASK, GtkAccelFlags(0),
- g_cclosure_new(G_CALLBACK(OnAccelerator), this, NULL));
- gtk_accel_group_connect(
- accel_group, kOpenFileKey, GDK_CONTROL_MASK, GtkAccelFlags(0),
- g_cclosure_new(G_CALLBACK(OnAccelerator), this, NULL));
+ for (size_t i = 0; i < arraysize(kAcceleratorMap); ++i) {
+ gtk_accel_group_connect(
+ accel_group, kAcceleratorMap[i].keyval, GDK_CONTROL_MASK,
+ GtkAccelFlags(0), g_cclosure_new(G_CALLBACK(OnAccelerator),
+ this, NULL));
+ }
}
void BrowserWindowGtk::SetCustomFrame(bool custom_frame) {