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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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; |
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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 } | 967 } |
980 } | 968 } |
981 | 969 |
982 // We do not clear the pending entry from the omnibox when a load is first | 970 // We do not clear the pending entry from the omnibox when a load is first |
983 // stopped. If the user presses Escape while stopped, we clear it. | 971 // stopped. If the user presses Escape while stopped, we clear it. |
984 if (delegate_->CurrentPageExists() && !delegate_->IsLoading()) { | 972 if (delegate_->CurrentPageExists() && !delegate_->IsLoading()) { |
985 delegate_->GetNavigationController().DiscardNonCommittedEntries(); | 973 delegate_->GetNavigationController().DiscardNonCommittedEntries(); |
986 view_->Update(); | 974 view_->Update(); |
987 } | 975 } |
988 | 976 |
989 // When using the origin chip, hitting escape to revert all should either | |
990 // display the URL (when search term replacement would not be performed for | |
991 // this page) or the search terms (when it would). To accomplish this, | |
992 // we'll need to disable URL replacement iff it's currently enabled and | |
993 // search term replacement wouldn't normally happen. | |
994 bool should_disable_url_replacement = | |
995 controller_->GetToolbarModel()->url_replacement_enabled() && | |
996 !controller_->GetToolbarModel()->WouldPerformSearchTermReplacement(true); | |
997 | |
998 // If the user wasn't editing, but merely had focus in the edit, allow <esc> | 977 // If the user wasn't editing, but merely had focus in the edit, allow <esc> |
999 // to be processed as an accelerator, so it can still be used to stop a load. | 978 // to be processed as an accelerator, so it can still be used to stop a load. |
1000 // When the permanent text isn't all selected we still fall through to the | 979 // When the permanent text isn't all selected we still fall through to the |
1001 // SelectAll() call below so users can arrow around in the text and then hit | 980 // SelectAll() call below so users can arrow around in the text and then hit |
1002 // <esc> to quickly replace all the text; this matches IE. | 981 // <esc> to quickly replace all the text; this matches IE. |
1003 const bool has_zero_suggest_match = match.provider && | 982 const bool has_zero_suggest_match = match.provider && |
1004 (match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST); | 983 (match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST); |
1005 if (!has_zero_suggest_match && !should_disable_url_replacement && | 984 if (!has_zero_suggest_match && !user_input_in_progress_ && |
1006 !user_input_in_progress_ && view_->IsSelectAll()) | 985 view_->IsSelectAll()) |
1007 return false; | 986 return false; |
1008 | 987 |
1009 if (!user_text_.empty()) { | 988 if (!user_text_.empty()) { |
1010 UMA_HISTOGRAM_ENUMERATION(kOmniboxUserTextClearedHistogram, | 989 UMA_HISTOGRAM_ENUMERATION(kOmniboxUserTextClearedHistogram, |
1011 OMNIBOX_USER_TEXT_CLEARED_WITH_ESCAPE, | 990 OMNIBOX_USER_TEXT_CLEARED_WITH_ESCAPE, |
1012 OMNIBOX_USER_TEXT_CLEARED_NUM_OF_ITEMS); | 991 OMNIBOX_USER_TEXT_CLEARED_NUM_OF_ITEMS); |
1013 } | 992 } |
1014 | 993 |
1015 if (should_disable_url_replacement) { | 994 view_->RevertAll(); |
1016 controller_->GetToolbarModel()->set_url_replacement_enabled(false); | |
1017 UpdatePermanentText(); | |
1018 } | |
1019 view_->RevertWithoutResettingSearchTermReplacement(); | |
1020 view_->SelectAll(true); | 995 view_->SelectAll(true); |
1021 return true; | 996 return true; |
1022 } | 997 } |
1023 | 998 |
1024 void OmniboxEditModel::OnControlKeyChanged(bool pressed) { | 999 void OmniboxEditModel::OnControlKeyChanged(bool pressed) { |
1025 if (pressed == (control_key_state_ == UP)) | 1000 if (pressed == (control_key_state_ == UP)) |
1026 control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP; | 1001 control_key_state_ = pressed ? DOWN_WITHOUT_CHANGE : UP; |
1027 } | 1002 } |
1028 | 1003 |
1029 void OmniboxEditModel::OnPaste() { | 1004 void OmniboxEditModel::OnPaste() { |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 // Update state and notify view if the omnibox has focus and the caret | 1442 // Update state and notify view if the omnibox has focus and the caret |
1468 // visibility changed. | 1443 // visibility changed. |
1469 const bool was_caret_visible = is_caret_visible(); | 1444 const bool was_caret_visible = is_caret_visible(); |
1470 focus_state_ = state; | 1445 focus_state_ = state; |
1471 if (focus_state_ != OMNIBOX_FOCUS_NONE && | 1446 if (focus_state_ != OMNIBOX_FOCUS_NONE && |
1472 is_caret_visible() != was_caret_visible) | 1447 is_caret_visible() != was_caret_visible) |
1473 view_->ApplyCaretVisibility(); | 1448 view_->ApplyCaretVisibility(); |
1474 | 1449 |
1475 delegate_->OnFocusChanged(focus_state_, reason); | 1450 delegate_->OnFocusChanged(focus_state_, reason); |
1476 } | 1451 } |
OLD | NEW |