OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/omnibox/location_bar_util.h" | 5 #include "chrome/browser/ui/omnibox/location_bar_util.h" |
6 | 6 |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/extensions/extension_action.h" | 10 #include "chrome/browser/extensions/extension_action.h" |
10 #include "third_party/skia/include/core/SkPaint.h" | 11 #include "third_party/skia/include/core/SkPaint.h" |
11 #include "third_party/skia/include/effects/SkGradientShader.h" | 12 #include "third_party/skia/include/effects/SkGradientShader.h" |
12 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
13 #include "ui/gfx/color_utils.h" | 14 #include "ui/gfx/color_utils.h" |
14 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
15 #include "ui/gfx/text_elider.h" | 16 #include "ui/gfx/text_elider.h" |
16 | 17 |
17 namespace location_bar_util { | 18 namespace location_bar_util { |
18 | 19 |
19 base::string16 CalculateMinString(const base::string16& description) { | 20 base::string16 CalculateMinString(const base::string16& description) { |
20 // Chop at the first '.' or whitespace. | 21 // Chop at the first '.' or whitespace. |
21 const size_t dot_index = description.find('.'); | 22 const size_t chop_index = description.find_first_of( |
22 const size_t ws_index = description.find_first_of(base::kWhitespaceUTF16); | 23 base::kWhitespaceUTF16 + base::ASCIIToUTF16(".")); |
23 size_t chop_index = std::min(dot_index, ws_index); | 24 base::string16 min_string((chop_index == base::string16::npos) ? |
24 base::string16 min_string; | 25 gfx::TruncateString(description, 3) : description.substr(0, chop_index)); |
25 if (chop_index == base::string16::npos) { | |
26 // No dot or whitespace, truncate to at most 3 chars. | |
27 min_string = gfx::TruncateString(description, 3); | |
28 } else { | |
29 min_string = description.substr(0, chop_index); | |
30 } | |
31 base::i18n::AdjustStringForLocaleDirection(&min_string); | 26 base::i18n::AdjustStringForLocaleDirection(&min_string); |
32 return min_string; | 27 return min_string; |
33 } | 28 } |
34 | 29 |
35 } // namespace location_bar_util | 30 } // namespace location_bar_util |
OLD | NEW |