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

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

Issue 14646034: Add onfocuschange to the Extended Search API, with associated isFocused attribute. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Trying again after rebase master. Created 7 years, 6 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 "chrome/browser/ui/search/instant_controller.h" 5 #include "chrome/browser/ui/search/instant_controller.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 instant_enabled_(false), 271 instant_enabled_(false),
272 use_local_page_only_(true), 272 use_local_page_only_(true),
273 preload_ntp_(true), 273 preload_ntp_(true),
274 model_(this), 274 model_(this),
275 use_tab_for_suggestions_(false), 275 use_tab_for_suggestions_(false),
276 last_omnibox_text_has_inline_autocompletion_(false), 276 last_omnibox_text_has_inline_autocompletion_(false),
277 last_verbatim_(false), 277 last_verbatim_(false),
278 last_transition_type_(content::PAGE_TRANSITION_LINK), 278 last_transition_type_(content::PAGE_TRANSITION_LINK),
279 last_match_was_search_(false), 279 last_match_was_search_(false),
280 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), 280 omnibox_focus_state_(OMNIBOX_FOCUS_NONE),
281 omnibox_focus_change_reason_(OMNIBOX_FOCUS_CHANGE_EXPLICIT),
281 omnibox_bounds_(-1, -1, 0, 0), 282 omnibox_bounds_(-1, -1, 0, 0),
282 allow_overlay_to_show_search_suggestions_(false), 283 allow_overlay_to_show_search_suggestions_(false),
283 weak_ptr_factory_(this) { 284 weak_ptr_factory_(this) {
284 285
285 // When the InstantController lives, the InstantService should live. 286 // When the InstantController lives, the InstantService should live.
286 // InstantService sets up profile-level facilities such as the ThemeSource for 287 // InstantService sets up profile-level facilities such as the ThemeSource for
287 // the NTP. 288 // the NTP.
288 // However, in some tests, browser_ may be null. 289 // However, in some tests, browser_ may be null.
289 if (browser_) 290 if (browser_)
290 InstantServiceFactory::GetForProfile(browser_->profile()); 291 InstantServiceFactory::GetForProfile(browser_->profile());
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 gfx::NativeView view_gaining_focus) { 954 gfx::NativeView view_gaining_focus) {
954 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( 955 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf(
955 "OmniboxFocusChanged: %d to %d for reason %d", omnibox_focus_state_, 956 "OmniboxFocusChanged: %d to %d for reason %d", omnibox_focus_state_,
956 state, reason)); 957 state, reason));
957 958
958 OmniboxFocusState old_focus_state = omnibox_focus_state_; 959 OmniboxFocusState old_focus_state = omnibox_focus_state_;
959 omnibox_focus_state_ = state; 960 omnibox_focus_state_ = state;
960 if (!extended_enabled() && !instant_enabled_) 961 if (!extended_enabled() && !instant_enabled_)
961 return; 962 return;
962 963
963 // Tell the page if the key capture mode changed unless the focus state 964 if (extended_enabled()) {
964 // changed because of TYPING. This is because in that case, the browser hasn't
965 // really stopped capturing key strokes.
966 //
967 // (More practically, if we don't do this check, the page would receive
968 // onkeycapturechange before the corresponding onchange, and the page would
969 // have no way of telling whether the keycapturechange happened because of
970 // some actual user action or just because they started typing.)
971 if (extended_enabled() && GetOverlayContents() &&
972 reason != OMNIBOX_FOCUS_CHANGE_TYPING) {
973 const bool is_key_capture_enabled =
974 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE;
975 if (overlay_) 965 if (overlay_)
976 overlay_->KeyCaptureChanged(is_key_capture_enabled); 966 overlay_->FocusChanged(omnibox_focus_state_, reason);
977 if (instant_tab_) 967 if (instant_tab_)
978 instant_tab_->KeyCaptureChanged(is_key_capture_enabled); 968 instant_tab_->FocusChanged(omnibox_focus_state_, reason);
979 } 969 }
980 970
981 if (state == OMNIBOX_FOCUS_VISIBLE && old_focus_state == OMNIBOX_FOCUS_NONE) { 971 if (state == OMNIBOX_FOCUS_VISIBLE && old_focus_state == OMNIBOX_FOCUS_NONE) {
982 // If the user explicitly focused the omnibox, then create the overlay if 972 // If the user explicitly focused the omnibox, then create the overlay if
983 // it doesn't exist. If we're using a fallback overlay, try loading the 973 // it doesn't exist. If we're using a fallback overlay, try loading the
984 // remote overlay again. 974 // remote overlay again.
985 if (!overlay_ || (overlay_->IsLocal() && !use_local_page_only_)) 975 if (!overlay_ || (overlay_->IsLocal() && !use_local_page_only_))
986 ResetOverlay(GetInstantURL()); 976 ResetOverlay(GetInstantURL());
987 } else if (state == OMNIBOX_FOCUS_NONE && 977 } else if (state == OMNIBOX_FOCUS_NONE &&
988 old_focus_state != OMNIBOX_FOCUS_NONE) { 978 old_focus_state != OMNIBOX_FOCUS_NONE) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 const content::WebContents* contents) { 1178 const content::WebContents* contents) {
1189 if (!extended_enabled()) 1179 if (!extended_enabled())
1190 return; 1180 return;
1191 1181
1192 // Update theme info so that the page picks it up. 1182 // Update theme info so that the page picks it up.
1193 browser_->UpdateThemeInfo(); 1183 browser_->UpdateThemeInfo();
1194 1184
1195 // Ensure the searchbox API has the correct initial state. 1185 // Ensure the searchbox API has the correct initial state.
1196 if (IsContentsFrom(overlay(), contents)) { 1186 if (IsContentsFrom(overlay(), contents)) {
1197 overlay_->SetDisplayInstantResults(instant_enabled_); 1187 overlay_->SetDisplayInstantResults(instant_enabled_);
1198 overlay_->KeyCaptureChanged( 1188 overlay_->FocusChanged(omnibox_focus_state_, omnibox_focus_change_reason_);
1199 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE);
1200 overlay_->SetOmniboxBounds(omnibox_bounds_); 1189 overlay_->SetOmniboxBounds(omnibox_bounds_);
1201 overlay_->InitializeFonts(); 1190 overlay_->InitializeFonts();
1202 } else if (IsContentsFrom(ntp(), contents)) { 1191 } else if (IsContentsFrom(ntp(), contents)) {
1203 ntp_->SetDisplayInstantResults(instant_enabled_); 1192 ntp_->SetDisplayInstantResults(instant_enabled_);
1204 ntp_->SetOmniboxBounds(omnibox_bounds_); 1193 ntp_->SetOmniboxBounds(omnibox_bounds_);
1205 ntp_->InitializeFonts(); 1194 ntp_->InitializeFonts();
1206 } else { 1195 } else {
1207 NOTREACHED(); 1196 NOTREACHED();
1208 } 1197 }
1209 StartListeningToMostVisitedChanges(); 1198 StartListeningToMostVisitedChanges();
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 } 1594 }
1606 } 1595 }
1607 1596
1608 void InstantController::UpdateInfoForInstantTab() { 1597 void InstantController::UpdateInfoForInstantTab() {
1609 if (instant_tab_) { 1598 if (instant_tab_) {
1610 browser_->UpdateThemeInfo(); 1599 browser_->UpdateThemeInfo();
1611 instant_tab_->SetDisplayInstantResults(instant_enabled_); 1600 instant_tab_->SetDisplayInstantResults(instant_enabled_);
1612 instant_tab_->SetOmniboxBounds(omnibox_bounds_); 1601 instant_tab_->SetOmniboxBounds(omnibox_bounds_);
1613 instant_tab_->InitializeFonts(); 1602 instant_tab_->InitializeFonts();
1614 StartListeningToMostVisitedChanges(); 1603 StartListeningToMostVisitedChanges();
1615 instant_tab_->KeyCaptureChanged( 1604 instant_tab_->FocusChanged(omnibox_focus_state_,
1616 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); 1605 omnibox_focus_change_reason_);
1617 } 1606 }
1618 } 1607 }
1619 1608
1620 void InstantController::HideOverlay() { 1609 void InstantController::HideOverlay() {
1621 HideInternal(); 1610 HideInternal();
1622 ReloadOverlayIfStale(); 1611 ReloadOverlayIfStale();
1623 } 1612 }
1624 1613
1625 void InstantController::HideInternal() { 1614 void InstantController::HideInternal() {
1626 LOG_INSTANT_DEBUG_EVENT(this, "Hide"); 1615 LOG_INSTANT_DEBUG_EVENT(this, "Hide");
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 result->transition = match.transition; 1864 result->transition = match.transition;
1876 result->relevance = match.relevance; 1865 result->relevance = match.relevance;
1877 result->autocomplete_match_index = autocomplete_match_index; 1866 result->autocomplete_match_index = autocomplete_match_index;
1878 1867
1879 DVLOG(1) << " " << result->relevance << " " 1868 DVLOG(1) << " " << result->relevance << " "
1880 << UTF8ToUTF16(AutocompleteMatchType::ToString(result->type)) << " " 1869 << UTF8ToUTF16(AutocompleteMatchType::ToString(result->type)) << " "
1881 << result->provider << " " << result->destination_url << " '" 1870 << result->provider << " " << result->destination_url << " '"
1882 << result->description << "' '" << result->search_query << "' " 1871 << result->description << "' '" << result->search_query << "' "
1883 << result->transition << " " << result->autocomplete_match_index; 1872 << result->transition << " " << result->autocomplete_match_index;
1884 } 1873 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/instant_controller.h ('k') | chrome/browser/ui/search/instant_extended_interactive_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698