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

Side by Side Diff: chrome/browser/ui/gtk/browser_window_gtk.cc

Issue 10117016: Implementation for switching between recently used tabs using ctrl tilde or quoteleft. Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Uploading patch for review after rebase. Created 8 years, 5 months 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 unified diff | Download patch
OLDNEW
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 #include "chrome/browser/ui/gtk/status_bubble_gtk.h" 71 #include "chrome/browser/ui/gtk/status_bubble_gtk.h"
72 #include "chrome/browser/ui/gtk/tab_contents_container_gtk.h" 72 #include "chrome/browser/ui/gtk/tab_contents_container_gtk.h"
73 #include "chrome/browser/ui/gtk/tabs/tab_strip_gtk.h" 73 #include "chrome/browser/ui/gtk/tabs/tab_strip_gtk.h"
74 #include "chrome/browser/ui/gtk/task_manager_gtk.h" 74 #include "chrome/browser/ui/gtk/task_manager_gtk.h"
75 #include "chrome/browser/ui/gtk/update_recommended_dialog.h" 75 #include "chrome/browser/ui/gtk/update_recommended_dialog.h"
76 #include "chrome/browser/ui/gtk/website_settings_popup_gtk.h" 76 #include "chrome/browser/ui/gtk/website_settings_popup_gtk.h"
77 #include "chrome/browser/ui/omnibox/location_bar.h" 77 #include "chrome/browser/ui/omnibox/location_bar.h"
78 #include "chrome/browser/ui/omnibox/omnibox_view.h" 78 #include "chrome/browser/ui/omnibox/omnibox_view.h"
79 #include "chrome/browser/ui/page_info_bubble.h" 79 #include "chrome/browser/ui/page_info_bubble.h"
80 #include "chrome/browser/ui/tab_contents/tab_contents.h" 80 #include "chrome/browser/ui/tab_contents/tab_contents.h"
81 #include "chrome/browser/ui/tabs/mru_tab_controller.h"
81 #include "chrome/browser/ui/tabs/tab_strip_model.h" 82 #include "chrome/browser/ui/tabs/tab_strip_model.h"
82 #include "chrome/browser/web_applications/web_app.h" 83 #include "chrome/browser/web_applications/web_app.h"
83 #include "chrome/common/chrome_notification_types.h" 84 #include "chrome/common/chrome_notification_types.h"
84 #include "chrome/common/chrome_switches.h" 85 #include "chrome/common/chrome_switches.h"
85 #include "chrome/common/pref_names.h" 86 #include "chrome/common/pref_names.h"
86 #include "content/public/browser/download_manager.h" 87 #include "content/public/browser/download_manager.h"
87 #include "content/public/browser/native_web_keyboard_event.h" 88 #include "content/public/browser/native_web_keyboard_event.h"
88 #include "content/public/browser/notification_service.h" 89 #include "content/public/browser/notification_service.h"
89 #include "content/public/browser/render_view_host.h" 90 #include "content/public/browser/render_view_host.h"
90 #include "content/public/browser/render_widget_host_view.h" 91 #include "content/public/browser/render_widget_host_view.h"
(...skipping 1695 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 g_signal_connect(window_, "delete-event", 1787 g_signal_connect(window_, "delete-event",
1787 G_CALLBACK(OnMainWindowDeleteEventThunk), this); 1788 G_CALLBACK(OnMainWindowDeleteEventThunk), this);
1788 g_signal_connect(window_, "destroy", 1789 g_signal_connect(window_, "destroy",
1789 G_CALLBACK(OnMainWindowDestroyThunk), this); 1790 G_CALLBACK(OnMainWindowDestroyThunk), this);
1790 g_signal_connect(window_, "configure-event", 1791 g_signal_connect(window_, "configure-event",
1791 G_CALLBACK(OnConfigureThunk), this); 1792 G_CALLBACK(OnConfigureThunk), this);
1792 g_signal_connect(window_, "window-state-event", 1793 g_signal_connect(window_, "window-state-event",
1793 G_CALLBACK(OnWindowStateThunk), this); 1794 G_CALLBACK(OnWindowStateThunk), this);
1794 g_signal_connect(window_, "key-press-event", 1795 g_signal_connect(window_, "key-press-event",
1795 G_CALLBACK(OnKeyPressThunk), this); 1796 G_CALLBACK(OnKeyPressThunk), this);
1797 g_signal_connect(window_, "key-release-event",
1798 G_CALLBACK(OnKeyReleaseThunk), this);
1796 g_signal_connect(window_, "motion-notify-event", 1799 g_signal_connect(window_, "motion-notify-event",
1797 G_CALLBACK(OnMouseMoveEventThunk), this); 1800 G_CALLBACK(OnMouseMoveEventThunk), this);
1798 g_signal_connect(window_, "button-press-event", 1801 g_signal_connect(window_, "button-press-event",
1799 G_CALLBACK(OnButtonPressEventThunk), this); 1802 G_CALLBACK(OnButtonPressEventThunk), this);
1800 g_signal_connect(window_, "focus-in-event", 1803 g_signal_connect(window_, "focus-in-event",
1801 G_CALLBACK(OnFocusInThunk), this); 1804 G_CALLBACK(OnFocusInThunk), this);
1802 g_signal_connect(window_, "focus-out-event", 1805 g_signal_connect(window_, "focus-out-event",
1803 G_CALLBACK(OnFocusOutThunk), this); 1806 G_CALLBACK(OnFocusOutThunk), this);
1804 } 1807 }
1805 1808
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
2206 return chrome::ExecuteCommand(browser_window->browser(), command_id); 2209 return chrome::ExecuteCommand(browser_window->browser(), command_id);
2207 } 2210 }
2208 2211
2209 // Let the focused widget have first crack at the key event so we don't 2212 // Let the focused widget have first crack at the key event so we don't
2210 // override their accelerators, except if there is a priority keybinding 2213 // override their accelerators, except if there is a priority keybinding
2211 // handler registered (it should take precedence). 2214 // handler registered (it should take precedence).
2212 gboolean BrowserWindowGtk::OnKeyPress(GtkWidget* widget, GdkEventKey* event) { 2215 gboolean BrowserWindowGtk::OnKeyPress(GtkWidget* widget, GdkEventKey* event) {
2213 if (extension_keybinding_registry_->HasPriorityHandler(event)) 2216 if (extension_keybinding_registry_->HasPriorityHandler(event))
2214 return FALSE; 2217 return FALSE;
2215 2218
2219 // Pause tab mru stack updates when control key is pressed. For eg. ignore
2220 // active tab changes when ctrl key is pressed. Commit the changes only
2221 // on releasing the ctrl key.
2222 MRUTabController* mru_tab_controller = browser()->mru_tab_controller();
2223 if (mru_tab_controller) {
2224 guint modifier = event->state & gtk_accelerator_get_default_mod_mask();
2225 if (GDK_CONTROL_MASK == modifier) {
2226 if ((event->keyval == GDK_KEY_asciitilde) ||
2227 (event->keyval == GDK_KEY_quoteleft)) {
2228 mru_tab_controller->CommitActiveTabChanges();
2229 } else {
2230 mru_tab_controller->PauseStackUpdates();
2231 }
2232 }
2233 }
2234
2216 // If a widget besides the native view is focused, we have to try to handle 2235 // If a widget besides the native view is focused, we have to try to handle
2217 // the custom accelerators before letting it handle them. 2236 // the custom accelerators before letting it handle them.
2218 WebContents* current_web_contents = chrome::GetActiveWebContents(browser()); 2237 WebContents* current_web_contents = chrome::GetActiveWebContents(browser());
2219 // The current tab might not have a render view if it crashed. 2238 // The current tab might not have a render view if it crashed.
2220 if (!current_web_contents || !current_web_contents->GetContentNativeView() || 2239 if (!current_web_contents || !current_web_contents->GetContentNativeView() ||
2221 !gtk_widget_is_focus(current_web_contents->GetContentNativeView())) { 2240 !gtk_widget_is_focus(current_web_contents->GetContentNativeView())) {
2222 int command_id = GetCustomCommandId(event); 2241 int command_id = GetCustomCommandId(event);
2223 if (command_id == -1) 2242 if (command_id == -1)
2224 command_id = GetPreHandleCommandId(event); 2243 command_id = GetPreHandleCommandId(event);
2225 2244
2226 if (command_id != -1 && chrome::ExecuteCommand(browser_.get(), command_id)) 2245 if (command_id != -1 && chrome::ExecuteCommand(browser_.get(), command_id))
2227 return TRUE; 2246 return TRUE;
2228 2247
2229 // Propagate the key event to child widget first, so we don't override their 2248 // Propagate the key event to child widget first, so we don't override their
2230 // accelerators. 2249 // accelerators.
2231 if (!gtk_window_propagate_key_event(GTK_WINDOW(widget), event)) { 2250 if (!gtk_window_propagate_key_event(GTK_WINDOW(widget), event)) {
2232 if (!gtk_window_activate_key(GTK_WINDOW(widget), event)) { 2251 if (!gtk_window_activate_key(GTK_WINDOW(widget), event)) {
2233 gtk_bindings_activate_event(GTK_OBJECT(widget), event); 2252 gtk_bindings_activate_event(GTK_OBJECT(widget), event);
2234 } 2253 }
2235 } 2254 }
2236 } else { 2255 } else {
2237 bool rv = gtk_window_propagate_key_event(GTK_WINDOW(widget), event); 2256 bool rv = gtk_window_propagate_key_event(GTK_WINDOW(widget), event);
2238 DCHECK(rv); 2257 DCHECK(rv);
2239 } 2258 }
2240 2259
2241 // Prevents the default handler from handling this event. 2260 // Prevents the default handler from handling this event.
2242 return TRUE; 2261 return TRUE;
2243 } 2262 }
2244 2263
2264 gboolean BrowserWindowGtk::OnKeyRelease(GtkWidget* widget, GdkEventKey* event) {
2265 MRUTabController* mru_tab_controller = browser()->mru_tab_controller();
2266 if (mru_tab_controller &&
2267 (event->keyval == GDK_KEY_Control_L ||
2268 event->keyval == GDK_KEY_Control_R)) {
2269 mru_tab_controller->CommitActiveTabChanges();
2270 }
2271
2272 return FALSE;
2273 }
2274
2245 gboolean BrowserWindowGtk::OnMouseMoveEvent(GtkWidget* widget, 2275 gboolean BrowserWindowGtk::OnMouseMoveEvent(GtkWidget* widget,
2246 GdkEventMotion* event) { 2276 GdkEventMotion* event) {
2247 // This method is used to update the mouse cursor when over the edge of the 2277 // This method is used to update the mouse cursor when over the edge of the
2248 // custom frame. If the custom frame is off or we're over some other widget, 2278 // custom frame. If the custom frame is off or we're over some other widget,
2249 // do nothing. 2279 // do nothing.
2250 if (!UseCustomFrame() || event->window != gtk_widget_get_window(widget)) { 2280 if (!UseCustomFrame() || event->window != gtk_widget_get_window(widget)) {
2251 // Reset the cursor. 2281 // Reset the cursor.
2252 if (frame_cursor_) { 2282 if (frame_cursor_) {
2253 frame_cursor_ = NULL; 2283 frame_cursor_ = NULL;
2254 gdk_window_set_cursor(gtk_widget_get_window(GTK_WIDGET(window_)), NULL); 2284 gdk_window_set_cursor(gtk_widget_get_window(GTK_WIDGET(window_)), NULL);
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
2597 wm_type == ui::WM_OPENBOX || 2627 wm_type == ui::WM_OPENBOX ||
2598 wm_type == ui::WM_XFWM4); 2628 wm_type == ui::WM_XFWM4);
2599 } 2629 }
2600 2630
2601 // static 2631 // static
2602 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { 2632 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) {
2603 BrowserWindowGtk* browser_window_gtk = new BrowserWindowGtk(browser); 2633 BrowserWindowGtk* browser_window_gtk = new BrowserWindowGtk(browser);
2604 browser_window_gtk->Init(); 2634 browser_window_gtk->Init();
2605 return browser_window_gtk; 2635 return browser_window_gtk;
2606 } 2636 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698