Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/instant/instant_controller.h" | 5 #include "chrome/browser/instant/instant_controller.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_match.h" | 10 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 return loader_manager_->current_loader()->IsMouseDownFromActivate(); | 245 return loader_manager_->current_loader()->IsMouseDownFromActivate(); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void InstantController::OnAutocompleteLostFocus( | 248 void InstantController::OnAutocompleteLostFocus( |
| 249 gfx::NativeView view_gaining_focus) { | 249 gfx::NativeView view_gaining_focus) { |
| 250 if (!is_active() || !GetPreviewContents()) | 250 if (!is_active() || !GetPreviewContents()) |
| 251 return; | 251 return; |
| 252 | 252 |
| 253 RenderWidgetHostView* rwhv = | 253 RenderWidgetHostView* rwhv = |
| 254 GetPreviewContents()->GetRenderWidgetHostView(); | 254 GetPreviewContents()->GetRenderWidgetHostView(); |
| 255 if (!view_gaining_focus || !rwhv) | 255 if (!view_gaining_focus || !rwhv) { |
| 256 return DestroyPreviewContents(); | 256 DestroyPreviewContents(); |
| 257 return; | |
| 258 } | |
| 257 | 259 |
| 258 gfx::NativeView tab_view = GetPreviewContents()->GetNativeView(); | 260 gfx::NativeView tab_view = GetPreviewContents()->GetNativeView(); |
| 259 // Focus is going to the renderer. | 261 // Focus is going to the renderer. |
| 260 if (rwhv->GetNativeView() == view_gaining_focus || | 262 if (rwhv->GetNativeView() == view_gaining_focus || |
| 261 tab_view == view_gaining_focus) { | 263 tab_view == view_gaining_focus) { |
| 262 if (!IsMouseDownFromActivate()) { | 264 if (!IsMouseDownFromActivate()) { |
| 263 // If the mouse is not down, focus is not going to the renderer. Someone | 265 // If the mouse is not down, focus is not going to the renderer. Someone |
| 264 // else moved focus and we shouldn't commit. | 266 // else moved focus and we shouldn't commit. |
| 265 return DestroyPreviewContents(); | 267 DestroyPreviewContents(); |
| 268 return; | |
| 266 } | 269 } |
| 267 | 270 |
| 268 if (IsShowingInstant()) { | 271 if (IsShowingInstant()) { |
| 269 // We're showing instant results. As instant results may shift when | 272 // We're showing instant results. As instant results may shift when |
| 270 // committing we commit on the mouse up. This way a slow click still | 273 // committing we commit on the mouse up. This way a slow click still |
| 271 // works fine. | 274 // works fine. |
| 272 return SetCommitOnMouseUp(); | 275 SetCommitOnMouseUp(); |
| 276 return; | |
| 273 } | 277 } |
| 274 | 278 |
| 275 return CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); | 279 CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); |
| 280 return; | |
|
sky
2010/11/17 00:02:35
no return here.
Jay Civelli
2010/11/17 00:11:08
We were returning previously, right?
sky
2010/11/17 00:15:03
My mistake, you're right.
| |
| 276 } | 281 } |
| 277 | 282 |
| 278 // Walk up the view hierarchy. If the view gaining focus is a subview of the | 283 // Walk up the view hierarchy. If the view gaining focus is a subview of the |
| 279 // TabContents view (such as a windowed plugin or http auth dialog), we want | 284 // TabContents view (such as a windowed plugin or http auth dialog), we want |
| 280 // to keep the preview contents. Otherwise, focus has gone somewhere else, | 285 // to keep the preview contents. Otherwise, focus has gone somewhere else, |
| 281 // such as the JS inspector, and we want to cancel the preview. | 286 // such as the JS inspector, and we want to cancel the preview. |
| 282 gfx::NativeView view_gaining_focus_ancestor = view_gaining_focus; | 287 gfx::NativeView view_gaining_focus_ancestor = view_gaining_focus; |
| 283 while (view_gaining_focus_ancestor && | 288 while (view_gaining_focus_ancestor && |
| 284 view_gaining_focus_ancestor != tab_view) { | 289 view_gaining_focus_ancestor != tab_view) { |
| 285 view_gaining_focus_ancestor = | 290 view_gaining_focus_ancestor = |
| 286 platform_util::GetParent(view_gaining_focus_ancestor); | 291 platform_util::GetParent(view_gaining_focus_ancestor); |
| 287 } | 292 } |
| 288 | 293 |
| 289 if (view_gaining_focus_ancestor) | 294 if (view_gaining_focus_ancestor) { |
| 290 return CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); | 295 CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); |
| 296 return; | |
| 297 } | |
| 291 | 298 |
| 292 return DestroyPreviewContents(); | 299 DestroyPreviewContents(); |
| 293 } | 300 } |
| 294 | 301 |
| 295 TabContents* InstantController::ReleasePreviewContents(InstantCommitType type) { | 302 TabContents* InstantController::ReleasePreviewContents(InstantCommitType type) { |
| 296 if (!loader_manager_.get()) | 303 if (!loader_manager_.get()) |
| 297 return NULL; | 304 return NULL; |
| 298 | 305 |
| 299 scoped_ptr<InstantLoader> loader(loader_manager_->ReleaseCurrentLoader()); | 306 scoped_ptr<InstantLoader> loader(loader_manager_->ReleaseCurrentLoader()); |
| 300 TabContents* tab = loader->ReleasePreviewContents(type); | 307 TabContents* tab = loader->ReleasePreviewContents(type); |
| 301 | 308 |
| 302 ClearBlacklist(); | 309 ClearBlacklist(); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 template_url = model ? model->GetDefaultSearchProvider() : NULL; | 509 template_url = model ? model->GetDefaultSearchProvider() : NULL; |
| 503 } | 510 } |
| 504 if (template_url && template_url->id() && | 511 if (template_url && template_url->id() && |
| 505 template_url->instant_url() && | 512 template_url->instant_url() && |
| 506 !IsBlacklistedFromInstant(template_url->id()) && | 513 !IsBlacklistedFromInstant(template_url->id()) && |
| 507 template_url->instant_url()->SupportsReplacement()) { | 514 template_url->instant_url()->SupportsReplacement()) { |
| 508 return template_url; | 515 return template_url; |
| 509 } | 516 } |
| 510 return NULL; | 517 return NULL; |
| 511 } | 518 } |
| OLD | NEW |