| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 controller_->GetToolbarModel()->url_replacement_enabled(), | 248 controller_->GetToolbarModel()->url_replacement_enabled(), |
| 249 focus_state_, focus_source_, input_); | 249 focus_state_, focus_source_, input_); |
| 250 } | 250 } |
| 251 | 251 |
| 252 void OmniboxEditModel::RestoreState(const State* state) { | 252 void OmniboxEditModel::RestoreState(const State* state) { |
| 253 // We need to update the permanent text correctly and revert the view | 253 // We need to update the permanent text correctly and revert the view |
| 254 // regardless of whether there is saved state. | 254 // regardless of whether there is saved state. |
| 255 bool url_replacement_enabled = !state || state->url_replacement_enabled; | 255 bool url_replacement_enabled = !state || state->url_replacement_enabled; |
| 256 controller_->GetToolbarModel()->set_url_replacement_enabled( | 256 controller_->GetToolbarModel()->set_url_replacement_enabled( |
| 257 url_replacement_enabled); | 257 url_replacement_enabled); |
| 258 controller_->GetToolbarModel()->set_origin_chip_enabled( | |
| 259 url_replacement_enabled); | |
| 260 permanent_text_ = controller_->GetToolbarModel()->GetText(); | 258 permanent_text_ = controller_->GetToolbarModel()->GetText(); |
| 261 // Don't muck with the search term replacement state, as we've just set it | 259 // Don't muck with the search term replacement state, as we've just set it |
| 262 // correctly. | 260 // correctly. |
| 263 view_->RevertWithoutResettingSearchTermReplacement(); | 261 view_->RevertWithoutResettingSearchTermReplacement(); |
| 264 // Restore the autocomplete controller's input, or clear it if this is a new | 262 // Restore the autocomplete controller's input, or clear it if this is a new |
| 265 // tab. | 263 // tab. |
| 266 input_ = state ? state->autocomplete_input : AutocompleteInput(); | 264 input_ = state ? state->autocomplete_input : AutocompleteInput(); |
| 267 if (!state) | 265 if (!state) |
| 268 return; | 266 return; |
| 269 | 267 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 if (user_input_in_progress_ == in_progress) | 507 if (user_input_in_progress_ == in_progress) |
| 510 return; | 508 return; |
| 511 | 509 |
| 512 user_input_in_progress_ = in_progress; | 510 user_input_in_progress_ = in_progress; |
| 513 if (user_input_in_progress_) { | 511 if (user_input_in_progress_) { |
| 514 time_user_first_modified_omnibox_ = base::TimeTicks::Now(); | 512 time_user_first_modified_omnibox_ = base::TimeTicks::Now(); |
| 515 content::RecordAction(base::UserMetricsAction("OmniboxInputInProgress")); | 513 content::RecordAction(base::UserMetricsAction("OmniboxInputInProgress")); |
| 516 autocomplete_controller()->ResetSession(); | 514 autocomplete_controller()->ResetSession(); |
| 517 } | 515 } |
| 518 | 516 |
| 519 // The following code handles two cases: | |
| 520 // * For HIDE_ON_USER_INPUT and ON_SRP, it hides the chip when user input | |
| 521 // begins. | |
| 522 // * For HIDE_ON_MOUSE_RELEASE, which only hides the chip on mouse release if | |
| 523 // the omnibox is empty, it handles the "omnibox was not empty" case by | |
| 524 // acting like HIDE_ON_USER_INPUT. | |
| 525 if (chrome::ShouldDisplayOriginChip() && in_progress) | |
| 526 controller()->GetToolbarModel()->set_origin_chip_enabled(false); | |
| 527 | |
| 528 controller_->GetToolbarModel()->set_input_in_progress(in_progress); | 517 controller_->GetToolbarModel()->set_input_in_progress(in_progress); |
| 529 controller_->EndOriginChipAnimations(true); | |
| 530 controller_->Update(NULL); | 518 controller_->Update(NULL); |
| 531 | 519 |
| 532 if (user_input_in_progress_ || !in_revert_) | 520 if (user_input_in_progress_ || !in_revert_) |
| 533 delegate_->OnInputStateChanged(); | 521 delegate_->OnInputStateChanged(); |
| 534 } | 522 } |
| 535 | 523 |
| 536 void OmniboxEditModel::Revert() { | 524 void OmniboxEditModel::Revert() { |
| 537 SetInputInProgress(false); | 525 SetInputInProgress(false); |
| 538 paste_state_ = NONE; | 526 paste_state_ = NONE; |
| 539 InternalSetUserText(base::string16()); | 527 InternalSetUserText(base::string16()); |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 } | 962 } |
| 975 } | 963 } |
| 976 | 964 |
| 977 // We do not clear the pending entry from the omnibox when a load is first | 965 // We do not clear the pending entry from the omnibox when a load is first |
| 978 // stopped. If the user presses Escape while stopped, we clear it. | 966 // stopped. If the user presses Escape while stopped, we clear it. |
| 979 if (delegate_->CurrentPageExists() && !delegate_->IsLoading()) { | 967 if (delegate_->CurrentPageExists() && !delegate_->IsLoading()) { |
| 980 delegate_->GetNavigationController().DiscardNonCommittedEntries(); | 968 delegate_->GetNavigationController().DiscardNonCommittedEntries(); |
| 981 view_->Update(); | 969 view_->Update(); |
| 982 } | 970 } |
| 983 | 971 |
| 984 // When using the origin chip, hitting escape to revert all should either | |
| 985 // display the URL (when search term replacement would not be performed for | |
| 986 // this page) or the search terms (when it would). To accomplish this, | |
| 987 // we'll need to disable URL replacement iff it's currently enabled and | |
| 988 // search term replacement wouldn't normally happen. | |
| 989 bool should_disable_url_replacement = | |
| 990 controller_->GetToolbarModel()->url_replacement_enabled() && | |
| 991 !controller_->GetToolbarModel()->WouldPerformSearchTermReplacement(true); | |
| 992 | |
| 993 // 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> |
| 994 // 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. |
| 995 // 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 |
| 996 // 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 |
| 997 // <esc> to quickly replace all the text; this matches IE. | 976 // <esc> to quickly replace all the text; this matches IE. |
| 998 const bool has_zero_suggest_match = match.provider && | 977 const bool has_zero_suggest_match = match.provider && |
| 999 (match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST); | 978 (match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST); |
| 1000 if (!has_zero_suggest_match && !should_disable_url_replacement && | 979 if (!has_zero_suggest_match && !user_input_in_progress_ && |
| 1001 !user_input_in_progress_ && view_->IsSelectAll()) | 980 view_->IsSelectAll()) |
| 1002 return false; | 981 return false; |
| 1003 | 982 |
| 1004 if (!user_text_.empty()) { | 983 if (!user_text_.empty()) { |
| 1005 UMA_HISTOGRAM_ENUMERATION(kOmniboxUserTextClearedHistogram, | 984 UMA_HISTOGRAM_ENUMERATION(kOmniboxUserTextClearedHistogram, |
| 1006 OMNIBOX_USER_TEXT_CLEARED_WITH_ESCAPE, | 985 OMNIBOX_USER_TEXT_CLEARED_WITH_ESCAPE, |
| 1007 OMNIBOX_USER_TEXT_CLEARED_NUM_OF_ITEMS); | 986 OMNIBOX_USER_TEXT_CLEARED_NUM_OF_ITEMS); |
| 1008 } | 987 } |
| 1009 | 988 |
| 1010 if (should_disable_url_replacement) { | 989 view_->RevertAll(); |
| 1011 controller_->GetToolbarModel()->set_url_replacement_enabled(false); | |
| 1012 UpdatePermanentText(); | |
| 1013 } | |
| 1014 view_->RevertWithoutResettingSearchTermReplacement(); | |
| 1015 view_->SelectAll(true); | 990 view_->SelectAll(true); |
| 1016 return true; | 991 return true; |
| 1017 } | 992 } |
| 1018 | 993 |
| 1019 void OmniboxEditModel::OnControlKeyChanged(bool pressed) { | 994 void OmniboxEditModel::OnControlKeyChanged(bool pressed) { |
| 1020 if (pressed == (control_key_state_ == UP)) | 995 if (pressed == (control_key_state_ == UP)) |
| 1021 control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP; | 996 control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP; |
| 1022 } | 997 } |
| 1023 | 998 |
| 1024 void OmniboxEditModel::OnPaste() { | 999 void OmniboxEditModel::OnPaste() { |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1462 // Update state and notify view if the omnibox has focus and the caret | 1437 // Update state and notify view if the omnibox has focus and the caret |
| 1463 // visibility changed. | 1438 // visibility changed. |
| 1464 const bool was_caret_visible = is_caret_visible(); | 1439 const bool was_caret_visible = is_caret_visible(); |
| 1465 focus_state_ = state; | 1440 focus_state_ = state; |
| 1466 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1441 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
| 1467 is_caret_visible() != was_caret_visible) | 1442 is_caret_visible() != was_caret_visible) |
| 1468 view_->ApplyCaretVisibility(); | 1443 view_->ApplyCaretVisibility(); |
| 1469 | 1444 |
| 1470 delegate_->OnFocusChanged(focus_state_, reason); | 1445 delegate_->OnFocusChanged(focus_state_, reason); |
| 1471 } | 1446 } |
| OLD | NEW |