summaryrefslogtreecommitdiffstats
path: root/chrome/browser/renderer_host
diff options
context:
space:
mode:
authorxji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-29 18:27:52 +0000
committerxji@chromium.org <xji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-29 18:27:52 +0000
commitde570ef650283a86f90d6179568b49a76df4f1d7 (patch)
tree6eaaa8789d7c7d2297d9269bf576bceafbcb7ce6 /chrome/browser/renderer_host
parent84303d8c22c35de5522758bf9b4fab1df15da3d2 (diff)
downloadchromium_src-de570ef650283a86f90d6179568b49a76df4f1d7.zip
chromium_src-de570ef650283a86f90d6179568b49a76df4f1d7.tar.gz
chromium_src-de570ef650283a86f90d6179568b49a76df4f1d7.tar.bz2
This CL fixes issue 17468: Regression: Directionality marks should not be inserted for LTR systems
To avoid empty square displayed around tooltip when system does not have RTL support, only add Unicode marks when element's directionality is not the same as UI's directionality. Note: 1. tooltip will be displayed using its element's directionality. 2. in system without RTL support, tooltip will only be displayed correctly (in its element's directionality and without empty square around) when both UI and element's directionality is LTR. BUG=http://crbug.com/17468 TEST= 1. Uninstall the right-to-left script and east Asian script through the Control Panel and restart system. 2. Run English Chrome. 3. given the following HTML, the displayed tooltip should not have empty square around. <html> <head> <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="TEXT/HTML; CHARSET=utf-8"> </head> <body> <span style="background-color:Blue" title="Hi!">And now here!</span> </body></html> Review URL: http://codereview.chromium.org/160262 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21975 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/renderer_host')
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc33
-rw-r--r--chrome/browser/renderer_host/render_view_host.h4
2 files changed, 34 insertions, 3 deletions
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index 9a97eb0..c8648a3 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -7,6 +7,7 @@
#include <string>
#include <vector>
+#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "base/gfx/native_widget_types.h"
#include "base/string_util.h"
@@ -50,6 +51,7 @@ using webkit_glue::PasswordFormDomManager;
using WebKit::WebConsoleMessage;
using WebKit::WebFindOptions;
using WebKit::WebInputEvent;
+using WebKit::WebTextDirection;
namespace {
@@ -1204,9 +1206,36 @@ void RenderViewHost::OnMsgGoToEntryAtOffset(int offset) {
integration_delegate->GoToEntryAtOffset(offset);
}
-void RenderViewHost::OnMsgSetTooltipText(const std::wstring& tooltip_text) {
+void RenderViewHost::OnMsgSetTooltipText(
+ const std::wstring& tooltip_text,
+ WebTextDirection text_direction_hint) {
+ // First, add directionality marks around tooltip text if necessary.
+ // A naive solution would be to simply always wrap the text. However, on
+ // windows, Unicode directional embedding characters can't be displayed on
+ // systems that lack RTL fonts and are instead displayed as empty squares.
+ //
+ // To get around this we only wrap the string when we deem it necessary i.e.
+ // when the locale direction is different than the tooltip direction hint.
+ //
+ // Currently, we use element's directionality as the tooltip direction hint.
+ // An alternate solution would be to set the overall directionality based on
+ // trying to detect the directionality from the tooltip text rather than the
+ // element direction. One could argue that would be a preferable solution
+ // but we use the current approach to match Fx & IE's behavior.
+ std::wstring wrapped_tooltip_text = tooltip_text;
+ if (!tooltip_text.empty()) {
+ if (text_direction_hint == WebKit::WebTextDirectionLeftToRight &&
+ l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) {
+ // Force the tooltip to have LTR directionality.
+ l10n_util::WrapStringWithLTRFormatting(&wrapped_tooltip_text);
+ } else if (text_direction_hint == WebKit::WebTextDirectionRightToLeft &&
+ l10n_util::GetTextDirection() == l10n_util::LEFT_TO_RIGHT) {
+ // Force the tooltip to have RTL directionality.
+ l10n_util::WrapStringWithRTLFormatting(&wrapped_tooltip_text);
+ }
+ }
if (view())
- view()->SetTooltipText(tooltip_text);
+ view()->SetTooltipText(wrapped_tooltip_text);
}
void RenderViewHost::OnMsgSelectionChanged(const std::string& text) {
diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h
index bbccd36..521ed51 100644
--- a/chrome/browser/renderer_host/render_view_host.h
+++ b/chrome/browser/renderer_host/render_view_host.h
@@ -16,6 +16,7 @@
#include "chrome/common/notification_registrar.h"
#include "chrome/common/page_zoom.h"
#include "webkit/api/public/WebConsoleMessage.h"
+#include "webkit/api/public/WebTextDirection.h"
#include "webkit/glue/autofill_form.h"
#include "webkit/glue/password_form_dom_manager.h"
#include "webkit/glue/window_open_disposition.h"
@@ -496,7 +497,8 @@ class RenderViewHost : public RenderWidgetHost,
const std::string& target);
void OnMsgDocumentLoadedInFrame();
void OnMsgGoToEntryAtOffset(int offset);
- void OnMsgSetTooltipText(const std::wstring& tooltip_text);
+ void OnMsgSetTooltipText(const std::wstring& tooltip_text,
+ WebKit::WebTextDirection text_direction_hint);
void OnMsgSelectionChanged(const std::string& text);
void OnMsgPasteFromSelectionClipboard();
void OnMsgRunFileChooser(bool multiple_files,