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 "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 #include "ui/base/dragdrop/os_exchange_data.h" | 59 #include "ui/base/dragdrop/os_exchange_data.h" |
60 #include "ui/base/hit_test.h" | 60 #include "ui/base/hit_test.h" |
61 #include "ui/compositor/layer.h" | 61 #include "ui/compositor/layer.h" |
62 #include "ui/compositor/scoped_layer_animation_settings.h" | 62 #include "ui/compositor/scoped_layer_animation_settings.h" |
63 #include "ui/events/event.h" | 63 #include "ui/events/event.h" |
64 #include "ui/events/event_utils.h" | 64 #include "ui/events/event_utils.h" |
65 #include "ui/gfx/canvas.h" | 65 #include "ui/gfx/canvas.h" |
66 #include "ui/gfx/image/image.h" | 66 #include "ui/gfx/image/image.h" |
67 #include "ui/gfx/image/image_png_rep.h" | 67 #include "ui/gfx/image/image_png_rep.h" |
68 #include "ui/gfx/image/image_skia.h" | 68 #include "ui/gfx/image/image_skia.h" |
69 #include "ui/gfx/native_widget_types.h" | |
69 #include "ui/gfx/screen.h" | 70 #include "ui/gfx/screen.h" |
70 #include "ui/wm/public/drag_drop_client.h" | 71 #include "ui/wm/public/drag_drop_client.h" |
71 #include "ui/wm/public/drag_drop_delegate.h" | 72 #include "ui/wm/public/drag_drop_delegate.h" |
72 | 73 |
74 #if defined(OS_WIN) | |
75 #include "content/browser/accessibility/browser_accessibility_manager.h" | |
76 #include "content/browser/accessibility/browser_accessibility_win.h" | |
77 #include "ui/base/win/hidden_window.h" | |
78 #endif | |
79 | |
73 namespace content { | 80 namespace content { |
74 WebContentsView* CreateWebContentsView( | 81 WebContentsView* CreateWebContentsView( |
75 WebContentsImpl* web_contents, | 82 WebContentsImpl* web_contents, |
76 WebContentsViewDelegate* delegate, | 83 WebContentsViewDelegate* delegate, |
77 RenderViewHostDelegateView** render_view_host_delegate_view) { | 84 RenderViewHostDelegateView** render_view_host_delegate_view) { |
78 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); | 85 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); |
79 *render_view_host_delegate_view = rv; | 86 *render_view_host_delegate_view = rv; |
80 return rv; | 87 return rv; |
81 } | 88 } |
82 | 89 |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
626 host_window_ = NULL; | 633 host_window_ = NULL; |
627 } | 634 } |
628 } | 635 } |
629 | 636 |
630 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { | 637 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { |
631 if (window == view_->window_) { | 638 if (window == view_->window_) { |
632 window->GetHost()->AddObserver(this); | 639 window->GetHost()->AddObserver(this); |
633 #if defined(OS_WIN) | 640 #if defined(OS_WIN) |
634 if (!window->GetRootWindow()->HasObserver(this)) | 641 if (!window->GetRootWindow()->HasObserver(this)) |
635 window->GetRootWindow()->AddObserver(this); | 642 window->GetRootWindow()->AddObserver(this); |
643 view_->legacy_hwnd_->UpdateParent( | |
644 window->GetHost()->GetAcceleratedWidget()); | |
636 #endif | 645 #endif |
637 } | 646 } |
638 } | 647 } |
639 | 648 |
640 virtual void OnWindowRemovingFromRootWindow(aura::Window* window, | 649 virtual void OnWindowRemovingFromRootWindow(aura::Window* window, |
641 aura::Window* new_root) OVERRIDE { | 650 aura::Window* new_root) OVERRIDE { |
642 if (window == view_->window_) { | 651 if (window == view_->window_) { |
643 window->GetHost()->RemoveObserver(this); | 652 window->GetHost()->RemoveObserver(this); |
644 #if defined(OS_WIN) | 653 #if defined(OS_WIN) |
645 window->GetRootWindow()->RemoveObserver(this); | 654 window->GetRootWindow()->RemoveObserver(this); |
646 | 655 |
647 const aura::Window::Windows& root_children = | 656 const aura::Window::Windows& root_children = |
648 window->GetRootWindow()->children(); | 657 window->GetRootWindow()->children(); |
649 for (size_t i = 0; i < root_children.size(); ++i) { | 658 for (size_t i = 0; i < root_children.size(); ++i) { |
650 if (root_children[i] != view_->window_ && | 659 if (root_children[i] != view_->window_ && |
651 root_children[i] != host_window_) { | 660 root_children[i] != host_window_) { |
652 root_children[i]->RemoveObserver(this); | 661 root_children[i]->RemoveObserver(this); |
653 } | 662 } |
654 } | 663 } |
664 | |
665 // Update the legacy window's parent temporarily to the desktop window. | |
666 // It will eventually get reparented to the right root. | |
667 view_->legacy_hwnd_->UpdateParent(::GetDesktopWindow()); | |
655 #endif | 668 #endif |
656 } | 669 } |
657 } | 670 } |
658 | 671 |
659 // Overridden WindowTreeHostObserver: | 672 // Overridden WindowTreeHostObserver: |
660 virtual void OnHostMoved(const aura::WindowTreeHost* host, | 673 virtual void OnHostMoved(const aura::WindowTreeHost* host, |
661 const gfx::Point& new_origin) OVERRIDE { | 674 const gfx::Point& new_origin) OVERRIDE { |
662 TRACE_EVENT1("ui", | 675 TRACE_EVENT1("ui", |
663 "WebContentsViewAura::WindowObserver::OnHostMoved", | 676 "WebContentsViewAura::WindowObserver::OnHostMoved", |
664 "new_origin", new_origin.ToString()); | 677 "new_origin", new_origin.ToString()); |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
998 | 1011 |
999 void WebContentsViewAura::GetContainerBounds(gfx::Rect *out) const { | 1012 void WebContentsViewAura::GetContainerBounds(gfx::Rect *out) const { |
1000 *out = window_->GetBoundsInScreen(); | 1013 *out = window_->GetBoundsInScreen(); |
1001 } | 1014 } |
1002 | 1015 |
1003 void WebContentsViewAura::SizeContents(const gfx::Size& size) { | 1016 void WebContentsViewAura::SizeContents(const gfx::Size& size) { |
1004 gfx::Rect bounds = window_->bounds(); | 1017 gfx::Rect bounds = window_->bounds(); |
1005 if (bounds.size() != size) { | 1018 if (bounds.size() != size) { |
1006 bounds.set_size(size); | 1019 bounds.set_size(size); |
1007 window_->SetBounds(bounds); | 1020 window_->SetBounds(bounds); |
1021 legacy_hwnd_->SetBounds(window_->GetBoundsInRootWindow()); | |
1008 } else { | 1022 } else { |
1009 // Our size matches what we want but the renderers size may not match. | 1023 // Our size matches what we want but the renderers size may not match. |
1010 // Pretend we were resized so that the renderers size is updated too. | 1024 // Pretend we were resized so that the renderers size is updated too. |
1011 SizeChangedCommon(size); | 1025 SizeChangedCommon(size); |
1012 } | 1026 } |
1013 } | 1027 } |
1014 | 1028 |
1015 void WebContentsViewAura::Focus() { | 1029 void WebContentsViewAura::Focus() { |
1016 if (web_contents_->GetInterstitialPage()) { | 1030 if (web_contents_->GetInterstitialPage()) { |
1017 web_contents_->GetInterstitialPage()->Focus(); | 1031 web_contents_->GetInterstitialPage()->Focus(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1091 // 1) guests do not support NPAPI plugins. | 1105 // 1) guests do not support NPAPI plugins. |
1092 // 2) guests' window bounds are supposed to come from its embedder. | 1106 // 2) guests' window bounds are supposed to come from its embedder. |
1093 if (!BrowserPluginGuest::IsGuest(web_contents_)) | 1107 if (!BrowserPluginGuest::IsGuest(web_contents_)) |
1094 window_observer_.reset(new WindowObserver(this)); | 1108 window_observer_.reset(new WindowObserver(this)); |
1095 | 1109 |
1096 // delegate_->GetDragDestDelegate() creates a new delegate on every call. | 1110 // delegate_->GetDragDestDelegate() creates a new delegate on every call. |
1097 // Hence, we save a reference to it locally. Similar model is used on other | 1111 // Hence, we save a reference to it locally. Similar model is used on other |
1098 // platforms as well. | 1112 // platforms as well. |
1099 if (delegate_) | 1113 if (delegate_) |
1100 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); | 1114 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); |
1115 | |
1116 #if defined(OS_WIN) | |
1117 HWND parent_hwnd; | |
1118 if (context && context->GetHost()) | |
1119 parent_hwnd = context->GetHost()->GetAcceleratedWidget(); | |
1120 else | |
1121 parent_hwnd = ::GetDesktopWindow(); | |
ananta
2014/08/04 19:28:34
When would context or GetHost be NULL?
dmazzoni
2014/09/10 23:01:31
I'm not sure. Note that context is NULL-checked ea
| |
1122 legacy_hwnd_.reset(LegacyRenderWidgetHostHWND::Create(parent_hwnd, this)); | |
1123 #endif | |
1101 } | 1124 } |
1102 | 1125 |
1103 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForWidget( | 1126 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForWidget( |
1104 RenderWidgetHost* render_widget_host) { | 1127 RenderWidgetHost* render_widget_host) { |
1105 if (render_widget_host->GetView()) { | 1128 if (render_widget_host->GetView()) { |
1106 // During testing, the view will already be set up in most cases to the | 1129 // During testing, the view will already be set up in most cases to the |
1107 // test view, so we don't want to clobber it with a real one. To verify that | 1130 // test view, so we don't want to clobber it with a real one. To verify that |
1108 // this actually is happening (and somebody isn't accidentally creating the | 1131 // this actually is happening (and somebody isn't accidentally creating the |
1109 // view twice), we check for the RVH Factory, which will be set when we're | 1132 // view twice), we check for the RVH Factory, which will be set when we're |
1110 // making special ones (which go along with the special views). | 1133 // making special ones (which go along with the special views). |
(...skipping 20 matching lines...) Expand all Loading... | |
1131 // We listen to drag drop events in the newly created view's window. | 1154 // We listen to drag drop events in the newly created view's window. |
1132 aura::client::SetDragDropDelegate(view->GetNativeView(), this); | 1155 aura::client::SetDragDropDelegate(view->GetNativeView(), this); |
1133 | 1156 |
1134 if (view->overscroll_controller() && | 1157 if (view->overscroll_controller() && |
1135 (!web_contents_->GetDelegate() || | 1158 (!web_contents_->GetDelegate() || |
1136 web_contents_->GetDelegate()->CanOverscrollContent())) { | 1159 web_contents_->GetDelegate()->CanOverscrollContent())) { |
1137 InstallOverscrollControllerDelegate(view); | 1160 InstallOverscrollControllerDelegate(view); |
1138 } | 1161 } |
1139 | 1162 |
1140 AttachTouchEditableToRenderView(); | 1163 AttachTouchEditableToRenderView(); |
1164 | |
1165 #if defined(OS_WIN) | |
1166 view->SetLegacyRenderWidgetHostHWND(legacy_hwnd_.get()); | |
1167 #endif | |
1168 | |
1141 return view; | 1169 return view; |
1142 } | 1170 } |
1143 | 1171 |
1144 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForPopupWidget( | 1172 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForPopupWidget( |
1145 RenderWidgetHost* render_widget_host) { | 1173 RenderWidgetHost* render_widget_host) { |
1146 return new RenderWidgetHostViewAura(render_widget_host); | 1174 RenderWidgetHostViewAura* view = |
1175 new RenderWidgetHostViewAura(render_widget_host); | |
1176 #if defined(OS_WIN) | |
1177 view->SetLegacyRenderWidgetHostHWND(legacy_hwnd_.get()); | |
1178 #endif | |
1179 return view; | |
1147 } | 1180 } |
1148 | 1181 |
1149 void WebContentsViewAura::SetPageTitle(const base::string16& title) { | 1182 void WebContentsViewAura::SetPageTitle(const base::string16& title) { |
1150 window_->SetTitle(title); | 1183 window_->SetTitle(title); |
1151 } | 1184 } |
1152 | 1185 |
1153 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { | 1186 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { |
1154 } | 1187 } |
1155 | 1188 |
1156 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { | 1189 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1605 } | 1638 } |
1606 return; | 1639 return; |
1607 } | 1640 } |
1608 if (visible) { | 1641 if (visible) { |
1609 if (!web_contents_->should_normally_be_visible()) | 1642 if (!web_contents_->should_normally_be_visible()) |
1610 web_contents_->WasShown(); | 1643 web_contents_->WasShown(); |
1611 } else { | 1644 } else { |
1612 if (web_contents_->should_normally_be_visible()) | 1645 if (web_contents_->should_normally_be_visible()) |
1613 web_contents_->WasHidden(); | 1646 web_contents_->WasHidden(); |
1614 } | 1647 } |
1648 | |
1649 #if defined(OS_WIN) | |
1650 if (visible) { | |
1651 legacy_hwnd_->UpdateParent( | |
1652 GetNativeView()->GetHost()->GetAcceleratedWidget()); | |
1653 legacy_hwnd_->SetBounds(window_->GetBoundsInRootWindow()); | |
1654 legacy_hwnd_->Show(); | |
1655 } else { | |
1656 // We reparent the legacy Chrome_RenderWidgetHostHWND window to the global | |
1657 // hidden window on the same lines as Windowed plugin windows. | |
1658 legacy_hwnd_->UpdateParent(ui::GetHiddenWindow()); | |
1659 legacy_hwnd_->Hide(); | |
1660 } | |
1661 #endif | |
1615 } | 1662 } |
1616 | 1663 |
1664 #if defined(OS_WIN) | |
1665 gfx::NativeViewAccessible | |
1666 WebContentsViewAura::GetNativeViewAccessible() { | |
1667 BrowserAccessibilityManager* manager = | |
1668 web_contents_->GetRootBrowserAccessibilityManager(); | |
1669 if (!manager) | |
1670 return NULL; | |
1671 | |
1672 return manager->GetRoot()->ToBrowserAccessibilityWin(); | |
1673 } | |
1674 #endif | |
1675 | |
1617 } // namespace content | 1676 } // namespace content |
OLD | NEW |