summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authoryosin@chromium.org <yosin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-05 08:29:26 +0000
committeryosin@chromium.org <yosin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-05 08:29:26 +0000
commitb36980b1c9726783cca0118aae333f5cd7d0ef49 (patch)
treed312ee7ca5be8152d3e6fa6064f3320b825d4ecb /views
parent7b937360dc15b2746cc601620a33a7273a4eb86b (diff)
downloadchromium_src-b36980b1c9726783cca0118aae333f5cd7d0ef49.zip
chromium_src-b36980b1c9726783cca0118aae333f5cd7d0ef49.tar.gz
chromium_src-b36980b1c9726783cca0118aae333f5cd7d0ef49.tar.bz2
Change std::wstring to string16 for views::Link
Change wst::string to string16 for view::Label and views::Link BUG=68267 TEST=no user visible changes Review URL: http://codereview.chromium.org/8113031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104076 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/label.cc40
-rw-r--r--views/controls/label.h15
-rw-r--r--views/controls/label_unittest.cc29
-rw-r--r--views/controls/link.cc15
-rw-r--r--views/controls/link.h2
-rw-r--r--views/controls/message_box_view.cc8
-rw-r--r--views/examples/examples_main.cc4
-rw-r--r--views/focus/focus_manager_unittest.cc31
-rw-r--r--views/widget/tooltip_manager_views.cc2
9 files changed, 76 insertions, 70 deletions
diff --git a/views/controls/label.cc b/views/controls/label.cc
index e61c6e1..867b24f 100644
--- a/views/controls/label.cc
+++ b/views/controls/label.cc
@@ -4,8 +4,10 @@
#include "views/controls/label.h"
+#include <algorithm>
#include <cmath>
#include <limits>
+#include <vector>
#include "base/i18n/rtl.h"
#include "base/logging.h"
@@ -33,14 +35,14 @@ const char Label::kViewClassName[] = "views/Label";
const int Label::kFocusBorderPadding = 1;
Label::Label() {
- Init(std::wstring(), GetDefaultFont());
+ Init(string16(), GetDefaultFont());
}
-Label::Label(const std::wstring& text) {
+Label::Label(const string16& text) {
Init(text, GetDefaultFont());
}
-Label::Label(const std::wstring& text, const gfx::Font& font) {
+Label::Label(const string16& text, const gfx::Font& font) {
Init(text, font);
}
@@ -54,16 +56,16 @@ void Label::SetFont(const gfx::Font& font) {
SchedulePaint();
}
-void Label::SetText(const std::wstring& text) {
- text_ = WideToUTF16Hack(text);
+void Label::SetText(const string16& text) {
+ text_ = text;
url_set_ = false;
text_size_valid_ = false;
PreferredSizeChanged();
SchedulePaint();
}
-const std::wstring Label::GetText() const {
- return url_set_ ? UTF8ToWide(url_.spec()) : UTF16ToWideHack(text_);
+const string16 Label::GetText() const {
+ return url_set_ ? UTF8ToUTF16(url_.spec()) : text_;
}
void Label::SetURL(const GURL& url) {
@@ -259,10 +261,10 @@ void Label::GetAccessibleState(ui::AccessibleViewState* state) {
}
void Label::PaintText(gfx::Canvas* canvas,
- const std::wstring& text,
+ const string16& text,
const gfx::Rect& text_bounds,
int flags) {
- canvas->DrawStringInt(WideToUTF16Hack(text), font_, color_,
+ canvas->DrawStringInt(text, font_, color_,
text_bounds.x(), text_bounds.y(),
text_bounds.width(), text_bounds.height(), flags);
@@ -303,7 +305,7 @@ void Label::OnBoundsChanged(const gfx::Rect& previous_bounds) {
void Label::OnPaint(gfx::Canvas* canvas) {
OnPaintBackground(canvas);
- std::wstring paint_text;
+ string16 paint_text;
gfx::Rect text_bounds;
int flags = 0;
CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
@@ -323,7 +325,7 @@ gfx::Font Label::GetDefaultFont() {
return ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont);
}
-void Label::Init(const std::wstring& text, const gfx::Font& font) {
+void Label::Init(const string16& text, const gfx::Font& font) {
static bool initialized = false;
if (!initialized) {
#if defined(OS_WIN)
@@ -432,7 +434,7 @@ gfx::Rect Label::GetAvailableRect() const {
return bounds;
}
-void Label::CalculateDrawStringParams(std::wstring* paint_text,
+void Label::CalculateDrawStringParams(string16* paint_text,
gfx::Rect* text_bounds,
int* flags) const {
DCHECK(paint_text && text_bounds && flags);
@@ -440,8 +442,8 @@ void Label::CalculateDrawStringParams(std::wstring* paint_text,
if (url_set_) {
// TODO(jungshik) : Figure out how to get 'intl.accept_languages'
// preference and use it when calling ElideUrl.
- *paint_text = UTF16ToWideHack(
- ui::ElideUrl(url_, font_, GetAvailableRect().width(), std::string()));
+ *paint_text = ui::ElideUrl(url_, font_, GetAvailableRect().width(),
+ std::string());
// An URLs is always treated as an LTR text and therefore we should
// explicitly mark it as such if the locale is RTL so that URLs containing
@@ -452,13 +454,13 @@ void Label::CalculateDrawStringParams(std::wstring* paint_text,
// characters. We use the locale settings because an URL is always treated
// as an LTR string, even if its containing view does not use an RTL UI
// layout.
- *paint_text = UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality(
- WideToUTF16(*paint_text)));
+ *paint_text = base::i18n::GetDisplayStringInLTRDirectionality(
+ *paint_text);
} else if (elide_in_middle_) {
- *paint_text = UTF16ToWideHack(ui::ElideText(text_,
- font_, GetAvailableRect().width(), true));
+ *paint_text = ui::ElideText(text_, font_, GetAvailableRect().width(),
+ true);
} else {
- *paint_text = UTF16ToWideHack(text_);
+ *paint_text = text_;
}
*text_bounds = GetTextBounds();
diff --git a/views/controls/label.h b/views/controls/label.h
index 617d08f..74cf667 100644
--- a/views/controls/label.h
+++ b/views/controls/label.h
@@ -9,6 +9,7 @@
#include <string>
#include "base/gtest_prod_util.h"
+#include "base/string16.h"
#include "googleurl/src/gurl.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/font.h"
@@ -52,21 +53,21 @@ class VIEWS_EXPORT Label : public View {
static const int kFocusBorderPadding;
Label();
- explicit Label(const std::wstring& text);
- Label(const std::wstring& text, const gfx::Font& font);
+ explicit Label(const string16& text);
+ Label(const string16& text, const gfx::Font& font);
virtual ~Label();
// Set the font.
virtual void SetFont(const gfx::Font& font);
// Set the label text.
- void SetText(const std::wstring& text);
+ void SetText(const string16& text);
// Return the font used by this label.
gfx::Font font() const { return font_; }
// Return the label text.
- const std::wstring GetText() const;
+ const string16 GetText() const;
// Set URL Value - text_ is set to spec().
void SetURL(const GURL& url);
@@ -182,7 +183,7 @@ class VIEWS_EXPORT Label : public View {
// Called by Paint to paint the text. Override this to change how
// text is painted.
virtual void PaintText(gfx::Canvas* canvas,
- const std::wstring& text,
+ const string16& text,
const gfx::Rect& text_bounds,
int flags);
@@ -208,7 +209,7 @@ class VIEWS_EXPORT Label : public View {
static gfx::Font GetDefaultFont();
- void Init(const std::wstring& text, const gfx::Font& font);
+ void Init(const string16& text, const gfx::Font& font);
// If the mouse is over the text, SetContainsMouse(true) is invoked, otherwise
// SetContainsMouse(false) is invoked.
@@ -227,7 +228,7 @@ class VIEWS_EXPORT Label : public View {
gfx::Rect GetAvailableRect() const;
// Returns parameters to be used for the DrawString call.
- void CalculateDrawStringParams(std::wstring* paint_text,
+ void CalculateDrawStringParams(string16* paint_text,
gfx::Rect* text_bounds,
int* flags) const;
diff --git a/views/controls/label_unittest.cc b/views/controls/label_unittest.cc
index db3d491..68fc296 100644
--- a/views/controls/label_unittest.cc
+++ b/views/controls/label_unittest.cc
@@ -41,7 +41,7 @@ TEST(LabelTest, FontPropertyArial) {
TEST(LabelTest, TextProperty) {
Label label;
- std::wstring test_text(L"A random string.");
+ string16 test_text(ASCIIToUTF16("A random string."));
label.SetText(test_text);
EXPECT_EQ(test_text, label.GetText());
}
@@ -52,7 +52,7 @@ TEST(LabelTest, UrlProperty) {
GURL url(my_url);
label.SetURL(url);
EXPECT_EQ(my_url, label.GetURL().spec());
- EXPECT_EQ(UTF8ToWide(my_url), label.GetText());
+ EXPECT_EQ(UTF8ToUTF16(my_url), label.GetText());
}
TEST(LabelTest, ColorProperty) {
@@ -111,7 +111,7 @@ TEST(LabelTest, MultiLineProperty) {
TEST(LabelTest, TooltipProperty) {
Label label;
string16 test_text(ASCIIToUTF16("My cool string."));
- label.SetText(UTF16ToWideHack(test_text));
+ label.SetText(test_text);
string16 tooltip;
EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip));
@@ -158,7 +158,7 @@ TEST(LabelTest, TooltipProperty) {
TEST(LabelTest, Accessibility) {
Label label;
string16 test_text(ASCIIToUTF16("My special text."));
- label.SetText(UTF16ToWideHack(test_text));
+ label.SetText(test_text);
ui::AccessibleViewState state;
label.GetAccessibleState(&state);
@@ -169,7 +169,7 @@ TEST(LabelTest, Accessibility) {
TEST(LabelTest, SingleLineSizing) {
Label label;
- std::wstring test_text(L"A not so random string in one line.");
+ string16 test_text(ASCIIToUTF16("A not so random string in one line."));
label.SetText(test_text);
// GetPreferredSize
@@ -196,7 +196,8 @@ TEST(LabelTest, SingleLineSizing) {
TEST(LabelTest, MultiLineSizing) {
Label label;
label.set_focusable(false);
- std::wstring test_text(L"A random string\nwith multiple lines\nand returns!");
+ string16 test_text(
+ ASCIIToUTF16("A random string\nwith multiple lines\nand returns!"));
label.SetText(test_text);
label.SetMultiLine(true);
@@ -284,7 +285,7 @@ TEST(LabelTest, DrawSingleLineString) {
// align right really means align left.
label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT);
- std::wstring test_text(L"Here's a string with no returns.");
+ string16 test_text(ASCIIToUTF16("Here's a string with no returns."));
label.SetText(test_text);
gfx::Size required_size(label.GetPreferredSize());
gfx::Size extra(22, 8);
@@ -294,7 +295,7 @@ TEST(LabelTest, DrawSingleLineString) {
required_size.height() + extra.height());
// Do some basic verifications for all three alignments.
- std::wstring paint_text;
+ string16 paint_text;
gfx::Rect text_bounds;
int flags;
@@ -402,7 +403,7 @@ TEST(LabelTest, DrawMultiLineString) {
// align right really means align left.
label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT);
- std::wstring test_text(L"Another string\nwith returns\n\n!");
+ string16 test_text(ASCIIToUTF16("Another string\nwith returns\n\n!"));
label.SetText(test_text);
label.SetMultiLine(true);
label.SizeToFit(0);
@@ -413,7 +414,7 @@ TEST(LabelTest, DrawMultiLineString) {
label.height() + extra.height());
// Do some basic verifications for all three alignments.
- std::wstring paint_text;
+ string16 paint_text;
gfx::Rect text_bounds;
int flags;
label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
@@ -542,7 +543,7 @@ TEST(LabelTest, DrawSingleLineStringInRTL) {
std::string locale = l10n_util::GetApplicationLocale("");
base::i18n::SetICUDefaultLocale("he");
- std::wstring test_text(L"Here's a string with no returns.");
+ string16 test_text(ASCIIToUTF16("Here's a string with no returns."));
label.SetText(test_text);
gfx::Size required_size(label.GetPreferredSize());
gfx::Size extra(22, 8);
@@ -552,7 +553,7 @@ TEST(LabelTest, DrawSingleLineStringInRTL) {
required_size.height() + extra.height());
// Do some basic verifications for all three alignments.
- std::wstring paint_text;
+ string16 paint_text;
gfx::Rect text_bounds;
int flags;
@@ -664,7 +665,7 @@ TEST(LabelTest, DrawMultiLineStringInRTL) {
std::string locale = l10n_util::GetApplicationLocale("");
base::i18n::SetICUDefaultLocale("he");
- std::wstring test_text(L"Another string\nwith returns\n\n!");
+ string16 test_text(ASCIIToUTF16("Another string\nwith returns\n\n!"));
label.SetText(test_text);
label.SetMultiLine(true);
label.SizeToFit(0);
@@ -675,7 +676,7 @@ TEST(LabelTest, DrawMultiLineStringInRTL) {
label.height() + extra.height());
// Do some basic verifications for all three alignments.
- std::wstring paint_text;
+ string16 paint_text;
gfx::Rect text_bounds;
int flags;
label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
diff --git a/views/controls/link.cc b/views/controls/link.cc
index b6874b9..99753d0 100644
--- a/views/controls/link.cc
+++ b/views/controls/link.cc
@@ -11,6 +11,7 @@
#endif
#include "base/logging.h"
+#include "base/utf_string_conversions.h"
#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/gfx/color_utils.h"
@@ -65,16 +66,18 @@ namespace views {
const char Link::kViewClassName[] = "views/Link";
-Link::Link() : Label(L""),
- listener_(NULL),
- highlighted_(false) {
+Link::Link()
+ : Label(string16()),
+ listener_(NULL),
+ highlighted_(false) {
Init();
set_focusable(true);
}
-Link::Link(const std::wstring& title) : Label(title),
- listener_(NULL),
- highlighted_(false) {
+Link::Link(const string16& title)
+ : Label(title),
+ listener_(NULL),
+ highlighted_(false) {
Init();
set_focusable(true);
}
diff --git a/views/controls/link.h b/views/controls/link.h
index 2392bee..cfded7b 100644
--- a/views/controls/link.h
+++ b/views/controls/link.h
@@ -25,7 +25,7 @@ class LinkListener;
class VIEWS_EXPORT Link : public Label {
public:
Link();
- explicit Link(const std::wstring& title);
+ explicit Link(const string16& title);
virtual ~Link();
const LinkListener* listener() { return listener_; }
diff --git a/views/controls/message_box_view.cc b/views/controls/message_box_view.cc
index cd51b67..a11edbd 100644
--- a/views/controls/message_box_view.cc
+++ b/views/controls/message_box_view.cc
@@ -32,7 +32,7 @@ MessageBoxView::MessageBoxView(int dialog_flags,
const std::wstring& message,
const std::wstring& default_prompt,
int message_width)
- : message_label_(new Label(message)),
+ : message_label_(new Label(WideToUTF16Hack(message))),
prompt_field_(NULL),
icon_(NULL),
checkbox_(NULL),
@@ -43,7 +43,7 @@ MessageBoxView::MessageBoxView(int dialog_flags,
MessageBoxView::MessageBoxView(int dialog_flags,
const std::wstring& message,
const std::wstring& default_prompt)
- : message_label_(new Label(message)),
+ : message_label_(new Label(WideToUTF16Hack(message))),
prompt_field_(NULL),
icon_(NULL),
checkbox_(NULL),
@@ -119,7 +119,7 @@ bool MessageBoxView::AcceleratorPressed(
return false;
ui::ScopedClipboardWriter scw(clipboard);
- scw.WriteText(WideToUTF16Hack(message_label_->GetText()));
+ scw.WriteText(message_label_->GetText());
return true;
}
@@ -135,7 +135,7 @@ void MessageBoxView::Init(int dialog_flags,
// with strong directionality.
base::i18n::TextDirection direction =
base::i18n::GetFirstStrongCharacterDirection(
- WideToUTF16(message_label_->GetText()));
+ message_label_->GetText());
Label::Alignment alignment;
if (direction == base::i18n::RIGHT_TO_LEFT)
alignment = Label::ALIGN_RIGHT;
diff --git a/views/examples/examples_main.cc b/views/examples/examples_main.cc
index 3287cbf..6656558 100644
--- a/views/examples/examples_main.cc
+++ b/views/examples/examples_main.cc
@@ -103,7 +103,7 @@ void ExamplesMain::Init() {
examples_.push_back(new WidgetExample(this));
examples_.push_back(new MenuExample(this));
- for(std::vector<ExampleBase*>::const_iterator i(examples_.begin());
+ for (std::vector<ExampleBase*>::const_iterator i(examples_.begin());
i != examples_.end(); ++i)
AddExample(*i);
@@ -111,7 +111,7 @@ void ExamplesMain::Init() {
}
void ExamplesMain::SetStatus(const std::string& status) {
- status_label_->SetText(UTF8ToWide(status));
+ status_label_->SetText(UTF8ToUTF16(status));
}
void ExamplesMain::AddExample(ExampleBase* example) {
diff --git a/views/focus/focus_manager_unittest.cc b/views/focus/focus_manager_unittest.cc
index 4f8ca5c..d3df95d 100644
--- a/views/focus/focus_manager_unittest.cc
+++ b/views/focus/focus_manager_unittest.cc
@@ -497,7 +497,7 @@ void FocusTraversalTest::InitContentView() {
int y = 10;
int gap_between_labels = 10;
- Label* label = new Label(L"Apple:");
+ Label* label = new Label(ASCIIToUTF16("Apple:"));
label->set_id(kAppleLabelID);
left_container_->AddChildView(label);
label->SetBounds(label_x, y, label_width, label_height);
@@ -510,7 +510,7 @@ void FocusTraversalTest::InitContentView() {
y += label_height + gap_between_labels;
- label = new Label(L"Orange:");
+ label = new Label(ASCIIToUTF16("Orange:"));
label->set_id(kOrangeLabelID);
left_container_->AddChildView(label);
label->SetBounds(label_x, y, label_width, label_height);
@@ -523,7 +523,7 @@ void FocusTraversalTest::InitContentView() {
y += label_height + gap_between_labels;
- label = new Label(L"Banana:");
+ label = new Label(ASCIIToUTF16("Banana:"));
label->set_id(kBananaLabelID);
left_container_->AddChildView(label);
label->SetBounds(label_x, y, label_width, label_height);
@@ -536,7 +536,7 @@ void FocusTraversalTest::InitContentView() {
y += label_height + gap_between_labels;
- label = new Label(L"Kiwi:");
+ label = new Label(ASCIIToUTF16("Kiwi:"));
label->set_id(kKiwiLabelID);
left_container_->AddChildView(label);
label->SetBounds(label_x, y, label_width, label_height);
@@ -616,11 +616,11 @@ void FocusTraversalTest::InitContentView() {
Background::CreateSolidBackground(200, 200, 200));
scroll_view->SetContents(scroll_content);
- static const wchar_t* const kTitles[] = {
- L"Rosetta", L"Stupeur et tremblement", L"The diner game",
- L"Ridicule", L"Le placard", L"Les Visiteurs", L"Amelie",
- L"Joyeux Noel", L"Camping", L"Brice de Nice",
- L"Taxi", L"Asterix"
+ static const char* const kTitles[] = {
+ "Rosetta", "Stupeur et tremblement", "The diner game",
+ "Ridicule", "Le placard", "Les Visiteurs", "Amelie",
+ "Joyeux Noel", "Camping", "Brice de Nice",
+ "Taxi", "Asterix"
};
static const int kIDs[] = {
@@ -634,7 +634,7 @@ void FocusTraversalTest::InitContentView() {
y = 5;
for (size_t i = 0; i < arraysize(kTitles); ++i) {
- Link* link = new Link(kTitles[i]);
+ Link* link = new Link(ASCIIToUTF16(kTitles[i]));
link->SetHorizontalAlignment(Label::ALIGN_LEFT);
link->set_id(kIDs[i]);
scroll_content->AddChildView(link);
@@ -681,7 +681,7 @@ void FocusTraversalTest::InitContentView() {
cb->SetBounds(130, 10, 70, 20);
cb->set_id(kUnderlinedCheckBoxID);
- Link* link = new Link(L"Help");
+ Link* link = new Link(ASCIIToUTF16("Help"));
contents->AddChildView(link);
link->SetBounds(10, 35, 70, 10);
link->set_id(kStyleHelpLinkID);
@@ -711,7 +711,7 @@ void FocusTraversalTest::InitContentView() {
button->SetBounds(112, 5, 60, 30);
button->set_id(kSearchButtonID);
- link = new Link(L"Help");
+ link = new Link(ASCIIToUTF16("Help"));
link->SetHorizontalAlignment(Label::ALIGN_LEFT);
link->set_id(kHelpLinkID);
contents->AddChildView(link);
@@ -1283,7 +1283,6 @@ TEST_F(FocusTraversalTest, PaneTraversal) {
EXPECT_EQ(kRightTraversalIDs[j], focused_view->id());
}
}
-
}
// Counts accelerator calls.
@@ -1451,7 +1450,7 @@ TEST_F(FocusManagerTest, CallsSelfDeletingAcceleratorTarget) {
class MessageTrackingView : public View {
public:
MessageTrackingView() : accelerator_pressed_(false) {
- }
+ }
virtual bool OnKeyPressed(const KeyEvent& e) {
keys_pressed_.push_back(e.key_code());
@@ -1664,7 +1663,7 @@ class FocusManagerDtorTest : public FocusManagerTest {
class TestFocusManagerFactory : public FocusManagerFactory {
public:
- TestFocusManagerFactory(DtorTrackVector* dtor_tracker)
+ explicit TestFocusManagerFactory(DtorTrackVector* dtor_tracker)
: dtor_tracker_(dtor_tracker) {
}
@@ -1693,7 +1692,7 @@ class FocusManagerDtorTest : public FocusManagerTest {
class WindowDtorTracked : public Widget {
public:
- WindowDtorTracked(DtorTrackVector* dtor_tracker)
+ explicit WindowDtorTracked(DtorTrackVector* dtor_tracker)
: dtor_tracker_(dtor_tracker) {
}
diff --git a/views/widget/tooltip_manager_views.cc b/views/widget/tooltip_manager_views.cc
index 759f939..01433d1 100644
--- a/views/widget/tooltip_manager_views.cc
+++ b/views/widget/tooltip_manager_views.cc
@@ -185,7 +185,7 @@ void TooltipManagerViews::Update() {
string16 tooltip_text(tooltip_text_);
TrimTooltipToFit(&tooltip_text, &max_width, &line_count,
curr_mouse_pos_.x(), curr_mouse_pos_.y());
- tooltip_label_.SetText(UTF16ToWideHack(tooltip_text));
+ tooltip_label_.SetText(tooltip_text);
SetTooltipBounds(curr_mouse_pos_, max_width,
tooltip_label_.GetPreferredSize().height());