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 <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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 return State( | 247 return State( |
| 248 user_input_in_progress_, user_text_, view_->GetGrayTextAutocompletion(), | 248 user_input_in_progress_, user_text_, view_->GetGrayTextAutocompletion(), |
| 249 keyword_, is_keyword_hint_, | 249 keyword_, is_keyword_hint_, |
| 250 controller_->GetToolbarModel()->url_replacement_enabled(), | 250 controller_->GetToolbarModel()->url_replacement_enabled(), |
| 251 focus_state_, focus_source_, input_); | 251 focus_state_, focus_source_, input_); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void OmniboxEditModel::RestoreState(const State* state) { | 254 void OmniboxEditModel::RestoreState(const State* state) { |
| 255 // We need to update the permanent text correctly and revert the view | 255 // We need to update the permanent text correctly and revert the view |
| 256 // regardless of whether there is saved state. | 256 // regardless of whether there is saved state. |
| 257 bool url_replacement_enabled = !state || state->url_replacement_enabled; | 257 bool url_replacement_enabled = !state || state->url_replacement_enabled; |
|
Justin Donnelly
2014/12/03 16:07:25
One of the reasons I thought it would be helpful t
Peter Kasting
2014/12/04 00:23:19
Yes, but given that the origin chip and search but
Justin Donnelly
2014/12/04 00:54:43
I think search term replacement is actually launch
Peter Kasting
2014/12/04 01:44:31
I would be very surprised if this code is used on
groby-ooo-7-16
2015/01/10 00:54:06
Filed as http://crbug.com/447810
| |
| 258 controller_->GetToolbarModel()->set_url_replacement_enabled( | 258 controller_->GetToolbarModel()->set_url_replacement_enabled( |
| 259 url_replacement_enabled); | 259 url_replacement_enabled); |
| 260 controller_->GetToolbarModel()->set_origin_chip_enabled( | |
| 261 url_replacement_enabled); | |
| 262 permanent_text_ = controller_->GetToolbarModel()->GetText(); | 260 permanent_text_ = controller_->GetToolbarModel()->GetText(); |
| 263 // Don't muck with the search term replacement state, as we've just set it | 261 // Don't muck with the search term replacement state, as we've just set it |
| 264 // correctly. | 262 // correctly. |
| 265 view_->RevertWithoutResettingSearchTermReplacement(); | 263 view_->RevertWithoutResettingSearchTermReplacement(); |
| 266 // Restore the autocomplete controller's input, or clear it if this is a new | 264 // Restore the autocomplete controller's input, or clear it if this is a new |
| 267 // tab. | 265 // tab. |
| 268 input_ = state ? state->autocomplete_input : AutocompleteInput(); | 266 input_ = state ? state->autocomplete_input : AutocompleteInput(); |
| 269 if (!state) | 267 if (!state) |
| 270 return; | 268 return; |
| 271 | 269 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 if (user_input_in_progress_ == in_progress) | 509 if (user_input_in_progress_ == in_progress) |
| 512 return; | 510 return; |
| 513 | 511 |
| 514 user_input_in_progress_ = in_progress; | 512 user_input_in_progress_ = in_progress; |
| 515 if (user_input_in_progress_) { | 513 if (user_input_in_progress_) { |
| 516 time_user_first_modified_omnibox_ = base::TimeTicks::Now(); | 514 time_user_first_modified_omnibox_ = base::TimeTicks::Now(); |
| 517 content::RecordAction(base::UserMetricsAction("OmniboxInputInProgress")); | 515 content::RecordAction(base::UserMetricsAction("OmniboxInputInProgress")); |
| 518 autocomplete_controller()->ResetSession(); | 516 autocomplete_controller()->ResetSession(); |
| 519 } | 517 } |
| 520 | 518 |
| 521 // The following code handles two cases: | |
| 522 // * For HIDE_ON_USER_INPUT and ON_SRP, it hides the chip when user input | |
| 523 // begins. | |
| 524 // * For HIDE_ON_MOUSE_RELEASE, which only hides the chip on mouse release if | |
| 525 // the omnibox is empty, it handles the "omnibox was not empty" case by | |
| 526 // acting like HIDE_ON_USER_INPUT. | |
| 527 if (chrome::ShouldDisplayOriginChip() && in_progress) | |
| 528 controller()->GetToolbarModel()->set_origin_chip_enabled(false); | |
| 529 | |
| 530 controller_->GetToolbarModel()->set_input_in_progress(in_progress); | 519 controller_->GetToolbarModel()->set_input_in_progress(in_progress); |
| 531 controller_->EndOriginChipAnimations(true); | |
| 532 controller_->Update(NULL); | 520 controller_->Update(NULL); |
| 533 | 521 |
| 534 if (user_input_in_progress_ || !in_revert_) | 522 if (user_input_in_progress_ || !in_revert_) |
| 535 delegate_->OnInputStateChanged(); | 523 delegate_->OnInputStateChanged(); |
| 536 } | 524 } |
| 537 | 525 |
| 538 void OmniboxEditModel::Revert() { | 526 void OmniboxEditModel::Revert() { |
| 539 SetInputInProgress(false); | 527 SetInputInProgress(false); |
| 540 paste_state_ = NONE; | 528 paste_state_ = NONE; |
| 541 InternalSetUserText(base::string16()); | 529 InternalSetUserText(base::string16()); |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 986 } | 974 } |
| 987 } | 975 } |
| 988 | 976 |
| 989 // We do not clear the pending entry from the omnibox when a load is first | 977 // We do not clear the pending entry from the omnibox when a load is first |
| 990 // stopped. If the user presses Escape while stopped, we clear it. | 978 // stopped. If the user presses Escape while stopped, we clear it. |
| 991 if (delegate_->CurrentPageExists() && !delegate_->IsLoading()) { | 979 if (delegate_->CurrentPageExists() && !delegate_->IsLoading()) { |
| 992 delegate_->GetNavigationController().DiscardNonCommittedEntries(); | 980 delegate_->GetNavigationController().DiscardNonCommittedEntries(); |
| 993 view_->Update(); | 981 view_->Update(); |
| 994 } | 982 } |
| 995 | 983 |
| 996 // When using the origin chip, hitting escape to revert all should either | |
| 997 // display the URL (when search term replacement would not be performed for | |
| 998 // this page) or the search terms (when it would). To accomplish this, | |
| 999 // we'll need to disable URL replacement iff it's currently enabled and | |
| 1000 // search term replacement wouldn't normally happen. | |
| 1001 bool should_disable_url_replacement = | |
| 1002 controller_->GetToolbarModel()->url_replacement_enabled() && | |
| 1003 !controller_->GetToolbarModel()->WouldPerformSearchTermReplacement(true); | |
| 1004 | |
| 1005 // If the user wasn't editing, but merely had focus in the edit, allow <esc> | 984 // If the user wasn't editing, but merely had focus in the edit, allow <esc> |
| 1006 // to be processed as an accelerator, so it can still be used to stop a load. | 985 // to be processed as an accelerator, so it can still be used to stop a load. |
| 1007 // When the permanent text isn't all selected we still fall through to the | 986 // When the permanent text isn't all selected we still fall through to the |
| 1008 // SelectAll() call below so users can arrow around in the text and then hit | 987 // SelectAll() call below so users can arrow around in the text and then hit |
| 1009 // <esc> to quickly replace all the text; this matches IE. | 988 // <esc> to quickly replace all the text; this matches IE. |
| 1010 const bool has_zero_suggest_match = match.provider && | 989 const bool has_zero_suggest_match = match.provider && |
| 1011 (match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST); | 990 (match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST); |
| 1012 if (!has_zero_suggest_match && !should_disable_url_replacement && | 991 if (!has_zero_suggest_match && !user_input_in_progress_ && |
| 1013 !user_input_in_progress_ && view_->IsSelectAll()) | 992 view_->IsSelectAll()) |
| 1014 return false; | 993 return false; |
| 1015 | 994 |
| 1016 if (!user_text_.empty()) { | 995 if (!user_text_.empty()) { |
| 1017 UMA_HISTOGRAM_ENUMERATION(kOmniboxUserTextClearedHistogram, | 996 UMA_HISTOGRAM_ENUMERATION(kOmniboxUserTextClearedHistogram, |
| 1018 OMNIBOX_USER_TEXT_CLEARED_WITH_ESCAPE, | 997 OMNIBOX_USER_TEXT_CLEARED_WITH_ESCAPE, |
| 1019 OMNIBOX_USER_TEXT_CLEARED_NUM_OF_ITEMS); | 998 OMNIBOX_USER_TEXT_CLEARED_NUM_OF_ITEMS); |
| 1020 } | 999 } |
| 1021 | 1000 |
| 1022 if (should_disable_url_replacement) { | 1001 view_->RevertAll(); |
| 1023 controller_->GetToolbarModel()->set_url_replacement_enabled(false); | |
| 1024 UpdatePermanentText(); | |
| 1025 } | |
| 1026 view_->RevertWithoutResettingSearchTermReplacement(); | |
| 1027 view_->SelectAll(true); | 1002 view_->SelectAll(true); |
| 1028 return true; | 1003 return true; |
| 1029 } | 1004 } |
| 1030 | 1005 |
| 1031 void OmniboxEditModel::OnControlKeyChanged(bool pressed) { | 1006 void OmniboxEditModel::OnControlKeyChanged(bool pressed) { |
| 1032 if (pressed == (control_key_state_ == UP)) | 1007 if (pressed == (control_key_state_ == UP)) |
| 1033 control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP; | 1008 control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP; |
| 1034 } | 1009 } |
| 1035 | 1010 |
| 1036 void OmniboxEditModel::OnPaste() { | 1011 void OmniboxEditModel::OnPaste() { |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1474 // Update state and notify view if the omnibox has focus and the caret | 1449 // Update state and notify view if the omnibox has focus and the caret |
| 1475 // visibility changed. | 1450 // visibility changed. |
| 1476 const bool was_caret_visible = is_caret_visible(); | 1451 const bool was_caret_visible = is_caret_visible(); |
| 1477 focus_state_ = state; | 1452 focus_state_ = state; |
| 1478 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1453 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
| 1479 is_caret_visible() != was_caret_visible) | 1454 is_caret_visible() != was_caret_visible) |
| 1480 view_->ApplyCaretVisibility(); | 1455 view_->ApplyCaretVisibility(); |
| 1481 | 1456 |
| 1482 delegate_->OnFocusChanged(focus_state_, reason); | 1457 delegate_->OnFocusChanged(focus_state_, reason); |
| 1483 } | 1458 } |
| OLD | NEW |