Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_edit_model.cc

Issue 22364007: AutocompleteInput::PageClassification -> AutocompleteInput::OmniboxContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 } 490 }
491 491
492 GURL current_url = 492 GURL current_url =
493 (delegate_->CurrentPageExists() && view_->IsIndicatingQueryRefinement()) ? 493 (delegate_->CurrentPageExists() && view_->IsIndicatingQueryRefinement()) ?
494 delegate_->GetURL() : GURL(); 494 delegate_->GetURL() : GURL();
495 bool keyword_is_selected = KeywordIsSelected(); 495 bool keyword_is_selected = KeywordIsSelected();
496 omnibox_controller_->StartAutocomplete( 496 omnibox_controller_->StartAutocomplete(
497 user_text_, 497 user_text_,
498 cursor_position, 498 cursor_position,
499 current_url, 499 current_url,
500 ClassifyPage(), 500 GetOmniboxContext(),
501 prevent_inline_autocomplete || just_deleted_text_ || 501 prevent_inline_autocomplete || just_deleted_text_ ||
502 (has_selected_text && inline_autocomplete_text_.empty()) || 502 (has_selected_text && inline_autocomplete_text_.empty()) ||
503 (paste_state_ != NONE), 503 (paste_state_ != NONE),
504 keyword_is_selected, 504 keyword_is_selected,
505 keyword_is_selected || allow_exact_keyword_match_, 505 keyword_is_selected || allow_exact_keyword_match_,
506 controller_->GetOmniboxBounds().x()); 506 controller_->GetOmniboxBounds().x());
507 } 507 }
508 508
509 void OmniboxEditModel::StopAutocomplete() { 509 void OmniboxEditModel::StopAutocomplete() {
510 autocomplete_controller()->Stop(true); 510 autocomplete_controller()->Stop(true);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 // as the desired TLD. Then use this autocomplete input to generate a 551 // as the desired TLD. Then use this autocomplete input to generate a
552 // URL_WHAT_YOU_TYPED AutocompleteMatch. Note that using the most recent 552 // URL_WHAT_YOU_TYPED AutocompleteMatch. Note that using the most recent
553 // input instead of the currently visible text means we'll ignore any 553 // input instead of the currently visible text means we'll ignore any
554 // visible inline autocompletion: if a user types "foo" and is autocompleted 554 // visible inline autocompletion: if a user types "foo" and is autocompleted
555 // to "foodnetwork.com", ctrl-enter will navigate to "foo.com", not 555 // to "foodnetwork.com", ctrl-enter will navigate to "foo.com", not
556 // "foodnetwork.com". At the time of writing, this behavior matches 556 // "foodnetwork.com". At the time of writing, this behavior matches
557 // Internet Explorer, but not Firefox. 557 // Internet Explorer, but not Firefox.
558 const AutocompleteInput& old_input = autocomplete_controller()->input(); 558 const AutocompleteInput& old_input = autocomplete_controller()->input();
559 AutocompleteInput input( 559 AutocompleteInput input(
560 old_input.text(), old_input.cursor_position(), ASCIIToUTF16("com"), 560 old_input.text(), old_input.cursor_position(), ASCIIToUTF16("com"),
561 GURL(), old_input.current_page_classification(), 561 GURL(), old_input.omnibox_context(),
562 old_input.prevent_inline_autocomplete(), old_input.prefer_keyword(), 562 old_input.prevent_inline_autocomplete(), old_input.prefer_keyword(),
563 old_input.allow_exact_keyword_match(), old_input.matches_requested()); 563 old_input.allow_exact_keyword_match(), old_input.matches_requested());
564 AutocompleteMatch url_match = HistoryURLProvider::SuggestExactInput( 564 AutocompleteMatch url_match = HistoryURLProvider::SuggestExactInput(
565 autocomplete_controller()->history_url_provider(), input, true); 565 autocomplete_controller()->history_url_provider(), input, true);
566 566
567 if (url_match.destination_url.is_valid()) { 567 if (url_match.destination_url.is_valid()) {
568 // We have a valid URL, we use this newly generated AutocompleteMatch. 568 // We have a valid URL, we use this newly generated AutocompleteMatch.
569 match = url_match; 569 match = url_match;
570 alternate_nav_url = GURL(); 570 alternate_nav_url = GURL();
571 } 571 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 base::TimeDelta::FromMilliseconds(-1); 625 base::TimeDelta::FromMilliseconds(-1);
626 elapsed_time_since_last_change_to_default_match = 626 elapsed_time_since_last_change_to_default_match =
627 base::TimeDelta::FromMilliseconds(-1); 627 base::TimeDelta::FromMilliseconds(-1);
628 } 628 }
629 OmniboxLog log( 629 OmniboxLog log(
630 autocomplete_controller()->input().text(), 630 autocomplete_controller()->input().text(),
631 just_deleted_text_, 631 just_deleted_text_,
632 autocomplete_controller()->input().type(), 632 autocomplete_controller()->input().type(),
633 popup_model()->selected_line(), 633 popup_model()->selected_line(),
634 -1, // don't yet know tab ID; set later if appropriate 634 -1, // don't yet know tab ID; set later if appropriate
635 ClassifyPage(), 635 GetOmniboxContext(),
636 elapsed_time_since_user_first_modified_omnibox, 636 elapsed_time_since_user_first_modified_omnibox,
637 match.inline_autocompletion.length(), 637 match.inline_autocompletion.length(),
638 elapsed_time_since_last_change_to_default_match, 638 elapsed_time_since_last_change_to_default_match,
639 result()); 639 result());
640 640
641 DCHECK(user_input_in_progress_ || (match.provider && 641 DCHECK(user_input_in_progress_ || (match.provider &&
642 match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST)) 642 match.provider->type() == AutocompleteProvider::TYPE_ZERO_SUGGEST))
643 << "We didn't get here through the expected series of calls. " 643 << "We didn't get here through the expected series of calls. "
644 << "time_user_first_modified_omnibox_ is not set correctly and other " 644 << "time_user_first_modified_omnibox_ is not set correctly and other "
645 << "things may be wrong. Match provider: " 645 << "things may be wrong. Match provider: "
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 SetFocusState(OMNIBOX_FOCUS_VISIBLE, OMNIBOX_FOCUS_CHANGE_EXPLICIT); 814 SetFocusState(OMNIBOX_FOCUS_VISIBLE, OMNIBOX_FOCUS_CHANGE_EXPLICIT);
815 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP; 815 control_key_state_ = control_down ? DOWN_WITHOUT_CHANGE : UP;
816 816
817 if (delegate_->CurrentPageExists()) { 817 if (delegate_->CurrentPageExists()) {
818 // TODO(jered): We may want to merge this into Start() and just call that 818 // TODO(jered): We may want to merge this into Start() and just call that
819 // here rather than having a special entry point for zero-suggest. Note 819 // here rather than having a special entry point for zero-suggest. Note
820 // that we avoid PermanentURL() here because it's not guaranteed to give us 820 // that we avoid PermanentURL() here because it's not guaranteed to give us
821 // the actual underlying current URL, e.g. if we're on the NTP and the 821 // the actual underlying current URL, e.g. if we're on the NTP and the
822 // |permanent_text_| is empty. 822 // |permanent_text_| is empty.
823 autocomplete_controller()->StartZeroSuggest(delegate_->GetURL(), 823 autocomplete_controller()->StartZeroSuggest(delegate_->GetURL(),
824 ClassifyPage(), 824 GetOmniboxContext(),
825 permanent_text_); 825 permanent_text_);
826 } 826 }
827 827
828 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_); 828 delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_);
829 } 829 }
830 830
831 void OmniboxEditModel::SetCaretVisibility(bool visible) { 831 void OmniboxEditModel::SetCaretVisibility(bool visible) {
832 // Caret visibility only matters if the omnibox has focus. 832 // Caret visibility only matters if the omnibox has focus.
833 if (focus_state_ != OMNIBOX_FOCUS_NONE) { 833 if (focus_state_ != OMNIBOX_FOCUS_NONE) {
834 SetFocusState(visible ? OMNIBOX_FOCUS_VISIBLE : OMNIBOX_FOCUS_INVISIBLE, 834 SetFocusState(visible ? OMNIBOX_FOCUS_VISIBLE : OMNIBOX_FOCUS_INVISIBLE,
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 bool OmniboxEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { 1264 bool OmniboxEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) {
1265 switch (c) { 1265 switch (c) {
1266 case 0x0020: // Space 1266 case 0x0020: // Space
1267 case 0x3000: // Ideographic Space 1267 case 0x3000: // Ideographic Space
1268 return true; 1268 return true;
1269 default: 1269 default:
1270 return false; 1270 return false;
1271 } 1271 }
1272 } 1272 }
1273 1273
1274 AutocompleteInput::PageClassification OmniboxEditModel::ClassifyPage() const { 1274 AutocompleteInput::OmniboxContext OmniboxEditModel::GetOmniboxContext() const {
1275 if (!delegate_->CurrentPageExists()) 1275 if (!delegate_->CurrentPageExists())
1276 return AutocompleteInput::OTHER; 1276 return AutocompleteInput::OTHER;
1277 if (delegate_->IsInstantNTP()) { 1277 if (delegate_->IsInstantNTP()) {
1278 // Note that we treat OMNIBOX as the source if focus_source_ is INVALID, 1278 // Note that we treat OMNIBOX as the source if focus_source_ is INVALID,
1279 // i.e., if input isn't actually in progress. 1279 // i.e., if input isn't actually in progress.
1280 return (focus_source_ == FAKEBOX) ? 1280 return (focus_source_ == FAKEBOX) ?
1281 AutocompleteInput::INSTANT_NEW_TAB_PAGE_WITH_FAKEBOX_AS_STARTING_FOCUS : 1281 AutocompleteInput::INSTANT_NEW_TAB_PAGE_WITH_FAKEBOX_AS_STARTING_FOCUS :
1282 AutocompleteInput::INSTANT_NEW_TAB_PAGE_WITH_OMNIBOX_AS_STARTING_FOCUS; 1282 AutocompleteInput::INSTANT_NEW_TAB_PAGE_WITH_OMNIBOX_AS_STARTING_FOCUS;
1283 } 1283 }
1284 const GURL& gurl = delegate_->GetURL(); 1284 const GURL& gurl = delegate_->GetURL();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 instant->OmniboxFocusChanged(state, reason, NULL); 1316 instant->OmniboxFocusChanged(state, reason, NULL);
1317 1317
1318 // Update state and notify view if the omnibox has focus and the caret 1318 // Update state and notify view if the omnibox has focus and the caret
1319 // visibility changed. 1319 // visibility changed.
1320 const bool was_caret_visible = is_caret_visible(); 1320 const bool was_caret_visible = is_caret_visible();
1321 focus_state_ = state; 1321 focus_state_ = state;
1322 if (focus_state_ != OMNIBOX_FOCUS_NONE && 1322 if (focus_state_ != OMNIBOX_FOCUS_NONE &&
1323 is_caret_visible() != was_caret_visible) 1323 is_caret_visible() != was_caret_visible)
1324 view_->ApplyCaretVisibility(); 1324 view_->ApplyCaretVisibility();
1325 } 1325 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698