summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-21 23:29:23 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-21 23:29:23 +0000
commit3fd22d99af8d466699b3078a72e15446b5bcbfe6 (patch)
treec70bed7386854214c622767dfc55e349ac3a9df8
parent63c06a2b6ad7c90e0ff5b5d7496109c11c560e3b (diff)
downloadchromium_src-3fd22d99af8d466699b3078a72e15446b5bcbfe6.zip
chromium_src-3fd22d99af8d466699b3078a72e15446b5bcbfe6.tar.gz
chromium_src-3fd22d99af8d466699b3078a72e15446b5bcbfe6.tar.bz2
Add and use a base::i18n::StringWithDirection for carrying titles.
This is a refactoring of r82400. We're going to need the title direction in a bunch of different places; it's better to package it up as one object. BUG=27094 Review URL: http://codereview.chromium.org/6878089 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82582 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/i18n/rtl.h19
-rw-r--r--chrome/browser/notifications/balloon_host.h8
-rw-r--r--chrome/browser/prerender/prerender_contents.cc13
-rw-r--r--chrome/browser/prerender/prerender_contents.h8
-rw-r--r--chrome/browser/prerender/prerender_manager.cc9
-rw-r--r--chrome/browser/tab_contents/web_contents_unittest.cc6
-rw-r--r--content/browser/renderer_host/render_view_host.cc8
-rw-r--r--content/browser/renderer_host/render_view_host_delegate.h7
-rw-r--r--content/browser/tab_contents/interstitial_page.cc10
-rw-r--r--content/browser/tab_contents/interstitial_page.h8
-rw-r--r--content/browser/tab_contents/navigation_entry.h6
-rw-r--r--content/browser/tab_contents/tab_contents.cc5
-rw-r--r--content/browser/tab_contents/tab_contents.h8
13 files changed, 72 insertions, 43 deletions
diff --git a/base/i18n/rtl.h b/base/i18n/rtl.h
index a75ed4f..5159b46 100644
--- a/base/i18n/rtl.h
+++ b/base/i18n/rtl.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -31,6 +31,23 @@ enum TextDirection {
LEFT_TO_RIGHT,
};
+// A string along with the text direction it should be displayed in.
+// Conceptually this is a struct; we just use 'class' to make it easier for
+// others to forward-declare us with 'class String16WithDirection'.
+class String16WithDirection {
+ public:
+ String16WithDirection() : direction_(UNKNOWN_DIRECTION) { }
+ String16WithDirection(const string16& str, TextDirection dir)
+ : string_(str), direction_(dir) { }
+
+ const string16& string() const { return string_; }
+ TextDirection direction() const { return direction_; }
+
+ private:
+ string16 string_;
+ TextDirection direction_;
+};
+
// Get the locale that the currently running process has been configured to use.
// The return value is of the form language[-country] (e.g., en-US) where the
// language is the 2 or 3 letter code from ISO-639.
diff --git a/chrome/browser/notifications/balloon_host.h b/chrome/browser/notifications/balloon_host.h
index aba22e06..0d483fa 100644
--- a/chrome/browser/notifications/balloon_host.h
+++ b/chrome/browser/notifications/balloon_host.h
@@ -56,10 +56,10 @@ class BalloonHost : public RenderViewHostDelegate,
virtual void RenderViewGone(RenderViewHost* render_view_host,
base::TerminationStatus status,
int error_code);
- virtual void UpdateTitle(RenderViewHost* render_view_host,
- int32 page_id,
- const string16& title,
- WebKit::WebTextDirection title_direction) OVERRIDE {}
+ virtual void UpdateTitle(
+ RenderViewHost* render_view_host,
+ int32 page_id,
+ const base::i18n::String16WithDirection& title) OVERRIDE {}
virtual int GetBrowserWindowID() const;
virtual ViewType::Type GetRenderViewType() const;
virtual RenderViewHostDelegate::View* GetViewDelegate();
diff --git a/chrome/browser/prerender/prerender_contents.cc b/chrome/browser/prerender/prerender_contents.cc
index 2d325955..f4fa033 100644
--- a/chrome/browser/prerender/prerender_contents.cc
+++ b/chrome/browser/prerender/prerender_contents.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/prerender/prerender_contents.h"
+#include "base/i18n/rtl.h"
#include "base/process_util.h"
#include "base/task.h"
#include "base/utf_string_conversions.h"
@@ -266,16 +267,16 @@ void PrerenderContents::DidNavigate(
url_ = params.url;
}
-void PrerenderContents::UpdateTitle(RenderViewHost* render_view_host,
- int32 page_id,
- const string16& title,
- WebKit::WebTextDirection title_direction) {
- if (title.empty())
+void PrerenderContents::UpdateTitle(
+ RenderViewHost* render_view_host,
+ int32 page_id,
+ const base::i18n::String16WithDirection& title) {
+ if (title.string().empty())
return;
// TODO(evan): use directionality of title.
// http://code.google.com/p/chromium/issues/detail?id=27094
- title_ = title;
+ title_ = title.string();
page_id_ = page_id;
}
diff --git a/chrome/browser/prerender/prerender_contents.h b/chrome/browser/prerender/prerender_contents.h
index 56ed08e..0b2476a 100644
--- a/chrome/browser/prerender/prerender_contents.h
+++ b/chrome/browser/prerender/prerender_contents.h
@@ -117,10 +117,10 @@ class PrerenderContents : public RenderViewHostDelegate,
virtual int GetBrowserWindowID() const;
virtual void DidNavigate(RenderViewHost* render_view_host,
const ViewHostMsg_FrameNavigate_Params& params);
- virtual void UpdateTitle(RenderViewHost* render_view_host,
- int32 page_id,
- const string16& title,
- WebKit::WebTextDirection title_direction) OVERRIDE;
+ virtual void UpdateTitle(
+ RenderViewHost* render_view_host,
+ int32 page_id,
+ const base::i18n::String16WithDirection& title) OVERRIDE;
virtual WebPreferences GetWebkitPrefs();
virtual void RunJavaScriptMessage(const std::wstring& message,
const std::wstring& default_prompt,
diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc
index 06507e0..372c4d3 100644
--- a/chrome/browser/prerender/prerender_manager.cc
+++ b/chrome/browser/prerender/prerender_manager.cc
@@ -350,10 +350,11 @@ bool PrerenderManager::MaybeUsePreloadedPage(TabContents* tc, const GURL& url) {
// TODO(evan): use directionality of title.
// http://code.google.com/p/chromium/issues/detail?id=27094
- string16 title = pc->title();
- if (!title.empty()) {
- tc->UpdateTitle(rvh, pc->page_id(), title,
- WebKit::WebTextDirectionLeftToRight);
+ string16 title_str = pc->title();
+ if (!title_str.empty()) {
+ base::i18n::String16WithDirection title(title_str,
+ base::i18n::LEFT_TO_RIGHT);
+ tc->UpdateTitle(rvh, pc->page_id(), title);
}
GURL icon_url = pc->icon_url();
diff --git a/chrome/browser/tab_contents/web_contents_unittest.cc b/chrome/browser/tab_contents/web_contents_unittest.cc
index f026b0c..7b21143 100644
--- a/chrome/browser/tab_contents/web_contents_unittest.cc
+++ b/chrome/browser/tab_contents/web_contents_unittest.cc
@@ -237,8 +237,10 @@ TEST_F(TabContentsTest, UpdateTitle) {
NavigationController::LoadCommittedDetails details;
controller().RendererDidNavigate(params, 0, &details);
- contents()->UpdateTitle(rvh(), 0, ASCIIToUTF16(" Lots O' Whitespace\n"),
- WebKit::WebTextDirectionLeftToRight);
+ base::i18n::String16WithDirection new_title(
+ ASCIIToUTF16(" Lots O' Whitespace\n"),
+ base::i18n::LEFT_TO_RIGHT);
+ contents()->UpdateTitle(rvh(), 0, new_title);
EXPECT_EQ(ASCIIToUTF16("Lots O' Whitespace"), contents()->GetTitle());
}
diff --git a/content/browser/renderer_host/render_view_host.cc b/content/browser/renderer_host/render_view_host.cc
index 4d9b7fd..a7a0fc7 100644
--- a/content/browser/renderer_host/render_view_host.cc
+++ b/content/browser/renderer_host/render_view_host.cc
@@ -1008,8 +1008,12 @@ void RenderViewHost::OnMsgUpdateTitle(
NOTREACHED() << "Renderer sent too many characters in title.";
return;
}
-
- delegate_->UpdateTitle(this, page_id, title, title_direction);
+ base::i18n::TextDirection dir =
+ title_direction == WebKit::WebTextDirectionLeftToRight ?
+ base::i18n::LEFT_TO_RIGHT :
+ base::i18n::RIGHT_TO_LEFT;
+ delegate_->UpdateTitle(this, page_id,
+ base::i18n::String16WithDirection(title, dir));
}
void RenderViewHost::OnMsgUpdateEncoding(const std::string& encoding_name) {
diff --git a/content/browser/renderer_host/render_view_host_delegate.h b/content/browser/renderer_host/render_view_host_delegate.h
index a46f701..7588a2e 100644
--- a/content/browser/renderer_host/render_view_host_delegate.h
+++ b/content/browser/renderer_host/render_view_host_delegate.h
@@ -22,7 +22,6 @@
#include "net/base/load_states.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupType.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextDirection.h"
#include "webkit/glue/window_open_disposition.h"
@@ -56,6 +55,9 @@ class WebKeyboardEvent;
struct WebPreferences;
namespace base {
+namespace i18n {
+class String16WithDirection;
+}
class WaitableEvent;
}
@@ -437,8 +439,7 @@ class RenderViewHostDelegate : public IPC::Channel::Listener {
// The page's title was changed and should be updated.
virtual void UpdateTitle(RenderViewHost* render_view_host,
int32 page_id,
- const string16& title,
- WebKit::WebTextDirection title_direction) {}
+ const base::i18n::String16WithDirection& title) {}
// The page's encoding was changed and should be updated.
virtual void UpdateEncoding(RenderViewHost* render_view_host,
diff --git a/content/browser/tab_contents/interstitial_page.cc b/content/browser/tab_contents/interstitial_page.cc
index ec074ff..c3d7291 100644
--- a/content/browser/tab_contents/interstitial_page.cc
+++ b/content/browser/tab_contents/interstitial_page.cc
@@ -383,10 +383,10 @@ void InterstitialPage::DidNavigate(
tab_->SetIsLoading(false, NULL);
}
-void InterstitialPage::UpdateTitle(RenderViewHost* render_view_host,
- int32 page_id,
- const string16& title,
- WebKit::WebTextDirection title_direction) {
+void InterstitialPage::UpdateTitle(
+ RenderViewHost* render_view_host,
+ int32 page_id,
+ const base::i18n::String16WithDirection& title) {
DCHECK(render_view_host == render_view_host_);
NavigationEntry* entry = tab_->controller().GetActiveEntry();
if (!entry) {
@@ -408,8 +408,6 @@ void InterstitialPage::UpdateTitle(RenderViewHost* render_view_host,
original_tab_title_ = UTF16ToWideHack(entry->title());
should_revert_tab_title_ = true;
}
- // TODO(evan): use directionality of title.
- // http://code.google.com/p/chromium/issues/detail?id=27094
entry->set_title(title);
tab_->NotifyNavigationStateChanged(TabContents::INVALIDATE_TITLE);
}
diff --git a/content/browser/tab_contents/interstitial_page.h b/content/browser/tab_contents/interstitial_page.h
index 0d5e043..7523050 100644
--- a/content/browser/tab_contents/interstitial_page.h
+++ b/content/browser/tab_contents/interstitial_page.h
@@ -128,10 +128,10 @@ class InterstitialPage : public NotificationObserver,
int error_code);
virtual void DidNavigate(RenderViewHost* render_view_host,
const ViewHostMsg_FrameNavigate_Params& params);
- virtual void UpdateTitle(RenderViewHost* render_view_host,
- int32 page_id,
- const string16& title,
- WebKit::WebTextDirection title_direction) OVERRIDE;
+ virtual void UpdateTitle(
+ RenderViewHost* render_view_host,
+ int32 page_id,
+ const base::i18n::String16WithDirection& title) OVERRIDE;
virtual void DomOperationResponse(const std::string& json_string,
int automation_id);
virtual RendererPreferences GetRendererPrefs(Profile* profile) const;
diff --git a/content/browser/tab_contents/navigation_entry.h b/content/browser/tab_contents/navigation_entry.h
index 671cc5b..2a25f57 100644
--- a/content/browser/tab_contents/navigation_entry.h
+++ b/content/browser/tab_contents/navigation_entry.h
@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
+#include "base/i18n/rtl.h"
#include "chrome/common/security_style.h"
#include "content/common/page_transition_types.h"
#include "content/common/page_type.h"
@@ -269,6 +270,11 @@ class NavigationEntry {
// The caller is responsible for detecting when there is no title and
// displaying the appropriate "Untitled" label if this is being displayed to
// the user.
+ void set_title(const base::i18n::String16WithDirection& title) {
+ set_title(title.string());
+ }
+ // TODO(evan): remove the string16-setter once callers are updated.
+ // http://code.google.com/p/chromium/issues/detail?id=27094
void set_title(const string16& title) {
title_ = title;
cached_display_title_.clear();
diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc
index 8bcc8e4..d4f871b 100644
--- a/content/browser/tab_contents/tab_contents.cc
+++ b/content/browser/tab_contents/tab_contents.cc
@@ -1992,8 +1992,7 @@ void TabContents::UpdateState(RenderViewHost* rvh,
void TabContents::UpdateTitle(RenderViewHost* rvh,
int32 page_id,
- const string16& title,
- WebKit::WebTextDirection title_direction) {
+ const base::i18n::String16WithDirection& title) {
// If we have a title, that's a pretty good indication that we've started
// getting useful data.
SetNotWaitingForResponse();
@@ -2003,7 +2002,7 @@ void TabContents::UpdateTitle(RenderViewHost* rvh,
page_id);
// TODO(evan): use directionality of title.
// http://code.google.com/p/chromium/issues/detail?id=27094
- if (!entry || !UpdateTitleForEntry(entry, UTF16ToWide(title)))
+ if (!entry || !UpdateTitleForEntry(entry, UTF16ToWide(title.string())))
return;
// Broadcast notifications when the UI should be updated.
diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h
index 7ac7ea8..fe70195 100644
--- a/content/browser/tab_contents/tab_contents.h
+++ b/content/browser/tab_contents/tab_contents.h
@@ -815,10 +815,10 @@ class TabContents : public PageNavigator,
virtual void UpdateState(RenderViewHost* render_view_host,
int32 page_id,
const std::string& state);
- virtual void UpdateTitle(RenderViewHost* render_view_host,
- int32 page_id,
- const string16& title,
- WebKit::WebTextDirection title_direction) OVERRIDE;
+ virtual void UpdateTitle(
+ RenderViewHost* render_view_host,
+ int32 page_id,
+ const base::i18n::String16WithDirection& title) OVERRIDE;
virtual void UpdateEncoding(RenderViewHost* render_view_host,
const std::string& encoding);
virtual void UpdateTargetURL(int32 page_id, const GURL& url);