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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 edit_model_->OnPopupDataChanged( | 122 edit_model_->OnPopupDataChanged( |
123 reset_to_default ? std::wstring() : match.fill_into_edit, | 123 reset_to_default ? std::wstring() : match.fill_into_edit, |
124 !reset_to_default, keyword, is_keyword_hint, match.type); | 124 !reset_to_default, keyword, is_keyword_hint, match.type); |
125 | 125 |
126 // Repaint old and new selected lines immediately, so that the edit doesn't | 126 // Repaint old and new selected lines immediately, so that the edit doesn't |
127 // appear to update [much] faster than the popup. We must not update | 127 // appear to update [much] faster than the popup. We must not update |
128 // |selected_line_| before calling OnPopupDataChanged() (since the edit may | 128 // |selected_line_| before calling OnPopupDataChanged() (since the edit may |
129 // call us back to get data about the old selection), and we must not call | 129 // call us back to get data about the old selection), and we must not call |
130 // UpdateWindow() before updating |selected_line_| (since the paint routine | 130 // UpdateWindow() before updating |selected_line_| (since the paint routine |
131 // relies on knowing the correct selected line). | 131 // relies on knowing the correct selected line). |
| 132 // |
| 133 // NOTE: We should never reach here with no selected line; the same code that |
| 134 // opened the popup and made it possible to get here should have also set a |
| 135 // selected line. |
| 136 CHECK(selected_line_ != kNoMatch); |
132 view_->InvalidateLine(selected_line_); | 137 view_->InvalidateLine(selected_line_); |
133 selected_line_ = line; | 138 selected_line_ = line; |
134 view_->InvalidateLine(selected_line_); | 139 view_->InvalidateLine(selected_line_); |
135 view_->PaintUpdatesNow(); | 140 view_->PaintUpdatesNow(); |
136 } | 141 } |
137 | 142 |
138 void AutocompletePopupModel::ResetToDefaultMatch() { | 143 void AutocompletePopupModel::ResetToDefaultMatch() { |
139 const AutocompleteResult& result = controller_->result(); | 144 const AutocompleteResult& result = controller_->result(); |
140 DCHECK(!result.empty()); | 145 DCHECK(!result.empty()); |
141 SetSelectedLine(result.default_match() - result.begin(), true); | 146 SetSelectedLine(result.default_match() - result.begin(), true); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 const NotificationDetails& details) { | 300 const NotificationDetails& details) { |
296 if (inside_synchronous_query_) | 301 if (inside_synchronous_query_) |
297 return; | 302 return; |
298 | 303 |
299 const AutocompleteResult* result = | 304 const AutocompleteResult* result = |
300 Details<const AutocompleteResult>(details).ptr(); | 305 Details<const AutocompleteResult>(details).ptr(); |
301 switch (type.value) { | 306 switch (type.value) { |
302 case NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED: { | 307 case NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED: { |
303 selected_line_ = (result->default_match() == result->end()) ? | 308 selected_line_ = (result->default_match() == result->end()) ? |
304 kNoMatch : (result->default_match() - result->begin()); | 309 kNoMatch : (result->default_match() - result->begin()); |
| 310 // There had better not be a nonempty result set with no default match. |
| 311 CHECK((selected_line_ != kNoMatch) || result->empty()); |
305 // If we're going to trim the window size to no longer include the hovered | 312 // If we're going to trim the window size to no longer include the hovered |
306 // line, turn hover off. Practically, this shouldn't happen, but it | 313 // line, turn hover off. Practically, this shouldn't happen, but it |
307 // doesn't hurt to be defensive. | 314 // doesn't hurt to be defensive. |
308 if ((hovered_line_ != kNoMatch) && (result->size() <= hovered_line_)) | 315 if ((hovered_line_ != kNoMatch) && (result->size() <= hovered_line_)) |
309 SetHoveredLine(kNoMatch); | 316 SetHoveredLine(kNoMatch); |
310 | 317 |
311 view_->UpdatePopupAppearance(); | 318 view_->UpdatePopupAppearance(); |
312 } | 319 } |
313 // FALL THROUGH | 320 // FALL THROUGH |
314 | 321 |
(...skipping 26 matching lines...) Expand all Loading... |
341 } | 348 } |
342 edit_model_->OnPopupDataChanged(inline_autocomplete_text, false, keyword, | 349 edit_model_->OnPopupDataChanged(inline_autocomplete_text, false, keyword, |
343 is_keyword_hint, type); | 350 is_keyword_hint, type); |
344 return; | 351 return; |
345 } | 352 } |
346 | 353 |
347 default: | 354 default: |
348 NOTREACHED(); | 355 NOTREACHED(); |
349 } | 356 } |
350 } | 357 } |
OLD | NEW |