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

Side by Side Diff: chrome/browser/ui/search/instant_controller.cc

Issue 14562006: Handle Esc key press event in Local NTP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 7 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/search/instant_controller.h" 5 #include "chrome/browser/ui/search/instant_controller.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 // The user is on a search results page. It may be showing results for 372 // The user is on a search results page. It may be showing results for
373 // a partial query the user typed before they hit Escape. Send the 373 // a partial query the user typed before they hit Escape. Send the
374 // omnibox text to the page to restore the original results. 374 // omnibox text to the page to restore the original results.
375 // 375 //
376 // In a tab switch, |instant_tab_| won't have updated yet, so it may 376 // In a tab switch, |instant_tab_| won't have updated yet, so it may
377 // be pointing to the previous tab (which was a search results page). 377 // be pointing to the previous tab (which was a search results page).
378 // Ensure we don't send the omnibox text to a random webpage (the new 378 // Ensure we don't send the omnibox text to a random webpage (the new
379 // tab), by comparing the old and new WebContents. 379 // tab), by comparing the old and new WebContents.
380 if (escape_pressed && 380 if (escape_pressed &&
381 instant_tab_->contents() == browser_->GetActiveWebContents()) { 381 instant_tab_->contents() == browser_->GetActiveWebContents()) {
382 // If the omnibox is blank, send an onchange("") instead of an 382 // TODO(kmadhusu): If the |full_text| is not empty, send an
383 // onsubmit(""). This is to avoid confusion with the onsubmit("") 383 // onkeypress(esc) to the Instant page. Do not call
384 // that we send when the user hits Enter to navigate to a URL. 384 // onsubmit(full_text). Fix.
385 // onchange("") is used for a similar situation with the overlay 385 if (full_text.empty()) {
386 // (when the overlay is dismissed because the user hit Escape); it
387 // does the right thing for committed tabs as well.
388 if (full_text.empty())
389 instant_tab_->Update(string16(), 0, 0, true); 386 instant_tab_->Update(string16(), 0, 0, true);
samarth 2013/05/06 19:13:37 Please add a comment for this call: because that w
kmadhusu 2013/05/06 20:24:44 Done.
390 else 387 instant_tab_->EscKeyPressed();
388 } else {
391 instant_tab_->Submit(full_text); 389 instant_tab_->Submit(full_text);
390 }
392 } 391 }
393 } else if (!full_text.empty()) { 392 } else if (!full_text.empty()) {
394 // If |full_text| is empty, the user is on the NTP. The overlay may 393 // If |full_text| is empty, the user is on the NTP. The overlay may
395 // be showing custom NTP content; hide only if that's not the case. 394 // be showing custom NTP content; hide only if that's not the case.
396 HideOverlay(); 395 HideOverlay();
397 } 396 }
398 } else if (full_text.empty()) { 397 } else if (full_text.empty()) {
399 // The user is typing, and backspaced away all omnibox text. Clear 398 // The user is typing, and backspaced away all omnibox text. Clear
400 // |last_omnibox_text_| so that we don't attempt to set suggestions. 399 // |last_omnibox_text_| so that we don't attempt to set suggestions.
401 last_omnibox_text_.clear(); 400 last_omnibox_text_.clear();
(...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 } 1702 }
1704 1703
1705 bool InstantController::UsingLocalPage() const { 1704 bool InstantController::UsingLocalPage() const {
1706 return (UseTabForSuggestions() && instant_tab_->IsLocal()) || 1705 return (UseTabForSuggestions() && instant_tab_->IsLocal()) ||
1707 (!UseTabForSuggestions() && overlay_ && overlay_->IsLocal()); 1706 (!UseTabForSuggestions() && overlay_ && overlay_->IsLocal());
1708 } 1707 }
1709 1708
1710 bool InstantController::UseTabForSuggestions() const { 1709 bool InstantController::UseTabForSuggestions() const {
1711 return instant_tab_ && use_tab_for_suggestions_; 1710 return instant_tab_ && use_tab_for_suggestions_;
1712 } 1711 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698