Skip to content

Commit

Permalink
Move text_elider to gfx.
Browse files Browse the repository at this point in the history
R=sky@chromium.org
http://crbug.com/103304

Review URL: https://codereview.chromium.org/23731010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222106 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
ben@chromium.org committed Sep 9, 2013
1 parent 9045c60 commit dbb97ba
Show file tree
Hide file tree
Showing 58 changed files with 2,513 additions and 172 deletions.
15 changes: 8 additions & 7 deletions ash/system/user/tray_user.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include "ui/aura/window.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/font.h"
#include "ui/gfx/image/image.h"
Expand All @@ -49,6 +48,7 @@
#include "ui/gfx/render_text.h"
#include "ui/gfx/size.h"
#include "ui/gfx/skia_util.h"
#include "ui/gfx/text_elider.h"
#include "ui/views/border.h"
#include "ui/views/bubble/tray_bubble_view.h"
#include "ui/views/controls/button/button.h"
Expand Down Expand Up @@ -452,8 +452,9 @@ void PublicAccountUserDetails::Layout() {
// Word-wrap the label text.
const gfx::Font font;
std::vector<base::string16> lines;
ui::ElideRectangleText(text_, font, contents_area.width(),
contents_area.height(), ui::ELIDE_LONG_WORDS, &lines);
gfx::ElideRectangleText(text_, font, contents_area.width(),
contents_area.height(), gfx::ELIDE_LONG_WORDS,
&lines);
// Loop through the lines, creating a renderer for each.
gfx::Point position = contents_area.origin();
gfx::Range display_name(gfx::Range::InvalidRange());
Expand Down Expand Up @@ -550,8 +551,8 @@ void PublicAccountUserDetails::CalculatePreferredSize(SystemTrayItem* owner,
while (min_width < max_width) {
lines.clear();
const int width = (min_width + max_width) / 2;
const bool too_narrow = ui::ElideRectangleText(
text_, font, width, INT_MAX, ui::TRUNCATE_LONG_WORDS, &lines) != 0;
const bool too_narrow = gfx::ElideRectangleText(
text_, font, width, INT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines) != 0;
int line_count = lines.size();
if (!too_narrow && line_count == 3 &&
width - font.GetStringWidth(lines.back()) <=
Expand All @@ -566,8 +567,8 @@ void PublicAccountUserDetails::CalculatePreferredSize(SystemTrayItem* owner,

// Calculate the corresponding height and set the preferred size.
lines.clear();
ui::ElideRectangleText(
text_, font, min_width, INT_MAX, ui::TRUNCATE_LONG_WORDS, &lines);
gfx::ElideRectangleText(
text_, font, min_width, INT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines);
int line_count = lines.size();
if (min_width - font.GetStringWidth(lines.back()) <=
space_width + link_size.width()) {
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/chromeos/external_protocol_dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/text_elider.h"
#include "ui/views/controls/message_box_view.h"
#include "ui/views/widget/widget.h"
#include "url/gurl.h"
Expand Down Expand Up @@ -95,7 +95,7 @@ ExternalProtocolDialog::ExternalProtocolDialog(WebContents* web_contents,
scheme_(url.scheme()) {
const int kMaxUrlWithoutSchemeSize = 256;
string16 elided_url_without_scheme;
ui::ElideString(ASCIIToUTF16(url.possibly_invalid_spec()),
gfx::ElideString(ASCIIToUTF16(url.possibly_invalid_spec()),
kMaxUrlWithoutSchemeSize, &elided_url_without_scheme);

views::MessageBoxView::InitParams params(
Expand Down
10 changes: 5 additions & 5 deletions chrome/browser/download/download_item_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/time_format.h"
#include "ui/base/text/bytes_formatting.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/text_elider.h"

using base::TimeDelta;
using content::DownloadItem;
Expand Down Expand Up @@ -325,14 +325,14 @@ string16 DownloadItemModel::GetTabProgressStatusText() const {

string16 DownloadItemModel::GetTooltipText(const gfx::FontList& font_list,
int max_width) const {
string16 tooltip = ui::ElideFilename(
string16 tooltip = gfx::ElideFilename(
download_->GetFileNameToReportUser(), font_list, max_width);
content::DownloadInterruptReason reason = download_->GetLastReason();
if (download_->GetState() == DownloadItem::INTERRUPTED &&
reason != content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED) {
tooltip += ASCIIToUTF16("\n");
tooltip += ui::ElideText(InterruptReasonStatusMessage(reason),
font_list, max_width, ui::ELIDE_AT_END);
tooltip += gfx::ElideText(InterruptReasonStatusMessage(reason),
font_list, max_width, gfx::ELIDE_AT_END);
}
return tooltip;
}
Expand All @@ -342,7 +342,7 @@ string16 DownloadItemModel::GetWarningText(const gfx::FontList& font_list,
// Should only be called if IsDangerous().
DCHECK(IsDangerous());
string16 elided_filename =
ui::ElideFilename(download_->GetFileNameToReportUser(), font_list,
gfx::ElideFilename(download_->GetFileNameToReportUser(), font_list,
base_width);
switch (download_->GetDangerType()) {
case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: {
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/extensions/menu_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/context_menu_params.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/favicon_size.h"
#include "ui/gfx/text_elider.h"

using content::WebContents;
using extensions::ExtensionSystem;
Expand Down Expand Up @@ -173,7 +173,7 @@ string16 MenuItem::TitleWithReplacement(
ReplaceSubstringsAfterOffset(&result, 0, ASCIIToUTF16("%s"), selection);

if (result.length() > max_length)
result = ui::TruncateString(result, max_length);
result = gfx::TruncateString(result, max_length);
return result;
}

Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/signin/signin_ui_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/font.h"
#include "ui/gfx/text_elider.h"

namespace {
// Maximum width of a username - we trim emails that are wider than this so
Expand Down Expand Up @@ -75,7 +75,7 @@ string16 GetSigninMenuLabel(Profile* profile) {
if (signin_manager)
username = signin_manager->GetAuthenticatedUsername();
if (!username.empty() && !signin_manager->AuthInProgress()) {
string16 elided_username = ui::ElideEmail(UTF8ToUTF16(username),
string16 elided_username = gfx::ElideEmail(UTF8ToUTF16(username),
gfx::Font(),
kUsernameMaxWidth);
return l10n_util::GetStringFUTF16(IDS_SYNC_MENU_SYNCED_LABEL,
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/tab_contents/render_view_context_menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@
#include "third_party/WebKit/public/web/WebPluginAction.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/favicon_size.h"
#include "ui/gfx/point.h"
#include "ui/gfx/size.h"
#include "ui/gfx/text_elider.h"

#if defined(ENABLE_PRINTING)
#include "chrome/common/print_messages.h"
Expand Down Expand Up @@ -2032,7 +2032,7 @@ bool RenderViewContextMenu::IsDevCommandEnabled(int id) const {
}

string16 RenderViewContextMenu::PrintableSelectionText() {
return ui::TruncateString(params_.selection_text,
return gfx::TruncateString(params_.selection_text,
kMaxSelectionTextLength);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/text_elider.h"

#if defined(USE_AURA)
#include "ui/aura/root_window.h"
Expand All @@ -31,11 +31,11 @@ const int kMessageTextMaxCols = 132;
const int kDefaultPromptMaxRows = 24;
const int kDefaultPromptMaxCols = 132;
void EnforceMaxTextSize(const string16& in_string, string16* out_string) {
ui::ElideRectangleString(in_string, kMessageTextMaxRows,
gfx::ElideRectangleString(in_string, kMessageTextMaxRows,
kMessageTextMaxCols, false, out_string);
}
void EnforceMaxPromptSize(const string16& in_string, string16* out_string) {
ui::ElideRectangleString(in_string, kDefaultPromptMaxRows,
gfx::ElideRectangleString(in_string, kDefaultPromptMaxRows,
kDefaultPromptMaxCols, false, out_string);
}
#else
Expand All @@ -44,10 +44,10 @@ void EnforceMaxPromptSize(const string16& in_string, string16* out_string) {
const int kMessageTextMaxSize = 3000;
const int kDefaultPromptMaxSize = 2000;
void EnforceMaxTextSize(const string16& in_string, string16* out_string) {
ui::ElideString(in_string, kMessageTextMaxSize, out_string);
gfx::ElideString(in_string, kMessageTextMaxSize, out_string);
}
void EnforceMaxPromptSize(const string16& in_string, string16* out_string) {
ui::ElideString(in_string, kDefaultPromptMaxSize, out_string);
gfx::ElideString(in_string, kDefaultPromptMaxSize, out_string);
}
#endif

Expand Down
10 changes: 5 additions & 5 deletions chrome/browser/ui/autofill/autofill_popup_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
#include "grit/webkit_resources.h"
#include "third_party/WebKit/public/web/WebAutofillClient.h"
#include "ui/base/events/event.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/display.h"
#include "ui/gfx/rect_conversions.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/text_elider.h"
#include "ui/gfx/vector2d.h"

using base::WeakPtr;
Expand Down Expand Up @@ -143,16 +143,16 @@ void AutofillPopupControllerImpl::Show(

// Each field recieves space in proportion to its length.
int name_size = available_width * name_width / total_text_length;
names_[i] = ui::ElideText(names_[i],
names_[i] = gfx::ElideText(names_[i],
GetNameFontForRow(i),
name_size,
ui::ELIDE_AT_END);
gfx::ELIDE_AT_END);

int subtext_size = available_width * subtext_width / total_text_length;
subtexts_[i] = ui::ElideText(subtexts_[i],
subtexts_[i] = gfx::ElideText(subtexts_[i],
subtext_font(),
subtext_size,
ui::ELIDE_AT_END);
gfx::ELIDE_AT_END);
}
#endif

Expand Down
8 changes: 4 additions & 4 deletions chrome/browser/ui/cocoa/download/download_item_cell.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h"
#import "third_party/GTM/AppKit/GTMNSColor+Luminance.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/text_elider.h"
#include "ui/gfx/canvas_skia_paint.h"
#include "ui/gfx/font.h"
#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
Expand Down Expand Up @@ -378,19 +378,19 @@ - (NSString*)elideTitle:(int)availableWidth {
[font pointSize]);

return base::SysUTF16ToNSString(
ui::ElideFilename(downloadPath_, font_chr, availableWidth));
gfx::ElideFilename(downloadPath_, font_chr, availableWidth));
}

- (NSString*)elideStatus:(int)availableWidth {
NSFont* font = [self secondaryFont];
gfx::Font font_chr(base::SysNSStringToUTF8([font fontName]),
[font pointSize]);

return base::SysUTF16ToNSString(ui::ElideText(
return base::SysUTF16ToNSString(gfx::ElideText(
base::SysNSStringToUTF16([self secondaryTitle]),
font_chr,
availableWidth,
ui::ELIDE_AT_END));
gfx::ELIDE_AT_END));
}

- (ui::ThemeProvider*)backgroundThemeWrappingProvider:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/text_elider.h"
#include "ui/gfx/font.h"
#include "ui/gfx/image/image.h"

Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/ui/cocoa/external_protocol_dialog.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/text_elider.h"

///////////////////////////////////////////////////////////////////////////////
// ExternalProtocolHandler
Expand Down Expand Up @@ -65,7 +65,7 @@ - (id)initWithGURL:(const GURL*)url {

const int kMaxUrlWithoutSchemeSize = 256;
string16 elided_url_without_scheme;
ui::ElideString(ASCIIToUTF16(url_.possibly_invalid_spec()),
gfx::ElideString(ASCIIToUTF16(url_.possibly_invalid_spec()),
kMaxUrlWithoutSchemeSize, &elided_url_without_scheme);

NSString* urlString = l10n_util::GetNSStringFWithFixup(
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#import "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/text_elider.h"
#include "ui/gfx/font.h"

namespace {
Expand Down Expand Up @@ -88,8 +88,8 @@
// prefix and the trailing country code in place.
gfx::Font font(GetFont());
NSString* elided_label = base::SysUTF16ToNSString(
ui::ElideText(base::SysNSStringToUTF16(full_label_), font, width_left,
ui::ELIDE_IN_MIDDLE));
gfx::ElideText(base::SysNSStringToUTF16(full_label_), font, width_left,
gfx::ELIDE_IN_MIDDLE));

// Use the elided label.
SetLabel(elided_label);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
#import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/text_elider.h"

namespace {

Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/ui/cocoa/status_bubble_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h"
#import "third_party/GTM/AppKit/GTMNSColor+Luminance.h"
#include "ui/base/cocoa/window_size_constants.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/text_elider.h"
#include "ui/gfx/font.h"
#include "ui/gfx/point.h"

Expand Down Expand Up @@ -154,7 +154,7 @@ - (void)animationDidStop:(CAAnimation*)animation finished:(BOOL)finished {
[font pointSize]);

string16 original_url_text = net::FormatUrl(url, languages);
string16 status = ui::ElideUrl(url, font_chr, text_width, languages);
string16 status = gfx::ElideUrl(url, font_chr, text_width, languages);

SetText(status, true);

Expand Down Expand Up @@ -623,7 +623,7 @@ - (void)animationDidStop:(CAAnimation*)animation finished:(BOOL)finished {
NSFont* font = [[window_ contentView] font];
gfx::Font font_chr(base::SysNSStringToUTF8([font fontName]),
[font pointSize]);
string16 expanded_url = ui::ElideUrl(
string16 expanded_url = gfx::ElideUrl(
url_, font_chr, max_bubble_width, languages_);

// Scale width from gfx::Font in view coordinates to window coordinates.
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/ui/external_protocol_dialog_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/text_elider.h"

ExternalProtocolDialogDelegate::ExternalProtocolDialogDelegate(const GURL& url)
: ProtocolDialogDelegate(url) {
Expand All @@ -32,9 +32,9 @@ string16 ExternalProtocolDialogDelegate::GetMessageText() const {
UTF8ToUTF16(ShellIntegration::GetApplicationForProtocol(url()));
string16 elided_url_without_scheme;
string16 elided_command;
ui::ElideString(ASCIIToUTF16(url().possibly_invalid_spec()),
gfx::ElideString(ASCIIToUTF16(url().possibly_invalid_spec()),
kMaxUrlWithoutSchemeSize, &elided_url_without_scheme);
ui::ElideString(command, kMaxCommandSize, &elided_command);
gfx::ElideString(command, kMaxCommandSize, &elided_command);

string16 message_text = l10n_util::GetStringFUTF16(
IDS_EXTERNAL_PROTOCOL_INFORMATION,
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/ui/gtk/avatar_menu_item_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#include "ui/base/gtk/gtk_hig_constants.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/gtk_util.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/text_elider.h"

namespace {

Expand Down Expand Up @@ -227,10 +227,10 @@ void AvatarMenuItemGtk::Init(GtkThemeService* theme_service) {
// The user name label.
GtkWidget* item_vbox = gtk_vbox_new(FALSE, 0);
GtkWidget* name_label = NULL;
string16 elided_name = ui::ElideText(item_.name,
string16 elided_name = gfx::ElideText(item_.name,
gfx::Font(),
kUserNameMaxWidth,
ui::ELIDE_AT_END);
gfx::ELIDE_AT_END);

name_label = theme_service->BuildLabel(UTF16ToUTF8(elided_name),
ui::kGdkBlack);
Expand Down
Loading

0 comments on commit dbb97ba

Please sign in to comment.