Index: content/renderer/render_view.cc |
diff --git a/content/renderer/render_view.cc b/content/renderer/render_view.cc |
index d0f09c703dba14c6bb62ff57a311adcc066ab4d2..a51719e9c2c6642b6027d632fc561a1de7ec02e1 100644 |
--- a/content/renderer/render_view.cc |
+++ b/content/renderer/render_view.cc |
@@ -12,6 +12,7 @@ |
#include "base/callback.h" |
#include "base/command_line.h" |
#include "base/compiler_specific.h" |
+#include "base/i18n/rtl.h" |
#include "base/json/json_writer.h" |
#include "base/lazy_instance.h" |
#include "base/metrics/histogram.h" |
@@ -242,6 +243,18 @@ using webkit_glue::WebAccessibility; |
//----------------------------------------------------------------------------- |
+namespace { |
+ |
+// Return true if the character is known to be a strong LTR character. |
+// A false return value can mean it's not an LTR character or just that |
+// it's a strongly LTR character not in the set we test. |
+// Used as a fast-path for the common case of LTR text. |
+bool IsStronglyLTR(char16 ch) { |
brettw
2011/07/29 17:14:00
If the check in rtl.h is slow, it seems like it mi
Evan Martin
2011/07/30 00:05:15
It's more that the function in rtl.h actually scan
|
+ return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'); |
+} |
+ |
+} // namespace |
+ |
typedef std::map<WebKit::WebView*, RenderView*> ViewMap; |
static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED); |
@@ -1177,15 +1190,27 @@ void RenderView::UpdateURL(WebFrame* frame) { |
} |
// Tell the embedding application that the title of the active page has changed |
-void RenderView::UpdateTitle(WebFrame* frame, const string16& title) { |
- // Ignore all but top level navigations... |
- if (!frame->parent()) { |
- Send(new ViewHostMsg_UpdateTitle( |
- routing_id_, |
- page_id_, |
- title.length() > content::kMaxTitleChars ? |
- title.substr(0, content::kMaxTitleChars) : title)); |
+void RenderView::UpdateTitle(WebFrame* frame, const string16& title, |
+ WebTextDirection title_direction) { |
+ // Ignore all but top level navigations. |
+ if (frame->parent()) |
+ return; |
+ |
+ string16 fixed_title = title.substr(0, content::kMaxTitleChars); |
+ |
+ // Wrap with extra Unicode formatting to make the title strongly directional. |
+ if (!fixed_title.empty()) { |
+ if (title_direction == WebKit::WebTextDirectionLeftToRight) { |
+ // To avoid needing to complicate tests that only use ASCII characters, |
+ // special-case out some known strongly directional characters. |
+ if (!IsStronglyLTR(title[0])) |
+ base::i18n::WrapStringWithLTRFormatting(&fixed_title); |
+ } else { |
+ base::i18n::WrapStringWithRTLFormatting(&fixed_title); |
+ } |
} |
+ |
+ Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, fixed_title)); |
} |
void RenderView::UpdateEncoding(WebFrame* frame, |
@@ -2530,9 +2555,7 @@ void RenderView::didCreateDocumentElement(WebFrame* frame) { |
void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title, |
WebTextDirection direction) { |
- // TODO: pass direction through various APIs. |
- // http://code.google.com/p/chromium/issues/detail?id=79903 |
- UpdateTitle(frame, title); |
+ UpdateTitle(frame, title, direction); |
// Also check whether we have new encoding name. |
UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
@@ -2597,7 +2620,11 @@ void RenderView::didNavigateWithinPage( |
didCommitProvisionalLoad(frame, is_new_navigation); |
- UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle()); |
+ // TODO(evan): update this to use ->pageTitleDirection() once we pull in new |
+ // WebKit. |
+ // http://code.google.com/p/chromium/issues/detail?id=27094 |
+ UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle(), |
+ WebKit::WebTextDirectionLeftToRight); |
} |
void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) { |