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

Side by Side Diff: components/omnibox/browser/omnibox_edit_model.cc

Issue 2738003002: Add title to current page in zero suggest. (Closed)
Patch Set: Add flag to show title for current URL suggestion. Created 3 years, 8 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
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 "components/omnibox/browser/omnibox_edit_model.h" 5 #include "components/omnibox/browser/omnibox_edit_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 385
386 // For keyword searches, the text that AutocompleteInput expects is 386 // For keyword searches, the text that AutocompleteInput expects is
387 // of the form "<keyword> <query>", where our query is |user_text_|. 387 // of the form "<keyword> <query>", where our query is |user_text_|.
388 // So we need to adjust the cursor position forward by the length of 388 // So we need to adjust the cursor position forward by the length of
389 // any keyword added by MaybePrependKeyword() above. 389 // any keyword added by MaybePrependKeyword() above.
390 if (is_keyword_selected()) 390 if (is_keyword_selected())
391 cursor_position += input_text.length() - user_text_.length(); 391 cursor_position += input_text.length() - user_text_.length();
392 392
393 input_ = AutocompleteInput( 393 input_ = AutocompleteInput(
394 input_text, cursor_position, std::string(), client_->GetURL(), 394 input_text, cursor_position, std::string(), client_->GetURL(),
395 ClassifyPage(), 395 client_->GetTitle(), ClassifyPage(),
396 prevent_inline_autocomplete || just_deleted_text_ || 396 prevent_inline_autocomplete || just_deleted_text_ ||
397 (has_selected_text && inline_autocomplete_text_.empty()) || 397 (has_selected_text && inline_autocomplete_text_.empty()) ||
398 (paste_state_ != NONE), 398 (paste_state_ != NONE),
399 is_keyword_selected(), 399 is_keyword_selected(),
400 is_keyword_selected() || allow_exact_keyword_match_, true, false, 400 is_keyword_selected() || allow_exact_keyword_match_, true, false,
401 client_->GetSchemeClassifier()); 401 client_->GetSchemeClassifier());
402
403 omnibox_controller_->StartAutocomplete(input_); 402 omnibox_controller_->StartAutocomplete(input_);
404 } 403 }
405 404
406 void OmniboxEditModel::StopAutocomplete() { 405 void OmniboxEditModel::StopAutocomplete() {
407 autocomplete_controller()->Stop(true); 406 autocomplete_controller()->Stop(true);
408 } 407 }
409 408
410 bool OmniboxEditModel::CanPasteAndGo(const base::string16& text) const { 409 bool OmniboxEditModel::CanPasteAndGo(const base::string16& text) const {
411 if (!client_->IsPasteAndGoEnabled()) 410 if (!client_->IsPasteAndGoEnabled())
412 return false; 411 return false;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 // Generate a new AutocompleteInput, copying the latest one but using "com" 448 // Generate a new AutocompleteInput, copying the latest one but using "com"
450 // as the desired TLD. Then use this autocomplete input to generate a 449 // as the desired TLD. Then use this autocomplete input to generate a
451 // URL_WHAT_YOU_TYPED AutocompleteMatch. Note that using the most recent 450 // URL_WHAT_YOU_TYPED AutocompleteMatch. Note that using the most recent
452 // input instead of the currently visible text means we'll ignore any 451 // input instead of the currently visible text means we'll ignore any
453 // visible inline autocompletion: if a user types "foo" and is autocompleted 452 // visible inline autocompletion: if a user types "foo" and is autocompleted
454 // to "foodnetwork.com", ctrl-enter will navigate to "foo.com", not 453 // to "foodnetwork.com", ctrl-enter will navigate to "foo.com", not
455 // "foodnetwork.com". At the time of writing, this behavior matches 454 // "foodnetwork.com". At the time of writing, this behavior matches
456 // Internet Explorer, but not Firefox. 455 // Internet Explorer, but not Firefox.
457 input_ = AutocompleteInput( 456 input_ = AutocompleteInput(
458 has_temporary_text_ ? view_->GetText() : input_.text(), 457 has_temporary_text_ ? view_->GetText() : input_.text(),
459 input_.cursor_position(), "com", GURL(), 458 input_.cursor_position(), "com", GURL(), base::string16(),
460 input_.current_page_classification(), 459 input_.current_page_classification(),
461 input_.prevent_inline_autocomplete(), input_.prefer_keyword(), 460 input_.prevent_inline_autocomplete(), input_.prefer_keyword(),
462 input_.allow_exact_keyword_match(), input_.want_asynchronous_matches(), 461 input_.allow_exact_keyword_match(), input_.want_asynchronous_matches(),
463 input_.from_omnibox_focus(), client_->GetSchemeClassifier()); 462 input_.from_omnibox_focus(), client_->GetSchemeClassifier());
464 AutocompleteMatch url_match( 463 AutocompleteMatch url_match(
465 autocomplete_controller()->history_url_provider()->SuggestExactInput( 464 autocomplete_controller()->history_url_provider()->SuggestExactInput(
466 input_, input_.canonicalized_url(), false)); 465 input_, input_.canonicalized_url(), false));
467 466
468 if (url_match.destination_url.is_valid()) { 467 if (url_match.destination_url.is_valid()) {
469 // We have a valid URL, we use this newly generated AutocompleteMatch. 468 // We have a valid URL, we use this newly generated AutocompleteMatch.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 543
545 base::string16 input_text(pasted_text); 544 base::string16 input_text(pasted_text);
546 if (input_text.empty()) 545 if (input_text.empty())
547 input_text = user_input_in_progress_ ? user_text_ : permanent_text_; 546 input_text = user_input_in_progress_ ? user_text_ : permanent_text_;
548 // Create a dummy AutocompleteInput for use in calling SuggestExactInput() 547 // Create a dummy AutocompleteInput for use in calling SuggestExactInput()
549 // to create an alternate navigational match. 548 // to create an alternate navigational match.
550 AutocompleteInput alternate_input( 549 AutocompleteInput alternate_input(
551 input_text, base::string16::npos, std::string(), 550 input_text, base::string16::npos, std::string(),
552 // Somehow we can occasionally get here with no active tab. It's not 551 // Somehow we can occasionally get here with no active tab. It's not
553 // clear why this happens. 552 // clear why this happens.
554 client_->GetURL(), ClassifyPage(), false, false, true, true, false, 553 client_->GetURL(), base::string16(), ClassifyPage(), false, false, true,
Mark P 2017/04/10 22:38:02 There is no reason not to use the real title here.
gcomanici 2017/04/11 20:51:41 Fixed.
555 client_->GetSchemeClassifier()); 554 true, false, client_->GetSchemeClassifier());
556 std::unique_ptr<OmniboxNavigationObserver> observer( 555 std::unique_ptr<OmniboxNavigationObserver> observer(
557 client_->CreateOmniboxNavigationObserver( 556 client_->CreateOmniboxNavigationObserver(
558 input_text, match, 557 input_text, match,
559 autocomplete_controller()->history_url_provider()->SuggestExactInput( 558 autocomplete_controller()->history_url_provider()->SuggestExactInput(
560 alternate_input, alternate_nav_url, false))); 559 alternate_input, alternate_nav_url, false)));
561 560
562 base::TimeDelta elapsed_time_since_last_change_to_default_match( 561 base::TimeDelta elapsed_time_since_last_change_to_default_match(
563 now - autocomplete_controller()->last_time_default_match_changed()); 562 now - autocomplete_controller()->last_time_default_match_changed());
564 DCHECK(match.provider); 563 DCHECK(match.provider);
565 // These elapsed times don't really make sense for matches that come from 564 // These elapsed times don't really make sense for matches that come from
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 // not been typing in the omnibox. The |user_input_in_progress_| check is 861 // not been typing in the omnibox. The |user_input_in_progress_| check is
863 // used to detect the case where this function is called after right-clicking 862 // used to detect the case where this function is called after right-clicking
864 // in the omnibox and selecting paste in Linux (in which case we actually get 863 // in the omnibox and selecting paste in Linux (in which case we actually get
865 // the OnSetFocus() call after the process of handling the paste has kicked 864 // the OnSetFocus() call after the process of handling the paste has kicked
866 // off). 865 // off).
867 // TODO(hfung): Remove this when crbug/271590 is fixed. 866 // TODO(hfung): Remove this when crbug/271590 is fixed.
868 if (client_->CurrentPageExists() && !user_input_in_progress_) { 867 if (client_->CurrentPageExists() && !user_input_in_progress_) {
869 // We avoid PermanentURL() here because it's not guaranteed to give us the 868 // We avoid PermanentURL() here because it's not guaranteed to give us the
870 // actual underlying current URL, e.g. if we're on the NTP and the 869 // actual underlying current URL, e.g. if we're on the NTP and the
871 // |permanent_text_| is empty. 870 // |permanent_text_| is empty.
872 input_ = 871 input_ = AutocompleteInput(
873 AutocompleteInput(permanent_text_, base::string16::npos, std::string(), 872 permanent_text_, base::string16::npos, std::string(), client_->GetURL(),
874 client_->GetURL(), ClassifyPage(), false, false, true, 873 client_->GetTitle(), ClassifyPage(), false, false, true, true, true,
875 true, true, client_->GetSchemeClassifier()); 874 client_->GetSchemeClassifier());
876 autocomplete_controller()->Start(input_); 875 autocomplete_controller()->Start(input_);
877 } 876 }
878 877
879 if (user_input_in_progress_ || !in_revert_) 878 if (user_input_in_progress_ || !in_revert_)
880 client_->OnInputStateChanged(); 879 client_->OnInputStateChanged();
881 } 880 }
882 881
883 void OmniboxEditModel::SetCaretVisibility(bool visible) { 882 void OmniboxEditModel::SetCaretVisibility(bool visible) {
884 // Caret visibility only matters if the omnibox has focus. 883 // Caret visibility only matters if the omnibox has focus.
885 if (focus_state_ != OMNIBOX_FOCUS_NONE) { 884 if (focus_state_ != OMNIBOX_FOCUS_NONE) {
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 // Update state and notify view if the omnibox has focus and the caret 1386 // Update state and notify view if the omnibox has focus and the caret
1388 // visibility changed. 1387 // visibility changed.
1389 const bool was_caret_visible = is_caret_visible(); 1388 const bool was_caret_visible = is_caret_visible();
1390 focus_state_ = state; 1389 focus_state_ = state;
1391 if (focus_state_ != OMNIBOX_FOCUS_NONE && 1390 if (focus_state_ != OMNIBOX_FOCUS_NONE &&
1392 is_caret_visible() != was_caret_visible) 1391 is_caret_visible() != was_caret_visible)
1393 view_->ApplyCaretVisibility(); 1392 view_->ApplyCaretVisibility();
1394 1393
1395 client_->OnFocusChanged(focus_state_, reason); 1394 client_->OnFocusChanged(focus_state_, reason);
1396 } 1395 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698