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/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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 extended_enabled_(extended_enabled), | 243 extended_enabled_(extended_enabled), |
244 instant_enabled_(false), | 244 instant_enabled_(false), |
245 use_local_page_only_(true), | 245 use_local_page_only_(true), |
246 preload_ntp_(true), | 246 preload_ntp_(true), |
247 model_(this), | 247 model_(this), |
248 use_tab_for_suggestions_(false), | 248 use_tab_for_suggestions_(false), |
249 last_omnibox_text_has_inline_autocompletion_(false), | 249 last_omnibox_text_has_inline_autocompletion_(false), |
250 last_verbatim_(false), | 250 last_verbatim_(false), |
251 last_transition_type_(content::PAGE_TRANSITION_LINK), | 251 last_transition_type_(content::PAGE_TRANSITION_LINK), |
252 last_match_was_search_(false), | 252 last_match_was_search_(false), |
253 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), | 253 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), |
samarth
2013/05/15 19:05:53
initialize reason_ here (to EXPLICIT)
Donn Denman
2013/05/20 23:48:14
Done.
| |
254 omnibox_bounds_(-1, -1, 0, 0), | 254 omnibox_bounds_(-1, -1, 0, 0), |
255 allow_overlay_to_show_search_suggestions_(false), | 255 allow_overlay_to_show_search_suggestions_(false), |
256 weak_ptr_factory_(this) { | 256 weak_ptr_factory_(this) { |
257 | 257 |
258 // When the InstantController lives, the InstantService should live. | 258 // When the InstantController lives, the InstantService should live. |
259 // InstantService sets up profile-level facilities such as the ThemeSource for | 259 // InstantService sets up profile-level facilities such as the ThemeSource for |
260 // the NTP. | 260 // the NTP. |
261 InstantServiceFactory::GetForProfile(browser_->profile()); | 261 InstantServiceFactory::GetForProfile(browser_->profile()); |
262 } | 262 } |
263 | 263 |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
916 void InstantController::OmniboxFocusChanged( | 916 void InstantController::OmniboxFocusChanged( |
917 OmniboxFocusState state, | 917 OmniboxFocusState state, |
918 OmniboxFocusChangeReason reason, | 918 OmniboxFocusChangeReason reason, |
919 gfx::NativeView view_gaining_focus) { | 919 gfx::NativeView view_gaining_focus) { |
920 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 920 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
921 "OmniboxFocusChanged: %d to %d for reason %d", omnibox_focus_state_, | 921 "OmniboxFocusChanged: %d to %d for reason %d", omnibox_focus_state_, |
922 state, reason)); | 922 state, reason)); |
923 | 923 |
924 OmniboxFocusState old_focus_state = omnibox_focus_state_; | 924 OmniboxFocusState old_focus_state = omnibox_focus_state_; |
925 omnibox_focus_state_ = state; | 925 omnibox_focus_state_ = state; |
926 reason_ = reason; | |
926 if (!extended_enabled_ && !instant_enabled_) | 927 if (!extended_enabled_ && !instant_enabled_) |
927 return; | 928 return; |
928 | 929 |
929 // Tell the page if the key capture mode changed unless the focus state | 930 if (extended_enabled_) { |
930 // changed because of TYPING. This is because in that case, the browser hasn't | |
931 // really stopped capturing key strokes. | |
932 // | |
933 // (More practically, if we don't do this check, the page would receive | |
934 // onkeycapturechange before the corresponding onchange, and the page would | |
935 // have no way of telling whether the keycapturechange happened because of | |
936 // some actual user action or just because they started typing.) | |
937 if (extended_enabled_ && GetOverlayContents() && | |
938 reason != OMNIBOX_FOCUS_CHANGE_TYPING) { | |
939 const bool is_key_capture_enabled = | |
940 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE; | |
941 if (overlay_) | 931 if (overlay_) |
942 overlay_->KeyCaptureChanged(is_key_capture_enabled); | 932 overlay_->FocusChanged(omnibox_focus_state_, reason); |
943 if (instant_tab_) | 933 if (instant_tab_) |
944 instant_tab_->KeyCaptureChanged(is_key_capture_enabled); | 934 instant_tab_->FocusChanged(omnibox_focus_state_, reason); |
945 } | 935 } |
946 | 936 |
947 if (state == OMNIBOX_FOCUS_VISIBLE && old_focus_state == OMNIBOX_FOCUS_NONE) { | 937 if (state == OMNIBOX_FOCUS_VISIBLE && old_focus_state == OMNIBOX_FOCUS_NONE) { |
948 // If the user explicitly focused the omnibox, then create the overlay if | 938 // If the user explicitly focused the omnibox, then create the overlay if |
949 // it doesn't exist. If we're using a fallback overlay, try loading the | 939 // it doesn't exist. If we're using a fallback overlay, try loading the |
950 // remote overlay again. | 940 // remote overlay again. |
951 if (!overlay_ || (overlay_->IsLocal() && !use_local_page_only_)) | 941 if (!overlay_ || (overlay_->IsLocal() && !use_local_page_only_)) |
952 ResetOverlay(GetInstantURL()); | 942 ResetOverlay(GetInstantURL()); |
953 } else if (state == OMNIBOX_FOCUS_NONE && | 943 } else if (state == OMNIBOX_FOCUS_NONE && |
954 old_focus_state != OMNIBOX_FOCUS_NONE) { | 944 old_focus_state != OMNIBOX_FOCUS_NONE) { |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1154 const content::WebContents* contents) { | 1144 const content::WebContents* contents) { |
1155 if (!extended_enabled_) | 1145 if (!extended_enabled_) |
1156 return; | 1146 return; |
1157 | 1147 |
1158 // Update theme info so that the page picks it up. | 1148 // Update theme info so that the page picks it up. |
1159 browser_->UpdateThemeInfo(); | 1149 browser_->UpdateThemeInfo(); |
1160 | 1150 |
1161 // Ensure the searchbox API has the correct initial state. | 1151 // Ensure the searchbox API has the correct initial state. |
1162 if (IsContentsFrom(overlay(), contents)) { | 1152 if (IsContentsFrom(overlay(), contents)) { |
1163 overlay_->SetDisplayInstantResults(instant_enabled_); | 1153 overlay_->SetDisplayInstantResults(instant_enabled_); |
1164 overlay_->KeyCaptureChanged( | 1154 overlay_->FocusChanged(omnibox_focus_state_, |
1165 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); | 1155 OMNIBOX_FOCUS_CHANGE_EXPLICIT); |
samarth
2013/05/15 19:05:53
Use the saved reason_ here.
Donn Denman
2013/05/20 23:48:14
Done.
| |
1166 overlay_->SetOmniboxBounds(omnibox_bounds_); | 1156 overlay_->SetOmniboxBounds(omnibox_bounds_); |
1167 overlay_->InitializeFonts(); | 1157 overlay_->InitializeFonts(); |
1168 } else if (IsContentsFrom(ntp(), contents)) { | 1158 } else if (IsContentsFrom(ntp(), contents)) { |
1169 ntp_->SetDisplayInstantResults(instant_enabled_); | 1159 ntp_->SetDisplayInstantResults(instant_enabled_); |
1170 ntp_->SetOmniboxBounds(omnibox_bounds_); | 1160 ntp_->SetOmniboxBounds(omnibox_bounds_); |
1171 ntp_->InitializeFonts(); | 1161 ntp_->InitializeFonts(); |
1172 } else { | 1162 } else { |
1173 NOTREACHED(); | 1163 NOTREACHED(); |
1174 } | 1164 } |
1175 StartListeningToMostVisitedChanges(); | 1165 StartListeningToMostVisitedChanges(); |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1534 } | 1524 } |
1535 } | 1525 } |
1536 | 1526 |
1537 void InstantController::UpdateInfoForInstantTab() { | 1527 void InstantController::UpdateInfoForInstantTab() { |
1538 if (instant_tab_) { | 1528 if (instant_tab_) { |
1539 browser_->UpdateThemeInfo(); | 1529 browser_->UpdateThemeInfo(); |
1540 instant_tab_->SetDisplayInstantResults(instant_enabled_); | 1530 instant_tab_->SetDisplayInstantResults(instant_enabled_); |
1541 instant_tab_->SetOmniboxBounds(omnibox_bounds_); | 1531 instant_tab_->SetOmniboxBounds(omnibox_bounds_); |
1542 instant_tab_->InitializeFonts(); | 1532 instant_tab_->InitializeFonts(); |
1543 StartListeningToMostVisitedChanges(); | 1533 StartListeningToMostVisitedChanges(); |
1544 instant_tab_->KeyCaptureChanged( | 1534 instant_tab_->FocusChanged(omnibox_focus_state_, |
1545 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); | 1535 OMNIBOX_FOCUS_CHANGE_EXPLICIT); |
samarth
2013/05/15 19:05:53
Here as well.
Donn Denman
2013/05/20 23:48:14
Done.
| |
1546 } | 1536 } |
1547 } | 1537 } |
1548 | 1538 |
1549 void InstantController::HideOverlay() { | 1539 void InstantController::HideOverlay() { |
1550 HideInternal(); | 1540 HideInternal(); |
1551 ReloadOverlayIfStale(); | 1541 ReloadOverlayIfStale(); |
1552 } | 1542 } |
1553 | 1543 |
1554 void InstantController::HideInternal() { | 1544 void InstantController::HideInternal() { |
1555 LOG_INSTANT_DEBUG_EVENT(this, "Hide"); | 1545 LOG_INSTANT_DEBUG_EVENT(this, "Hide"); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1806 | 1796 |
1807 result->transition = match.transition; | 1797 result->transition = match.transition; |
1808 result->relevance = match.relevance; | 1798 result->relevance = match.relevance; |
1809 result->autocomplete_match_index = autocomplete_match_index; | 1799 result->autocomplete_match_index = autocomplete_match_index; |
1810 | 1800 |
1811 DVLOG(1) << " " << result->relevance << " " << result->type << " " | 1801 DVLOG(1) << " " << result->relevance << " " << result->type << " " |
1812 << result->provider << " " << result->destination_url << " '" | 1802 << result->provider << " " << result->destination_url << " '" |
1813 << result->description << "' '" << result->search_query << "' " | 1803 << result->description << "' '" << result->search_query << "' " |
1814 << result->transition << " " << result->autocomplete_match_index; | 1804 << result->transition << " " << result->autocomplete_match_index; |
1815 } | 1805 } |
OLD | NEW |