Chromium Code Reviews| 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 InternalSetUserText(permanent_text_); | 907 InternalSetUserText(permanent_text_); |
| 914 view_->UpdatePopup(); | 908 view_->UpdatePopup(); |
| 915 return; | 909 return; |
| 916 } | 910 } |
| 917 | 911 |
| 918 // TODO(pkasting): The popup is working on a query but is not open. We should | 912 // TODO(pkasting): The popup is working on a query but is not open. We should |
| 919 // force it to open immediately. | 913 // force it to open immediately. |
| 920 } | 914 } |
| 921 | 915 |
| 922 void OmniboxEditModel::OnPopupDataChanged( | 916 void OmniboxEditModel::OnPopupDataChanged( |
| 923 const string16& text, | 917 const string16 text, |
| 924 GURL* destination_for_temporary_text_change, | 918 GURL* destination_for_temporary_text_change, |
| 925 const string16& keyword, | 919 const string16& keyword, |
| 926 bool is_keyword_hint) { | 920 bool is_keyword_hint) { |
| 927 // The popup changed its data, the match in the controller is no longer valid. | 921 // The popup changed its data, the match in the controller is no longer valid. |
| 928 omnibox_controller_->InvalidateCurrentMatch(); | 922 omnibox_controller_->InvalidateCurrentMatch(); |
| 929 | 923 |
| 930 // Update keyword/hint-related local state. | 924 // Update keyword/hint-related local state. |
| 931 bool keyword_state_changed = (keyword_ != keyword) || | 925 bool keyword_state_changed = (keyword_ != keyword) || |
| 932 ((is_keyword_hint_ != is_keyword_hint) && !keyword.empty()); | 926 ((is_keyword_hint_ != is_keyword_hint) && !keyword.empty()); |
| 933 if (keyword_state_changed) { | 927 if (keyword_state_changed) { |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1103 void OmniboxEditModel::OnCurrentMatchChanged() { | 1097 void OmniboxEditModel::OnCurrentMatchChanged() { |
| 1104 has_temporary_text_ = false; | 1098 has_temporary_text_ = false; |
| 1105 | 1099 |
| 1106 const AutocompleteMatch& match = omnibox_controller_->current_match(); | 1100 const AutocompleteMatch& match = omnibox_controller_->current_match(); |
| 1107 | 1101 |
| 1108 // We store |keyword| and |is_keyword_hint| in temporary variables since | 1102 // We store |keyword| and |is_keyword_hint| in temporary variables since |
| 1109 // OnPopupDataChanged use their previous state to detect changes. | 1103 // OnPopupDataChanged use their previous state to detect changes. |
| 1110 string16 keyword; | 1104 string16 keyword; |
| 1111 bool is_keyword_hint; | 1105 bool is_keyword_hint; |
| 1112 match.GetKeywordUIState(profile_, &keyword, &is_keyword_hint); | 1106 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. | |
|
Peter Kasting
2013/07/16 18:09:05
This TODO should perhaps be preserved?
Mark P
2013/07/16 18:53:23
Okay. Done.
| |
| 1118 inline_autocomplete_text = | |
| 1119 match.fill_into_edit.substr(match.inline_autocomplete_offset); | |
| 1120 } | |
| 1121 popup_model()->OnResultChanged(); | 1107 popup_model()->OnResultChanged(); |
| 1122 OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, | 1108 OnPopupDataChanged(match.inline_autocompletion, NULL, keyword, |
| 1123 is_keyword_hint); | 1109 is_keyword_hint); |
| 1124 } | 1110 } |
| 1125 | 1111 |
| 1126 string16 OmniboxEditModel::GetViewText() const { | 1112 string16 OmniboxEditModel::GetViewText() const { |
| 1127 return view_->GetText(); | 1113 return view_->GetText(); |
| 1128 } | 1114 } |
| 1129 | 1115 |
| 1130 InstantController* OmniboxEditModel::GetInstantController() const { | 1116 InstantController* OmniboxEditModel::GetInstantController() const { |
| 1131 return controller_->GetInstant(); | 1117 return controller_->GetInstant(); |
| 1132 } | 1118 } |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1298 instant->OmniboxFocusChanged(state, reason, NULL); | 1284 instant->OmniboxFocusChanged(state, reason, NULL); |
| 1299 | 1285 |
| 1300 // Update state and notify view if the omnibox has focus and the caret | 1286 // Update state and notify view if the omnibox has focus and the caret |
| 1301 // visibility changed. | 1287 // visibility changed. |
| 1302 const bool was_caret_visible = is_caret_visible(); | 1288 const bool was_caret_visible = is_caret_visible(); |
| 1303 focus_state_ = state; | 1289 focus_state_ = state; |
| 1304 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1290 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
| 1305 is_caret_visible() != was_caret_visible) | 1291 is_caret_visible() != was_caret_visible) |
| 1306 view_->ApplyCaretVisibility(); | 1292 view_->ApplyCaretVisibility(); |
| 1307 } | 1293 } |
| OLD | NEW |