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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 } | 494 } |
| 495 | 495 |
| 496 if (user_input_in_progress_ == in_progress) | 496 if (user_input_in_progress_ == in_progress) |
| 497 return; | 497 return; |
| 498 | 498 |
| 499 user_input_in_progress_ = in_progress; | 499 user_input_in_progress_ = in_progress; |
| 500 if (user_input_in_progress_) { | 500 if (user_input_in_progress_) { |
| 501 time_user_first_modified_omnibox_ = base::TimeTicks::Now(); | 501 time_user_first_modified_omnibox_ = base::TimeTicks::Now(); |
| 502 content::RecordAction(base::UserMetricsAction("OmniboxInputInProgress")); | 502 content::RecordAction(base::UserMetricsAction("OmniboxInputInProgress")); |
| 503 autocomplete_controller()->ResetSession(); | 503 autocomplete_controller()->ResetSession(); |
| 504 // Once the user starts editing, re-enable URL replacement, so that it will | |
| 505 // kick in if applicable once the edit is committed or reverted. (While the | |
| 506 // edit is in progress, this won't have a visible effect.) | |
| 507 controller_->GetToolbarModel()->set_url_replacement_enabled(true); | |
| 508 } | 504 } |
| 509 | 505 |
| 510 // The following code handles three cases: | 506 // The following code handles two cases: |
| 511 // * For HIDE_ON_USER_INPUT, it hides the chip when user input begins. | 507 // * For HIDE_ON_USER_INPUT, it hides the chip when user input begins. |
| 512 // * For HIDE_ON_MOUSE_RELEASE, which only hides the chip on mouse release if | 508 // * For HIDE_ON_MOUSE_RELEASE, which only hides the chip on mouse release if |
| 513 // the omnibox is empty, it handles the "omnibox was not empty" case by | 509 // the omnibox is empty, it handles the "omnibox was not empty" case by |
| 514 // acting like HIDE_ON_USER_INPUT. (If the omnibox was empty, it | 510 // acting like HIDE_ON_USER_INPUT. |
| 515 // effectively no-ops.) | 511 if (chrome::ShouldDisplayOriginChipV2() && in_progress) |
| 516 // * For both hide behaviors, it allows the chip to be reshown once input | 512 controller()->GetToolbarModel()->set_origin_chip_enabled(false); |
| 517 // ends. (The chip won't actually be re-shown until there's no pending | |
| 518 // typed navigation; see OriginChipView::ShouldShow() and | |
| 519 // OriginChipDecoration::ShouldShow().) | |
| 520 if (chrome::ShouldDisplayOriginChipV2()) | |
| 521 controller()->GetToolbarModel()->set_origin_chip_enabled(!in_progress); | |
| 522 | 513 |
| 523 controller_->GetToolbarModel()->set_input_in_progress(in_progress); | 514 controller_->GetToolbarModel()->set_input_in_progress(in_progress); |
| 524 controller_->Update(NULL); | 515 controller_->Update(NULL); |
| 525 | 516 |
| 526 if (user_input_in_progress_ || !in_revert_) | 517 if (user_input_in_progress_ || !in_revert_) |
| 527 delegate_->OnInputStateChanged(); | 518 delegate_->OnInputStateChanged(); |
| 528 } | 519 } |
| 529 | 520 |
| 530 void OmniboxEditModel::Revert() { | 521 void OmniboxEditModel::Revert() { |
| 531 SetInputInProgress(false); | 522 SetInputInProgress(false); |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 963 } | 954 } |
| 964 } | 955 } |
| 965 | 956 |
| 966 // We do not clear the pending entry from the omnibox when a load is first | 957 // We do not clear the pending entry from the omnibox when a load is first |
| 967 // stopped. If the user presses Escape while stopped, we clear it. | 958 // stopped. If the user presses Escape while stopped, we clear it. |
| 968 if (delegate_->CurrentPageExists() && !delegate_->IsLoading()) { | 959 if (delegate_->CurrentPageExists() && !delegate_->IsLoading()) { |
| 969 delegate_->GetNavigationController().DiscardNonCommittedEntries(); | 960 delegate_->GetNavigationController().DiscardNonCommittedEntries(); |
| 970 view_->Update(); | 961 view_->Update(); |
| 971 } | 962 } |
| 972 | 963 |
| 964 // If URL replacement is enabled, we'll need to disable it and update the | |
| 965 // permanent text below in order to bring the URL back. Unless search term | |
| 966 // replacement is being performed, in which case we want to keep the search | |
| 967 // terms. | |
|
Peter Kasting
2014/03/27 22:04:12
Nit: How about this comment:
When using the origi
Justin Donnelly
2014/03/27 22:10:07
Done.
| |
| 968 bool should_disable_url_replacement = | |
| 969 controller_->GetToolbarModel()->url_replacement_enabled() && | |
| 970 !controller_->GetToolbarModel()->WouldPerformSearchTermReplacement(true); | |
| 971 | |
| 973 // If the user wasn't editing, but merely had focus in the edit, allow <esc> | 972 // If the user wasn't editing, but merely had focus in the edit, allow <esc> |
| 974 // to be processed as an accelerator, so it can still be used to stop a load. | 973 // to be processed as an accelerator, so it can still be used to stop a load. |
| 975 // When the permanent text isn't all selected we still fall through to the | 974 // When the permanent text isn't all selected we still fall through to the |
| 976 // SelectAll() call below so users can arrow around in the text and then hit | 975 // SelectAll() call below so users can arrow around in the text and then hit |
| 977 // <esc> to quickly replace all the text; this matches IE. | 976 // <esc> to quickly replace all the text; this matches IE. |
| 978 const bool has_zero_suggest_match = match.provider && | 977 const bool has_zero_suggest_match = match.provider && |
| 979 (match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST); | 978 (match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST); |
| 980 if (!has_zero_suggest_match && !user_input_in_progress_ && | 979 if (!has_zero_suggest_match && !should_disable_url_replacement && |
| 981 view_->IsSelectAll()) | 980 !user_input_in_progress_ && view_->IsSelectAll()) |
| 982 return false; | 981 return false; |
| 983 | 982 |
| 984 if (!user_text_.empty()) { | 983 if (!user_text_.empty()) { |
| 985 UMA_HISTOGRAM_ENUMERATION(kOmniboxUserTextClearedHistogram, | 984 UMA_HISTOGRAM_ENUMERATION(kOmniboxUserTextClearedHistogram, |
| 986 OMNIBOX_USER_TEXT_CLEARED_WITH_ESCAPE, | 985 OMNIBOX_USER_TEXT_CLEARED_WITH_ESCAPE, |
| 987 OMNIBOX_USER_TEXT_CLEARED_NUM_OF_ITEMS); | 986 OMNIBOX_USER_TEXT_CLEARED_NUM_OF_ITEMS); |
| 988 } | 987 } |
| 989 view_->RevertAll(); | 988 |
| 989 if (should_disable_url_replacement) { | |
| 990 controller_->GetToolbarModel()->set_url_replacement_enabled(false); | |
| 991 UpdatePermanentText(); | |
| 992 } | |
| 993 view_->RevertWithoutResettingSearchTermReplacement(); | |
| 990 view_->SelectAll(true); | 994 view_->SelectAll(true); |
| 991 return true; | 995 return true; |
| 992 } | 996 } |
| 993 | 997 |
| 994 void OmniboxEditModel::OnControlKeyChanged(bool pressed) { | 998 void OmniboxEditModel::OnControlKeyChanged(bool pressed) { |
| 995 if (pressed == (control_key_state_ == UP)) | 999 if (pressed == (control_key_state_ == UP)) |
| 996 control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP; | 1000 control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP; |
| 997 } | 1001 } |
| 998 | 1002 |
| 999 void OmniboxEditModel::OnPaste() { | 1003 void OmniboxEditModel::OnPaste() { |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1436 // Update state and notify view if the omnibox has focus and the caret | 1440 // Update state and notify view if the omnibox has focus and the caret |
| 1437 // visibility changed. | 1441 // visibility changed. |
| 1438 const bool was_caret_visible = is_caret_visible(); | 1442 const bool was_caret_visible = is_caret_visible(); |
| 1439 focus_state_ = state; | 1443 focus_state_ = state; |
| 1440 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1444 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
| 1441 is_caret_visible() != was_caret_visible) | 1445 is_caret_visible() != was_caret_visible) |
| 1442 view_->ApplyCaretVisibility(); | 1446 view_->ApplyCaretVisibility(); |
| 1443 | 1447 |
| 1444 delegate_->OnFocusChanged(focus_state_, reason); | 1448 delegate_->OnFocusChanged(focus_state_, reason); |
| 1445 } | 1449 } |
| OLD | NEW |