OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "app/gfx/font.h" | 7 #include "app/gfx/font.h" |
8 #include "app/text_elider.h" | 8 #include "app/text_elider.h" |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/i18n/rtl.h" |
11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
12 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
15 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
16 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
17 #include "net/base/registry_controlled_domain.h" | 18 #include "net/base/registry_controlled_domain.h" |
18 | 19 |
19 const wchar_t kEllipsis[] = L"\x2026"; | 20 const wchar_t kEllipsis[] = L"\x2026"; |
20 | 21 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 257 |
257 return ElideText(final_elided_url_string, font, available_pixel_width); | 258 return ElideText(final_elided_url_string, font, available_pixel_width); |
258 } | 259 } |
259 | 260 |
260 std::wstring ElideFilename(const FilePath& filename, | 261 std::wstring ElideFilename(const FilePath& filename, |
261 const gfx::Font& font, | 262 const gfx::Font& font, |
262 int available_pixel_width) { | 263 int available_pixel_width) { |
263 int full_width = font.GetStringWidth(filename.ToWStringHack()); | 264 int full_width = font.GetStringWidth(filename.ToWStringHack()); |
264 if (full_width <= available_pixel_width) { | 265 if (full_width <= available_pixel_width) { |
265 std::wstring elided_name = filename.ToWStringHack(); | 266 std::wstring elided_name = filename.ToWStringHack(); |
266 return l10n_util::GetDisplayStringInLTRDirectionality(&elided_name); | 267 return base::i18n::GetDisplayStringInLTRDirectionality(&elided_name); |
267 } | 268 } |
268 | 269 |
269 #if defined(OS_WIN) | 270 #if defined(OS_WIN) |
270 std::wstring extension = filename.Extension(); | 271 std::wstring extension = filename.Extension(); |
271 #elif defined(OS_POSIX) | 272 #elif defined(OS_POSIX) |
272 std::wstring extension = base::SysNativeMBToWide(filename.Extension()); | 273 std::wstring extension = base::SysNativeMBToWide(filename.Extension()); |
273 #endif | 274 #endif |
274 std::wstring rootname = | 275 std::wstring rootname = |
275 filename.BaseName().RemoveExtension().ToWStringHack(); | 276 filename.BaseName().RemoveExtension().ToWStringHack(); |
276 | 277 |
277 if (rootname.empty() || extension.empty()) { | 278 if (rootname.empty() || extension.empty()) { |
278 std::wstring elided_name = ElideText(filename.ToWStringHack(), font, | 279 std::wstring elided_name = ElideText(filename.ToWStringHack(), font, |
279 available_pixel_width); | 280 available_pixel_width); |
280 return l10n_util::GetDisplayStringInLTRDirectionality(&elided_name); | 281 return base::i18n::GetDisplayStringInLTRDirectionality(&elided_name); |
281 } | 282 } |
282 | 283 |
283 int ext_width = font.GetStringWidth(extension); | 284 int ext_width = font.GetStringWidth(extension); |
284 int root_width = font.GetStringWidth(rootname); | 285 int root_width = font.GetStringWidth(rootname); |
285 | 286 |
286 // We may have trimmed the path. | 287 // We may have trimmed the path. |
287 if (root_width + ext_width <= available_pixel_width) { | 288 if (root_width + ext_width <= available_pixel_width) { |
288 std::wstring elided_name = rootname + extension; | 289 std::wstring elided_name = rootname + extension; |
289 return l10n_util::GetDisplayStringInLTRDirectionality(&elided_name); | 290 return base::i18n::GetDisplayStringInLTRDirectionality(&elided_name); |
290 } | 291 } |
291 | 292 |
292 int available_root_width = available_pixel_width - ext_width; | 293 int available_root_width = available_pixel_width - ext_width; |
293 std::wstring elided_name = ElideText(rootname, font, available_root_width); | 294 std::wstring elided_name = ElideText(rootname, font, available_root_width); |
294 elided_name += extension; | 295 elided_name += extension; |
295 return l10n_util::GetDisplayStringInLTRDirectionality(&elided_name); | 296 return base::i18n::GetDisplayStringInLTRDirectionality(&elided_name); |
296 } | 297 } |
297 | 298 |
298 // This function adds an ellipsis at the end of the text if the text | 299 // This function adds an ellipsis at the end of the text if the text |
299 // does not fit the given pixel width. | 300 // does not fit the given pixel width. |
300 std::wstring ElideText(const std::wstring& text, | 301 std::wstring ElideText(const std::wstring& text, |
301 const gfx::Font& font, | 302 const gfx::Font& font, |
302 int available_pixel_width) { | 303 int available_pixel_width) { |
303 if (text.empty()) | 304 if (text.empty()) |
304 return text; | 305 return text; |
305 | 306 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 string16 SortedDisplayURL::AfterHost() const { | 414 string16 SortedDisplayURL::AfterHost() const { |
414 size_t slash_index = display_url_.find(sort_host_, prefix_end_); | 415 size_t slash_index = display_url_.find(sort_host_, prefix_end_); |
415 if (slash_index == string16::npos) { | 416 if (slash_index == string16::npos) { |
416 NOTREACHED(); | 417 NOTREACHED(); |
417 return string16(); | 418 return string16(); |
418 } | 419 } |
419 return display_url_.substr(slash_index + sort_host_.length()); | 420 return display_url_.substr(slash_index + sort_host_.length()); |
420 } | 421 } |
421 | 422 |
422 } // namespace gfx. | 423 } // namespace gfx. |
OLD | NEW |