diff options
-rw-r--r-- | chrome/browser/automation/ui_controls_linux.cc | 12 | ||||
-rw-r--r-- | chrome/browser/browser_init.cc | 16 | ||||
-rw-r--r-- | chrome/browser/gtk/gtk_util.cc | 10 | ||||
-rw-r--r-- | chrome/browser/gtk/gtk_util.h | 10 |
4 files changed, 37 insertions, 11 deletions
diff --git a/chrome/browser/automation/ui_controls_linux.cc b/chrome/browser/automation/ui_controls_linux.cc index aac9134..77be4c1 100644 --- a/chrome/browser/automation/ui_controls_linux.cc +++ b/chrome/browser/automation/ui_controls_linux.cc @@ -21,12 +21,6 @@ namespace { -guint32 EventTimeNow() { - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; -} - class EventWaiter : public MessageLoopForUI::Observer { public: EventWaiter(Task* task, GdkEventType type, int count) @@ -95,7 +89,7 @@ bool SendKeyEvent(GdkWindow* window, bool press, guint gdk_key, guint state) { event->key.window = window; g_object_ref(event->key.window); event->key.send_event = false; - event->key.time = EventTimeNow(); + event->key.time = gtk_util::XTimeNow(); event->key.state = state; event->key.keyval = gdk_key; @@ -120,7 +114,7 @@ void FakeAMouseMotionEvent(gint x, gint y) { GdkEvent* event = gdk_event_new(GDK_MOTION_NOTIFY); event->motion.send_event = false; - event->motion.time = EventTimeNow(); + event->motion.time = gtk_util::XTimeNow(); GtkWidget* grab_widget = gtk_grab_get_current(); if (grab_widget) { @@ -260,7 +254,7 @@ bool SendMouseEvents(MouseButton type, int state) { GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS); event->button.send_event = false; - event->button.time = EventTimeNow(); + event->button.time = gtk_util::XTimeNow(); gint x, y; GtkWidget* grab_widget = gtk_grab_get_current(); diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc index af39c5b..301d7db 100644 --- a/chrome/browser/browser_init.cc +++ b/chrome/browser/browser_init.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -62,6 +62,10 @@ #include "app/win_util.h" #endif +#if defined(TOOLKIT_GTK) +#include "chrome/browser/gtk/gtk_util.h" +#endif + #if defined(OS_CHROMEOS) #include "chrome/browser/chromeos/browser_notification_observers.h" #include "chrome/browser/dom_ui/mediaplayer_ui.h" @@ -694,8 +698,16 @@ Browser* BrowserInit::LaunchWithProfile::OpenTabsInBrowser( if (!profile_ && browser) profile_ = browser->profile(); - if (!browser || browser->type() != Browser::TYPE_NORMAL) + if (!browser || browser->type() != Browser::TYPE_NORMAL) { browser = Browser::Create(profile_); + } else { +#if defined(TOOLKIT_GTK) + // Setting the time of the last action on the window here allows us to steal + // focus, which is what the user wants when opening a new tab in an existing + // browser window. + gtk_util::SetWMLastUserActionTime(browser->window()->GetNativeHandle()); +#endif + } #if !defined(OS_MACOSX) // In kiosk mode, we want to always be fullscreen, so switch to that now. diff --git a/chrome/browser/gtk/gtk_util.cc b/chrome/browser/gtk/gtk_util.cc index 0f8b629..4d5796a 100644 --- a/chrome/browser/gtk/gtk_util.cc +++ b/chrome/browser/gtk/gtk_util.cc @@ -861,6 +861,16 @@ gfx::Rect WidgetBounds(GtkWidget* widget) { return gfx::Rect(0, 0, widget->allocation.width, widget->allocation.height); } +void SetWMLastUserActionTime(GtkWindow* window) { + gdk_x11_window_set_user_time(GTK_WIDGET(window)->window, XTimeNow()); +} + +guint32 XTimeNow() { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; +} + bool URLFromPrimarySelection(Profile* profile, GURL* url) { GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); DCHECK(clipboard); diff --git a/chrome/browser/gtk/gtk_util.h b/chrome/browser/gtk/gtk_util.h index 02ae615..1d8b6d3 100644 --- a/chrome/browser/gtk/gtk_util.h +++ b/chrome/browser/gtk/gtk_util.h @@ -262,6 +262,16 @@ bool GrabAllInput(GtkWidget* widget); // returns is the same as widget->allocation, but anchored at (0, 0). gfx::Rect WidgetBounds(GtkWidget* widget); +// Update the timestamp for the given window. This is usually the time of the +// last user event, but on rare occasions we wish to update it despite not +// receiving a user event. +void SetWMLastUserActionTime(GtkWindow* window); + +// The current system time, using the format expected by the X server, but not +// retrieved from the X server. NOTE: You should almost never need to use this +// function, instead using the timestamp from the latest GDK event. +guint32 XTimeNow(); + // Uses the autocomplete controller for |profile| to convert the contents of the // PRIMARY selection to a parsed URL. Returns true and sets |url| on success, // otherwise returns false. |