OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/gtk/browser_window_gtk.h" | 5 #include "chrome/browser/gtk/browser_window_gtk.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 #include <X11/XF86keysym.h> | 8 #include <X11/XF86keysym.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 { XF86XK_Go, IDC_FOCUS_LOCATION, GdkModifierType(0) }, | 191 { XF86XK_Go, IDC_FOCUS_LOCATION, GdkModifierType(0) }, |
192 | 192 |
193 // Tab/window controls. | 193 // Tab/window controls. |
194 { GDK_Page_Down, IDC_SELECT_NEXT_TAB, GDK_CONTROL_MASK }, | 194 { GDK_Page_Down, IDC_SELECT_NEXT_TAB, GDK_CONTROL_MASK }, |
195 { GDK_Page_Up, IDC_SELECT_PREVIOUS_TAB, GDK_CONTROL_MASK }, | 195 { GDK_Page_Up, IDC_SELECT_PREVIOUS_TAB, GDK_CONTROL_MASK }, |
196 { GDK_Page_Down, IDC_MOVE_TAB_NEXT, | 196 { GDK_Page_Down, IDC_MOVE_TAB_NEXT, |
197 GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) }, | 197 GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) }, |
198 { GDK_Page_Up, IDC_MOVE_TAB_PREVIOUS, | 198 { GDK_Page_Up, IDC_MOVE_TAB_PREVIOUS, |
199 GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) }, | 199 GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) }, |
200 { GDK_Page_Up, IDC_SELECT_PREVIOUS_TAB, GDK_CONTROL_MASK }, | 200 { GDK_Page_Up, IDC_SELECT_PREVIOUS_TAB, GDK_CONTROL_MASK }, |
| 201 { GDK_t, IDC_NEW_TAB, GDK_CONTROL_MASK }, |
| 202 { GDK_n, IDC_NEW_WINDOW, GDK_CONTROL_MASK }, |
| 203 { GDK_n, IDC_NEW_INCOGNITO_WINDOW, |
| 204 GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) }, |
201 { GDK_w, IDC_CLOSE_TAB, GDK_CONTROL_MASK }, | 205 { GDK_w, IDC_CLOSE_TAB, GDK_CONTROL_MASK }, |
202 { GDK_t, IDC_RESTORE_TAB, | 206 { GDK_t, IDC_RESTORE_TAB, |
203 GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) }, | 207 GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) }, |
204 | 208 |
205 { GDK_1, IDC_SELECT_TAB_0, GDK_CONTROL_MASK }, | 209 { GDK_1, IDC_SELECT_TAB_0, GDK_CONTROL_MASK }, |
206 { GDK_2, IDC_SELECT_TAB_1, GDK_CONTROL_MASK }, | 210 { GDK_2, IDC_SELECT_TAB_1, GDK_CONTROL_MASK }, |
207 { GDK_3, IDC_SELECT_TAB_2, GDK_CONTROL_MASK }, | 211 { GDK_3, IDC_SELECT_TAB_2, GDK_CONTROL_MASK }, |
208 { GDK_4, IDC_SELECT_TAB_3, GDK_CONTROL_MASK }, | 212 { GDK_4, IDC_SELECT_TAB_3, GDK_CONTROL_MASK }, |
209 { GDK_5, IDC_SELECT_TAB_4, GDK_CONTROL_MASK }, | 213 { GDK_5, IDC_SELECT_TAB_4, GDK_CONTROL_MASK }, |
210 { GDK_6, IDC_SELECT_TAB_5, GDK_CONTROL_MASK }, | 214 { GDK_6, IDC_SELECT_TAB_5, GDK_CONTROL_MASK }, |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 // Bug 9806: If capslock is on, we will get a capital letter as accel_key. | 358 // Bug 9806: If capslock is on, we will get a capital letter as accel_key. |
355 accel_key = gdk_keyval_to_lower(accel_key); | 359 accel_key = gdk_keyval_to_lower(accel_key); |
356 // Filter modifier to only include accelerator modifiers. | 360 // Filter modifier to only include accelerator modifiers. |
357 modifier = static_cast<GdkModifierType>( | 361 modifier = static_cast<GdkModifierType>( |
358 modifier & gtk_accelerator_get_default_mod_mask()); | 362 modifier & gtk_accelerator_get_default_mod_mask()); |
359 for (size_t i = 0; i < arraysize(kAcceleratorMap); ++i) { | 363 for (size_t i = 0; i < arraysize(kAcceleratorMap); ++i) { |
360 if (kAcceleratorMap[i].keyval == accel_key && | 364 if (kAcceleratorMap[i].keyval == accel_key && |
361 kAcceleratorMap[i].modifier_type == modifier) | 365 kAcceleratorMap[i].modifier_type == modifier) |
362 return kAcceleratorMap[i].command_id; | 366 return kAcceleratorMap[i].command_id; |
363 } | 367 } |
364 NOTREACHED(); | 368 |
365 return 0; | 369 return -1; |
366 } | 370 } |
367 | 371 |
368 // An event handler for key press events. We need to special case key | 372 int GetCustomCommandId(guint keyval, GdkModifierType modifier) { |
369 // combinations that are not valid gtk accelerators. This function returns | |
370 // TRUE if it can handle the key press. | |
371 gboolean HandleCustomAccelerator(guint keyval, GdkModifierType modifier, | |
372 Browser* browser) { | |
373 // Filter modifier to only include accelerator modifiers. | 373 // Filter modifier to only include accelerator modifiers. |
374 modifier = static_cast<GdkModifierType>( | 374 modifier = static_cast<GdkModifierType>( |
375 modifier & gtk_accelerator_get_default_mod_mask()); | 375 modifier & gtk_accelerator_get_default_mod_mask()); |
| 376 |
376 switch (keyval) { | 377 switch (keyval) { |
377 // Gtk doesn't allow GDK_Tab or GDK_ISO_Left_Tab to be an accelerator (see | 378 // Gtk doesn't allow GDK_Tab or GDK_ISO_Left_Tab to be an accelerator (see |
378 // gtk_accelerator_valid), so we need to handle these accelerators | 379 // gtk_accelerator_valid), so we need to handle these accelerators |
379 // manually. | 380 // manually. |
380 // Some X clients (e.g. cygwin, NX client, etc.) also send GDK_KP_Tab when | 381 // Some X clients (e.g. cygwin, NX client, etc.) also send GDK_KP_Tab when |
381 // typing a tab key. We should also handle GDK_KP_Tab for such X clients as | 382 // typing a tab key. We should also handle GDK_KP_Tab for such X clients as |
382 // Firefox does. | 383 // Firefox does. |
383 case GDK_Tab: | 384 case GDK_Tab: |
384 case GDK_ISO_Left_Tab: | 385 case GDK_ISO_Left_Tab: |
385 case GDK_KP_Tab: | 386 case GDK_KP_Tab: |
386 if (GDK_CONTROL_MASK == modifier) { | 387 if (GDK_CONTROL_MASK == modifier) { |
387 browser->ExecuteCommand(IDC_SELECT_NEXT_TAB); | 388 return IDC_SELECT_NEXT_TAB; |
388 return TRUE; | |
389 } else if ((GDK_CONTROL_MASK | GDK_SHIFT_MASK) == modifier) { | 389 } else if ((GDK_CONTROL_MASK | GDK_SHIFT_MASK) == modifier) { |
390 browser->ExecuteCommand(IDC_SELECT_PREVIOUS_TAB); | 390 return IDC_SELECT_PREVIOUS_TAB; |
391 return TRUE; | |
392 } | 391 } |
393 break; | 392 break; |
394 | 393 |
395 default: | 394 default: |
396 break; | 395 break; |
397 } | 396 } |
398 return FALSE; | 397 return -1; |
| 398 } |
| 399 |
| 400 // An event handler for key press events. We need to special case key |
| 401 // combinations that are not valid gtk accelerators. This function returns |
| 402 // TRUE if it can handle the key press. |
| 403 gboolean HandleCustomAccelerator(guint keyval, GdkModifierType modifier, |
| 404 Browser* browser) { |
| 405 int command = GetCustomCommandId(keyval, modifier); |
| 406 if (command == -1) |
| 407 return FALSE; |
| 408 |
| 409 browser->ExecuteCommand(command); |
| 410 return TRUE; |
399 } | 411 } |
400 | 412 |
401 // Handle accelerators that we don't want the native widget to be able to | 413 // Handle accelerators that we don't want the native widget to be able to |
402 // override. | 414 // override. |
403 gboolean PreHandleAccelerator(guint keyval, GdkModifierType modifier, | 415 gboolean PreHandleAccelerator(guint keyval, GdkModifierType modifier, |
404 Browser* browser) { | 416 Browser* browser) { |
405 // Filter modifier to only include accelerator modifiers. | 417 // Filter modifier to only include accelerator modifiers. |
406 modifier = static_cast<GdkModifierType>( | 418 modifier = static_cast<GdkModifierType>( |
407 modifier & gtk_accelerator_get_default_mod_mask()); | 419 modifier & gtk_accelerator_get_default_mod_mask()); |
408 switch (keyval) { | 420 switch (keyval) { |
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 bool show_history) { | 1158 bool show_history) { |
1147 browser::ShowPageInfo(window_, profile, url, ssl, show_history); | 1159 browser::ShowPageInfo(window_, profile, url, ssl, show_history); |
1148 } | 1160 } |
1149 | 1161 |
1150 void BrowserWindowGtk::ShowPageMenu() { | 1162 void BrowserWindowGtk::ShowPageMenu() { |
1151 } | 1163 } |
1152 | 1164 |
1153 void BrowserWindowGtk::ShowAppMenu() { | 1165 void BrowserWindowGtk::ShowAppMenu() { |
1154 } | 1166 } |
1155 | 1167 |
| 1168 int BrowserWindowGtk::GetCommandId(const NativeWebKeyboardEvent& event) { |
| 1169 if (!event.os_event) |
| 1170 return -1; |
| 1171 |
| 1172 guint keyval = event.os_event->keyval; |
| 1173 GdkModifierType modifier = GdkModifierType(event.os_event->state); |
| 1174 int command = ::GetCommandId(keyval, modifier); |
| 1175 if (command == -1) |
| 1176 command = GetCustomCommandId(keyval, modifier); |
| 1177 return command; |
| 1178 } |
| 1179 |
1156 void BrowserWindowGtk::ConfirmBrowserCloseWithPendingDownloads() { | 1180 void BrowserWindowGtk::ConfirmBrowserCloseWithPendingDownloads() { |
1157 new DownloadInProgressDialogGtk(browser()); | 1181 new DownloadInProgressDialogGtk(browser()); |
1158 } | 1182 } |
1159 | 1183 |
1160 void BrowserWindowGtk::Observe(NotificationType type, | 1184 void BrowserWindowGtk::Observe(NotificationType type, |
1161 const NotificationSource& source, | 1185 const NotificationSource& source, |
1162 const NotificationDetails& details) { | 1186 const NotificationDetails& details) { |
1163 switch (type.value) { | 1187 switch (type.value) { |
1164 case NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: | 1188 case NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: |
1165 MaybeShowBookmarkBar(browser_->GetSelectedTabContents(), true); | 1189 MaybeShowBookmarkBar(browser_->GetSelectedTabContents(), true); |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1866 window_preferences->SetInteger(L"work_area_right", work_area.right()); | 1890 window_preferences->SetInteger(L"work_area_right", work_area.right()); |
1867 window_preferences->SetInteger(L"work_area_bottom", work_area.bottom()); | 1891 window_preferences->SetInteger(L"work_area_bottom", work_area.bottom()); |
1868 } | 1892 } |
1869 | 1893 |
1870 // static | 1894 // static |
1871 gboolean BrowserWindowGtk::OnGtkAccelerator(GtkAccelGroup* accel_group, | 1895 gboolean BrowserWindowGtk::OnGtkAccelerator(GtkAccelGroup* accel_group, |
1872 GObject* acceleratable, | 1896 GObject* acceleratable, |
1873 guint keyval, | 1897 guint keyval, |
1874 GdkModifierType modifier, | 1898 GdkModifierType modifier, |
1875 BrowserWindowGtk* browser_window) { | 1899 BrowserWindowGtk* browser_window) { |
1876 int command_id = GetCommandId(keyval, modifier); | 1900 int command_id = ::GetCommandId(keyval, modifier); |
| 1901 DCHECK(command_id != -1); |
1877 browser_window->ExecuteBrowserCommand(command_id); | 1902 browser_window->ExecuteBrowserCommand(command_id); |
1878 | 1903 |
1879 return TRUE; | 1904 return TRUE; |
1880 } | 1905 } |
1881 | 1906 |
1882 // static | 1907 // static |
1883 gboolean BrowserWindowGtk::OnMouseMoveEvent(GtkWidget* widget, | 1908 gboolean BrowserWindowGtk::OnMouseMoveEvent(GtkWidget* widget, |
1884 GdkEventMotion* event, BrowserWindowGtk* browser) { | 1909 GdkEventMotion* event, BrowserWindowGtk* browser) { |
1885 // This method is used to update the mouse cursor when over the edge of the | 1910 // This method is used to update the mouse cursor when over the edge of the |
1886 // custom frame. If the custom frame is off or we're over some other widget, | 1911 // custom frame. If the custom frame is off or we're over some other widget, |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2210 // are taken from the WMs' source code. | 2235 // are taken from the WMs' source code. |
2211 return (wm_name == "Blackbox" || | 2236 return (wm_name == "Blackbox" || |
2212 wm_name == "compiz" || | 2237 wm_name == "compiz" || |
2213 wm_name == "e16" || // Enlightenment DR16 | 2238 wm_name == "e16" || // Enlightenment DR16 |
2214 wm_name == "KWin" || | 2239 wm_name == "KWin" || |
2215 wm_name == "Metacity" || | 2240 wm_name == "Metacity" || |
2216 wm_name == "Mutter" || | 2241 wm_name == "Mutter" || |
2217 wm_name == "Openbox" || | 2242 wm_name == "Openbox" || |
2218 wm_name == "Xfwm4"); | 2243 wm_name == "Xfwm4"); |
2219 } | 2244 } |
OLD | NEW |