OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/gtk/browser_window_gtk.h" | 5 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "chrome/browser/browser_process.h" | 30 #include "chrome/browser/browser_process.h" |
31 #include "chrome/browser/debugger/devtools_window.h" | 31 #include "chrome/browser/debugger/devtools_window.h" |
32 #include "chrome/browser/download/download_item_model.h" | 32 #include "chrome/browser/download/download_item_model.h" |
33 #include "chrome/browser/prefs/pref_service.h" | 33 #include "chrome/browser/prefs/pref_service.h" |
34 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 34 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
35 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
36 #include "chrome/browser/themes/theme_service.h" | 36 #include "chrome/browser/themes/theme_service.h" |
37 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" | 37 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" |
38 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 38 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
39 #include "chrome/browser/ui/browser.h" | 39 #include "chrome/browser/ui/browser.h" |
| 40 #include "chrome/browser/ui/browser_command_controller.h" |
40 #include "chrome/browser/ui/browser_commands.h" | 41 #include "chrome/browser/ui/browser_commands.h" |
41 #include "chrome/browser/ui/browser_dialogs.h" | 42 #include "chrome/browser/ui/browser_dialogs.h" |
42 #include "chrome/browser/ui/browser_list.h" | 43 #include "chrome/browser/ui/browser_list.h" |
43 #include "chrome/browser/ui/browser_window_state.h" | 44 #include "chrome/browser/ui/browser_window_state.h" |
44 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 45 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
45 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 46 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
46 #include "chrome/browser/ui/gtk/accelerators_gtk.h" | 47 #include "chrome/browser/ui/gtk/accelerators_gtk.h" |
47 #include "chrome/browser/ui/gtk/avatar_menu_bubble_gtk.h" | 48 #include "chrome/browser/ui/gtk/avatar_menu_bubble_gtk.h" |
48 #include "chrome/browser/ui/gtk/avatar_menu_button_gtk.h" | 49 #include "chrome/browser/ui/gtk/avatar_menu_button_gtk.h" |
49 #include "chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h" | 50 #include "chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h" |
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 // |browser_| object. | 1173 // |browser_| object. |
1173 // | 1174 // |
1174 // Pros of this approach: | 1175 // Pros of this approach: |
1175 // 1. We don't need to care about keyboard layout problem, as | 1176 // 1. We don't need to care about keyboard layout problem, as |
1176 // gtk_window_activate_key() method handles it for us. | 1177 // gtk_window_activate_key() method handles it for us. |
1177 // | 1178 // |
1178 // Cons: | 1179 // Cons: |
1179 // 1. The logic is a little complicated. | 1180 // 1. The logic is a little complicated. |
1180 // 2. We should be careful not to introduce any accelerators that trigger | 1181 // 2. We should be careful not to introduce any accelerators that trigger |
1181 // customized code instead of browser commands. | 1182 // customized code instead of browser commands. |
1182 browser_->SetBlockCommandExecution(true); | 1183 browser_->command_controller()->SetBlockCommandExecution(true); |
1183 gtk_window_activate_key(window_, os_event); | 1184 gtk_window_activate_key(window_, os_event); |
1184 // We don't need to care about the WindowOpenDisposition value, | 1185 // We don't need to care about the WindowOpenDisposition value, |
1185 // because all commands executed in this path use the default value. | 1186 // because all commands executed in this path use the default value. |
1186 id = browser_->GetLastBlockedCommand(NULL); | 1187 id = browser_->command_controller()->GetLastBlockedCommand(NULL); |
1187 browser_->SetBlockCommandExecution(false); | 1188 browser_->command_controller()->SetBlockCommandExecution(false); |
1188 } | 1189 } |
1189 | 1190 |
1190 if (id == -1) | 1191 if (id == -1) |
1191 return false; | 1192 return false; |
1192 | 1193 |
1193 // Executing the command may cause |this| object to be destroyed. | 1194 // Executing the command may cause |this| object to be destroyed. |
1194 if (browser_->IsReservedCommandOrKey(id, event) && !event.match_edit_command) | 1195 if (browser_->command_controller()->IsReservedCommandOrKey(id, event) && |
1195 return browser_->ExecuteCommandIfEnabled(id); | 1196 !event.match_edit_command) { |
| 1197 return chrome::ExecuteCommand(browser_.get(), id); |
| 1198 } |
1196 | 1199 |
1197 // The |event| is a keyboard shortcut. | 1200 // The |event| is a keyboard shortcut. |
1198 DCHECK(is_keyboard_shortcut != NULL); | 1201 DCHECK(is_keyboard_shortcut != NULL); |
1199 *is_keyboard_shortcut = true; | 1202 *is_keyboard_shortcut = true; |
1200 | 1203 |
1201 return false; | 1204 return false; |
1202 } | 1205 } |
1203 | 1206 |
1204 void BrowserWindowGtk::HandleKeyboardEvent( | 1207 void BrowserWindowGtk::HandleKeyboardEvent( |
1205 const NativeWebKeyboardEvent& event) { | 1208 const NativeWebKeyboardEvent& event) { |
1206 GdkEventKey* os_event = &event.os_event->key; | 1209 GdkEventKey* os_event = &event.os_event->key; |
1207 | 1210 |
1208 if (!os_event || event.type != WebKit::WebInputEvent::RawKeyDown) | 1211 if (!os_event || event.type != WebKit::WebInputEvent::RawKeyDown) |
1209 return; | 1212 return; |
1210 | 1213 |
1211 // Handles a key event in following sequence: | 1214 // Handles a key event in following sequence: |
1212 // 1. Our special key accelerators, such as ctrl-tab, etc. | 1215 // 1. Our special key accelerators, such as ctrl-tab, etc. |
1213 // 2. Gtk accelerators. | 1216 // 2. Gtk accelerators. |
1214 // This sequence matches the default key press handler of GtkWindow. | 1217 // This sequence matches the default key press handler of GtkWindow. |
1215 // | 1218 // |
1216 // It's not necessary to care about the keyboard layout, as | 1219 // It's not necessary to care about the keyboard layout, as |
1217 // gtk_window_activate_key() takes care of it automatically. | 1220 // gtk_window_activate_key() takes care of it automatically. |
1218 int id = GetCustomCommandId(os_event); | 1221 int id = GetCustomCommandId(os_event); |
1219 if (id != -1) | 1222 if (id != -1) |
1220 browser_->ExecuteCommandIfEnabled(id); | 1223 chrome::ExecuteCommand(browser_.get(), id); |
1221 else | 1224 else |
1222 gtk_window_activate_key(window_, os_event); | 1225 gtk_window_activate_key(window_, os_event); |
1223 } | 1226 } |
1224 | 1227 |
1225 void BrowserWindowGtk::ShowCreateWebAppShortcutsDialog( | 1228 void BrowserWindowGtk::ShowCreateWebAppShortcutsDialog( |
1226 TabContents* tab_contents) { | 1229 TabContents* tab_contents) { |
1227 CreateWebApplicationShortcutsDialogGtk::Show(window_, tab_contents); | 1230 CreateWebApplicationShortcutsDialogGtk::Show(window_, tab_contents); |
1228 } | 1231 } |
1229 | 1232 |
1230 void BrowserWindowGtk::ShowCreateChromeAppShortcutsDialog( | 1233 void BrowserWindowGtk::ShowCreateChromeAppShortcutsDialog( |
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2198 // static | 2201 // static |
2199 gboolean BrowserWindowGtk::OnGtkAccelerator(GtkAccelGroup* accel_group, | 2202 gboolean BrowserWindowGtk::OnGtkAccelerator(GtkAccelGroup* accel_group, |
2200 GObject* acceleratable, | 2203 GObject* acceleratable, |
2201 guint keyval, | 2204 guint keyval, |
2202 GdkModifierType modifier, | 2205 GdkModifierType modifier, |
2203 void* user_data) { | 2206 void* user_data) { |
2204 int command_id = GPOINTER_TO_INT(user_data); | 2207 int command_id = GPOINTER_TO_INT(user_data); |
2205 BrowserWindowGtk* browser_window = | 2208 BrowserWindowGtk* browser_window = |
2206 GetBrowserWindowForNativeWindow(GTK_WINDOW(acceleratable)); | 2209 GetBrowserWindowForNativeWindow(GTK_WINDOW(acceleratable)); |
2207 DCHECK(browser_window != NULL); | 2210 DCHECK(browser_window != NULL); |
2208 return browser_window->browser()->ExecuteCommandIfEnabled(command_id); | 2211 return chrome::ExecuteCommand(browser_window->browser(), command_id); |
2209 } | 2212 } |
2210 | 2213 |
2211 // Let the focused widget have first crack at the key event so we don't | 2214 // Let the focused widget have first crack at the key event so we don't |
2212 // override their accelerators, except if there is a priority keybinding | 2215 // override their accelerators, except if there is a priority keybinding |
2213 // handler registered (it should take precedence). | 2216 // handler registered (it should take precedence). |
2214 gboolean BrowserWindowGtk::OnKeyPress(GtkWidget* widget, GdkEventKey* event) { | 2217 gboolean BrowserWindowGtk::OnKeyPress(GtkWidget* widget, GdkEventKey* event) { |
2215 if (extension_keybinding_registry_->HasPriorityHandler(event)) | 2218 if (extension_keybinding_registry_->HasPriorityHandler(event)) |
2216 return FALSE; | 2219 return FALSE; |
2217 | 2220 |
2218 // If a widget besides the native view is focused, we have to try to handle | 2221 // If a widget besides the native view is focused, we have to try to handle |
2219 // the custom accelerators before letting it handle them. | 2222 // the custom accelerators before letting it handle them. |
2220 WebContents* current_web_contents = | 2223 WebContents* current_web_contents = |
2221 browser()->GetActiveWebContents(); | 2224 browser()->GetActiveWebContents(); |
2222 // The current tab might not have a render view if it crashed. | 2225 // The current tab might not have a render view if it crashed. |
2223 if (!current_web_contents || !current_web_contents->GetContentNativeView() || | 2226 if (!current_web_contents || !current_web_contents->GetContentNativeView() || |
2224 !gtk_widget_is_focus(current_web_contents->GetContentNativeView())) { | 2227 !gtk_widget_is_focus(current_web_contents->GetContentNativeView())) { |
2225 int command_id = GetCustomCommandId(event); | 2228 int command_id = GetCustomCommandId(event); |
2226 if (command_id == -1) | 2229 if (command_id == -1) |
2227 command_id = GetPreHandleCommandId(event); | 2230 command_id = GetPreHandleCommandId(event); |
2228 | 2231 |
2229 if (command_id != -1 && browser_->ExecuteCommandIfEnabled(command_id)) | 2232 if (command_id != -1 && chrome::ExecuteCommand(browser_.get(), command_id)) |
2230 return TRUE; | 2233 return TRUE; |
2231 | 2234 |
2232 // Propagate the key event to child widget first, so we don't override their | 2235 // Propagate the key event to child widget first, so we don't override their |
2233 // accelerators. | 2236 // accelerators. |
2234 if (!gtk_window_propagate_key_event(GTK_WINDOW(widget), event)) { | 2237 if (!gtk_window_propagate_key_event(GTK_WINDOW(widget), event)) { |
2235 if (!gtk_window_activate_key(GTK_WINDOW(widget), event)) { | 2238 if (!gtk_window_activate_key(GTK_WINDOW(widget), event)) { |
2236 gtk_bindings_activate_event(GTK_OBJECT(widget), event); | 2239 gtk_bindings_activate_event(GTK_OBJECT(widget), event); |
2237 } | 2240 } |
2238 } | 2241 } |
2239 } else { | 2242 } else { |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2600 wm_type == ui::WM_OPENBOX || | 2603 wm_type == ui::WM_OPENBOX || |
2601 wm_type == ui::WM_XFWM4); | 2604 wm_type == ui::WM_XFWM4); |
2602 } | 2605 } |
2603 | 2606 |
2604 // static | 2607 // static |
2605 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { | 2608 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { |
2606 BrowserWindowGtk* browser_window_gtk = new BrowserWindowGtk(browser); | 2609 BrowserWindowGtk* browser_window_gtk = new BrowserWindowGtk(browser); |
2607 browser_window_gtk->Init(); | 2610 browser_window_gtk->Init(); |
2608 return browser_window_gtk; | 2611 return browser_window_gtk; |
2609 } | 2612 } |
OLD | NEW |