Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3712)

Unified Diff: chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.mm

Issue 2748103013: Adjust elision of omnibox keyword search label. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/BUILD.gn ('k') | chrome/browser/ui/location_bar/location_bar_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.mm
diff --git a/chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.mm b/chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.mm
index 426c4d139f407ba1020fc470672ef742e1be79c0..9a01da2e7abf62df389d5decedb583b36b8c04d0 100644
--- a/chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.mm
+++ b/chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.mm
@@ -4,15 +4,37 @@
#import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h"
+#include <stddef.h>
+
+#include "base/i18n/rtl.h"
+#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
+#include "base/strings/utf_string_conversions.h"
#import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
-#include "chrome/browser/ui/location_bar/location_bar_util.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
#include "skia/ext/skia_utils_mac.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/gfx/color_palette.h"
+#include "ui/gfx/text_elider.h"
+
+namespace {
+
+// Build a short string to use in keyword-search when the field isn't very big.
+base::string16 CalculateMinString(const base::string16& description) {
+ // Chop at the first '.' or whitespace.
+ const size_t chop_index = description.find_first_of(base::kWhitespaceUTF16 +
+ base::ASCIIToUTF16("."));
+ base::string16 min_string(
+ (chop_index == base::string16::npos)
+ ? gfx::TruncateString(description, 3, gfx::WORD_BREAK)
+ : description.substr(0, chop_index));
+ base::i18n::AdjustStringForLocaleDirection(&min_string);
+ return min_string;
+}
+
+} // namespace
SelectedKeywordDecoration::SelectedKeywordDecoration() {
// Note: the unit test
@@ -58,8 +80,7 @@ ui::NinePartImageIds SelectedKeywordDecoration::GetBubbleImageIds() {
void SelectedKeywordDecoration::SetKeyword(const base::string16& short_name,
bool is_extension_keyword) {
- const base::string16 min_name(
- location_bar_util::CalculateMinString(short_name));
+ const base::string16 min_name(CalculateMinString(short_name));
const int keyword_text_id = IDS_OMNIBOX_KEYWORD_TEXT_MD;
NSString* full_string =
« no previous file with comments | « chrome/browser/ui/BUILD.gn ('k') | chrome/browser/ui/location_bar/location_bar_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698