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/profile.h" | 10 #include "chrome/browser/profile.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 } | 102 } |
103 | 103 |
104 if (line == selected_line_) | 104 if (line == selected_line_) |
105 return; // Nothing else to do. | 105 return; // Nothing else to do. |
106 | 106 |
107 // Update the edit with the new data for this match. | 107 // Update the edit with the new data for this match. |
108 // TODO(pkasting): If |selected_line_| moves to the controller, this can be | 108 // TODO(pkasting): If |selected_line_| moves to the controller, this can be |
109 // eliminated and just become a call to the observer on the edit. | 109 // eliminated and just become a call to the observer on the edit. |
110 std::wstring keyword; | 110 std::wstring keyword; |
111 const bool is_keyword_hint = GetKeywordForMatch(match, &keyword); | 111 const bool is_keyword_hint = GetKeywordForMatch(match, &keyword); |
112 edit_model_->OnPopupDataChanged( | 112 |
113 reset_to_default ? std::wstring() : match.fill_into_edit, | 113 if (reset_to_default) { |
114 !reset_to_default, keyword, is_keyword_hint, match.type); | 114 std::wstring inline_autocomplete_text; |
| 115 if ((match.inline_autocomplete_offset != std::wstring::npos) && |
| 116 (match.inline_autocomplete_offset < match.fill_into_edit.length())) { |
| 117 inline_autocomplete_text = |
| 118 match.fill_into_edit.substr(match.inline_autocomplete_offset); |
| 119 } |
| 120 edit_model_->OnPopupDataChanged(inline_autocomplete_text, false, |
| 121 keyword, is_keyword_hint, match.type); |
| 122 } else { |
| 123 edit_model_->OnPopupDataChanged(match.fill_into_edit, true, |
| 124 keyword, is_keyword_hint, match.type); |
| 125 } |
115 | 126 |
116 // Repaint old and new selected lines immediately, so that the edit doesn't | 127 // Repaint old and new selected lines immediately, so that the edit doesn't |
117 // appear to update [much] faster than the popup. We must not update | 128 // appear to update [much] faster than the popup. We must not update |
118 // |selected_line_| before calling OnPopupDataChanged() (since the edit may | 129 // |selected_line_| before calling OnPopupDataChanged() (since the edit may |
119 // call us back to get data about the old selection), and we must not call | 130 // call us back to get data about the old selection), and we must not call |
120 // UpdateWindow() before updating |selected_line_| (since the paint routine | 131 // UpdateWindow() before updating |selected_line_| (since the paint routine |
121 // relies on knowing the correct selected line). | 132 // relies on knowing the correct selected line). |
122 // | 133 // |
123 // NOTE: We should never reach here with no selected line; the same code that | 134 // NOTE: We should never reach here with no selected line; the same code that |
124 // opened the popup and made it possible to get here should have also set a | 135 // opened the popup and made it possible to get here should have also set a |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 // There had better not be a nonempty result set with no default match. | 278 // There had better not be a nonempty result set with no default match. |
268 CHECK((selected_line_ != kNoMatch) || result->empty()); | 279 CHECK((selected_line_ != kNoMatch) || result->empty()); |
269 // If we're going to trim the window size to no longer include the hovered | 280 // If we're going to trim the window size to no longer include the hovered |
270 // line, turn hover off. Practically, this shouldn't happen, but it | 281 // line, turn hover off. Practically, this shouldn't happen, but it |
271 // doesn't hurt to be defensive. | 282 // doesn't hurt to be defensive. |
272 if ((hovered_line_ != kNoMatch) && (result->size() <= hovered_line_)) | 283 if ((hovered_line_ != kNoMatch) && (result->size() <= hovered_line_)) |
273 SetHoveredLine(kNoMatch); | 284 SetHoveredLine(kNoMatch); |
274 | 285 |
275 view_->UpdatePopupAppearance(); | 286 view_->UpdatePopupAppearance(); |
276 } | 287 } |
OLD | NEW |