Chromium Code Reviews| Index: chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm |
| diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm |
| index 17678d2c9d15f74f20e18e8a2c04200f71bd9bfd..4df87c00ceacf1ee9d5e96c369e5bcdb91ef4c38 100644 |
| --- a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm |
| +++ b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm |
| @@ -123,11 +123,64 @@ void OmniboxPopupViewMac::UpdatePopupAppearance() { |
| // Load the results into the popup's matrix. |
| DCHECK_GT(rows, 0U); |
| [matrix_ renewRows:rows columns:1]; |
| + |
| + CGFloat max_match_width = 0; |
| + CGFloat max_required_width = 0; |
| + CGFloat ignored_prefix_width = 0; |
| + CGFloat ellipsis_prefix_width = 0; |
| for (size_t ii = 0; ii < rows; ++ii) { |
| OmniboxPopupCell* cell = [matrix_ cellAtRow:ii column:0]; |
| const AutocompleteMatch& match = GetResult().match_at(ii + start_match); |
| [cell setImage:ImageForMatch(match)]; |
| - [cell setAttributedTitle:MatchText(match, result_font, matrix_width)]; |
| + NSAttributedString* match_text = |
| + MatchText(match, result_font, matrix_width); |
| + |
| + if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_INFINITE) { |
| + // Use ignored_prefix from the fill_into_edit to compute the |
| + // required_width and max_required_width. |
| + size_t input_start = |
| + (match.transition == content::PAGE_TRANSITION_KEYWORD) ? |
| + match.keyword.length() + 1 : 0; |
| + string16 ignored_prefix = match.fill_into_edit.substr(input_start, |
| + match.fill_into_edit.rfind(match.contents) - input_start); |
| + NSMutableAttributedString* ignored_prefix_as = DecorateMatchedString( |
| + ignored_prefix, ACMatchClassifications(), ContentTextColor(), |
| + DimContentTextColor(), result_font); |
|
Scott Hess - ex-Googler
2013/12/14 00:40:57
This is confusing. Since you're passing empty cla
Anuj
2013/12/16 02:53:19
Done.
|
| + if (ignored_prefix_width == 0) |
| + ignored_prefix_width = [ignored_prefix_as size].width; |
|
Scott Hess - ex-Googler
2013/12/14 00:40:57
My concern about this (and others) isn't actually
Anuj
2013/12/16 02:53:19
Done.
|
| + [ignored_prefix_as appendAttributedString:match_text]; |
| + CGFloat required_width = [ignored_prefix_as size].width; |
| + if (required_width > max_required_width) |
| + max_required_width = required_width; |
| + |
| + // Use ellipsis prefix to compute the match_width and max_match_width. |
| + NSMutableAttributedString* ellipsis_prefix = DecorateMatchedString( |
| + base::string16(gfx::kEllipsisUTF16).append(UTF8ToUTF16(" ")), |
| + ACMatchClassifications(), ContentTextColor(), DimContentTextColor(), |
| + result_font); |
|
Scott Hess - ex-Googler
2013/12/14 00:40:57
Use the abstracted helper here, too.
Anuj
2013/12/16 02:53:19
Done.
|
| + if (ellipsis_prefix_width == 0) |
| + ellipsis_prefix_width = [ellipsis_prefix size].width; |
| + [ellipsis_prefix appendAttributedString:match_text]; |
| + CGFloat match_width = [ellipsis_prefix size].width; |
| + if (match_width > max_match_width) |
| + max_match_width = match_width; |
| + match_text = ellipsis_prefix; |
| + } |
| + [cell setAttributedTitle:match_text]; |
| + } |
| + |
| + const float text_width = matrix_width - kTextXOffset; |
| + CGFloat infinite_suggest_offset = (max_required_width < text_width) ? |
| + std::max(ignored_prefix_width - ellipsis_prefix_width, 0.0f) : |
| + std::max(text_width - max_match_width, 0.0f); |
| + |
| + for (size_t ii = 0; ii < rows; ++ii) { |
| + const AutocompleteMatch& match = GetResult().match_at(ii + start_match); |
| + OmniboxPopupCell* cell = [matrix_ cellAtRow:ii column:0]; |
| + CGFloat additional_offset = |
| + (match.type != AutocompleteMatchType::SEARCH_SUGGEST_INFINITE) ? |
| + 0 : infinite_suggest_offset; |
| + [cell setAdditionalOffset:additional_offset]; |
| } |
|
Scott Hess - ex-Googler
2013/12/14 00:40:57
This is all very complicated. I honestly have no
Anuj
2013/12/16 02:53:19
I have modified the implementation. Note that the
Anuj
2013/12/19 05:36:13
Since cells get reused, the offset needs to be res
Scott Hess - ex-Googler
2013/12/19 20:12:50
The point to tracking the infinite cells is becaus
|
| // Set the cell size to fit a line of text in the cell's font. All |