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

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: This function does not take into account the cursor position while
138 // running various normalizations, including a call to FixupURL(). In order
139 // to make it work properly, we need to ensure that all logic above is
140 // cursor-aware and offsets the input cursor accordingly.
141 // For now we simply pretend that the cursor was not set at all.
142 // See http://crbug/163932 for more details.
143 input->UpdateText(output, string16::npos, parts);
138 return !output.empty(); 144 return !output.empty();
139 } 145 }
140 146
141 // static 147 // static
142 size_t HistoryProvider::TrimHttpPrefix(string16* url) { 148 size_t HistoryProvider::TrimHttpPrefix(string16* url) {
143 // Find any "http:". 149 // Find any "http:".
144 if (!HasHTTPScheme(*url)) 150 if (!HasHTTPScheme(*url))
145 return 0; 151 return 0;
146 size_t scheme_pos = 152 size_t scheme_pos =
147 url->find(ASCIIToUTF16(chrome::kHttpScheme) + char16(':')); 153 url->find(ASCIIToUTF16(chrome::kHttpScheme) + char16(':'));
148 DCHECK_NE(string16::npos, scheme_pos); 154 DCHECK_NE(string16::npos, scheme_pos);
149 155
150 // Erase scheme plus up to two slashes. 156 // Erase scheme plus up to two slashes.
151 size_t prefix_end = scheme_pos + strlen(chrome::kHttpScheme) + 1; 157 size_t prefix_end = scheme_pos + strlen(chrome::kHttpScheme) + 1;
152 const size_t after_slashes = std::min(url->length(), prefix_end + 2); 158 const size_t after_slashes = std::min(url->length(), prefix_end + 2);
153 while ((prefix_end < after_slashes) && ((*url)[prefix_end] == '/')) 159 while ((prefix_end < after_slashes) && ((*url)[prefix_end] == '/'))
154 ++prefix_end; 160 ++prefix_end;
155 url->erase(scheme_pos, prefix_end - scheme_pos); 161 url->erase(scheme_pos, prefix_end - scheme_pos);
156 return (scheme_pos == 0) ? prefix_end : 0; 162 return (scheme_pos == 0) ? prefix_end : 0;
157 } 163 }
158 164
159 // static 165 // static
160 bool HistoryProvider::PreventInlineAutocomplete( 166 bool HistoryProvider::PreventInlineAutocomplete(
161 const AutocompleteInput& input) { 167 const AutocompleteInput& input) {
162 return input.prevent_inline_autocomplete() || 168 return input.prevent_inline_autocomplete() ||
163 always_prevent_inline_autocomplete_ || 169 always_prevent_inline_autocomplete_ ||
164 (!input.text().empty() && 170 (!input.text().empty() &&
165 IsWhitespace(input.text()[input.text().length() - 1])); 171 IsWhitespace(input.text()[input.text().length() - 1]));
166 } 172 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698