| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 // Histogram name which counts the number of times the user enters | 91 // Histogram name which counts the number of times the user enters |
| 92 // keyword hint mode and via what method. The possible values are listed | 92 // keyword hint mode and via what method. The possible values are listed |
| 93 // in the EnteredKeywordModeMethod enum which is defined in the .h file. | 93 // in the EnteredKeywordModeMethod enum which is defined in the .h file. |
| 94 const char kEnteredKeywordModeHistogram[] = "Omnibox.EnteredKeywordMode"; | 94 const char kEnteredKeywordModeHistogram[] = "Omnibox.EnteredKeywordMode"; |
| 95 | 95 |
| 96 // Histogram name which counts the number of milliseconds a user takes | 96 // Histogram name which counts the number of milliseconds a user takes |
| 97 // between focusing and editing the omnibox. | 97 // between focusing and editing the omnibox. |
| 98 const char kFocusToEditTimeHistogram[] = "Omnibox.FocusToEditTime"; | 98 const char kFocusToEditTimeHistogram[] = "Omnibox.FocusToEditTime"; |
| 99 | 99 |
| 100 // Histogram name which counts the number of milliseconds a user takes |
| 101 // between focusing and opening an omnibox match. |
| 102 const char kFocusToOpenTimeHistogram[] = "Omnibox.FocusToOpenTime"; |
| 103 |
| 100 void RecordPercentageMatchHistogram(const string16& old_text, | 104 void RecordPercentageMatchHistogram(const string16& old_text, |
| 101 const string16& new_text, | 105 const string16& new_text, |
| 102 bool search_term_replacement_active, | 106 bool search_term_replacement_active, |
| 103 content::PageTransition transition) { | 107 content::PageTransition transition) { |
| 104 size_t avg_length = (old_text.length() + new_text.length()) / 2; | 108 size_t avg_length = (old_text.length() + new_text.length()) / 2; |
| 105 | 109 |
| 106 int percent = 0; | 110 int percent = 0; |
| 107 if (!old_text.empty() && !new_text.empty()) { | 111 if (!old_text.empty() && !new_text.empty()) { |
| 108 size_t shorter_length = std::min(old_text.length(), new_text.length()); | 112 size_t shorter_length = std::min(old_text.length(), new_text.length()); |
| 109 string16::const_iterator end(old_text.begin() + shorter_length); | 113 string16::const_iterator end(old_text.begin() + shorter_length); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 /////////////////////////////////////////////////////////////////////////////// | 161 /////////////////////////////////////////////////////////////////////////////// |
| 158 // OmniboxEditModel | 162 // OmniboxEditModel |
| 159 | 163 |
| 160 OmniboxEditModel::OmniboxEditModel(OmniboxView* view, | 164 OmniboxEditModel::OmniboxEditModel(OmniboxView* view, |
| 161 OmniboxEditController* controller, | 165 OmniboxEditController* controller, |
| 162 Profile* profile) | 166 Profile* profile) |
| 163 : view_(view), | 167 : view_(view), |
| 164 controller_(controller), | 168 controller_(controller), |
| 165 focus_state_(OMNIBOX_FOCUS_NONE), | 169 focus_state_(OMNIBOX_FOCUS_NONE), |
| 166 user_input_in_progress_(false), | 170 user_input_in_progress_(false), |
| 171 user_input_since_focus_(true), |
| 167 just_deleted_text_(false), | 172 just_deleted_text_(false), |
| 168 has_temporary_text_(false), | 173 has_temporary_text_(false), |
| 169 paste_state_(NONE), | 174 paste_state_(NONE), |
| 170 control_key_state_(UP), | 175 control_key_state_(UP), |
| 171 is_keyword_hint_(false), | 176 is_keyword_hint_(false), |
| 172 profile_(profile), | 177 profile_(profile), |
| 173 in_revert_(false), | 178 in_revert_(false), |
| 174 allow_exact_keyword_match_(false) { | 179 allow_exact_keyword_match_(false) { |
| 175 omnibox_controller_.reset(new OmniboxController(this, profile)); | 180 omnibox_controller_.reset(new OmniboxController(this, profile)); |
| 176 delegate_.reset(new OmniboxCurrentPageDelegateImpl(controller, profile)); | 181 delegate_.reset(new OmniboxCurrentPageDelegateImpl(controller, profile)); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 url->SchemeIs(chrome::kHttpScheme) && perm_url.host() == url->host()) { | 412 url->SchemeIs(chrome::kHttpScheme) && perm_url.host() == url->host()) { |
| 408 *write_url = true; | 413 *write_url = true; |
| 409 string16 http = ASCIIToUTF16(chrome::kHttpScheme) + | 414 string16 http = ASCIIToUTF16(chrome::kHttpScheme) + |
| 410 ASCIIToUTF16(content::kStandardSchemeSeparator); | 415 ASCIIToUTF16(content::kStandardSchemeSeparator); |
| 411 if (text->compare(0, http.length(), http) != 0) | 416 if (text->compare(0, http.length(), http) != 0) |
| 412 *text = http + *text; | 417 *text = http + *text; |
| 413 } | 418 } |
| 414 } | 419 } |
| 415 | 420 |
| 416 void OmniboxEditModel::SetInputInProgress(bool in_progress) { | 421 void OmniboxEditModel::SetInputInProgress(bool in_progress) { |
| 417 if (in_progress && !last_omnibox_focus_without_user_input_.is_null()) { | 422 if (in_progress && !user_input_since_focus_) { |
| 418 base::TimeTicks now = base::TimeTicks::Now(); | 423 base::TimeTicks now = base::TimeTicks::Now(); |
| 419 DCHECK(last_omnibox_focus_without_user_input_ <= now); | 424 DCHECK(last_omnibox_focus_ <= now); |
| 420 UMA_HISTOGRAM_TIMES(kFocusToEditTimeHistogram, | 425 UMA_HISTOGRAM_TIMES(kFocusToEditTimeHistogram, now - last_omnibox_focus_); |
| 421 now - last_omnibox_focus_without_user_input_); | 426 user_input_since_focus_ = true; |
| 422 // We only want to count the time from focus to the first user input, so | |
| 423 // reset |last_omnibox_focus_without_user_input_| to null. | |
| 424 last_omnibox_focus_without_user_input_ = base::TimeTicks(); | |
| 425 } | 427 } |
| 426 | 428 |
| 427 if (user_input_in_progress_ == in_progress) | 429 if (user_input_in_progress_ == in_progress) |
| 428 return; | 430 return; |
| 429 | 431 |
| 430 user_input_in_progress_ = in_progress; | 432 user_input_in_progress_ = in_progress; |
| 431 if (user_input_in_progress_) { | 433 if (user_input_in_progress_) { |
| 432 time_user_first_modified_omnibox_ = base::TimeTicks::Now(); | 434 time_user_first_modified_omnibox_ = base::TimeTicks::Now(); |
| 433 content::RecordAction(content::UserMetricsAction("OmniboxInputInProgress")); | 435 content::RecordAction(content::UserMetricsAction("OmniboxInputInProgress")); |
| 434 autocomplete_controller()->ResetSession(); | 436 autocomplete_controller()->ResetSession(); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 // we can easily get the tab ID. (If it's being opened in a new | 653 // we can easily get the tab ID. (If it's being opened in a new |
| 652 // tab, we don't know the tab ID yet.) | 654 // tab, we don't know the tab ID yet.) |
| 653 log.tab_id = delegate_->GetSessionID().id(); | 655 log.tab_id = delegate_->GetSessionID().id(); |
| 654 } | 656 } |
| 655 autocomplete_controller()->AddProvidersInfo(&log.providers_info); | 657 autocomplete_controller()->AddProvidersInfo(&log.providers_info); |
| 656 content::NotificationService::current()->Notify( | 658 content::NotificationService::current()->Notify( |
| 657 chrome::NOTIFICATION_OMNIBOX_OPENED_URL, | 659 chrome::NOTIFICATION_OMNIBOX_OPENED_URL, |
| 658 content::Source<Profile>(profile_), | 660 content::Source<Profile>(profile_), |
| 659 content::Details<OmniboxLog>(&log)); | 661 content::Details<OmniboxLog>(&log)); |
| 660 HISTOGRAM_ENUMERATION("Omnibox.EventCount", 1, 2); | 662 HISTOGRAM_ENUMERATION("Omnibox.EventCount", 1, 2); |
| 663 DCHECK(!last_omnibox_focus_.is_null()) |
| 664 << "An omnibox focus should have occurred before opening a match."; |
| 665 UMA_HISTOGRAM_TIMES(kFocusToOpenTimeHistogram, now - last_omnibox_focus_); |
| 661 } | 666 } |
| 662 | 667 |
| 663 TemplateURL* template_url = match.GetTemplateURL(profile_, false); | 668 TemplateURL* template_url = match.GetTemplateURL(profile_, false); |
| 664 if (template_url) { | 669 if (template_url) { |
| 665 if (match.transition == content::PAGE_TRANSITION_KEYWORD) { | 670 if (match.transition == content::PAGE_TRANSITION_KEYWORD) { |
| 666 // The user is using a non-substituting keyword or is explicitly in | 671 // The user is using a non-substituting keyword or is explicitly in |
| 667 // keyword mode. | 672 // keyword mode. |
| 668 const AutocompleteMatch& match = (index == OmniboxPopupModel::kNoMatch) ? | 673 const AutocompleteMatch& match = (index == OmniboxPopupModel::kNoMatch) ? |
| 669 CurrentMatch(NULL) : result().match_at(index); | 674 CurrentMatch(NULL) : result().match_at(index); |
| 670 | 675 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 // since the edit contents have actually grown | 792 // since the edit contents have actually grown |
| 788 // longer. | 793 // longer. |
| 789 } else { | 794 } else { |
| 790 is_keyword_hint_ = true; | 795 is_keyword_hint_ = true; |
| 791 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length(), | 796 view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length(), |
| 792 false, true); | 797 false, true); |
| 793 } | 798 } |
| 794 } | 799 } |
| 795 | 800 |
| 796 void OmniboxEditModel::OnSetFocus(bool control_down) { | 801 void OmniboxEditModel::OnSetFocus(bool control_down) { |
| 797 last_omnibox_focus_without_user_input_ = base::TimeTicks::Now(); | 802 last_omnibox_focus_ = base::TimeTicks::Now(); |
| 803 user_input_since_focus_ = false; |
| 798 | 804 |
| 799 // If the omnibox lost focus while the caret was hidden and then regained | 805 // If the omnibox lost focus while the caret was hidden and then regained |
| 800 // focus, OnSetFocus() is called and should restore visibility. Note that | 806 // focus, OnSetFocus() is called and should restore visibility. Note that |
| 801 // focus can be regained without an accompanying call to | 807 // focus can be regained without an accompanying call to |
| 802 // OmniboxView::SetFocus(), e.g. by tabbing in. | 808 // OmniboxView::SetFocus(), e.g. by tabbing in. |
| 803 SetFocusState(OMNIBOX_FOCUS_VISIBLE, OMNIBOX_FOCUS_CHANGE_EXPLICIT); | 809 SetFocusState(OMNIBOX_FOCUS_VISIBLE, OMNIBOX_FOCUS_CHANGE_EXPLICIT); |
| 804 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; | 810 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; |
| 805 | 811 |
| 806 if (delegate_->CurrentPageExists()) { | 812 if (delegate_->CurrentPageExists()) { |
| 807 // TODO(jered): We may want to merge this into Start() and just call that | 813 // TODO(jered): We may want to merge this into Start() and just call that |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 instant->OmniboxFocusChanged(state, reason, NULL); | 1297 instant->OmniboxFocusChanged(state, reason, NULL); |
| 1292 | 1298 |
| 1293 // Update state and notify view if the omnibox has focus and the caret | 1299 // Update state and notify view if the omnibox has focus and the caret |
| 1294 // visibility changed. | 1300 // visibility changed. |
| 1295 const bool was_caret_visible = is_caret_visible(); | 1301 const bool was_caret_visible = is_caret_visible(); |
| 1296 focus_state_ = state; | 1302 focus_state_ = state; |
| 1297 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1303 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
| 1298 is_caret_visible() != was_caret_visible) | 1304 is_caret_visible() != was_caret_visible) |
| 1299 view_->ApplyCaretVisibility(); | 1305 view_->ApplyCaretVisibility(); |
| 1300 } | 1306 } |
| OLD | NEW |