summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-16 10:16:47 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-16 10:16:47 +0000
commiteac1d595e6fc1cf80da54002b265776489ba437a (patch)
tree4ed2a24f351431b43918cfa53be2c4dde0ad2b17
parentc983d972c5cdb253352c6a835571788beb664352 (diff)
downloadchromium_src-eac1d595e6fc1cf80da54002b265776489ba437a.zip
chromium_src-eac1d595e6fc1cf80da54002b265776489ba437a.tar.gz
chromium_src-eac1d595e6fc1cf80da54002b265776489ba437a.tar.bz2
Work on RTL / BiDi Omnibox.
Based on work from Evan Stade. Review URL: http://codereview.chromium.org/155567 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20862 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc38
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.cc29
-rw-r--r--chrome/browser/gtk/custom_button.cc2
-rw-r--r--chrome/browser/gtk/download_item_gtk.cc2
-rw-r--r--chrome/browser/gtk/menu_gtk.cc2
-rw-r--r--chrome/browser/gtk/nine_box.cc3
6 files changed, 49 insertions, 27 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
index 260fef8..5b5d6ca 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
@@ -9,6 +9,7 @@
#include <algorithm>
#include "app/gfx/font.h"
+#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "base/basictypes.h"
#include "base/gfx/gtk_util.h"
@@ -61,6 +62,9 @@ const int kRightPadding = 3;
// the total width.
const float kContentWidthPercentage = 0.7;
+// UTF-8 Left-to-right embedding.
+const char* kLRE = "\xe2\x80\xaa";
+
// TODO(deanm): We should put this on gfx::Font so it can be shared.
// Returns a new pango font, free with pango_font_description_free().
PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& chrome_font) {
@@ -120,10 +124,10 @@ size_t GetUTF8Offset(const std::wstring& wide_text, size_t wide_text_offset) {
}
void SetupLayoutForMatch(PangoLayout* layout,
- const std::wstring& text,
- AutocompleteMatch::ACMatchClassifications classifications,
- const GdkColor* base_color,
- const std::string& prefix_text) {
+ const std::wstring& text,
+ AutocompleteMatch::ACMatchClassifications classifications,
+ const GdkColor* base_color,
+ const std::string& prefix_text) {
std::string text_utf8 = prefix_text + WideToUTF8(text);
pango_layout_set_text(layout, text_utf8.data(), text_utf8.size());
@@ -176,6 +180,7 @@ void SetupLayoutForMatch(PangoLayout* layout,
GdkPixbuf* IconForMatch(const AutocompleteMatch& match, bool selected) {
// TODO(deanm): These would be better as pixmaps someday.
+ // TODO(estade): Do we want to flip these for RTL? (Windows doesn't).
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
static GdkPixbuf* o2_globe = rb.GetPixbufNamed(IDR_O2_GLOBE);
static GdkPixbuf* o2_globe_s = rb.GetPixbufNamed(IDR_O2_GLOBE_SELECTED_DARK);
@@ -244,6 +249,8 @@ AutocompletePopupViewGtk::AutocompletePopupViewGtk(
// were a real widget we should handle changing directions, but we're not
// doing RTL or anything yet, so it shouldn't be important now.
layout_ = gtk_widget_create_pango_layout(window_, NULL);
+ // We don't want the layout of search results depending on their language.
+ pango_layout_set_auto_dir(layout_, FALSE);
// We always ellipsize when drawing our text runs.
pango_layout_set_ellipsize(layout_, PANGO_ELLIPSIZE_END);
// TODO(deanm): We might want to eventually follow what Windows does and
@@ -386,6 +393,7 @@ gboolean AutocompletePopupViewGtk::HandleButtonRelease(GtkWidget* widget,
gboolean AutocompletePopupViewGtk::HandleExpose(GtkWidget* widget,
GdkEventExpose* event) {
+ bool ltr = (l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT);
const AutocompleteResult& result = model_->result();
gfx::Rect window_rect = GetWindowRect(event->window);
@@ -435,9 +443,11 @@ gboolean AutocompletePopupViewGtk::HandleExpose(GtkWidget* widget,
line_rect.width(), line_rect.height());
}
- // Draw the icon for this result time.
+ int icon_start_x = ltr ? kIconLeftPadding :
+ line_rect.width() - kIconLeftPadding - kIconWidth;
+ // Draw the icon for this result.
DrawFullPixbuf(drawable, gc, IconForMatch(match, is_selected),
- kIconLeftPadding, line_rect.y() + kIconTopPadding);
+ icon_start_x, line_rect.y() + kIconTopPadding);
// Draw the results text vertically centered in the results space.
// First draw the contents / url, but don't let it take up the whole width
@@ -448,8 +458,9 @@ gboolean AutocompletePopupViewGtk::HandleExpose(GtkWidget* widget,
text_width * kContentWidthPercentage : text_width;
pango_layout_set_width(layout_, allocated_content_width * PANGO_SCALE);
+ // Note: We force to URL to LTR for all text directions.
SetupLayoutForMatch(layout_, match.contents, match.contents_class,
- &kContentTextColor, std::string());
+ &kContentTextColor, std::string(kLRE));
int actual_content_width, actual_content_height;
pango_layout_get_size(layout_,
@@ -463,8 +474,8 @@ gboolean AutocompletePopupViewGtk::HandleExpose(GtkWidget* widget,
line_rect.y() + ((kHeightPerResult - actual_content_height) / 2));
gdk_draw_layout(drawable, gc,
- kIconAreaWidth, content_y,
- layout_);
+ ltr ? kIconAreaWidth : text_width - actual_content_width,
+ content_y, layout_);
if (has_description) {
pango_layout_set_width(layout_,
@@ -473,10 +484,13 @@ gboolean AutocompletePopupViewGtk::HandleExpose(GtkWidget* widget,
is_selected ? &kDescriptionSelectedTextColor :
&kDescriptionTextColor,
std::string(" - "));
-
+ gint actual_description_width;
+ pango_layout_get_size(layout_, &actual_description_width, NULL);
gdk_draw_layout(drawable, gc,
- kIconAreaWidth + actual_content_width, content_y,
- layout_);
+ ltr ? kIconAreaWidth + actual_content_width :
+ text_width - actual_content_width -
+ actual_description_width / PANGO_SCALE,
+ content_y, layout_);
}
}
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc
index a571778..a608d96 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.cc
+++ b/chrome/browser/gtk/browser_toolbar_gtk.cc
@@ -310,22 +310,29 @@ void BrowserToolbarGtk::UpdateTabContents(TabContents* contents,
}
gfx::Rect BrowserToolbarGtk::GetPopupBounds() const {
- GtkWidget* star = star_->widget();
- GtkWidget* go = go_->widget();
+ GtkWidget* left;
+ GtkWidget* right;
+ if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) {
+ left = go_->widget();
+ right = star_->widget();
+ } else {
+ left = star_->widget();
+ right = go_->widget();
+ }
// TODO(deanm): The go and star buttons probably share the same window,
// so this could be optimized to only one origin request.
- gint go_x, go_y;
- gdk_window_get_origin(go->window, &go_x, &go_y);
- go_x += go->allocation.x + go->allocation.width; // Right edge.
+ gint right_x;
+ gdk_window_get_origin(right->window, &right_x, NULL);
+ right_x += right->allocation.x + right->allocation.width;
- gint star_x, star_y;
- gdk_window_get_origin(star->window, &star_x, &star_y);
- star_x += star->allocation.x; // Left edge.
- star_y += star->allocation.y + star->allocation.height; // Bottom edge.
+ gint left_x, left_y;
+ gdk_window_get_origin(left->window, &left_x, &left_y);
+ left_x += left->allocation.x;
+ left_y += left->allocation.y + left->allocation.height; // Bottom edge.
- return gfx::Rect(star_x + kPopupLeftRightMargin, star_y + kPopupTopMargin,
- go_x - star_x - (2 * kPopupLeftRightMargin), 0);
+ return gfx::Rect(left_x + kPopupLeftRightMargin, left_y + kPopupTopMargin,
+ right_x - left_x - (2 * kPopupLeftRightMargin), 0);
}
// BrowserToolbarGtk, private --------------------------------------------------
diff --git a/chrome/browser/gtk/custom_button.cc b/chrome/browser/gtk/custom_button.cc
index b49c422..d31b903 100644
--- a/chrome/browser/gtk/custom_button.cc
+++ b/chrome/browser/gtk/custom_button.cc
@@ -65,7 +65,7 @@ gboolean CustomDrawButtonBase::OnExpose(GtkWidget* widget, GdkEventExpose* e) {
// start of the widget (left for LTR, right for RTL).
int pixbuf_width = gdk_pixbuf_get_width(pixbuf);
int widget_width = widget->allocation.width;
- int x = gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL ?
+ int x = (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
widget_width - pixbuf_width : 0;
gdk_cairo_set_source_pixbuf(cairo_context, pixbuf, x, 0);
diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc
index b7c7780..78a0b46 100644
--- a/chrome/browser/gtk/download_item_gtk.cc
+++ b/chrome/browser/gtk/download_item_gtk.cc
@@ -692,7 +692,7 @@ void DownloadItemGtk::OnShelfResized(GtkWidget *widget,
bool out_of_bounds =
item->hbox_->allocation.x + item->hbox_->allocation.width >
item->bounding_widget_->allocation.x;
- if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
+ if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
out_of_bounds = !out_of_bounds;
if (out_of_bounds)
diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc
index b3775df..d1c66d8 100644
--- a/chrome/browser/gtk/menu_gtk.cc
+++ b/chrome/browser/gtk/menu_gtk.cc
@@ -271,7 +271,7 @@ void MenuGtk::MenuPositionFunc(GtkMenu* menu,
bool start_align =
!!g_object_get_data(G_OBJECT(widget), "left-align-popup");
- if (gtk_widget_get_direction(GTK_WIDGET(menu)) == GTK_TEXT_DIR_RTL)
+ if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
start_align = !start_align;
if (!start_align)
diff --git a/chrome/browser/gtk/nine_box.cc b/chrome/browser/gtk/nine_box.cc
index 66e7793..041fc3b 100644
--- a/chrome/browser/gtk/nine_box.cc
+++ b/chrome/browser/gtk/nine_box.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/gtk/nine_box.h"
+#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "app/theme_provider.h"
#include "base/basictypes.h"
@@ -94,7 +95,7 @@ void NineBox::RenderToWidget(GtkWidget* dst) const {
cairo_translate(cr, dst->allocation.x, dst->allocation.y);
}
- if (gtk_widget_get_direction(dst) == GTK_TEXT_DIR_RTL) {
+ if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) {
cairo_translate(cr, dst_width, 0.0f);
cairo_scale(cr, -1.0f, 1.0f);
}