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

Side by Side Diff: chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.mm

Issue 98463012: Infinite Suggest for mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add Infinite Suggest for Mac Created 7 years 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 unified diff | Download patch
OLDNEW
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/cocoa/omnibox/omnibox_popup_view_mac.h" 5 #include "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 29 matching lines...) Expand all
40 // How far to offset the text column from the left. 40 // How far to offset the text column from the left.
41 const CGFloat kTextXOffset = 28.0; 41 const CGFloat kTextXOffset = 28.0;
42 42
43 // Animation duration when animating the popup window smaller. 43 // Animation duration when animating the popup window smaller.
44 const NSTimeInterval kShrinkAnimationDuration = 0.1; 44 const NSTimeInterval kShrinkAnimationDuration = 0.1;
45 45
46 // Maximum fraction of the popup width that can be used to display match 46 // Maximum fraction of the popup width that can be used to display match
47 // contents. 47 // contents.
48 const CGFloat kMaxContentsFraction = 0.7; 48 const CGFloat kMaxContentsFraction = 0.7;
49 49
50 const char16 kEllipsis[] = { 0x2026, 0x20, 0x0 };
Scott Hess - ex-Googler 2013/12/12 19:11:15 Don't define your own constant. ElideString() use
Anuj 2013/12/12 23:56:22 Done.
51
50 // Background colors for different states of the popup elements. 52 // Background colors for different states of the popup elements.
51 NSColor* BackgroundColor() { 53 NSColor* BackgroundColor() {
52 return [NSColor controlBackgroundColor]; 54 return [NSColor controlBackgroundColor];
53 } 55 }
54 56
55 NSColor* ContentTextColor() { 57 NSColor* ContentTextColor() {
56 return [NSColor blackColor]; 58 return [NSColor blackColor];
57 } 59 }
58 NSColor* DimContentTextColor() { 60 NSColor* DimContentTextColor() {
59 return [NSColor darkGrayColor]; 61 return [NSColor darkGrayColor];
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 gfx::Font result_font(OmniboxViewMac::GetFieldFont()); 118 gfx::Font result_font(OmniboxViewMac::GetFieldFont());
117 119
118 // Calculate the width of the matrix based on backing out the popup's border 120 // Calculate the width of the matrix based on backing out the popup's border
119 // from the width of the field. 121 // from the width of the field.
120 const CGFloat matrix_width = NSWidth([field_ bounds]); 122 const CGFloat matrix_width = NSWidth([field_ bounds]);
121 DCHECK_GT(matrix_width, 0.0); 123 DCHECK_GT(matrix_width, 0.0);
122 124
123 // Load the results into the popup's matrix. 125 // Load the results into the popup's matrix.
124 DCHECK_GT(rows, 0U); 126 DCHECK_GT(rows, 0U);
125 [matrix_ renewRows:rows columns:1]; 127 [matrix_ renewRows:rows columns:1];
128
129 CGFloat max_match_width = 0;
130 CGFloat max_required_width = 0;
131 CGFloat ignored_prefix_width = 0;
132 CGFloat ellipsis_prefix_width = 0;
126 for (size_t ii = 0; ii < rows; ++ii) { 133 for (size_t ii = 0; ii < rows; ++ii) {
127 OmniboxPopupCell* cell = [matrix_ cellAtRow:ii column:0]; 134 OmniboxPopupCell* cell = [matrix_ cellAtRow:ii column:0];
128 const AutocompleteMatch& match = GetResult().match_at(ii + start_match); 135 const AutocompleteMatch& match = GetResult().match_at(ii + start_match);
129 [cell setImage:ImageForMatch(match)]; 136 [cell setImage:ImageForMatch(match)];
130 [cell setAttributedTitle:MatchText(match, result_font, matrix_width)]; 137 NSAttributedString* match_text =
138 MatchText(match, result_font, matrix_width);
Scott Hess - ex-Googler 2013/12/12 19:11:15 This is going to construct a result which you are
Anuj 2013/12/12 19:40:55 1. I can change the code as follows if (ignored_pr
139
140 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_INFINITE) {
141
Scott Hess - ex-Googler 2013/12/12 19:11:15 No empty line.
Anuj 2013/12/12 23:56:22 Done.
142 string16 ignored_prefix = match.fill_into_edit.substr(
143 0, match.fill_into_edit.rfind(match.contents));
144 NSMutableAttributedString* ignored_prefix_as = DecorateMatchedString(
145 ignored_prefix, ACMatchClassifications(), ContentTextColor(),
146 DimContentTextColor(), result_font);
147 ignored_prefix_width = [ignored_prefix_as size].width;
148 [ignored_prefix_as appendAttributedString:match_text];
149 CGFloat required_width = [ignored_prefix_as size].width;
150 if (required_width > max_required_width)
151 max_required_width = required_width;
152
153 NSMutableAttributedString* ellipsis_prefix = DecorateMatchedString(
154 kEllipsis, ACMatchClassifications(), ContentTextColor(),
155 DimContentTextColor(), result_font);
156 ellipsis_prefix_width = [ellipsis_prefix size].width;
157 [ellipsis_prefix appendAttributedString:match_text];
158 CGFloat match_width = [ellipsis_prefix size].width;
159 if (match_width > max_match_width)
160 max_match_width = match_width;
161 match_text = ellipsis_prefix;
162 }
163 [cell setAttributedTitle:match_text];
164 }
165
166 for (size_t ii = 0; ii < rows; ++ii) {
167 const AutocompleteMatch& match = GetResult().match_at(ii + start_match);
168 OmniboxPopupCell* cell = [matrix_ cellAtRow:ii column:0];
169 [cell setAdditionalOffset:0];
170 if (match.type != AutocompleteMatchType::SEARCH_SUGGEST_INFINITE) {
171 continue;
172 }
173
174 const float text_width = matrix_width - kTextXOffset;
175 CGFloat additional_offset = (max_required_width < text_width) ?
176 (ignored_prefix_width - ellipsis_prefix_width) :
177 (text_width - max_match_width);
178 if (additional_offset > 0)
179 [cell setAdditionalOffset:additional_offset];
131 } 180 }
132 181
133 // Set the cell size to fit a line of text in the cell's font. All 182 // Set the cell size to fit a line of text in the cell's font. All
134 // cells should use the same font and each should layout in one 183 // cells should use the same font and each should layout in one
135 // line, so they should all be about the same height. 184 // line, so they should all be about the same height.
136 const NSSize cell_size = [[matrix_ cellAtRow:0 column:0] cellSize]; 185 const NSSize cell_size = [[matrix_ cellAtRow:0 column:0] cellSize];
137 DCHECK_GT(cell_size.height, 0.0); 186 DCHECK_GT(cell_size.height, 0.0);
138 const CGFloat cell_height = cell_size.height + kCellHeightAdjust; 187 const CGFloat cell_height = cell_size.height + kCellHeightAdjust;
139 [matrix_ setCellSize:NSMakeSize(matrix_width, cell_height)]; 188 [matrix_ setCellSize:NSMakeSize(matrix_width, cell_height)];
140 189
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 return OmniboxViewMac::ImageForResource(resource_id); 541 return OmniboxViewMac::ImageForResource(resource_id);
493 } 542 }
494 543
495 void OmniboxPopupViewMac::OpenURLForRow(size_t row, 544 void OmniboxPopupViewMac::OpenURLForRow(size_t row,
496 WindowOpenDisposition disposition) { 545 WindowOpenDisposition disposition) {
497 size_t start_match = model_->result().ShouldHideTopMatch() ? 1 : 0; 546 size_t start_match = model_->result().ShouldHideTopMatch() ? 1 : 0;
498 row += start_match; 547 row += start_match;
499 DCHECK_LT(row, GetResult().size()); 548 DCHECK_LT(row, GetResult().size());
500 omnibox_view_->OpenMatch(GetResult().match_at(row), disposition, GURL(), row); 549 omnibox_view_->OpenMatch(GetResult().match_at(row), disposition, GURL(), row);
501 } 550 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698