OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/ui/omnibox/omnibox_edit_model.h" | 5 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 is_keyword_hint_ = state.is_keyword_hint; | 180 is_keyword_hint_ = state.is_keyword_hint; |
181 view_->SetUserText(state.user_text, | 181 view_->SetUserText(state.user_text, |
182 DisplayTextFromUserText(state.user_text), false); | 182 DisplayTextFromUserText(state.user_text), false); |
183 view_->SetInstantSuggestion(state.instant_suggestion); | 183 view_->SetInstantSuggestion(state.instant_suggestion); |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 AutocompleteMatch OmniboxEditModel::CurrentMatch( | 187 AutocompleteMatch OmniboxEditModel::CurrentMatch( |
188 GURL* alternate_nav_url) const { | 188 GURL* alternate_nav_url) const { |
189 // If we have a valid match use it. Otherwise get one for the current text. | 189 // If we have a valid match use it. Otherwise get one for the current text. |
190 AutocompleteMatch match = | 190 AutocompleteMatch match = omnibox_controller_->current_match(); |
191 omnibox_controller_->CurrentMatch(alternate_nav_url); | 191 |
192 if (!match.destination_url.is_valid()) | 192 if (match.destination_url.is_valid()) { |
Peter Kasting
2013/06/18 23:31:19
Nit: Less indenting:
if (!match.destination_url
beaudoin
2013/06/19 18:21:10
Done.
| |
193 if (alternate_nav_url) { | |
194 *alternate_nav_url = AutocompleteResult::ComputeAlternateNavUrl( | |
195 autocomplete_controller()->input(), match); | |
196 } | |
197 } else { | |
193 GetInfoForCurrentText(&match, alternate_nav_url); | 198 GetInfoForCurrentText(&match, alternate_nav_url); |
199 } | |
194 return match; | 200 return match; |
195 } | 201 } |
196 | 202 |
197 bool OmniboxEditModel::UpdatePermanentText(const string16& new_permanent_text) { | 203 bool OmniboxEditModel::UpdatePermanentText(const string16& new_permanent_text) { |
198 // When there's a new URL, and the user is not editing anything or the edit | 204 // When there's a new URL, and the user is not editing anything or the edit |
199 // doesn't have focus, we want to revert the edit to show the new URL. (The | 205 // doesn't have focus, we want to revert the edit to show the new URL. (The |
200 // common case where the edit doesn't have focus is when the user has started | 206 // common case where the edit doesn't have focus is when the user has started |
201 // an edit and then abandoned it and clicked a link on the page.) | 207 // an edit and then abandoned it and clicked a link on the page.) |
202 // | 208 // |
203 // If the page is auto-committing an instant suggestion, however, we generally | 209 // If the page is auto-committing an instant suggestion, however, we generally |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1119 // true from this function. | 1125 // true from this function. |
1120 return !(text_differs && allow_keyword_ui_change && !just_deleted_text && | 1126 return !(text_differs && allow_keyword_ui_change && !just_deleted_text && |
1121 no_selection && (selection_start == user_text_.length()) && | 1127 no_selection && (selection_start == user_text_.length()) && |
1122 MaybeAcceptKeywordBySpace(user_text_)); | 1128 MaybeAcceptKeywordBySpace(user_text_)); |
1123 } | 1129 } |
1124 | 1130 |
1125 void OmniboxEditModel::OnCurrentMatchChanged(bool is_temporary_set_by_instant) { | 1131 void OmniboxEditModel::OnCurrentMatchChanged(bool is_temporary_set_by_instant) { |
1126 has_temporary_text_ = is_temporary_set_by_instant; | 1132 has_temporary_text_ = is_temporary_set_by_instant; |
1127 is_temporary_text_set_by_instant_ = is_temporary_set_by_instant; | 1133 is_temporary_text_set_by_instant_ = is_temporary_set_by_instant; |
1128 | 1134 |
1129 const AutocompleteMatch& match = omnibox_controller_->CurrentMatch(NULL); | 1135 const AutocompleteMatch& match = omnibox_controller_->current_match(); |
1130 | 1136 |
1131 if (is_temporary_set_by_instant) { | 1137 if (is_temporary_set_by_instant) { |
1132 view_->OnTemporaryTextMaybeChanged( | 1138 view_->OnTemporaryTextMaybeChanged( |
1133 DisplayTextFromUserText(match.fill_into_edit), !has_temporary_text_, | 1139 DisplayTextFromUserText(match.fill_into_edit), !has_temporary_text_, |
1134 false); | 1140 false); |
1135 } else { | 1141 } else { |
1136 // We store |keyword| and |is_keyword_hint| in temporary variables since | 1142 // We store |keyword| and |is_keyword_hint| in temporary variables since |
1137 // OnPopupDataChanged use their previous state to detect changes. | 1143 // OnPopupDataChanged use their previous state to detect changes. |
1138 string16 keyword; | 1144 string16 keyword; |
1139 bool is_keyword_hint; | 1145 bool is_keyword_hint; |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1411 instant->OmniboxFocusChanged(state, reason, NULL); | 1417 instant->OmniboxFocusChanged(state, reason, NULL); |
1412 | 1418 |
1413 // Update state and notify view if the omnibox has focus and the caret | 1419 // Update state and notify view if the omnibox has focus and the caret |
1414 // visibility changed. | 1420 // visibility changed. |
1415 const bool was_caret_visible = is_caret_visible(); | 1421 const bool was_caret_visible = is_caret_visible(); |
1416 focus_state_ = state; | 1422 focus_state_ = state; |
1417 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1423 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
1418 is_caret_visible() != was_caret_visible) | 1424 is_caret_visible() != was_caret_visible) |
1419 view_->ApplyCaretVisibility(); | 1425 view_->ApplyCaretVisibility(); |
1420 } | 1426 } |
OLD | NEW |