| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_edit.h" | 5 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 return true; | 206 return true; |
| 207 } | 207 } |
| 208 | 208 |
| 209 bool AutocompleteEditModel::AcceptCurrentInstantPreview() { | 209 bool AutocompleteEditModel::AcceptCurrentInstantPreview() { |
| 210 return InstantController::CommitIfCurrent(controller_->GetInstant()); | 210 return InstantController::CommitIfCurrent(controller_->GetInstant()); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void AutocompleteEditModel::OnChanged() { | 213 void AutocompleteEditModel::OnChanged() { |
| 214 const AutocompleteMatch current_match = CurrentMatch(); | 214 const AutocompleteMatch current_match = CurrentMatch(); |
| 215 | 215 |
| 216 string16 suggested_text; | 216 NetworkActionPredictor::Action recommended_action = |
| 217 | 217 NetworkActionPredictor::ACTION_NONE; |
| 218 // Confer with the NetworkActionPredictor to determine what action, if any, | |
| 219 // we should take. Get the recommended action here even if we don't need it | |
| 220 // so we can get stats for anyone who is opted in to UMA, but only get it if | |
| 221 // the user has actually typed something to avoid constructing it before it's | |
| 222 // needed. Note: This event is triggered as part of startup when the initial | |
| 223 // tab transitions to the start page. | |
| 224 NetworkActionPredictor* network_action_predictor = user_input_in_progress() ? | 218 NetworkActionPredictor* network_action_predictor = user_input_in_progress() ? |
| 225 profile_->GetNetworkActionPredictor() : NULL; | 219 profile_->GetNetworkActionPredictor() : NULL; |
| 226 NetworkActionPredictor::Action recommended_action = network_action_predictor ? | 220 if (network_action_predictor) { |
| 227 network_action_predictor->RecommendAction(user_text_, current_match) : | 221 network_action_predictor->RegisterTransitionalMatches(user_text_, |
| 228 NetworkActionPredictor::ACTION_NONE; | 222 result()); |
| 223 // Confer with the NetworkActionPredictor to determine what action, if any, |
| 224 // we should take. Get the recommended action here even if we don't need it |
| 225 // so we can get stats for anyone who is opted in to UMA, but only get it if |
| 226 // the user has actually typed something to avoid constructing it before |
| 227 // it's needed. Note: This event is triggered as part of startup when the |
| 228 // initial tab transitions to the start page. |
| 229 recommended_action = |
| 230 network_action_predictor->RecommendAction(user_text_, current_match); |
| 231 } |
| 232 |
| 229 UMA_HISTOGRAM_ENUMERATION("NetworkActionPredictor.Action_" + | 233 UMA_HISTOGRAM_ENUMERATION("NetworkActionPredictor.Action_" + |
| 230 prerender::GetOmniboxHistogramSuffix(), | 234 prerender::GetOmniboxHistogramSuffix(), |
| 231 recommended_action, | 235 recommended_action, |
| 232 NetworkActionPredictor::LAST_PREDICT_ACTION); | 236 NetworkActionPredictor::LAST_PREDICT_ACTION); |
| 237 string16 suggested_text; |
| 238 |
| 233 if (DoInstant(current_match, &suggested_text)) { | 239 if (DoInstant(current_match, &suggested_text)) { |
| 234 SetSuggestedText(suggested_text, instant_complete_behavior_); | 240 SetSuggestedText(suggested_text, instant_complete_behavior_); |
| 235 } else { | 241 } else { |
| 236 switch (recommended_action) { | 242 switch (recommended_action) { |
| 237 case NetworkActionPredictor::ACTION_PRERENDER: | 243 case NetworkActionPredictor::ACTION_PRERENDER: |
| 238 DoPrerender(current_match); | 244 DoPrerender(current_match); |
| 239 break; | 245 break; |
| 240 case NetworkActionPredictor::ACTION_PRECONNECT: | 246 case NetworkActionPredictor::ACTION_PRECONNECT: |
| 241 DoPreconnect(current_match); | 247 DoPreconnect(current_match); |
| 242 break; | 248 break; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 393 |
| 388 void AutocompleteEditModel::Revert() { | 394 void AutocompleteEditModel::Revert() { |
| 389 SetInputInProgress(false); | 395 SetInputInProgress(false); |
| 390 paste_state_ = NONE; | 396 paste_state_ = NONE; |
| 391 InternalSetUserText(string16()); | 397 InternalSetUserText(string16()); |
| 392 keyword_.clear(); | 398 keyword_.clear(); |
| 393 is_keyword_hint_ = false; | 399 is_keyword_hint_ = false; |
| 394 has_temporary_text_ = false; | 400 has_temporary_text_ = false; |
| 395 view_->SetWindowTextAndCaretPos(permanent_text_, | 401 view_->SetWindowTextAndCaretPos(permanent_text_, |
| 396 has_focus_ ? permanent_text_.length() : 0); | 402 has_focus_ ? permanent_text_.length() : 0); |
| 403 NetworkActionPredictor* network_action_predictor = |
| 404 profile_->GetNetworkActionPredictor(); |
| 405 if (network_action_predictor) |
| 406 network_action_predictor->ClearTransitionalMatches(); |
| 397 } | 407 } |
| 398 | 408 |
| 399 void AutocompleteEditModel::StartAutocomplete( | 409 void AutocompleteEditModel::StartAutocomplete( |
| 400 bool has_selected_text, | 410 bool has_selected_text, |
| 401 bool prevent_inline_autocomplete) const { | 411 bool prevent_inline_autocomplete) const { |
| 402 bool keyword_is_selected = KeywordIsSelected(); | 412 bool keyword_is_selected = KeywordIsSelected(); |
| 403 popup_->SetHoveredLine(AutocompletePopupModel::kNoMatch); | 413 popup_->SetHoveredLine(AutocompletePopupModel::kNoMatch); |
| 404 // We don't explicitly clear AutocompletePopupModel::manually_selected_match, | 414 // We don't explicitly clear AutocompletePopupModel::manually_selected_match, |
| 405 // as Start ends up invoking AutocompletePopupModel::OnResultChanged which | 415 // as Start ends up invoking AutocompletePopupModel::OnResultChanged which |
| 406 // clears it. | 416 // clears it. |
| (...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 // static | 1075 // static |
| 1066 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { | 1076 bool AutocompleteEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { |
| 1067 switch (c) { | 1077 switch (c) { |
| 1068 case 0x0020: // Space | 1078 case 0x0020: // Space |
| 1069 case 0x3000: // Ideographic Space | 1079 case 0x3000: // Ideographic Space |
| 1070 return true; | 1080 return true; |
| 1071 default: | 1081 default: |
| 1072 return false; | 1082 return false; |
| 1073 } | 1083 } |
| 1074 } | 1084 } |
| OLD | NEW |