OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "content/browser/web_contents/web_contents_view_aura.h" | 5 #include "content/browser/web_contents/web_contents_view_aura.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 #include "ui/base/dragdrop/os_exchange_data.h" | 62 #include "ui/base/dragdrop/os_exchange_data.h" |
63 #include "ui/base/hit_test.h" | 63 #include "ui/base/hit_test.h" |
64 #include "ui/compositor/layer.h" | 64 #include "ui/compositor/layer.h" |
65 #include "ui/display/screen.h" | 65 #include "ui/display/screen.h" |
66 #include "ui/events/event.h" | 66 #include "ui/events/event.h" |
67 #include "ui/events/event_utils.h" | 67 #include "ui/events/event_utils.h" |
68 #include "ui/gfx/canvas.h" | 68 #include "ui/gfx/canvas.h" |
69 #include "ui/gfx/image/image.h" | 69 #include "ui/gfx/image/image.h" |
70 #include "ui/gfx/image/image_png_rep.h" | 70 #include "ui/gfx/image/image_png_rep.h" |
71 #include "ui/gfx/image/image_skia.h" | 71 #include "ui/gfx/image/image_skia.h" |
72 #include "ui/touch_selection/touch_selection_controller.h" | 72 #include "ui/gfx/native_widget_types.h" |
| 73 |
73 #include "ui/wm/public/drag_drop_client.h" | 74 #include "ui/wm/public/drag_drop_client.h" |
74 #include "ui/wm/public/drag_drop_delegate.h" | 75 #include "ui/wm/public/drag_drop_delegate.h" |
75 | 76 |
| 77 #if defined(OS_WIN) |
| 78 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 79 #include "content/browser/accessibility/browser_accessibility_win.h" |
| 80 #include "ui/base/win/hidden_window.h" |
| 81 #endif |
| 82 |
76 namespace content { | 83 namespace content { |
77 WebContentsView* CreateWebContentsView( | 84 WebContentsView* CreateWebContentsView( |
78 WebContentsImpl* web_contents, | 85 WebContentsImpl* web_contents, |
79 WebContentsViewDelegate* delegate, | 86 WebContentsViewDelegate* delegate, |
80 RenderViewHostDelegateView** render_view_host_delegate_view) { | 87 RenderViewHostDelegateView** render_view_host_delegate_view) { |
81 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); | 88 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); |
82 *render_view_host_delegate_view = rv; | 89 *render_view_host_delegate_view = rv; |
83 return rv; | 90 return rv; |
84 } | 91 } |
85 | 92 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 } | 457 } |
451 | 458 |
452 void OnWindowDestroying(aura::Window* window) override { | 459 void OnWindowDestroying(aura::Window* window) override { |
453 if (window == host_window_) { | 460 if (window == host_window_) { |
454 host_window_->RemoveObserver(this); | 461 host_window_->RemoveObserver(this); |
455 host_window_ = NULL; | 462 host_window_ = NULL; |
456 } | 463 } |
457 } | 464 } |
458 | 465 |
459 void OnWindowAddedToRootWindow(aura::Window* window) override { | 466 void OnWindowAddedToRootWindow(aura::Window* window) override { |
460 if (window == view_->window_.get()) | 467 if (window == view_->window_.get()) { |
461 window->GetHost()->AddObserver(this); | 468 window->GetHost()->AddObserver(this); |
| 469 #if defined(OS_WIN) |
| 470 if (view_->legacy_hwnd_) { |
| 471 view_->legacy_hwnd_->UpdateParent( |
| 472 window->GetHost()->GetAcceleratedWidget()); |
| 473 } |
| 474 #endif |
| 475 } |
462 } | 476 } |
463 | 477 |
464 void OnWindowRemovingFromRootWindow(aura::Window* window, | 478 void OnWindowRemovingFromRootWindow(aura::Window* window, |
465 aura::Window* new_root) override { | 479 aura::Window* new_root) override { |
466 if (window == view_->window_.get()) | 480 if (window == view_->window_.get()) { |
467 window->GetHost()->RemoveObserver(this); | 481 window->GetHost()->RemoveObserver(this); |
| 482 #if defined(OS_WIN) |
| 483 if (view_->legacy_hwnd_) |
| 484 view_->legacy_hwnd_->UpdateParent(ui::GetHiddenWindow()); |
| 485 #endif |
| 486 } |
468 } | 487 } |
469 | 488 |
470 // Overridden WindowTreeHostObserver: | 489 // Overridden WindowTreeHostObserver: |
471 void OnHostMoved(const aura::WindowTreeHost* host, | 490 void OnHostMoved(const aura::WindowTreeHost* host, |
472 const gfx::Point& new_origin) override { | 491 const gfx::Point& new_origin) override { |
473 TRACE_EVENT1("ui", | 492 TRACE_EVENT1("ui", |
474 "WebContentsViewAura::WindowObserver::OnHostMoved", | 493 "WebContentsViewAura::WindowObserver::OnHostMoved", |
475 "new_origin", new_origin.ToString()); | 494 "new_origin", new_origin.ToString()); |
476 | 495 |
477 // This is for the desktop case (i.e. Aura desktop). | 496 // This is for the desktop case (i.e. Aura desktop). |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 | 638 |
620 void WebContentsViewAura::GetContainerBounds(gfx::Rect *out) const { | 639 void WebContentsViewAura::GetContainerBounds(gfx::Rect *out) const { |
621 *out = window_->GetBoundsInScreen(); | 640 *out = window_->GetBoundsInScreen(); |
622 } | 641 } |
623 | 642 |
624 void WebContentsViewAura::SizeContents(const gfx::Size& size) { | 643 void WebContentsViewAura::SizeContents(const gfx::Size& size) { |
625 gfx::Rect bounds = window_->bounds(); | 644 gfx::Rect bounds = window_->bounds(); |
626 if (bounds.size() != size) { | 645 if (bounds.size() != size) { |
627 bounds.set_size(size); | 646 bounds.set_size(size); |
628 window_->SetBounds(bounds); | 647 window_->SetBounds(bounds); |
| 648 #if defined(OS_WIN) |
| 649 if (legacy_hwnd_) |
| 650 legacy_hwnd_->SetBounds(window_->GetBoundsInRootWindow()); |
| 651 #endif |
629 } else { | 652 } else { |
630 // Our size matches what we want but the renderers size may not match. | 653 // Our size matches what we want but the renderers size may not match. |
631 // Pretend we were resized so that the renderers size is updated too. | 654 // Pretend we were resized so that the renderers size is updated too. |
632 SizeChangedCommon(size); | 655 SizeChangedCommon(size); |
633 } | 656 } |
634 } | 657 } |
635 | 658 |
636 void WebContentsViewAura::Focus() { | 659 void WebContentsViewAura::Focus() { |
637 if (web_contents_->GetInterstitialPage()) { | 660 if (web_contents_->GetInterstitialPage()) { |
638 web_contents_->GetInterstitialPage()->Focus(); | 661 web_contents_->GetInterstitialPage()->Focus(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 // 1) guests do not support NPAPI plugins. | 735 // 1) guests do not support NPAPI plugins. |
713 // 2) guests' window bounds are supposed to come from its embedder. | 736 // 2) guests' window bounds are supposed to come from its embedder. |
714 if (!BrowserPluginGuest::IsGuest(web_contents_)) | 737 if (!BrowserPluginGuest::IsGuest(web_contents_)) |
715 window_observer_.reset(new WindowObserver(this)); | 738 window_observer_.reset(new WindowObserver(this)); |
716 | 739 |
717 // delegate_->GetDragDestDelegate() creates a new delegate on every call. | 740 // delegate_->GetDragDestDelegate() creates a new delegate on every call. |
718 // Hence, we save a reference to it locally. Similar model is used on other | 741 // Hence, we save a reference to it locally. Similar model is used on other |
719 // platforms as well. | 742 // platforms as well. |
720 if (delegate_) | 743 if (delegate_) |
721 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); | 744 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); |
| 745 |
| 746 #if defined(OS_WIN) |
| 747 if (context && context->GetHost()) { |
| 748 HWND parent_hwnd = context->GetHost()->GetAcceleratedWidget(); |
| 749 CHECK(parent_hwnd); |
| 750 legacy_hwnd_.reset(LegacyRenderWidgetHostHWND::Create(parent_hwnd, this)); |
| 751 } |
| 752 #endif |
722 } | 753 } |
723 | 754 |
724 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForWidget( | 755 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForWidget( |
725 RenderWidgetHost* render_widget_host, bool is_guest_view_hack) { | 756 RenderWidgetHost* render_widget_host, bool is_guest_view_hack) { |
726 if (render_widget_host->GetView()) { | 757 if (render_widget_host->GetView()) { |
727 // During testing, the view will already be set up in most cases to the | 758 // During testing, the view will already be set up in most cases to the |
728 // test view, so we don't want to clobber it with a real one. To verify that | 759 // test view, so we don't want to clobber it with a real one. To verify that |
729 // this actually is happening (and somebody isn't accidentally creating the | 760 // this actually is happening (and somebody isn't accidentally creating the |
730 // view twice), we check for the RVH Factory, which will be set when we're | 761 // view twice), we check for the RVH Factory, which will be set when we're |
731 // making special ones (which go along with the special views). | 762 // making special ones (which go along with the special views). |
(...skipping 14 matching lines...) Expand all Loading... |
746 | 777 |
747 // We listen to drag drop events in the newly created view's window. | 778 // We listen to drag drop events in the newly created view's window. |
748 aura::client::SetDragDropDelegate(view->GetNativeView(), this); | 779 aura::client::SetDragDropDelegate(view->GetNativeView(), this); |
749 | 780 |
750 if (view->overscroll_controller() && | 781 if (view->overscroll_controller() && |
751 (!web_contents_->GetDelegate() || | 782 (!web_contents_->GetDelegate() || |
752 web_contents_->GetDelegate()->CanOverscrollContent())) { | 783 web_contents_->GetDelegate()->CanOverscrollContent())) { |
753 InstallOverscrollControllerDelegate(view); | 784 InstallOverscrollControllerDelegate(view); |
754 } | 785 } |
755 | 786 |
| 787 #if defined(OS_WIN) |
| 788 if (legacy_hwnd_) |
| 789 view->SetLegacyRenderWidgetHostHWND(legacy_hwnd_.get()); |
| 790 #endif |
| 791 |
756 return view; | 792 return view; |
757 } | 793 } |
758 | 794 |
759 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForPopupWidget( | 795 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForPopupWidget( |
760 RenderWidgetHost* render_widget_host) { | 796 RenderWidgetHost* render_widget_host) { |
761 return new RenderWidgetHostViewAura(render_widget_host, false); | 797 RenderWidgetHostViewAura* view = |
| 798 new RenderWidgetHostViewAura(render_widget_host, false); |
| 799 #if defined(OS_WIN) |
| 800 if (legacy_hwnd_) |
| 801 view->SetLegacyRenderWidgetHostHWND(legacy_hwnd_.get()); |
| 802 #endif |
| 803 return view; |
762 } | 804 } |
763 | 805 |
764 void WebContentsViewAura::SetPageTitle(const base::string16& title) { | 806 void WebContentsViewAura::SetPageTitle(const base::string16& title) { |
765 window_->SetTitle(title); | 807 window_->SetTitle(title); |
766 } | 808 } |
767 | 809 |
768 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { | 810 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { |
769 } | 811 } |
770 | 812 |
771 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { | 813 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 return ConvertFromWeb(current_drag_op_); | 1160 return ConvertFromWeb(current_drag_op_); |
1119 } | 1161 } |
1120 | 1162 |
1121 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window, | 1163 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window, |
1122 bool visible) { | 1164 bool visible) { |
1123 // Ignore any visibility changes in the hierarchy below. | 1165 // Ignore any visibility changes in the hierarchy below. |
1124 if (window != window_.get() && window_->Contains(window)) | 1166 if (window != window_.get() && window_->Contains(window)) |
1125 return; | 1167 return; |
1126 | 1168 |
1127 web_contents_->UpdateWebContentsVisibility(visible); | 1169 web_contents_->UpdateWebContentsVisibility(visible); |
| 1170 |
| 1171 #if defined(OS_WIN) |
| 1172 if (!legacy_hwnd_) |
| 1173 return; |
| 1174 |
| 1175 if (visible && GetNativeView() && GetNativeView()->GetHost()) { |
| 1176 legacy_hwnd_->UpdateParent( |
| 1177 GetNativeView()->GetHost()->GetAcceleratedWidget()); |
| 1178 legacy_hwnd_->SetBounds(window_->GetBoundsInRootWindow()); |
| 1179 legacy_hwnd_->Show(); |
| 1180 } else { |
| 1181 // We reparent the legacy Chrome_RenderWidgetHostHWND window to the global |
| 1182 // hidden window on the same lines as Windowed plugin windows. |
| 1183 legacy_hwnd_->UpdateParent(ui::GetHiddenWindow()); |
| 1184 legacy_hwnd_->Hide(); |
| 1185 } |
| 1186 #endif |
1128 } | 1187 } |
1129 | 1188 |
| 1189 #if defined(OS_WIN) |
| 1190 gfx::NativeViewAccessible |
| 1191 WebContentsViewAura::GetNativeViewAccessible() { |
| 1192 BrowserAccessibilityManager* manager = |
| 1193 web_contents_->GetRootBrowserAccessibilityManager(); |
| 1194 if (!manager) |
| 1195 return nullptr; |
| 1196 |
| 1197 return ToBrowserAccessibilityWin(manager->GetRoot()); |
| 1198 } |
| 1199 #endif |
| 1200 |
1130 } // namespace content | 1201 } // namespace content |
OLD | NEW |