| 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()) { |
| 193 GetInfoForCurrentText(&match, alternate_nav_url); | 193 GetInfoForCurrentText(&match, alternate_nav_url); |
| 194 } else if (alternate_nav_url) { |
| 195 *alternate_nav_url = AutocompleteResult::ComputeAlternateNavUrl( |
| 196 autocomplete_controller()->input(), match); |
| 197 } |
| 194 return match; | 198 return match; |
| 195 } | 199 } |
| 196 | 200 |
| 197 bool OmniboxEditModel::UpdatePermanentText(const string16& new_permanent_text) { | 201 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 | 202 // 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 | 203 // 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 | 204 // 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.) | 205 // an edit and then abandoned it and clicked a link on the page.) |
| 202 // | 206 // |
| 203 // If the page is auto-committing an instant suggestion, however, we generally | 207 // 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. | 1123 // true from this function. |
| 1120 return !(text_differs && allow_keyword_ui_change && !just_deleted_text && | 1124 return !(text_differs && allow_keyword_ui_change && !just_deleted_text && |
| 1121 no_selection && (selection_start == user_text_.length()) && | 1125 no_selection && (selection_start == user_text_.length()) && |
| 1122 MaybeAcceptKeywordBySpace(user_text_)); | 1126 MaybeAcceptKeywordBySpace(user_text_)); |
| 1123 } | 1127 } |
| 1124 | 1128 |
| 1125 void OmniboxEditModel::OnCurrentMatchChanged(bool is_temporary_set_by_instant) { | 1129 void OmniboxEditModel::OnCurrentMatchChanged(bool is_temporary_set_by_instant) { |
| 1126 has_temporary_text_ = is_temporary_set_by_instant; | 1130 has_temporary_text_ = is_temporary_set_by_instant; |
| 1127 is_temporary_text_set_by_instant_ = is_temporary_set_by_instant; | 1131 is_temporary_text_set_by_instant_ = is_temporary_set_by_instant; |
| 1128 | 1132 |
| 1129 const AutocompleteMatch& match = omnibox_controller_->CurrentMatch(NULL); | 1133 const AutocompleteMatch& match = omnibox_controller_->current_match(); |
| 1130 | 1134 |
| 1131 if (is_temporary_set_by_instant) { | 1135 if (is_temporary_set_by_instant) { |
| 1132 view_->OnTemporaryTextMaybeChanged( | 1136 view_->OnTemporaryTextMaybeChanged( |
| 1133 DisplayTextFromUserText(match.fill_into_edit), !has_temporary_text_, | 1137 DisplayTextFromUserText(match.fill_into_edit), !has_temporary_text_, |
| 1134 false); | 1138 false); |
| 1135 } else { | 1139 } else { |
| 1136 // We store |keyword| and |is_keyword_hint| in temporary variables since | 1140 // We store |keyword| and |is_keyword_hint| in temporary variables since |
| 1137 // OnPopupDataChanged use their previous state to detect changes. | 1141 // OnPopupDataChanged use their previous state to detect changes. |
| 1138 string16 keyword; | 1142 string16 keyword; |
| 1139 bool is_keyword_hint; | 1143 bool is_keyword_hint; |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1411 instant->OmniboxFocusChanged(state, reason, NULL); | 1415 instant->OmniboxFocusChanged(state, reason, NULL); |
| 1412 | 1416 |
| 1413 // Update state and notify view if the omnibox has focus and the caret | 1417 // Update state and notify view if the omnibox has focus and the caret |
| 1414 // visibility changed. | 1418 // visibility changed. |
| 1415 const bool was_caret_visible = is_caret_visible(); | 1419 const bool was_caret_visible = is_caret_visible(); |
| 1416 focus_state_ = state; | 1420 focus_state_ = state; |
| 1417 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1421 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
| 1418 is_caret_visible() != was_caret_visible) | 1422 is_caret_visible() != was_caret_visible) |
| 1419 view_->ApplyCaretVisibility(); | 1423 view_->ApplyCaretVisibility(); |
| 1420 } | 1424 } |
| OLD | NEW |