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

Side by Side Diff: chrome/browser/autocomplete/history_provider.cc

Issue 11414303: Make Google Search autocomplete provider cursor aware. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 8 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 | Annotate | Revision Log
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/autocomplete/history_provider.h" 5 #include "chrome/browser/autocomplete/history_provider.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 const size_t num_output_slashes = 127 const size_t num_output_slashes =
128 (last_output_nonslash == string16::npos) ? 128 (last_output_nonslash == string16::npos) ?
129 output.length() : (output.length() - 1 - last_output_nonslash); 129 output.length() : (output.length() - 1 - last_output_nonslash);
130 if (num_output_slashes < num_input_slashes) 130 if (num_output_slashes < num_input_slashes)
131 output.append(num_input_slashes - num_output_slashes, '/'); 131 output.append(num_input_slashes - num_output_slashes, '/');
132 else if (num_output_slashes > num_input_slashes) 132 else if (num_output_slashes > num_input_slashes)
133 output.erase(output.length() - num_output_slashes + num_input_slashes); 133 output.erase(output.length() - num_output_slashes + num_input_slashes);
134 134
135 url_parse::Parsed parts; 135 url_parse::Parsed parts;
136 URLFixerUpper::SegmentURL(output, &parts); 136 URLFixerUpper::SegmentURL(output, &parts);
137 input->UpdateText(output, parts); 137 // TODO: Rather then risking bogus cursor location, we simply pretend it was
138 // not set. It should be fine as long as the current implementation is not
139 // cursor aware (which is true as of Nov 2012).
Peter Kasting 2012/12/05 20:49:38 We probably should do the right thing here, since
Bart N. 2012/12/06 21:43:32 Done.
140 input->UpdateText(output, string16::npos, parts);
138 return !output.empty(); 141 return !output.empty();
139 } 142 }
140 143
141 // static 144 // static
142 size_t HistoryProvider::TrimHttpPrefix(string16* url) { 145 size_t HistoryProvider::TrimHttpPrefix(string16* url) {
143 // Find any "http:". 146 // Find any "http:".
144 if (!HasHTTPScheme(*url)) 147 if (!HasHTTPScheme(*url))
145 return 0; 148 return 0;
146 size_t scheme_pos = 149 size_t scheme_pos =
147 url->find(ASCIIToUTF16(chrome::kHttpScheme) + char16(':')); 150 url->find(ASCIIToUTF16(chrome::kHttpScheme) + char16(':'));
148 DCHECK_NE(string16::npos, scheme_pos); 151 DCHECK_NE(string16::npos, scheme_pos);
149 152
150 // Erase scheme plus up to two slashes. 153 // Erase scheme plus up to two slashes.
151 size_t prefix_end = scheme_pos + strlen(chrome::kHttpScheme) + 1; 154 size_t prefix_end = scheme_pos + strlen(chrome::kHttpScheme) + 1;
152 const size_t after_slashes = std::min(url->length(), prefix_end + 2); 155 const size_t after_slashes = std::min(url->length(), prefix_end + 2);
153 while ((prefix_end < after_slashes) && ((*url)[prefix_end] == '/')) 156 while ((prefix_end < after_slashes) && ((*url)[prefix_end] == '/'))
154 ++prefix_end; 157 ++prefix_end;
155 url->erase(scheme_pos, prefix_end - scheme_pos); 158 url->erase(scheme_pos, prefix_end - scheme_pos);
156 return (scheme_pos == 0) ? prefix_end : 0; 159 return (scheme_pos == 0) ? prefix_end : 0;
157 } 160 }
158 161
159 // static 162 // static
160 bool HistoryProvider::PreventInlineAutocomplete( 163 bool HistoryProvider::PreventInlineAutocomplete(
161 const AutocompleteInput& input) { 164 const AutocompleteInput& input) {
162 return input.prevent_inline_autocomplete() || 165 return input.prevent_inline_autocomplete() ||
163 always_prevent_inline_autocomplete_ || 166 always_prevent_inline_autocomplete_ ||
164 (!input.text().empty() && 167 (!input.text().empty() &&
165 IsWhitespace(input.text()[input.text().length() - 1])); 168 IsWhitespace(input.text()[input.text().length() - 1]));
166 } 169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698