| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 void AutocompletePopupModel::ResetToDefaultMatch() { | 138 void AutocompletePopupModel::ResetToDefaultMatch() { |
| 139 const AutocompleteResult& result = controller_->result(); | 139 const AutocompleteResult& result = controller_->result(); |
| 140 DCHECK(!result.empty()); | 140 DCHECK(!result.empty()); |
| 141 SetSelectedLine(result.default_match() - result.begin(), true); | 141 SetSelectedLine(result.default_match() - result.begin(), true); |
| 142 } | 142 } |
| 143 | 143 |
| 144 GURL AutocompletePopupModel::URLsForCurrentSelection( | 144 GURL AutocompletePopupModel::URLsForCurrentSelection( |
| 145 PageTransition::Type* transition, | 145 PageTransition::Type* transition, |
| 146 bool* is_history_what_you_typed_match, | 146 bool* is_history_what_you_typed_match, |
| 147 GURL* alternate_nav_url) const { | 147 GURL* alternate_nav_url) const { |
| 148 // We need to use the result on the controller, because if the popup is open, | 148 const AutocompleteResult* result; |
| 149 // the user changes the contents of the edit, and then presses enter before | |
| 150 // any results have been displayed, results_ will be nonempty but wrong. (In | |
| 151 // most other cases, the controller's results will match the popup's.) | |
| 152 // TODO(pkasting): If manually_selected_match_ moves to the controller, this | |
| 153 // can move to the edit. | |
| 154 if (controller_->result().empty()) | |
| 155 return GURL(); | |
| 156 | |
| 157 const AutocompleteResult& result = controller_->result(); | |
| 158 AutocompleteResult::const_iterator match; | 149 AutocompleteResult::const_iterator match; |
| 159 if (!controller_->done()) { | 150 if (!controller_->done()) { |
| 151 result = &controller_->latest_result(); |
| 152 // It's technically possible for |result| to be empty if no provider returns |
| 153 // a synchronous result but the query has not completed synchronously; |
| 154 // pratically, however, that should never actually happen. |
| 155 if (result->empty()) |
| 156 return GURL(); |
| 160 // The user cannot have manually selected a match, or the query would have | 157 // The user cannot have manually selected a match, or the query would have |
| 161 // stopped. So the default match must be the desired selection. | 158 // stopped. So the default match must be the desired selection. |
| 162 match = result.default_match(); | 159 match = result->default_match(); |
| 163 } else { | 160 } else { |
| 164 // The query isn't running, so the popup can't possibly be out of date. | 161 // The query isn't running, so the standard result set can't possibly be out |
| 165 DCHECK(selected_line_ < result.size()); | 162 // of date. |
| 166 match = result.begin() + selected_line_; | 163 // |
| 164 // NOTE: In practice, it should actually be safe to use |
| 165 // controller_->latest_result() here too, since the controller keeps that |
| 166 // up-to-date. However we generally try to avoid referring to that. |
| 167 result = &controller_->result(); |
| 168 // If there are no results, the popup is closed, so URLsForDefaultMatch() |
| 169 // should have been called instead. |
| 170 DCHECK(!result->empty()); |
| 171 DCHECK(selected_line_ < result->size()); |
| 172 match = result->begin() + selected_line_; |
| 167 } | 173 } |
| 168 if (transition) | 174 if (transition) |
| 169 *transition = match->transition; | 175 *transition = match->transition; |
| 170 if (is_history_what_you_typed_match) | 176 if (is_history_what_you_typed_match) |
| 171 *is_history_what_you_typed_match = match->is_history_what_you_typed_match; | 177 *is_history_what_you_typed_match = match->is_history_what_you_typed_match; |
| 172 if (alternate_nav_url && manually_selected_match_.empty()) | 178 if (alternate_nav_url && manually_selected_match_.empty()) |
| 173 *alternate_nav_url = result.alternate_nav_url(); | 179 *alternate_nav_url = result->alternate_nav_url(); |
| 174 return match->destination_url; | 180 return match->destination_url; |
| 175 } | 181 } |
| 176 | 182 |
| 177 GURL AutocompletePopupModel::URLsForDefaultMatch( | 183 GURL AutocompletePopupModel::URLsForDefaultMatch( |
| 178 const std::wstring& text, | 184 const std::wstring& text, |
| 179 const std::wstring& desired_tld, | 185 const std::wstring& desired_tld, |
| 180 PageTransition::Type* transition, | 186 PageTransition::Type* transition, |
| 181 bool* is_history_what_you_typed_match, | 187 bool* is_history_what_you_typed_match, |
| 182 GURL* alternate_nav_url) { | 188 GURL* alternate_nav_url) { |
| 183 // We had better not already be doing anything, or this call will blow it | 189 // We had better not already be doing anything, or this call will blow it |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 } | 347 } |
| 342 edit_model_->OnPopupDataChanged(inline_autocomplete_text, false, keyword, | 348 edit_model_->OnPopupDataChanged(inline_autocomplete_text, false, keyword, |
| 343 is_keyword_hint, type); | 349 is_keyword_hint, type); |
| 344 return; | 350 return; |
| 345 } | 351 } |
| 346 | 352 |
| 347 default: | 353 default: |
| 348 NOTREACHED(); | 354 NOTREACHED(); |
| 349 } | 355 } |
| 350 } | 356 } |
| OLD | NEW |