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 "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 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1162 ShowOverlay(100, INSTANT_SIZE_PERCENT); | 1162 ShowOverlay(100, INSTANT_SIZE_PERCENT); |
1163 } | 1163 } |
1164 | 1164 |
1165 void InstantController::ShowInstantOverlay(const content::WebContents* contents, | 1165 void InstantController::ShowInstantOverlay(const content::WebContents* contents, |
1166 int height, | 1166 int height, |
1167 InstantSizeUnits units) { | 1167 InstantSizeUnits units) { |
1168 if (extended_enabled_ && IsContentsFrom(overlay(), contents)) | 1168 if (extended_enabled_ && IsContentsFrom(overlay(), contents)) |
1169 ShowOverlay(height, units); | 1169 ShowOverlay(height, units); |
1170 } | 1170 } |
1171 | 1171 |
1172 void InstantController::FocusOmnibox(const content::WebContents* contents) { | 1172 void InstantController::FocusOmnibox(const content::WebContents* contents, |
1173 OmniboxFocusState state) { | |
1173 if (!extended_enabled_) | 1174 if (!extended_enabled_) |
1174 return; | 1175 return; |
1175 | 1176 |
1176 DCHECK(IsContentsFrom(instant_tab(), contents)); | 1177 DCHECK(IsContentsFrom(instant_tab(), contents)); |
1177 browser_->FocusOmnibox(true); | 1178 switch (state) { |
1178 } | 1179 case OMNIBOX_FOCUS_VISIBLE: |
1179 | 1180 browser_->FocusOmnibox(true); |
1180 void InstantController::StartCapturingKeyStrokes( | 1181 break; |
1181 const content::WebContents* contents) { | 1182 case OMNIBOX_FOCUS_INVISIBLE: |
1182 if (!extended_enabled_) | 1183 browser_->FocusOmnibox(false); |
1183 return; | 1184 break; |
1184 | 1185 case OMNIBOX_FOCUS_NONE: |
1185 DCHECK(IsContentsFrom(instant_tab(), contents)); | 1186 if (omnibox_focus_state_ != OMNIBOX_FOCUS_INVISIBLE) |
1186 browser_->FocusOmnibox(false); | 1187 contents->GetView()->Focus(); |
1187 } | 1188 break; |
1188 | 1189 } |
jln (very slow on Chromium)
2013/04/05 21:32:45
I'm surprised the compiler didn't complain about d
sreeram
2013/04/05 21:47:13
All the enum values are explicitly handled here, s
jln (very slow on Chromium)
2013/04/05 21:53:59
It's all about review-ability. It's easy to assert
sreeram
2013/04/05 22:03:38
Okay, how about we don't add the "default:" clause
kmadhusu
2013/04/05 22:08:51
sreeram@: How about adding a COMPILE_ASSERT macro
jln (very slow on Chromium)
2013/04/05 22:32:44
This wouldn't work and needs to be a run-time chec
sreeram
2013/04/05 22:38:48
So it turns out enum variables are explicitly allo
jln (very slow on Chromium)
2013/04/05 22:43:50
As explained above, it's much harder to assess the
kmadhusu
2013/04/05 23:51:37
Added a detailed comment. PTAL.
| |
1189 void InstantController::StopCapturingKeyStrokes( | |
1190 content::WebContents* contents) { | |
1191 // Nothing to do if omnibox doesn't have invisible focus. | |
1192 if (!extended_enabled_ || omnibox_focus_state_ != OMNIBOX_FOCUS_INVISIBLE) | |
1193 return; | |
1194 | |
1195 DCHECK(IsContentsFrom(instant_tab(), contents)); | |
1196 contents->GetView()->Focus(); | |
1197 } | 1190 } |
1198 | 1191 |
1199 void InstantController::NavigateToURL(const content::WebContents* contents, | 1192 void InstantController::NavigateToURL(const content::WebContents* contents, |
1200 const GURL& url, | 1193 const GURL& url, |
1201 content::PageTransition transition, | 1194 content::PageTransition transition, |
1202 WindowOpenDisposition disposition) { | 1195 WindowOpenDisposition disposition) { |
1203 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 1196 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
1204 "NavigateToURL: url='%s'", url.spec().c_str())); | 1197 "NavigateToURL: url='%s'", url.spec().c_str())); |
1205 | 1198 |
1206 // TODO(samarth): handle case where contents are no longer "active" (e.g. user | 1199 // TODO(samarth): handle case where contents are no longer "active" (e.g. user |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1624 | 1617 |
1625 // If this is not window startup, switch. | 1618 // If this is not window startup, switch. |
1626 // TODO(shishir): This is not completely reliable. Find a better way to detect | 1619 // TODO(shishir): This is not completely reliable. Find a better way to detect |
1627 // startup time. | 1620 // startup time. |
1628 if (browser_->GetActiveWebContents()) | 1621 if (browser_->GetActiveWebContents()) |
1629 return true; | 1622 return true; |
1630 | 1623 |
1631 return chrome::IsAggressiveLocalNTPFallbackEnabled(); | 1624 return chrome::IsAggressiveLocalNTPFallbackEnabled(); |
1632 } | 1625 } |
1633 | 1626 |
OLD | NEW |