diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-10 16:48:58 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-10 16:48:58 +0000 |
commit | 8050ca9e629f560af14653566de54a12dc2bcc78 (patch) | |
tree | 7a260a343229527e5a958d52f2d81d89da4610d7 /views | |
parent | 94cf539833e4c68c2a2ceaf59443a6cdc0cc684d (diff) | |
download | chromium_src-8050ca9e629f560af14653566de54a12dc2bcc78.zip chromium_src-8050ca9e629f560af14653566de54a12dc2bcc78.tar.gz chromium_src-8050ca9e629f560af14653566de54a12dc2bcc78.tar.bz2 |
Remove wstring from views. Part 1: Switch member variables to string16.
BUG=68267
TEST=no visible changes; all tests pass
Review URL: http://codereview.chromium.org/6123003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70899 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
23 files changed, 69 insertions, 59 deletions
diff --git a/views/controls/button/button.cc b/views/controls/button/button.cc index f35b178..a80902d 100644 --- a/views/controls/button/button.cc +++ b/views/controls/button/button.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "views/controls/button/button.h" +#include "base/utf_string_conversions.h" namespace views { @@ -13,12 +14,12 @@ Button::~Button() { } void Button::SetTooltipText(const std::wstring& tooltip_text) { - tooltip_text_ = tooltip_text; + tooltip_text_ = WideToUTF16Hack(tooltip_text); TooltipTextChanged(); } void Button::SetAccessibleKeyboardShortcut(const std::wstring& shortcut) { - accessible_shortcut_.assign(shortcut); + accessible_shortcut_ = WideToUTF16Hack(shortcut); } //////////////////////////////////////////////////////////////////////////////// @@ -28,12 +29,12 @@ bool Button::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { if (tooltip_text_.empty()) return false; - *tooltip = tooltip_text_; + *tooltip = UTF16ToWideHack(tooltip_text_); return true; } std::wstring Button::GetAccessibleKeyboardShortcut() { - return accessible_shortcut_; + return UTF16ToWideHack(accessible_shortcut_); } AccessibilityTypes::Role Button::GetAccessibleRole() { diff --git a/views/controls/button/button.h b/views/controls/button/button.h index fe08a19..0f9eb9d 100644 --- a/views/controls/button/button.h +++ b/views/controls/button/button.h @@ -57,10 +57,10 @@ class Button : public View { private: // The text shown in a tooltip. - std::wstring tooltip_text_; + string16 tooltip_text_; // Accessibility data. - std::wstring accessible_shortcut_; + string16 accessible_shortcut_; // The id tag associated with this button. Used to disambiguate buttons in // the ButtonListener implementation. diff --git a/views/controls/button/image_button.cc b/views/controls/button/image_button.cc index 306633e..820e8da 100644 --- a/views/controls/button/image_button.cc +++ b/views/controls/button/image_button.cc @@ -4,6 +4,7 @@ #include "views/controls/button/image_button.h" +#include "base/utf_string_conversions.h" #include "gfx/canvas.h" #include "gfx/skbitmap_operations.h" #include "ui/base/animation/throb_animation.h" @@ -141,7 +142,7 @@ void ToggleImageButton::SetToggledImage(ButtonState state, } void ToggleImageButton::SetToggledTooltipText(const std::wstring& tooltip) { - toggled_tooltip_text_.assign(tooltip); + toggled_tooltip_text_ = WideToUTF16Hack(tooltip); } //////////////////////////////////////////////////////////////////////////////// @@ -166,7 +167,7 @@ bool ToggleImageButton::GetTooltipText(const gfx::Point& p, if (!toggled_ || toggled_tooltip_text_.empty()) return Button::GetTooltipText(p, tooltip); - *tooltip = toggled_tooltip_text_; + *tooltip = UTF16ToWideHack(toggled_tooltip_text_); return true; } diff --git a/views/controls/button/image_button.h b/views/controls/button/image_button.h index bbdf42b..7d214c0 100644 --- a/views/controls/button/image_button.h +++ b/views/controls/button/image_button.h @@ -112,7 +112,7 @@ class ToggleImageButton : public ImageButton { // The parent class's tooltip_text_ is displayed when not toggled, and // this one is shown when toggled. - std::wstring toggled_tooltip_text_; + string16 toggled_tooltip_text_; DISALLOW_COPY_AND_ASSIGN(ToggleImageButton); }; diff --git a/views/controls/button/native_button.cc b/views/controls/button/native_button.cc index e1693d3..84eee12 100644 --- a/views/controls/button/native_button.cc +++ b/views/controls/button/native_button.cc @@ -62,7 +62,7 @@ NativeButton::~NativeButton() { } void NativeButton::SetLabel(const std::wstring& label) { - label_ = label; + label_ = WideToUTF16Hack(label); // Even though we create a flipped HWND for a native button when the locale // is right-to-left, Windows does not render text for the button using a diff --git a/views/controls/button/native_button.h b/views/controls/button/native_button.h index 08aa36f..86a935a 100644 --- a/views/controls/button/native_button.h +++ b/views/controls/button/native_button.h @@ -6,6 +6,8 @@ #define VIEWS_CONTROLS_BUTTON_NATIVE_BUTTON_H_ #pragma once +// TODO(avi): remove when not needed +#include "base/utf_string_conversions.h" #include "gfx/font.h" #include "views/controls/button/button.h" #include "views/controls/button/native_button_wrapper.h" @@ -27,7 +29,7 @@ class NativeButton : public Button { // Sets/Gets the text to be used as the button's label. virtual void SetLabel(const std::wstring& label); - std::wstring label() const { return label_; } + std::wstring label() const { return UTF16ToWideHack(label_); } // Sets the font to be used when displaying the button's label. void set_font(const gfx::Font& font) { font_ = font; } @@ -82,7 +84,7 @@ class NativeButton : public Button { private: // The button label. - std::wstring label_; + string16 label_; // True if the button is the default button in its context. bool is_default_; diff --git a/views/controls/button/text_button.cc b/views/controls/button/text_button.cc index 4c3460f..63eeb0e 100644 --- a/views/controls/button/text_button.cc +++ b/views/controls/button/text_button.cc @@ -210,7 +210,7 @@ TextButton::~TextButton() { } void TextButton::SetText(const std::wstring& text) { - text_ = text; + text_ = WideToUTF16Hack(text); SetAccessibleName(text); UpdateTextSize(); } @@ -360,7 +360,7 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) { text_bounds.y(), text_bounds.width(), text_bounds.height(), draw_string_flags); #else - canvas->DrawStringInt(text_, + canvas->DrawStringInt(UTF16ToWideHack(text_), font_, text_color, text_bounds.x(), @@ -371,11 +371,11 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) { #endif } else if (has_text_halo_) { canvas->AsCanvasSkia()->DrawStringWithHalo( - text_, font_, text_color, text_halo_color_, text_bounds.x(), - text_bounds.y(), text_bounds.width(), text_bounds.height(), - draw_string_flags); + UTF16ToWideHack(text_), font_, text_color, text_halo_color_, + text_bounds.x(), text_bounds.y(), text_bounds.width(), + text_bounds.height(), draw_string_flags); } else { - canvas->DrawStringInt(text_, + canvas->DrawStringInt(UTF16ToWideHack(text_), font_, text_color, text_bounds.x(), @@ -403,7 +403,7 @@ void TextButton::UpdateColor() { void TextButton::UpdateTextSize() { int width = 0, height = 0; gfx::CanvasSkia::SizeStringInt( - WideToUTF16Hack(text_), font_, &width, &height, + text_, font_, &width, &height, gfx::Canvas::NO_ELLIPSIS | PrefixTypeToCanvasType(prefix_type_)); // Add 2 extra pixels to width and height when text halo is used. diff --git a/views/controls/button/text_button.h b/views/controls/button/text_button.h index b9329b4..f9e3722 100644 --- a/views/controls/button/text_button.h +++ b/views/controls/button/text_button.h @@ -8,6 +8,8 @@ #include <string> +// TODO(avi): remove when not needed +#include "base/utf_string_conversions.h" #include "gfx/font.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkColor.h" @@ -97,7 +99,7 @@ class TextButton : public CustomButton { // creation time, so that it can contain the largest of them and avoid // resizing the button when the text changes. virtual void SetText(const std::wstring& text); - std::wstring text() const { return text_; } + std::wstring text() const { return UTF16ToWideHack(text_); } enum TextAlignment { ALIGN_LEFT, @@ -184,7 +186,7 @@ class TextButton : public CustomButton { void UpdateTextSize(); // The text string that is displayed in the button. - std::wstring text_; + string16 text_; // The size of the text string. gfx::Size text_size_; diff --git a/views/controls/image_view.cc b/views/controls/image_view.cc index ad18842..68b7b9d 100644 --- a/views/controls/image_view.cc +++ b/views/controls/image_view.cc @@ -5,6 +5,7 @@ #include "views/controls/image_view.h" #include "base/logging.h" +#include "base/utf_string_conversions.h" #include "gfx/canvas.h" #include "gfx/insets.h" @@ -152,12 +153,12 @@ ImageView::Alignment ImageView::GetVerticalAlignment() { } void ImageView::SetTooltipText(const std::wstring& tooltip) { - tooltip_text_ = tooltip; + tooltip_text_ = WideToUTF16Hack(tooltip); SetAccessibleName(tooltip); } std::wstring ImageView::GetTooltipText() { - return tooltip_text_; + return UTF16ToWideHack(tooltip_text_); } bool ImageView::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { diff --git a/views/controls/image_view.h b/views/controls/image_view.h index 285b873..f119dc1 100644 --- a/views/controls/image_view.h +++ b/views/controls/image_view.h @@ -101,7 +101,7 @@ class ImageView : public View { Alignment vert_alignment_; // The current tooltip text. - std::wstring tooltip_text_; + string16 tooltip_text_; DISALLOW_COPY_AND_ASSIGN(ImageView); }; diff --git a/views/controls/label.cc b/views/controls/label.cc index cdf2c8a..d4bf9f7 100644 --- a/views/controls/label.cc +++ b/views/controls/label.cc @@ -68,7 +68,7 @@ int Label::GetHeightForWidth(int w) { w = std::max(0, w - GetInsets().width()); int h = font_.GetHeight(); - gfx::CanvasSkia::SizeStringInt(WideToUTF16Hack(text_), font_, &w, &h, + gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, ComputeMultiLineFlags()); return h + GetInsets().height(); } @@ -104,7 +104,7 @@ void Label::SetFont(const gfx::Font& font) { } void Label::SetText(const std::wstring& text) { - text_ = text; + text_ = WideToUTF16Hack(text); url_set_ = false; text_size_valid_ = false; SetAccessibleName(text); @@ -113,12 +113,12 @@ void Label::SetText(const std::wstring& text) { } const std::wstring Label::GetText() const { - return url_set_ ? UTF8ToWide(url_.spec()) : text_; + return url_set_ ? UTF8ToWide(url_.spec()) : UTF16ToWideHack(text_); } void Label::SetURL(const GURL& url) { url_ = url; - text_ = UTF8ToWide(url_.spec()); + text_ = UTF8ToUTF16(url_.spec()); url_set_ = true; text_size_valid_ = false; PreferredSizeChanged(); @@ -126,7 +126,7 @@ void Label::SetURL(const GURL& url) { } const GURL Label::GetURL() const { - return url_set_ ? url_ : GURL(WideToUTF8(text_)); + return url_set_ ? url_ : GURL(UTF16ToUTF8(text_)); } void Label::SetHorizontalAlignment(Alignment alignment) { @@ -172,7 +172,7 @@ void Label::SetElideInMiddle(bool elide_in_middle) { } void Label::SetTooltipText(const std::wstring& tooltip_text) { - tooltip_text_ = tooltip_text; + tooltip_text_ = WideToUTF16Hack(tooltip_text); } bool Label::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { @@ -180,15 +180,14 @@ bool Label::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { // If a tooltip has been explicitly set, use it. if (!tooltip_text_.empty()) { - tooltip->assign(tooltip_text_); + tooltip->assign(UTF16ToWideHack(tooltip_text_)); return true; } // Show the full text if the text does not fit. if (!is_multi_line_ && - (font_.GetStringWidth(WideToUTF16Hack(text_)) > - GetAvailableRect().width())) { - *tooltip = text_; + (font_.GetStringWidth(text_) > GetAvailableRect().width())) { + *tooltip = UTF16ToWideHack(text_); return true; } return false; @@ -234,7 +233,7 @@ void Label::SizeToFit(int max_width) { DCHECK(is_multi_line_); std::vector<std::wstring> lines; - base::SplitString(text_, L'\n', &lines); + base::SplitString(UTF16ToWideHack(text_), L'\n', &lines); int label_width = 0; for (std::vector<std::wstring>::const_iterator iter = lines.begin(); @@ -298,8 +297,7 @@ gfx::Size Label::GetTextSize() const { int flags = ComputeMultiLineFlags(); if (!is_multi_line_) flags |= gfx::Canvas::NO_ELLIPSIS; - gfx::CanvasSkia::SizeStringInt(WideToUTF16Hack(text_), font_, &w, &h, - flags); + gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, flags); text_size_.SetSize(w, h); text_size_valid_ = true; } @@ -444,10 +442,10 @@ void Label::CalculateDrawStringParams(std::wstring* paint_text, *paint_text = UTF16ToWide(base::i18n::GetDisplayStringInLTRDirectionality( WideToUTF16(*paint_text))); } else if (elide_in_middle_) { - *paint_text = UTF16ToWideHack(gfx::ElideText(WideToUTF16Hack(text_), + *paint_text = UTF16ToWideHack(gfx::ElideText(text_, font_, GetAvailableRect().width(), true)); } else { - *paint_text = text_; + *paint_text = UTF16ToWideHack(text_); } *text_bounds = GetTextBounds(); diff --git a/views/controls/label.h b/views/controls/label.h index f863999..8b27740 100644 --- a/views/controls/label.h +++ b/views/controls/label.h @@ -245,7 +245,7 @@ class Label : public View { // The colors to use for enabled and disabled labels. static SkColor kEnabledColor, kDisabledColor; - std::wstring text_; + string16 text_; GURL url_; gfx::Font font_; SkColor color_; @@ -256,7 +256,7 @@ class Label : public View { bool elide_in_middle_; bool url_set_; Alignment horiz_alignment_; - std::wstring tooltip_text_; + string16 tooltip_text_; // Whether the mouse is over this label. bool contains_mouse_; scoped_ptr<Background> mouse_over_background_; diff --git a/views/controls/menu/menu_item_view.cc b/views/controls/menu/menu_item_view.cc index 985ecb7..4086018 100644 --- a/views/controls/menu/menu_item_view.cc +++ b/views/controls/menu/menu_item_view.cc @@ -98,7 +98,7 @@ MenuItemView::~MenuItemView() { } bool MenuItemView::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { - *tooltip = tooltip_; + *tooltip = UTF16ToWideHack(tooltip_); return !tooltip_.empty(); } @@ -305,7 +305,7 @@ SubmenuView* MenuItemView::CreateSubmenu() { } void MenuItemView::SetTitle(const std::wstring& title) { - title_ = title; + title_ = WideToUTF16Hack(title); SetAccessibleName(GetAccessibleNameForMenuItem(title, GetAcceleratorText())); } @@ -317,7 +317,7 @@ void MenuItemView::SetSelected(bool selected) { void MenuItemView::SetTooltip(const std::wstring& tooltip, int item_id) { MenuItemView* item = GetMenuItemByID(item_id); DCHECK(item); - item->tooltip_ = tooltip; + item->tooltip_ = WideToUTF16Hack(tooltip); } void MenuItemView::SetIcon(const SkBitmap& icon, int item_id) { diff --git a/views/controls/menu/menu_item_view.h b/views/controls/menu/menu_item_view.h index 0a19870..86347f9 100644 --- a/views/controls/menu/menu_item_view.h +++ b/views/controls/menu/menu_item_view.h @@ -12,6 +12,8 @@ #include <windows.h> #endif +// TODO(avi): remove when not needed +#include "base/utf_string_conversions.h" #include "third_party/skia/include/core/SkBitmap.h" #include "views/view.h" @@ -209,7 +211,8 @@ class MenuItemView : public View { void SetTitle(const std::wstring& title); // Returns the title. - const std::wstring& GetTitle() const { return title_; } + // TODO(avi): switch back to returning a const reference. + const std::wstring GetTitle() const { return UTF16ToWideHack(title_); } // Returns the type of this menu. const Type& GetType() { return type_; } @@ -383,7 +386,7 @@ class MenuItemView : public View { SubmenuView* submenu_; // Title. - std::wstring title_; + string16 title_; // Icon. SkBitmap icon_; @@ -398,7 +401,7 @@ class MenuItemView : public View { bool has_icons_; // The tooltip to show on hover for this menu item. - std::wstring tooltip_; + string16 tooltip_; // X-coordinate of where the label starts. static int label_start_; diff --git a/views/controls/menu/menu_item_view_gtk.cc b/views/controls/menu/menu_item_view_gtk.cc index 87fcdca..ab4c5315 100644 --- a/views/controls/menu/menu_item_view_gtk.cc +++ b/views/controls/menu/menu_item_view_gtk.cc @@ -31,7 +31,7 @@ gfx::Size MenuItemView::GetPreferredSize() { // kFavIconSize if we're showing icons. int content_height = std::max(kFavIconSize, font.GetHeight()); return gfx::Size( - font.GetStringWidth(WideToUTF16Hack(title_)) + label_start_ + + font.GetStringWidth(title_) + label_start_ + item_right_margin_ + GetChildPreferredWidth(), content_height + GetBottomMargin() + GetTopMargin()); } diff --git a/views/controls/progress_bar.cc b/views/controls/progress_bar.cc index 7e4aecf..136ffb8 100644 --- a/views/controls/progress_bar.cc +++ b/views/controls/progress_bar.cc @@ -8,6 +8,7 @@ #include "base/logging.h" #include "base/string_util.h" +#include "base/utf_string_conversions.h" #include "gfx/canvas_skia.h" #include "gfx/color_utils.h" #include "gfx/font.h" @@ -291,14 +292,14 @@ void ProgressBar::AddProgress(int tick) { } void ProgressBar::SetTooltipText(const std::wstring& tooltip_text) { - tooltip_text_ = tooltip_text; + tooltip_text_ = WideToUTF16Hack(tooltip_text); } bool ProgressBar::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { DCHECK(tooltip); if (tooltip == NULL) return false; - tooltip->assign(tooltip_text_); + tooltip->assign(UTF16ToWideHack(tooltip_text_)); return !tooltip_text_.empty(); } diff --git a/views/controls/progress_bar.h b/views/controls/progress_bar.h index e7fe4d2..8eaadf54 100644 --- a/views/controls/progress_bar.h +++ b/views/controls/progress_bar.h @@ -69,7 +69,7 @@ class ProgressBar : public View { int progress_; // Tooltip text. - std::wstring tooltip_text_; + string16 tooltip_text_; // The view class name. static const char kViewClassName[]; diff --git a/views/controls/table/table_view.h b/views/controls/table/table_view.h index b8ae795..83ac85a 100644 --- a/views/controls/table/table_view.h +++ b/views/controls/table/table_view.h @@ -490,7 +490,7 @@ class TableView : public NativeControl, scoped_array<int> view_to_model_; scoped_array<int> model_to_view_; - std::wstring alt_text_; + string16 alt_text_; DISALLOW_COPY_AND_ASSIGN(TableView); }; diff --git a/views/controls/textfield/native_textfield_win.h b/views/controls/textfield/native_textfield_win.h index 35baa2c..bfe0c8e 100644 --- a/views/controls/textfield/native_textfield_win.h +++ b/views/controls/textfield/native_textfield_win.h @@ -226,7 +226,7 @@ class NativeTextfieldWin bool can_discard_mousemove_; // The text of this control before a possible change. - std::wstring text_before_change_; + string16 text_before_change_; // If true, the mouse is over the edit. bool contains_mouse_; diff --git a/views/view.cc b/views/view.cc index 96dfdf1..fa8f1a4 100644 --- a/views/view.cc +++ b/views/view.cc @@ -1165,7 +1165,7 @@ bool View::GetAccessibleName(std::wstring* name) { if (accessible_name_.empty()) return false; - *name = accessible_name_; + *name = UTF16ToWideHack(accessible_name_); return true; } @@ -1174,7 +1174,7 @@ AccessibilityTypes::Role View::GetAccessibleRole() { } void View::SetAccessibleName(const std::wstring& name) { - accessible_name_ = name; + accessible_name_ = WideToUTF16Hack(name); } // static diff --git a/views/view.h b/views/view.h index a3c6050..895e097 100644 --- a/views/view.h +++ b/views/view.h @@ -1292,7 +1292,7 @@ class View : public AcceleratorTarget { scoped_ptr<ViewList> descendants_to_notify_; // Name for this view, which can be retrieved by accessibility APIs. - std::wstring accessible_name_; + string16 accessible_name_; // Next view to be focused when the Tab key is pressed. View* next_focusable_view_; diff --git a/views/widget/tooltip_manager_win.cc b/views/widget/tooltip_manager_win.cc index b7b3a09..04e990b 100644 --- a/views/widget/tooltip_manager_win.cc +++ b/views/widget/tooltip_manager_win.cc @@ -160,7 +160,7 @@ LRESULT TooltipManagerWin::OnNotify(int w_param, clipped_text_.clear(); if (last_tooltip_view_ != NULL) { tooltip_text_.clear(); - // Mouse is over a View, ask the View for it's tooltip. + // Mouse is over a View, ask the View for its tooltip. gfx::Point view_loc = last_mouse_pos_; View::ConvertPointToView(widget_->GetRootView(), last_tooltip_view_, &view_loc); diff --git a/views/widget/tooltip_manager_win.h b/views/widget/tooltip_manager_win.h index 27c7e7a..3bca4ef 100644 --- a/views/widget/tooltip_manager_win.h +++ b/views/widget/tooltip_manager_win.h @@ -11,6 +11,7 @@ #include <string> #include "base/basictypes.h" +#include "base/string16.h" #include "gfx/native_widget_types.h" #include "gfx/point.h" #include "base/task.h" @@ -125,10 +126,10 @@ class TooltipManagerWin : public TooltipManager { bool last_view_out_of_sync_; // Text for tooltip from the view. - std::wstring tooltip_text_; + string16 tooltip_text_; // The clipped tooltip. - std::wstring clipped_text_; + string16 clipped_text_; // Number of lines in the tooltip. int line_count_; |