Index: chrome/browser/tab_contents/tab_contents_view_gtk.cc |
diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc |
index 9787050cc348532b537513ab7c4bd0ffc95f5934..11a0da005b554721d9b05741ee3dbf78fd1cc584 100644 |
--- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc |
+++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc |
@@ -41,25 +41,6 @@ using WebKit::WebDragOperationsMask; |
namespace { |
-// Called when the content view gtk widget is tabbed to, or after the call to |
-// gtk_widget_child_focus() in TakeFocus(). We return true |
-// and grab focus if we don't have it. The call to |
-// FocusThroughTabTraversal(bool) forwards the "move focus forward" effect to |
-// webkit. |
-gboolean OnFocus(GtkWidget* widget, GtkDirectionType focus, |
- TabContents* tab_contents) { |
- // If we already have focus, let the next widget have a shot at it. We will |
- // reach this situation after the call to gtk_widget_child_focus() in |
- // TakeFocus(). |
- if (gtk_widget_is_focus(widget)) |
- return FALSE; |
- |
- gtk_widget_grab_focus(widget); |
- bool reverse = focus == GTK_DIR_TAB_BACKWARD; |
- tab_contents->FocusThroughTabTraversal(reverse); |
- return TRUE; |
-} |
- |
// Called when the mouse leaves the widget. We notify our delegate. |
gboolean OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event, |
TabContents* tab_contents) { |
@@ -165,8 +146,7 @@ RenderWidgetHostView* TabContentsViewGtk::CreateViewForWidget( |
new RenderWidgetHostViewGtk(render_widget_host); |
view->InitAsChild(); |
gfx::NativeView content_view = view->native_view(); |
- g_signal_connect(content_view, "focus", |
- G_CALLBACK(OnFocus), tab_contents()); |
+ g_signal_connect(content_view, "focus", G_CALLBACK(OnFocusThunk), this); |
g_signal_connect(content_view, "leave-notify-event", |
G_CALLBACK(OnLeaveNotify), tab_contents()); |
g_signal_connect(content_view, "motion-notify-event", |
@@ -243,7 +223,7 @@ void TabContentsViewGtk::SizeContents(const gfx::Size& size) { |
void TabContentsViewGtk::Focus() { |
if (tab_contents()->showing_interstitial_page()) { |
tab_contents()->interstitial_page()->Focus(); |
- } else { |
+ } else if (!constrained_window_) { |
GtkWidget* widget = GetContentNativeView(); |
if (widget) |
gtk_widget_grab_focus(widget); |
@@ -268,6 +248,10 @@ void TabContentsViewGtk::RestoreFocus() { |
SetInitialFocus(); |
} |
+void TabContentsViewGtk::SetFocusedWidget(GtkWidget* widget) { |
+ focus_store_.SetWidget(widget); |
+} |
+ |
void TabContentsViewGtk::UpdateDragCursor(WebDragOperation operation) { |
drag_dest_->UpdateDragStatus(operation); |
} |
@@ -332,6 +316,38 @@ void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) { |
gtk_container_add(GTK_CONTAINER(expanded_), widget); |
} |
+// Called when the content view gtk widget is tabbed to, or after the call to |
+// gtk_widget_child_focus() in TakeFocus(). We return true |
+// and grab focus if we don't have it. The call to |
+// FocusThroughTabTraversal(bool) forwards the "move focus forward" effect to |
+// webkit. |
+gboolean TabContentsViewGtk::OnFocus(GtkWidget* widget, |
+ GtkDirectionType focus) { |
+ // If we are showing a constrained window, don't allow the native view to take |
+ // focus. |
+ if (constrained_window_) { |
+ // If we return false, it will revert to the default handler, which will |
+ // take focus. We don't want that. But if we return true, the event will |
+ // stop being propagated, leaving focus wherever it is currently. That is |
+ // also bad. So we return false to let the default handler run, but take |
+ // focus first so as to trick it into thinking the view was already focused |
+ // and allowing the event to propagate. |
+ gtk_widget_grab_focus(widget); |
+ return FALSE; |
+ } |
+ |
+ // If we already have focus, let the next widget have a shot at it. We will |
+ // reach this situation after the call to gtk_widget_child_focus() in |
+ // TakeFocus(). |
+ if (gtk_widget_is_focus(widget)) |
+ return FALSE; |
+ |
+ gtk_widget_grab_focus(widget); |
+ bool reverse = focus == GTK_DIR_TAB_BACKWARD; |
+ tab_contents()->FocusThroughTabTraversal(reverse); |
+ return TRUE; |
+} |
+ |
gboolean TabContentsViewGtk::OnMouseDown(GtkWidget* widget, |
GdkEventButton* event) { |
last_mouse_down_ = *event; |