OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 25 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
27 #include "chrome/common/chrome_notification_types.h" | 27 #include "chrome/common/chrome_notification_types.h" |
28 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
30 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
31 #include "content/browser/renderer_host/render_widget_host_view.h" | 31 #include "content/browser/renderer_host/render_widget_host_view.h" |
32 #include "content/browser/tab_contents/tab_contents.h" | 32 #include "content/browser/tab_contents/tab_contents.h" |
33 #include "content/common/notification_service.h" | 33 #include "content/common/notification_service.h" |
34 | 34 |
| 35 #if defined(TOOLKIT_VIEWS) |
| 36 #include "views/focus/focus_manager.h" |
| 37 #include "views/view.h" |
| 38 #include "views/widget/widget.h" |
| 39 #endif |
| 40 |
35 namespace { | 41 namespace { |
36 | 42 |
37 // Number of ms to delay between loading urls. | 43 // Number of ms to delay between loading urls. |
38 const int kUpdateDelayMS = 200; | 44 const int kUpdateDelayMS = 200; |
39 | 45 |
40 // Amount of time we delay before showing pages that have a non-200 status. | 46 // Amount of time we delay before showing pages that have a non-200 status. |
41 const int kShowDelayMS = 800; | 47 const int kShowDelayMS = 800; |
42 | 48 |
43 bool IsBlacklistedUrl(const GURL& url) { | 49 bool IsBlacklistedUrl(const GURL& url) { |
44 for (int i = 0; i < chrome::kNumberOfChromeDebugURLs; ++i) { | 50 for (int i = 0; i < chrome::kNumberOfChromeDebugURLs; ++i) { |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 return; | 351 return; |
346 } | 352 } |
347 | 353 |
348 RenderWidgetHostView* rwhv = | 354 RenderWidgetHostView* rwhv = |
349 GetPreviewContents()->tab_contents()->GetRenderWidgetHostView(); | 355 GetPreviewContents()->tab_contents()->GetRenderWidgetHostView(); |
350 if (!view_gaining_focus || !rwhv) { | 356 if (!view_gaining_focus || !rwhv) { |
351 DestroyPreviewContents(); | 357 DestroyPreviewContents(); |
352 return; | 358 return; |
353 } | 359 } |
354 | 360 |
| 361 #if defined(TOOLKIT_VIEWS) |
| 362 // For views the top level widget is always focused. If the focus change |
| 363 // originated in views determine the child Widget from the view that is being |
| 364 // focused. |
| 365 if (view_gaining_focus) { |
| 366 views::Widget* widget = |
| 367 views::Widget::GetWidgetForNativeView(view_gaining_focus); |
| 368 if (widget) { |
| 369 views::FocusManager* focus_manager = widget->GetFocusManager(); |
| 370 if (focus_manager && focus_manager->is_changing_focus() && |
| 371 focus_manager->GetFocusedView() && |
| 372 focus_manager->GetFocusedView()->GetWidget()) { |
| 373 view_gaining_focus = |
| 374 focus_manager->GetFocusedView()->GetWidget()->GetNativeView(); |
| 375 } |
| 376 } |
| 377 } |
| 378 #endif |
| 379 |
355 gfx::NativeView tab_view = | 380 gfx::NativeView tab_view = |
356 GetPreviewContents()->tab_contents()->GetNativeView(); | 381 GetPreviewContents()->tab_contents()->GetNativeView(); |
357 // Focus is going to the renderer. | 382 // Focus is going to the renderer. |
358 if (rwhv->GetNativeView() == view_gaining_focus || | 383 if (rwhv->GetNativeView() == view_gaining_focus || |
359 tab_view == view_gaining_focus) { | 384 tab_view == view_gaining_focus) { |
360 if (!IsMouseDownFromActivate()) { | 385 if (!IsMouseDownFromActivate()) { |
361 // If the mouse is not down, focus is not going to the renderer. Someone | 386 // If the mouse is not down, focus is not going to the renderer. Someone |
362 // else moved focus and we shouldn't commit. | 387 // else moved focus and we shouldn't commit. |
363 DestroyPreviewContents(); | 388 DestroyPreviewContents(); |
364 return; | 389 return; |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 if (destroy_factory_.empty()) { | 787 if (destroy_factory_.empty()) { |
763 MessageLoop::current()->PostTask( | 788 MessageLoop::current()->PostTask( |
764 FROM_HERE, destroy_factory_.NewRunnableMethod( | 789 FROM_HERE, destroy_factory_.NewRunnableMethod( |
765 &InstantController::DestroyLoaders)); | 790 &InstantController::DestroyLoaders)); |
766 } | 791 } |
767 } | 792 } |
768 | 793 |
769 void InstantController::DestroyLoaders() { | 794 void InstantController::DestroyLoaders() { |
770 loaders_to_destroy_.reset(); | 795 loaders_to_destroy_.reset(); |
771 } | 796 } |
OLD | NEW |