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 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 } | 621 } |
622 OmniboxLog log( | 622 OmniboxLog log( |
623 autocomplete_controller()->input().text(), | 623 autocomplete_controller()->input().text(), |
624 just_deleted_text_, | 624 just_deleted_text_, |
625 autocomplete_controller()->input().type(), | 625 autocomplete_controller()->input().type(), |
626 popup_model()->selected_line(), | 626 popup_model()->selected_line(), |
627 -1, // don't yet know tab ID; set later if appropriate | 627 -1, // don't yet know tab ID; set later if appropriate |
628 delegate_->CurrentPageExists() ? ClassifyPage(delegate_->GetURL()) : | 628 delegate_->CurrentPageExists() ? ClassifyPage(delegate_->GetURL()) : |
629 metrics::OmniboxEventProto_PageClassification_OTHER, | 629 metrics::OmniboxEventProto_PageClassification_OTHER, |
630 elapsed_time_since_user_first_modified_omnibox, | 630 elapsed_time_since_user_first_modified_omnibox, |
631 string16::npos, // completed_length; possibly set later | 631 match.inline_autocompletion.length(), |
632 elapsed_time_since_last_change_to_default_match, | 632 elapsed_time_since_last_change_to_default_match, |
633 result()); | 633 result()); |
634 | 634 |
635 DCHECK(user_input_in_progress_ || (match.provider && | 635 DCHECK(user_input_in_progress_ || (match.provider && |
636 match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST)) | 636 match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST)) |
637 << "We didn't get here through the expected series of calls. " | 637 << "We didn't get here through the expected series of calls. " |
638 << "time_user_first_modified_omnibox_ is not set correctly and other " | 638 << "time_user_first_modified_omnibox_ is not set correctly and other " |
639 << "things may be wrong. Match provider: " | 639 << "things may be wrong. Match provider: " |
640 << (match.provider ? match.provider->GetName() : "NULL"); | 640 << (match.provider ? match.provider->GetName() : "NULL"); |
641 DCHECK(log.elapsed_time_since_user_first_modified_omnibox >= | 641 DCHECK(log.elapsed_time_since_user_first_modified_omnibox >= |
642 log.elapsed_time_since_last_change_to_default_match) | 642 log.elapsed_time_since_last_change_to_default_match) |
643 << "We should've got the notification that the user modified the " | 643 << "We should've got the notification that the user modified the " |
644 << "omnibox text at same time or before the most recent time the " | 644 << "omnibox text at same time or before the most recent time the " |
645 << "default match changed."; | 645 << "default match changed."; |
646 | 646 |
647 if (index != OmniboxPopupModel::kNoMatch) | 647 if (index != OmniboxPopupModel::kNoMatch) |
648 log.selected_index = index; | 648 log.selected_index = index; |
649 if (match.inline_autocomplete_offset != string16::npos) { | |
650 DCHECK_GE(match.fill_into_edit.length(), | |
651 match.inline_autocomplete_offset); | |
652 log.completed_length = | |
653 match.fill_into_edit.length() - match.inline_autocomplete_offset; | |
654 } | |
655 | 649 |
656 if ((disposition == CURRENT_TAB) && delegate_->CurrentPageExists()) { | 650 if ((disposition == CURRENT_TAB) && delegate_->CurrentPageExists()) { |
657 // If we know the destination is being opened in the current tab, | 651 // If we know the destination is being opened in the current tab, |
658 // we can easily get the tab ID. (If it's being opened in a new | 652 // we can easily get the tab ID. (If it's being opened in a new |
659 // tab, we don't know the tab ID yet.) | 653 // tab, we don't know the tab ID yet.) |
660 log.tab_id = delegate_->GetSessionID().id(); | 654 log.tab_id = delegate_->GetSessionID().id(); |
661 } | 655 } |
662 autocomplete_controller()->AddProvidersInfo(&log.providers_info); | 656 autocomplete_controller()->AddProvidersInfo(&log.providers_info); |
663 content::NotificationService::current()->Notify( | 657 content::NotificationService::current()->Notify( |
664 chrome::NOTIFICATION_OMNIBOX_OPENED_URL, | 658 chrome::NOTIFICATION_OMNIBOX_OPENED_URL, |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 // determine what keyword, if any, is applicable. | 1087 // determine what keyword, if any, is applicable. |
1094 // | 1088 // |
1095 // If MaybeAcceptKeywordBySpace() accepts the keyword and returns true, that | 1089 // If MaybeAcceptKeywordBySpace() accepts the keyword and returns true, that |
1096 // will have updated our state already, so in that case we don't also return | 1090 // will have updated our state already, so in that case we don't also return |
1097 // true from this function. | 1091 // true from this function. |
1098 return !(text_differs && allow_keyword_ui_change && !just_deleted_text && | 1092 return !(text_differs && allow_keyword_ui_change && !just_deleted_text && |
1099 no_selection && (selection_start == user_text_.length()) && | 1093 no_selection && (selection_start == user_text_.length()) && |
1100 MaybeAcceptKeywordBySpace(user_text_)); | 1094 MaybeAcceptKeywordBySpace(user_text_)); |
1101 } | 1095 } |
1102 | 1096 |
| 1097 // TODO(beaudoin): Merge OnPopupDataChanged with this method once the popup |
| 1098 // handling has completely migrated to omnibox_controller. |
1103 void OmniboxEditModel::OnCurrentMatchChanged() { | 1099 void OmniboxEditModel::OnCurrentMatchChanged() { |
1104 has_temporary_text_ = false; | 1100 has_temporary_text_ = false; |
1105 | 1101 |
1106 const AutocompleteMatch& match = omnibox_controller_->current_match(); | 1102 const AutocompleteMatch& match = omnibox_controller_->current_match(); |
1107 | 1103 |
1108 // We store |keyword| and |is_keyword_hint| in temporary variables since | 1104 // We store |keyword| and |is_keyword_hint| in temporary variables since |
1109 // OnPopupDataChanged use their previous state to detect changes. | 1105 // OnPopupDataChanged use their previous state to detect changes. |
1110 string16 keyword; | 1106 string16 keyword; |
1111 bool is_keyword_hint; | 1107 bool is_keyword_hint; |
1112 match.GetKeywordUIState(profile_, &keyword, &is_keyword_hint); | 1108 match.GetKeywordUIState(profile_, &keyword, &is_keyword_hint); |
1113 string16 inline_autocomplete_text; | |
1114 if (match.inline_autocomplete_offset < match.fill_into_edit.length()) { | |
1115 // We have blue text, go through OnPopupDataChanged. | |
1116 // TODO(beaudoin): Merge OnPopupDataChanged with this method once the | |
1117 // popup handling has completely migrated to omnibox_controller. | |
1118 inline_autocomplete_text = | |
1119 match.fill_into_edit.substr(match.inline_autocomplete_offset); | |
1120 } | |
1121 popup_model()->OnResultChanged(); | 1109 popup_model()->OnResultChanged(); |
1122 OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, | 1110 // OnPopupDataChanged() resets OmniboxController's |current_match_| early |
1123 is_keyword_hint); | 1111 // on. Therefore, copy match.inline_autocompletion to a temp to preserve |
| 1112 // its value across the entire call. |
| 1113 const string16 inline_autocompletion(match.inline_autocompletion); |
| 1114 OnPopupDataChanged(inline_autocompletion, NULL, keyword, is_keyword_hint); |
1124 } | 1115 } |
1125 | 1116 |
1126 string16 OmniboxEditModel::GetViewText() const { | 1117 string16 OmniboxEditModel::GetViewText() const { |
1127 return view_->GetText(); | 1118 return view_->GetText(); |
1128 } | 1119 } |
1129 | 1120 |
1130 InstantController* OmniboxEditModel::GetInstantController() const { | 1121 InstantController* OmniboxEditModel::GetInstantController() const { |
1131 return controller_->GetInstant(); | 1122 return controller_->GetInstant(); |
1132 } | 1123 } |
1133 | 1124 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 instant->OmniboxFocusChanged(state, reason, NULL); | 1289 instant->OmniboxFocusChanged(state, reason, NULL); |
1299 | 1290 |
1300 // Update state and notify view if the omnibox has focus and the caret | 1291 // Update state and notify view if the omnibox has focus and the caret |
1301 // visibility changed. | 1292 // visibility changed. |
1302 const bool was_caret_visible = is_caret_visible(); | 1293 const bool was_caret_visible = is_caret_visible(); |
1303 focus_state_ = state; | 1294 focus_state_ = state; |
1304 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1295 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
1305 is_caret_visible() != was_caret_visible) | 1296 is_caret_visible() != was_caret_visible) |
1306 view_->ApplyCaretVisibility(); | 1297 view_->ApplyCaretVisibility(); |
1307 } | 1298 } |
OLD | NEW |