OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/autocomplete_popup_model.h" | 5 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 8 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
9 #include "chrome/browser/autocomplete/autocomplete_popup_view.h" | 9 #include "chrome/browser/autocomplete/autocomplete_popup_view.h" |
10 #include "chrome/browser/net/dns_global.h" | 10 #include "chrome/browser/net/dns_global.h" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 243 |
244 void AutocompletePopupModel::Move(int count) { | 244 void AutocompletePopupModel::Move(int count) { |
245 // TODO(pkasting): Temporary hack. If the query is running while the popup is | 245 // TODO(pkasting): Temporary hack. If the query is running while the popup is |
246 // open, we might be showing the results of the previous query still. Force | 246 // open, we might be showing the results of the previous query still. Force |
247 // the popup to display the latest results so the popup and the controller | 247 // the popup to display the latest results so the popup and the controller |
248 // aren't out of sync. The better fix here is to roll the controller back to | 248 // aren't out of sync. The better fix here is to roll the controller back to |
249 // be in sync with what the popup is showing. | 249 // be in sync with what the popup is showing. |
250 if (IsOpen() && !controller_->done()) { | 250 if (IsOpen() && !controller_->done()) { |
251 Observe(NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED, | 251 Observe(NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED, |
252 Source<AutocompleteController>(controller_.get()), | 252 Source<AutocompleteController>(controller_.get()), |
253 NotificationService::NoDetails()); | 253 Details<const AutocompleteResult>(&controller_->result())); |
254 } | 254 } |
255 | 255 |
256 const AutocompleteResult& result = controller_->result(); | 256 const AutocompleteResult& result = controller_->result(); |
257 if (result.empty()) | 257 if (result.empty()) |
258 return; | 258 return; |
259 | 259 |
260 // The user is using the keyboard to change the selection, so stop tracking | 260 // The user is using the keyboard to change the selection, so stop tracking |
261 // hover. | 261 // hover. |
262 SetHoveredLine(kNoMatch); | 262 SetHoveredLine(kNoMatch); |
263 | 263 |
(...skipping 25 matching lines...) Expand all Loading... |
289 } | 289 } |
290 } | 290 } |
291 } | 291 } |
292 | 292 |
293 void AutocompletePopupModel::Observe(NotificationType type, | 293 void AutocompletePopupModel::Observe(NotificationType type, |
294 const NotificationSource& source, | 294 const NotificationSource& source, |
295 const NotificationDetails& details) { | 295 const NotificationDetails& details) { |
296 if (inside_synchronous_query_) | 296 if (inside_synchronous_query_) |
297 return; | 297 return; |
298 | 298 |
299 const AutocompleteResult& result = controller_->result(); | 299 const AutocompleteResult* result = |
| 300 Details<const AutocompleteResult>(details).ptr(); |
300 switch (type.value) { | 301 switch (type.value) { |
301 case NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED: { | 302 case NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED: { |
302 selected_line_ = (result.default_match() == result.end()) ? | 303 selected_line_ = (result->default_match() == result->end()) ? |
303 kNoMatch : (result.default_match() - result.begin()); | 304 kNoMatch : (result->default_match() - result->begin()); |
304 // If we're going to trim the window size to no longer include the hovered | 305 // If we're going to trim the window size to no longer include the hovered |
305 // line, turn hover off. Practically, this shouldn't happen, but it | 306 // line, turn hover off. Practically, this shouldn't happen, but it |
306 // doesn't hurt to be defensive. | 307 // doesn't hurt to be defensive. |
307 if ((hovered_line_ != kNoMatch) && (result.size() <= hovered_line_)) | 308 if ((hovered_line_ != kNoMatch) && (result->size() <= hovered_line_)) |
308 SetHoveredLine(kNoMatch); | 309 SetHoveredLine(kNoMatch); |
309 | 310 |
310 view_->UpdatePopupAppearance(); | 311 view_->UpdatePopupAppearance(); |
311 } | 312 } |
312 // FALL THROUGH | 313 // FALL THROUGH |
313 | 314 |
314 case NotificationType:: | 315 case NotificationType:: |
315 AUTOCOMPLETE_CONTROLLER_SYNCHRONOUS_MATCHES_AVAILABLE: { | 316 AUTOCOMPLETE_CONTROLLER_SYNCHRONOUS_MATCHES_AVAILABLE: { |
316 // Update the edit with the possibly new data for this match. | 317 // Update the edit with the possibly new data for this match. |
317 // NOTE: This must be done after the code above, so that our internal | 318 // NOTE: This must be done after the code above, so that our internal |
318 // state will be consistent when the edit calls back to | 319 // state will be consistent when the edit calls back to |
319 // URLsForCurrentSelection(). | 320 // URLsForCurrentSelection(). |
320 std::wstring inline_autocomplete_text; | 321 std::wstring inline_autocomplete_text; |
321 std::wstring keyword; | 322 std::wstring keyword; |
322 bool is_keyword_hint = false; | 323 bool is_keyword_hint = false; |
323 AutocompleteMatch::Type type = AutocompleteMatch::SEARCH_WHAT_YOU_TYPED; | 324 AutocompleteMatch::Type type = AutocompleteMatch::SEARCH_WHAT_YOU_TYPED; |
324 const AutocompleteResult::const_iterator match(result.default_match()); | 325 const AutocompleteResult::const_iterator match(result->default_match()); |
325 if (match != result.end()) { | 326 if (match != result->end()) { |
326 if ((match->inline_autocomplete_offset != std::wstring::npos) && | 327 if ((match->inline_autocomplete_offset != std::wstring::npos) && |
327 (match->inline_autocomplete_offset < | 328 (match->inline_autocomplete_offset < |
328 match->fill_into_edit.length())) { | 329 match->fill_into_edit.length())) { |
329 inline_autocomplete_text = | 330 inline_autocomplete_text = |
330 match->fill_into_edit.substr(match->inline_autocomplete_offset); | 331 match->fill_into_edit.substr(match->inline_autocomplete_offset); |
331 } | 332 } |
332 // Warm up DNS Prefetch Cache. | 333 // Warm up DNS Prefetch Cache. |
333 chrome_browser_net::DnsPrefetchUrl(match->destination_url); | 334 chrome_browser_net::DnsPrefetchUrl(match->destination_url); |
334 // We could prefetch the alternate nav URL, if any, but because there | 335 // We could prefetch the alternate nav URL, if any, but because there |
335 // can be many of these as a user types an initial series of characters, | 336 // can be many of these as a user types an initial series of characters, |
336 // the OS DNS cache could suffer eviction problems for minimal gain. | 337 // the OS DNS cache could suffer eviction problems for minimal gain. |
337 | 338 |
338 is_keyword_hint = GetKeywordForMatch(*match, &keyword); | 339 is_keyword_hint = GetKeywordForMatch(*match, &keyword); |
339 type = match->type; | 340 type = match->type; |
340 } | 341 } |
341 edit_model_->OnPopupDataChanged(inline_autocomplete_text, false, keyword, | 342 edit_model_->OnPopupDataChanged(inline_autocomplete_text, false, keyword, |
342 is_keyword_hint, type); | 343 is_keyword_hint, type); |
343 return; | 344 return; |
344 } | 345 } |
345 | 346 |
346 default: | 347 default: |
347 NOTREACHED(); | 348 NOTREACHED(); |
348 } | 349 } |
349 } | 350 } |
OLD | NEW |