summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-08 19:01:11 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-08 19:01:11 +0000
commit7a1f7a2f2bf0c09d2767a496a09509898d4aaa02 (patch)
tree6a10586956ec2b8b9ad6cfffc742e5d069bb1138 /chrome
parent0f38ceaebbc66b29fb3297516f74f9c8379d902f (diff)
downloadchromium_src-7a1f7a2f2bf0c09d2767a496a09509898d4aaa02.zip
chromium_src-7a1f7a2f2bf0c09d2767a496a09509898d4aaa02.tar.gz
chromium_src-7a1f7a2f2bf0c09d2767a496a09509898d4aaa02.tar.bz2
Linux: clean up some focus issues.
- Set focus to render view after finishing find. - Make all custom buttons unfocusable. (matches windows chrome) - Let the GtkWindow's default keyhandler run when the child widget fails to handle the key press event. Previously I optimized this out, but it turns out to be necessary because when a tab is pressed while focus is at the boundary of a child widget (e.g. the last button in an infobar) the focus has to traverse to the next child widget (e.g. the render view), and this is handled by the GtkWindow's key handler (and not the infobar's key handler). BUG=8604,11560 Review URL: http://codereview.chromium.org/115113 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15666 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.cc3
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc10
-rw-r--r--chrome/browser/gtk/custom_button.cc1
-rw-r--r--chrome/browser/gtk/find_bar_gtk.cc3
-rw-r--r--chrome/browser/gtk/link_button_gtk.cc1
-rw-r--r--chrome/browser/gtk/toolbar_star_toggle_gtk.cc19
-rw-r--r--chrome/browser/tab_contents/tab_contents_view_gtk.cc20
7 files changed, 33 insertions, 24 deletions
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc
index 3a02d7f..e0ac467 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.cc
+++ b/chrome/browser/gtk/browser_toolbar_gtk.cc
@@ -276,7 +276,6 @@ CustomDrawButton* BrowserToolbarGtk::BuildToolbarButton(
localized_tooltip.c_str());
g_signal_connect(G_OBJECT(button->widget()), "clicked",
G_CALLBACK(OnButtonClick), this);
- GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS);
gtk_box_pack_start(GTK_BOX(toolbar_), button->widget(), FALSE, FALSE, 0);
return button;
@@ -290,7 +289,6 @@ ToolbarStarToggleGtk* BrowserToolbarGtk::BuildStarButton(
localized_tooltip.c_str());
g_signal_connect(G_OBJECT(button->widget()), "clicked",
G_CALLBACK(OnButtonClick), this);
- GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS);
gtk_box_pack_start(GTK_BOX(toolbar_), button->widget(), FALSE, FALSE, 0);
return button;
@@ -391,7 +389,6 @@ CustomDrawButton* BrowserToolbarGtk::BuildBackForwardButton(
G_CALLBACK(OnBackForwardPressEvent), this);
g_signal_connect(G_OBJECT(button->widget()), "clicked",
G_CALLBACK(OnButtonClick), this);
- GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS);
gtk_box_pack_start(GTK_BOX(toolbar_), button->widget(), FALSE, FALSE, 0);
// Popup the menu as left-aligned relative to this widget rather than the
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index 9f07858..2a46a8d 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -241,13 +241,13 @@ gboolean OnKeyPress(GtkWindow* window, GdkEventKey* event, Browser* browser) {
GdkModifierType(event->state), browser)) {
return TRUE;
}
- }
- if (!gtk_window_propagate_key_event(window, event)) {
- static_cast<BrowserWindowGtk*>(browser->window())->HandleAccelerator(
- event->keyval, GdkModifierType(event->state));
+ return gtk_window_propagate_key_event(window, event);
+ } else {
+ bool rv = gtk_window_propagate_key_event(window, event);
+ DCHECK(rv);
+ return TRUE;
}
- return TRUE;
}
gboolean OnButtonPressEvent(GtkWidget* widget, GdkEventButton* event,
diff --git a/chrome/browser/gtk/custom_button.cc b/chrome/browser/gtk/custom_button.cc
index fd263af..ed1f0b3 100644
--- a/chrome/browser/gtk/custom_button.cc
+++ b/chrome/browser/gtk/custom_button.cc
@@ -56,6 +56,7 @@ CustomDrawButton::CustomDrawButton(
int depressed_id)
: button_base_(normal_id, active_id, highlight_id, depressed_id) {
widget_.Own(gtk_button_new());
+ GTK_WIDGET_UNSET_FLAGS(widget_.get(), GTK_CAN_FOCUS);
gtk_widget_set_size_request(widget_.get(),
gdk_pixbuf_get_width(button_base_.pixbufs(0)),
diff --git a/chrome/browser/gtk/find_bar_gtk.cc b/chrome/browser/gtk/find_bar_gtk.cc
index 5c2e571..0f5b6c7 100644
--- a/chrome/browser/gtk/find_bar_gtk.cc
+++ b/chrome/browser/gtk/find_bar_gtk.cc
@@ -235,6 +235,9 @@ bool FindBarGtk::IsFindBarVisible() {
}
void FindBarGtk::RestoreSavedFocus() {
+ // TODO(estade): We should save focus and restore its previous location if we
+ // don't find any matches in our search.
+ find_bar_controller_->tab_contents()->Focus();
}
FindBarTesting* FindBarGtk::GetFindBarTesting() {
diff --git a/chrome/browser/gtk/link_button_gtk.cc b/chrome/browser/gtk/link_button_gtk.cc
index 9c81208..73eb309 100644
--- a/chrome/browser/gtk/link_button_gtk.cc
+++ b/chrome/browser/gtk/link_button_gtk.cc
@@ -79,6 +79,7 @@ gboolean LinkButtonGtk::OnLeave(GtkWidget* widget,
return FALSE;
}
+// TODO(estade): we need some visual indication when this widget is focused.
// static
gboolean LinkButtonGtk::OnExpose(GtkWidget* widget,
GdkEventExpose* event,
diff --git a/chrome/browser/gtk/toolbar_star_toggle_gtk.cc b/chrome/browser/gtk/toolbar_star_toggle_gtk.cc
index 11ebfae..0785e2a 100644
--- a/chrome/browser/gtk/toolbar_star_toggle_gtk.cc
+++ b/chrome/browser/gtk/toolbar_star_toggle_gtk.cc
@@ -14,15 +14,16 @@ ToolbarStarToggleGtk::ToolbarStarToggleGtk()
is_starred_(false),
unstarred_(IDR_STAR, IDR_STAR_P, IDR_STAR_H, IDR_STAR_D),
starred_(IDR_STARRED, IDR_STARRED_P, IDR_STARRED_H, 0) {
- gtk_widget_set_size_request(widget_.get(),
- gdk_pixbuf_get_width(unstarred_.pixbufs(0)),
- gdk_pixbuf_get_height(unstarred_.pixbufs(0)));
-
- gtk_widget_set_app_paintable(widget_.get(), TRUE);
- // We effectively double-buffer by virtue of having only one image...
- gtk_widget_set_double_buffered(widget_.get(), FALSE);
- g_signal_connect(G_OBJECT(widget_.get()), "expose-event",
- G_CALLBACK(OnExpose), this);
+ gtk_widget_set_size_request(widget_.get(),
+ gdk_pixbuf_get_width(unstarred_.pixbufs(0)),
+ gdk_pixbuf_get_height(unstarred_.pixbufs(0)));
+
+ gtk_widget_set_app_paintable(widget_.get(), TRUE);
+ // We effectively double-buffer by virtue of having only one image...
+ gtk_widget_set_double_buffered(widget_.get(), FALSE);
+ g_signal_connect(G_OBJECT(widget_.get()), "expose-event",
+ G_CALLBACK(OnExpose), this);
+ GTK_WIDGET_UNSET_FLAGS(widget_.get(), GTK_CAN_FOCUS);
}
ToolbarStarToggleGtk::~ToolbarStarToggleGtk() {
diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc
index 2c3c808..98143bc 100644
--- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc
+++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc
@@ -24,15 +24,17 @@
namespace {
-// Called when the content view gtk widget is tabbed to. We always return true
+// 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 SetInitialFocus(bool)
-// forwards the tab to webkit. We leave focus via TakeFocus().
-// We cast the TabContents to a TabContents because SetInitialFocus is public
-// in TabContents and protected in TabContents.
+// 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_HAS_FOCUS(widget))
- return TRUE;
+ return FALSE;
gtk_widget_grab_focus(widget);
bool reverse = focus == GTK_DIR_TAB_BACKWARD;
@@ -177,13 +179,16 @@ bool TabContentsViewGtk::GetFindBarWindowInfo(gfx::Point* position,
}
void TabContentsViewGtk::Focus() {
+ GtkWidget* widget = GetContentNativeView();
+ if (widget)
+ gtk_widget_grab_focus(widget);
}
void TabContentsViewGtk::SetInitialFocus() {
if (tab_contents()->FocusLocationBarByDefault())
tab_contents()->delegate()->SetFocusToLocationBar();
else
- gtk_widget_grab_focus(GetContentNativeView());
+ Focus();
}
void TabContentsViewGtk::StoreFocus() {
@@ -202,7 +207,8 @@ void TabContentsViewGtk::UpdateDragCursor(bool is_drop_target) {
// This is called when we the renderer asks us to take focus back (i.e., it has
// iterated past the last focusable element on the page).
void TabContentsViewGtk::TakeFocus(bool reverse) {
- tab_contents()->delegate()->SetFocusToLocationBar();
+ gtk_widget_child_focus(GTK_WIDGET(GetTopLevelNativeWindow()),
+ reverse ? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD);
}
void TabContentsViewGtk::HandleKeyboardEvent(