diff options
author | suzhe@chromium.org <suzhe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-23 09:01:08 +0000 |
---|---|---|
committer | suzhe@chromium.org <suzhe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-23 09:01:08 +0000 |
commit | a068b8fe6850b13c9d0418ebed0fede4518c0da0 (patch) | |
tree | ab123f45d1cce86c27d8c1868b2497a2bfaa8396 /chrome | |
parent | bbe916d18774ba82f892a2e770bc16a3df45e7ed (diff) | |
download | chromium_src-a068b8fe6850b13c9d0418ebed0fede4518c0da0.zip chromium_src-a068b8fe6850b13c9d0418ebed0fede4518c0da0.tar.gz chromium_src-a068b8fe6850b13c9d0418ebed0fede4518c0da0.tar.bz2 |
[Linux]Fix text justification of find bar.
BUG=34724 Text in omnibox and find bar is not right justified correct under RTL locale.
TEST=Run chrome with LTR locale, the text in find bar should always be left justified, regardless of the text's direction. With RTL locale, the text should always be right justified. It matches the behavior of windows version.
Review URL: http://codereview.chromium.org/652105
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39702 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_gtk.h | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/find_bar_gtk.cc | 62 | ||||
-rw-r--r-- | chrome/browser/gtk/find_bar_gtk.h | 22 |
3 files changed, 86 insertions, 2 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h index 7549c6c..0affbd8 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h @@ -303,13 +303,13 @@ class AutocompleteEditViewGtk : public AutocompleteEditView, static void HandleWidgetDirectionChangedThunk( GtkWidget* widget, GtkTextDirection previous_direction, gpointer self) { - return reinterpret_cast<AutocompleteEditViewGtk*>(self)-> + reinterpret_cast<AutocompleteEditViewGtk*>(self)-> AdjustTextJustification(); } static void HandleKeymapDirectionChangedThunk(GdkKeymap* keymap, gpointer self) { - return reinterpret_cast<AutocompleteEditViewGtk*>(self)-> + reinterpret_cast<AutocompleteEditViewGtk*>(self)-> AdjustTextJustification(); } diff --git a/chrome/browser/gtk/find_bar_gtk.cc b/chrome/browser/gtk/find_bar_gtk.cc index 1ffa900..8cd5606 100644 --- a/chrome/browser/gtk/find_bar_gtk.cc +++ b/chrome/browser/gtk/find_bar_gtk.cc @@ -194,6 +194,12 @@ FindBarGtk::FindBarGtk(Browser* browser) G_CALLBACK(OnButtonPress), this); g_signal_connect(text_entry_, "move-cursor", G_CALLBACK(OnMoveCursor), this); g_signal_connect(text_entry_, "activate", G_CALLBACK(OnActivate), this); + g_signal_connect(text_entry_, "direction-changed", + G_CALLBACK(OnWidgetDirectionChanged), this); + g_signal_connect(text_entry_, "focus-in-event", + G_CALLBACK(OnFocusIn), this); + g_signal_connect(text_entry_, "focus-out-event", + G_CALLBACK(OnFocusOut), this); g_signal_connect(container_, "expose-event", G_CALLBACK(OnExpose), this); } @@ -614,6 +620,34 @@ bool FindBarGtk::MaybeForwardKeyEventToRenderer(GdkEventKey* event) { return true; } +void FindBarGtk::AdjustTextAlignment() { + PangoDirection content_dir = + pango_find_base_dir(gtk_entry_get_text(GTK_ENTRY(text_entry_)), -1); + + GtkTextDirection widget_dir = gtk_widget_get_direction(text_entry_); + + // Use keymap or widget direction if content does not have strong direction. + // It matches the behavior of GtkEntry. + if (content_dir == PANGO_DIRECTION_NEUTRAL) { + if (GTK_WIDGET_HAS_FOCUS(text_entry_)) { + content_dir = gdk_keymap_get_direction( + gdk_keymap_get_for_display(gtk_widget_get_display(text_entry_))); + } else { + if (widget_dir == GTK_TEXT_DIR_RTL) + content_dir = PANGO_DIRECTION_RTL; + else + content_dir = PANGO_DIRECTION_LTR; + } + } + + if ((widget_dir == GTK_TEXT_DIR_RTL && content_dir == PANGO_DIRECTION_LTR) || + (widget_dir == GTK_TEXT_DIR_LTR && content_dir == PANGO_DIRECTION_RTL)) { + gtk_entry_set_alignment(GTK_ENTRY(text_entry_), 1.0); + } else { + gtk_entry_set_alignment(GTK_ENTRY(text_entry_), 0.0); + } +} + // static void FindBarGtk::OnParentSet(GtkWidget* widget, GtkObject* old_parent, FindBarGtk* find_bar) { @@ -647,8 +681,11 @@ void FindBarGtk::OnSetFloatingPosition( // static gboolean FindBarGtk::OnChanged(GtkWindow* window, FindBarGtk* find_bar) { + find_bar->AdjustTextAlignment(); + if (!find_bar->ignore_changed_signal_) find_bar->FindEntryTextInContents(true); + return FALSE; } @@ -828,6 +865,7 @@ gboolean FindBarGtk::OnButtonPress(GtkWidget* text_entry, GdkEventButton* e, return FALSE; } +// static void FindBarGtk::OnMoveCursor(GtkEntry* entry, GtkMovementStep step, gint count, gboolean selection, FindBarGtk* bar) { static guint signal_id = g_signal_lookup("move-cursor", GTK_TYPE_ENTRY); @@ -843,6 +881,30 @@ void FindBarGtk::OnMoveCursor(GtkEntry* entry, GtkMovementStep step, gint count, } } +// static void FindBarGtk::OnActivate(GtkEntry* entry, FindBarGtk* bar) { bar->FindEntryTextInContents(true); } + +// static +gboolean FindBarGtk::OnFocusIn(GtkWidget* entry, GdkEventFocus* event, + FindBarGtk* find_bar) { + g_signal_connect( + gdk_keymap_get_for_display(gtk_widget_get_display(entry)), + "direction-changed", + G_CALLBACK(&OnKeymapDirectionChanged), find_bar); + + find_bar->AdjustTextAlignment(); + + return FALSE; // Continue propagation. +} + +// static +gboolean FindBarGtk::OnFocusOut(GtkWidget* entry, GdkEventFocus* event, + FindBarGtk* find_bar) { + g_signal_handlers_disconnect_by_func( + gdk_keymap_get_for_display(gtk_widget_get_display(entry)), + reinterpret_cast<gpointer>(&OnKeymapDirectionChanged), find_bar); + + return FALSE; // Continue propagation. +} diff --git a/chrome/browser/gtk/find_bar_gtk.h b/chrome/browser/gtk/find_bar_gtk.h index abb7675..9e66551 100644 --- a/chrome/browser/gtk/find_bar_gtk.h +++ b/chrome/browser/gtk/find_bar_gtk.h @@ -102,6 +102,11 @@ class FindBarGtk : public FindBar, // coordinates). The returned value is relative to the browser window. gfx::Rect GetDialogPosition(gfx::Rect avoid_overlapping_rect); + // Adjust the text alignment according to the text direction of the widget + // and |text_entry_|'s content, to make sure the real text alignment is + // always in sync with the UI language direction. + void AdjustTextAlignment(); + static void OnParentSet(GtkWidget* widget, GtkObject* old_parent, FindBarGtk* find_bar); @@ -142,6 +147,23 @@ class FindBarGtk : public FindBar, // Handles Enter key. static void OnActivate(GtkEntry* entry, FindBarGtk* bar); + static void OnWidgetDirectionChanged(GtkWidget* widget, + GtkTextDirection previous_direction, + FindBarGtk* find_bar) { + find_bar->AdjustTextAlignment(); + } + + static void OnKeymapDirectionChanged(GdkKeymap* keymap, + FindBarGtk* find_bar) { + find_bar->AdjustTextAlignment(); + } + + static gboolean OnFocusIn(GtkWidget* entry, GdkEventFocus* event, + FindBarGtk* find_bar); + + static gboolean OnFocusOut(GtkWidget* entry, GdkEventFocus* event, + FindBarGtk* find_bar); + Browser* browser_; BrowserWindowGtk* window_; |