diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-06 22:12:34 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-06 22:12:34 +0000 |
commit | 449f8d6c9a2ba105405a0ea0625300fec73eaadb (patch) | |
tree | 2fa3d3bb10425d32b9b50633d836774809353b44 /chrome/browser | |
parent | af0285648087cda5acfd903a99975a2560556b83 (diff) | |
download | chromium_src-449f8d6c9a2ba105405a0ea0625300fec73eaadb.zip chromium_src-449f8d6c9a2ba105405a0ea0625300fec73eaadb.tar.gz chromium_src-449f8d6c9a2ba105405a0ea0625300fec73eaadb.tar.bz2 |
Implement accelerators in the gtk port (try 2).
- Adds accelerators to all the menu items that had them on windows.
- Adds accelerators to back (Alt+left), forward (Alt+right), reload
(Ctr+R) and focus the URL box (Ctr+L).
Review URL: http://codereview.chromium.org/39278
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11166 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 32 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.h | 12 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.cc | 5 | ||||
-rw-r--r-- | chrome/browser/gtk/download_item_gtk.cc | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/menu_gtk.cc | 16 | ||||
-rw-r--r-- | chrome/browser/gtk/menu_gtk.h | 9 | ||||
-rw-r--r-- | chrome/browser/gtk/standard_menus.cc | 80 | ||||
-rw-r--r-- | chrome/browser/gtk/standard_menus.h | 6 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents_view_gtk.cc | 32 |
9 files changed, 142 insertions, 52 deletions
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index c011d5c..b218beb 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -4,6 +4,8 @@ #include "chrome/browser/gtk/browser_toolbar_gtk.h" +#include <gdk/gdkkeysyms.h> + #include "base/logging.h" #include "base/base_paths_linux.h" #include "base/path_service.h" @@ -49,7 +51,9 @@ BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser) BrowserToolbarGtk::~BrowserToolbarGtk() { } -void BrowserToolbarGtk::Init(Profile* profile) { +void BrowserToolbarGtk::Init(Profile* profile, GtkAccelGroup* accel_group) { + accel_group_ = accel_group; + show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); toolbar_ = gtk_hbox_new(FALSE, 0); @@ -63,14 +67,17 @@ void BrowserToolbarGtk::Init(Profile* profile) { back_.reset(BuildBackForwardButton(IDR_BACK, IDR_BACK_P, IDR_BACK_H, IDR_BACK_D, l10n_util::GetString(IDS_TOOLTIP_BACK))); + AddAcceleratorToButton(back_, GDK_Left, GDK_MOD1_MASK); forward_.reset(BuildBackForwardButton(IDR_FORWARD, IDR_FORWARD_P, IDR_FORWARD_H, IDR_FORWARD_D, l10n_util::GetString(IDS_TOOLTIP_FORWARD))); + AddAcceleratorToButton(forward_, GDK_Right, GDK_MOD1_MASK); gtk_box_pack_start(GTK_BOX(toolbar_), gtk_label_new(" "), FALSE, FALSE, 0); reload_.reset(BuildToolbarButton(IDR_RELOAD, IDR_RELOAD_P, IDR_RELOAD_H, 0, l10n_util::GetString(IDS_TOOLTIP_RELOAD))); + AddAcceleratorToButton(reload_, GDK_r, GDK_CONTROL_MASK); // TODO(port): we need to dynamically react to changes in show_home_button_ // and hide/show home appropriately. But we don't have a UI for it yet. @@ -92,6 +99,9 @@ void BrowserToolbarGtk::Init(Profile* profile) { G_CALLBACK(OnEntryFocusIn), this); g_signal_connect(G_OBJECT(entry_), "focus-out-event", G_CALLBACK(OnEntryFocusOut), this); + gtk_widget_add_accelerator( + entry_, "grab-focus", accel_group_, GDK_l, + GDK_CONTROL_MASK, GtkAccelFlags(0)); gtk_box_pack_start(GTK_BOX(toolbar_), entry_, TRUE, TRUE, 0); @@ -101,9 +111,12 @@ void BrowserToolbarGtk::Init(Profile* profile) { page_menu_button_.reset(BuildToolbarMenuButton(IDR_MENU_PAGE, l10n_util::GetString(IDS_PAGEMENU_TOOLTIP))); + page_menu_.reset(new MenuGtk(this, GetStandardPageMenu(), accel_group_)); + app_menu_button_.reset(BuildToolbarMenuButton(IDR_MENU_CHROME, l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, l10n_util::GetString(IDS_PRODUCT_NAME)))); + app_menu_.reset(new MenuGtk(this, GetStandardAppMenu(), accel_group_)); SetProfile(profile); } @@ -351,6 +364,15 @@ CustomDrawButton* BrowserToolbarGtk::BuildBackForwardButton( return button; } +void BrowserToolbarGtk::AddAcceleratorToButton( + const scoped_ptr<CustomDrawButton>& button, + unsigned int accelerator, + unsigned int accelerator_mod) { + gtk_widget_add_accelerator( + button->widget(), "clicked", accel_group_, accelerator, + GdkModifierType(accelerator_mod), GtkAccelFlags(0)); +} + // static gboolean BrowserToolbarGtk::OnBackForwardPressEvent(GtkWidget* widget, GdkEventButton* event, @@ -376,18 +398,10 @@ void BrowserToolbarGtk::ShowBackForwardMenu(GtkWidget* widget, } void BrowserToolbarGtk::RunPageMenu(GdkEvent* button_press_event) { - if (page_menu_ == NULL) { - page_menu_.reset(new MenuGtk(this, GetStandardPageMenu())); - } - page_menu_->Popup(page_menu_button_->widget(), button_press_event); } void BrowserToolbarGtk::RunAppMenu(GdkEvent* button_press_event) { - if (app_menu_ == NULL) { - app_menu_.reset(new MenuGtk(this, GetStandardAppMenu())); - } - app_menu_->Popup(app_menu_button_->widget(), button_press_event); } diff --git a/chrome/browser/gtk/browser_toolbar_gtk.h b/chrome/browser/gtk/browser_toolbar_gtk.h index 4962ca2e..c943db4 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.h +++ b/chrome/browser/gtk/browser_toolbar_gtk.h @@ -36,7 +36,7 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver, virtual ~BrowserToolbarGtk(); // Create the contents of the toolbar - void Init(Profile* profile); + void Init(Profile* profile, GtkAccelGroup* accel_group); // Adds this GTK toolbar into a sizing box. void AddToolbarToBox(GtkWidget* box); @@ -76,6 +76,13 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver, int icon_id, const std::wstring& localized_tooltip); + // Adds a keyboard accelerator which trigers a button. (i.e., Ctrl+R is now + // equivalent to a reload click). + void AddAcceleratorToButton( + const scoped_ptr<CustomDrawButton>& button, + unsigned int accelerator, + unsigned int accelerator_mod); + // Gtk callback for the "activate" signal on the |entry_| widget. Responds to // enter. static void OnEntryActivate(GtkEntry *entry, BrowserToolbarGtk* toolbar); @@ -122,6 +129,9 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver, // Our temporary URL bar (until we get the omnibox up). GtkWidget* entry_; + // A pointer to our window's accelerator list. + GtkAccelGroup* accel_group_; + // All the buttons in the toolbar. scoped_ptr<CustomDrawButton> back_, forward_; scoped_ptr<CustomDrawButton> reload_; diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index 30d6e9f..a0b9d50 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -140,6 +140,9 @@ void BrowserWindowGtk::Init() { G_CALLBACK(MainWindowStateChanged), this); bounds_ = GetInitialWindowBounds(window_); + GtkAccelGroup* accel_group = gtk_accel_group_new(); + gtk_window_add_accel_group(window_, accel_group); + GdkPixbuf* images[9] = { LoadThemeImage(IDR_CONTENT_TOP_LEFT_CORNER), LoadThemeImage(IDR_CONTENT_TOP_CENTER), @@ -162,7 +165,7 @@ void BrowserWindowGtk::Init() { G_CALLBACK(&OnContentAreaExpose), this); toolbar_.reset(new BrowserToolbarGtk(browser_.get())); - toolbar_->Init(browser_->profile()); + toolbar_->Init(browser_->profile(), accel_group); toolbar_->AddToolbarToBox(vbox_); contents_container_.reset(new TabContentsContainerGtk()); diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc index 240ac9f..00de04e 100644 --- a/chrome/browser/gtk/download_item_gtk.cc +++ b/chrome/browser/gtk/download_item_gtk.cc @@ -46,7 +46,7 @@ class DownloadShelfContextMenuGtk : public DownloadShelfContextMenu, if (menu_.get() == NULL || (download_is_complete && !menu_is_for_complete_download_)) { menu_.reset(new MenuGtk(this, download_is_complete ? - finished_download_menu : in_progress_download_menu)); + finished_download_menu : in_progress_download_menu, NULL)); menu_is_for_complete_download_ = download_is_complete; } menu_->Popup(widget, event); diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc index af6c4e9..d9a3860 100644 --- a/chrome/browser/gtk/menu_gtk.cc +++ b/chrome/browser/gtk/menu_gtk.cc @@ -73,8 +73,10 @@ GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap) { } // namespace MenuGtk::MenuGtk(MenuGtk::Delegate* delegate, - const MenuCreateMaterial* menu_data) + const MenuCreateMaterial* menu_data, + GtkAccelGroup* accel_group) : delegate_(delegate), + accel_group_(accel_group), menu_(gtk_menu_new()) { g_object_ref_sink(menu_); BuildMenuIn(menu_, menu_data); @@ -146,6 +148,18 @@ void MenuGtk::BuildMenuIn(GtkWidget* menu, gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), submenu); } + if (accel_group_ && menu_data->accel_key) { + // If we ever want to let the user do any key remaping, we'll need to + // change the following so we make a gtk_accel_map which keeps the actual + // keys. + gtk_widget_add_accelerator(menu_item, + "activate", + accel_group_, + menu_data->accel_key, + GdkModifierType(menu_data->accel_modifiers), + GTK_ACCEL_VISIBLE); + } + g_object_set_data(G_OBJECT(menu_item), "menu-data", const_cast<MenuCreateMaterial*>(menu_data)); diff --git a/chrome/browser/gtk/menu_gtk.h b/chrome/browser/gtk/menu_gtk.h index bef318f..6dd1d05 100644 --- a/chrome/browser/gtk/menu_gtk.h +++ b/chrome/browser/gtk/menu_gtk.h @@ -38,7 +38,8 @@ class MenuGtk { // Builds a MenuGtk that uses |delegate| to perform actions and |menu_data| // to create the menu. - MenuGtk(MenuGtk::Delegate* delegate, const MenuCreateMaterial* menu_data); + MenuGtk(MenuGtk::Delegate* delegate, const MenuCreateMaterial* menu_data, + GtkAccelGroup* accel_group); // Builds a MenuGtk that uses |delegate| to create the menu as well as perform // actions. explicit MenuGtk(MenuGtk::Delegate* delegate); @@ -84,6 +85,12 @@ class MenuGtk { // Queries this object about the menu state. MenuGtk::Delegate* delegate_; + // Accelerator group to add keyboard accelerators to. + GtkAccelGroup* accel_group_; + + // The window this menu is attached to. + GtkWindow* window_; + // gtk_menu_popup() does not appear to take ownership of popup menus, so // MenuGtk explicitly manages the lifetime of the menu. GtkWidget* menu_; diff --git a/chrome/browser/gtk/standard_menus.cc b/chrome/browser/gtk/standard_menus.cc index bb0b6f8..bb781ec 100644 --- a/chrome/browser/gtk/standard_menus.cc +++ b/chrome/browser/gtk/standard_menus.cc @@ -10,65 +10,81 @@ #include "grit/chromium_strings.h" #include "grit/generated_resources.h" +#include <gtk/gtk.h> +#include <gdk/gdkkeysyms.h> + namespace { struct MenuCreateMaterial zoom_menu_materials[] = { - { MENU_NORMAL, IDC_ZOOM_PLUS, IDS_ZOOM_MENU, 0, NULL }, - { MENU_NORMAL, IDC_ZOOM_PLUS, IDS_ZOOM_PLUS, 0, NULL }, - { MENU_NORMAL, IDC_ZOOM_NORMAL, IDS_ZOOM_NORMAL, 0, NULL }, - { MENU_NORMAL, IDC_ZOOM_MINUS, IDS_ZOOM_MINUS, 0, NULL }, - { MENU_END, 0, 0, NULL } + { MENU_NORMAL, IDC_ZOOM_PLUS, IDS_ZOOM_PLUS, 0, NULL, + GDK_plus, GDK_CONTROL_MASK }, + { MENU_NORMAL, IDC_ZOOM_NORMAL, IDS_ZOOM_NORMAL, 0, NULL, + GDK_0, GDK_CONTROL_MASK }, + { MENU_NORMAL, IDC_ZOOM_MINUS, IDS_ZOOM_MINUS, 0, NULL, + GDK_minus, GDK_CONTROL_MASK }, + { MENU_END, 0, 0, 0, NULL } }; struct MenuCreateMaterial encoding_menu_materials[] = { { MENU_CHECKBOX, IDC_ENCODING_AUTO_DETECT, IDS_ENCODING_AUTO_DETECT, 0, NULL }, - { MENU_END, 0, 0, NULL } + { MENU_END, 0, 0, 0, NULL } }; struct MenuCreateMaterial developer_menu_materials[] = { - { MENU_NORMAL, IDC_VIEW_SOURCE, IDS_VIEW_SOURCE, 0, NULL }, - { MENU_NORMAL, IDC_DEBUGGER, IDS_DEBUGGER, 0, NULL }, - { MENU_NORMAL, IDC_JS_CONSOLE, IDS_JS_CONSOLE, 0, NULL }, - { MENU_NORMAL, IDC_TASK_MANAGER, IDS_TASK_MANAGER, 0, NULL }, - { MENU_END, 0, 0, NULL } + { MENU_NORMAL, IDC_VIEW_SOURCE, IDS_VIEW_SOURCE, 0, NULL, + GDK_u, GDK_CONTROL_MASK }, + { MENU_NORMAL, IDC_DEBUGGER, IDS_DEBUGGER, 0, NULL, + GDK_l, GDK_CONTROL_MASK | GDK_SHIFT_MASK }, + { MENU_NORMAL, IDC_JS_CONSOLE, IDS_JS_CONSOLE, 0, NULL, + GDK_j, GDK_CONTROL_MASK | GDK_SHIFT_MASK }, + { MENU_NORMAL, IDC_TASK_MANAGER, IDS_TASK_MANAGER, 0, NULL, + GDK_Escape, GDK_SHIFT_MASK }, + { MENU_END, 0, 0, 0, NULL } }; struct MenuCreateMaterial standard_page_menu_materials[] = { { MENU_NORMAL, IDC_CREATE_SHORTCUTS, IDS_CREATE_SHORTCUTS, 0, NULL }, { MENU_SEPARATOR, 0, 0, 0, NULL }, - { MENU_NORMAL, IDC_CUT, IDS_CUT, 0, NULL }, - { MENU_NORMAL, IDC_COPY, IDS_COPY, 0, NULL }, - { MENU_NORMAL, IDC_PASTE, IDS_PASTE, 0, NULL }, + { MENU_NORMAL, IDC_CUT, IDS_CUT, 0, NULL, GDK_x, GDK_CONTROL_MASK }, + { MENU_NORMAL, IDC_COPY, IDS_COPY, 0, NULL, GDK_c, GDK_CONTROL_MASK }, + { MENU_NORMAL, IDC_PASTE, IDS_PASTE, 0, NULL, GDK_v, GDK_CONTROL_MASK }, { MENU_SEPARATOR, 0, 0, 0, NULL }, - { MENU_NORMAL, IDC_FIND, IDS_FIND, 0, NULL }, - { MENU_NORMAL, IDC_SAVE_PAGE, IDS_SAVE_PAGE, 0, NULL }, - { MENU_NORMAL, IDC_PRINT, IDS_PRINT, 0, NULL }, + { MENU_NORMAL, IDC_FIND, IDS_FIND, 0, NULL, GDK_f, GDK_CONTROL_MASK }, + { MENU_NORMAL, IDC_SAVE_PAGE, IDS_SAVE_PAGE, 0, NULL, GDK_s, + GDK_CONTROL_MASK }, + { MENU_NORMAL, IDC_PRINT, IDS_PRINT, 0, NULL, GDK_p, GDK_CONTROL_MASK }, { MENU_SEPARATOR, 0, 0, 0, NULL }, - { MENU_NORMAL, IDC_ZOOM_MENU, IDS_ZOOM_MENU, 0, zoom_menu_materials }, + { MENU_NORMAL, IDC_ZOOM_MENU, IDS_ZOOM_MENU, 0, zoom_menu_materials, 0, 0 }, { MENU_NORMAL, IDC_ENCODING_MENU, IDS_ENCODING_MENU, 0, - encoding_menu_materials }, + encoding_menu_materials, 0, 0 }, { MENU_SEPARATOR, 0, 0, 0, NULL }, { MENU_NORMAL, IDC_DEVELOPER_MENU, IDS_DEVELOPER_MENU, 0, - developer_menu_materials }, + developer_menu_materials, 0, 0 }, { MENU_SEPARATOR, 0, 0, 0, NULL }, { MENU_NORMAL, IDC_REPORT_BUG, IDS_REPORT_BUG, 0, NULL }, - { MENU_END, 0, 0, NULL } + { MENU_END, 0, 0, 0, NULL } }; // ----------------------------------------------------------------------- struct MenuCreateMaterial standard_app_menu_materials[] = { - { MENU_NORMAL, IDC_NEW_TAB, IDS_NEW_TAB, 0, NULL }, - { MENU_NORMAL, IDC_NEW_WINDOW, IDS_NEW_WINDOW, 0, NULL }, - { MENU_NORMAL, IDC_NEW_INCOGNITO_WINDOW, IDS_NEW_INCOGNITO_WINDOW, 0, NULL }, - { MENU_NORMAL, IDC_PROFILE_MENU, IDS_PROFILE_MENU, 0, NULL }, + { MENU_NORMAL, IDC_NEW_TAB, IDS_NEW_TAB, 0, NULL, + GDK_t, GDK_CONTROL_MASK }, + { MENU_NORMAL, IDC_NEW_WINDOW, IDS_NEW_WINDOW, 0, NULL, + GDK_n, GDK_CONTROL_MASK }, + { MENU_NORMAL, IDC_NEW_INCOGNITO_WINDOW, IDS_NEW_INCOGNITO_WINDOW, 0, NULL, + GDK_n, GDK_CONTROL_MASK | GDK_SHIFT_MASK}, { MENU_SEPARATOR, 0, 0, NULL }, - { MENU_NORMAL, IDC_SHOW_BOOKMARK_BAR, IDS_SHOW_BOOKMARK_BAR }, + { MENU_NORMAL, IDC_SHOW_BOOKMARK_BAR, IDS_SHOW_BOOKMARK_BAR, 0, NULL, + GDK_b, GDK_CONTROL_MASK }, { MENU_SEPARATOR, 0, 0, NULL }, - { MENU_NORMAL, IDC_SHOW_HISTORY, IDS_SHOW_HISTORY }, - { MENU_NORMAL, IDC_SHOW_BOOKMARK_MANAGER, IDS_BOOKMARK_MANAGER }, - { MENU_NORMAL, IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS }, + { MENU_NORMAL, IDC_SHOW_HISTORY, IDS_SHOW_HISTORY, 0, NULL, + GDK_h, GDK_CONTROL_MASK }, + { MENU_NORMAL, IDC_SHOW_BOOKMARK_MANAGER, IDS_BOOKMARK_MANAGER, 0, NULL, + GDK_b, GDK_CONTROL_MASK | GDK_SHIFT_MASK }, + { MENU_NORMAL, IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS, 0, NULL, + GDK_j, GDK_CONTROL_MASK }, { MENU_SEPARATOR, 0, 0, NULL }, // TODO(erg): P13N stuff goes here as soon as they get IDS strings. { MENU_NORMAL, IDC_CLEAR_BROWSING_DATA, IDS_CLEAR_BROWSING_DATA, 0, NULL }, @@ -76,12 +92,12 @@ struct MenuCreateMaterial standard_app_menu_materials[] = { { MENU_SEPARATOR, 0, 0, 0, NULL }, { MENU_NORMAL, IDC_OPTIONS, IDS_OPTIONS, IDS_PRODUCT_NAME, NULL }, { MENU_NORMAL, IDC_ABOUT, IDS_ABOUT, IDS_PRODUCT_NAME, NULL }, - { MENU_NORMAL, IDC_HELP_PAGE, IDS_HELP_PAGE, 0, NULL }, + { MENU_NORMAL, IDC_HELP_PAGE, IDS_HELP_PAGE, 0, NULL, + GDK_F1, 0 }, { MENU_SEPARATOR, 0, 0, 0, NULL }, { MENU_NORMAL, IDC_EXIT, IDS_EXIT, 0, NULL }, - { MENU_END, 0, 0, NULL } + { MENU_END, 0, 0, 0, NULL } }; - } // namespace const MenuCreateMaterial* GetStandardPageMenu() { diff --git a/chrome/browser/gtk/standard_menus.h b/chrome/browser/gtk/standard_menus.h index 89c6d10..90d289d 100644 --- a/chrome/browser/gtk/standard_menus.h +++ b/chrome/browser/gtk/standard_menus.h @@ -33,6 +33,12 @@ struct MenuCreateMaterial { // If non-NULL, a pointer to the struct we're supposed to use MenuCreateMaterial* submenu; + + // A gdk keysym that is used to activate this item from outside the menu. + unsigned int accel_key; + + // GDK modifiers for the menu items (i.e., shift, ctrl, etc). + unsigned int accel_modifiers; }; // Returns the menu construction data structure for the page menu. diff --git a/chrome/browser/tab_contents/web_contents_view_gtk.cc b/chrome/browser/tab_contents/web_contents_view_gtk.cc index 35ca7b1..d90c9ae 100644 --- a/chrome/browser/tab_contents/web_contents_view_gtk.cc +++ b/chrome/browser/tab_contents/web_contents_view_gtk.cc @@ -4,6 +4,8 @@ #include "chrome/browser/tab_contents/web_contents_view_gtk.h" +#include <gdk/gdk.h> +#include <gdk/gdkkeysyms.h> #include <gtk/gtk.h> #include "base/gfx/point.h" @@ -13,6 +15,8 @@ #include "chrome/browser/tab_contents/tab_contents_delegate.h" #include "chrome/browser/tab_contents/web_contents.h" +#include "webkit/glue/webinputevent.h" + namespace { // Called when the content view gtk widget is tabbed to. We always return true @@ -146,12 +150,28 @@ void WebContentsViewGtk::TakeFocus(bool reverse) { web_contents_->delegate()->SetFocusToLocationBar(); } -void WebContentsViewGtk::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { - // The renderer returned a keyboard event it did not process. This may be - // a keyboard shortcut that we have to process. - // The windows code forwards this event onwards to accelerator handling, - // and then to DefWindowProc. TODO(port): should do something similar. - NOTIMPLEMENTED(); + +void WebContentsViewGtk::HandleKeyboardEvent( + const NativeWebKeyboardEvent& event) { + // The renderer returned a keyboard event it did not process. This may be a + // keyboard shortcut that we have to process or a cursor key/page up/down + // etc. + switch (event.os_event->keyval) { + case GDK_Page_Up: + case GDK_Page_Down: + case GDK_Left: + case GDK_Right: + case GDK_Up: + case GDK_Down: + NOTIMPLEMENTED() + << "Need better navigation support in HandleKeyboardEvent"; + break; + default: + // This may be an accelerator. Pass it on to GTK. + gtk_accel_groups_activate(G_OBJECT(vbox_->window), + event.os_event->keyval, + GdkModifierType(event.os_event->state)); + } } void WebContentsViewGtk::OnFindReply(int request_id, |