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/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 #include "ui/base/dragdrop/os_exchange_data.h" | 60 #include "ui/base/dragdrop/os_exchange_data.h" |
61 #include "ui/base/hit_test.h" | 61 #include "ui/base/hit_test.h" |
62 #include "ui/compositor/layer.h" | 62 #include "ui/compositor/layer.h" |
63 #include "ui/compositor/scoped_layer_animation_settings.h" | 63 #include "ui/compositor/scoped_layer_animation_settings.h" |
64 #include "ui/events/event.h" | 64 #include "ui/events/event.h" |
65 #include "ui/events/event_utils.h" | 65 #include "ui/events/event_utils.h" |
66 #include "ui/gfx/canvas.h" | 66 #include "ui/gfx/canvas.h" |
67 #include "ui/gfx/image/image.h" | 67 #include "ui/gfx/image/image.h" |
68 #include "ui/gfx/image/image_png_rep.h" | 68 #include "ui/gfx/image/image_png_rep.h" |
69 #include "ui/gfx/image/image_skia.h" | 69 #include "ui/gfx/image/image_skia.h" |
70 #include "ui/gfx/native_widget_types.h" | |
70 #include "ui/gfx/screen.h" | 71 #include "ui/gfx/screen.h" |
71 #include "ui/wm/public/drag_drop_client.h" | 72 #include "ui/wm/public/drag_drop_client.h" |
72 #include "ui/wm/public/drag_drop_delegate.h" | 73 #include "ui/wm/public/drag_drop_delegate.h" |
73 | 74 |
75 #if defined(OS_WIN) | |
76 #include "content/browser/accessibility/browser_accessibility_manager.h" | |
77 #include "content/browser/accessibility/browser_accessibility_win.h" | |
78 #include "ui/base/win/hidden_window.h" | |
79 #endif | |
80 | |
74 namespace content { | 81 namespace content { |
75 WebContentsView* CreateWebContentsView( | 82 WebContentsView* CreateWebContentsView( |
76 WebContentsImpl* web_contents, | 83 WebContentsImpl* web_contents, |
77 WebContentsViewDelegate* delegate, | 84 WebContentsViewDelegate* delegate, |
78 RenderViewHostDelegateView** render_view_host_delegate_view) { | 85 RenderViewHostDelegateView** render_view_host_delegate_view) { |
79 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); | 86 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); |
80 *render_view_host_delegate_view = rv; | 87 *render_view_host_delegate_view = rv; |
81 return rv; | 88 return rv; |
82 } | 89 } |
83 | 90 |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 host_window_ = NULL; | 642 host_window_ = NULL; |
636 } | 643 } |
637 } | 644 } |
638 | 645 |
639 virtual void OnWindowAddedToRootWindow(aura::Window* window) override { | 646 virtual void OnWindowAddedToRootWindow(aura::Window* window) override { |
640 if (window == view_->window_) { | 647 if (window == view_->window_) { |
641 window->GetHost()->AddObserver(this); | 648 window->GetHost()->AddObserver(this); |
642 #if defined(OS_WIN) | 649 #if defined(OS_WIN) |
643 if (!window->GetRootWindow()->HasObserver(this)) | 650 if (!window->GetRootWindow()->HasObserver(this)) |
644 window->GetRootWindow()->AddObserver(this); | 651 window->GetRootWindow()->AddObserver(this); |
652 if (view_->legacy_hwnd_) { | |
653 view_->legacy_hwnd_->UpdateParent( | |
654 window->GetHost()->GetAcceleratedWidget()); | |
655 } | |
645 #endif | 656 #endif |
646 } | 657 } |
647 } | 658 } |
648 | 659 |
649 virtual void OnWindowRemovingFromRootWindow(aura::Window* window, | 660 virtual void OnWindowRemovingFromRootWindow(aura::Window* window, |
650 aura::Window* new_root) override { | 661 aura::Window* new_root) override { |
651 if (window == view_->window_) { | 662 if (window == view_->window_) { |
652 window->GetHost()->RemoveObserver(this); | 663 window->GetHost()->RemoveObserver(this); |
653 #if defined(OS_WIN) | 664 #if defined(OS_WIN) |
654 window->GetRootWindow()->RemoveObserver(this); | 665 window->GetRootWindow()->RemoveObserver(this); |
655 | 666 |
656 const aura::Window::Windows& root_children = | 667 const aura::Window::Windows& root_children = |
657 window->GetRootWindow()->children(); | 668 window->GetRootWindow()->children(); |
658 for (size_t i = 0; i < root_children.size(); ++i) { | 669 for (size_t i = 0; i < root_children.size(); ++i) { |
659 if (root_children[i] != view_->window_ && | 670 if (root_children[i] != view_->window_ && |
660 root_children[i] != host_window_) { | 671 root_children[i] != host_window_) { |
661 root_children[i]->RemoveObserver(this); | 672 root_children[i]->RemoveObserver(this); |
662 } | 673 } |
663 } | 674 } |
675 | |
676 if (view_->legacy_hwnd_) | |
677 view_->legacy_hwnd_->UpdateParent(ui::GetHiddenWindow()); | |
664 #endif | 678 #endif |
665 } | 679 } |
666 } | 680 } |
667 | 681 |
668 // Overridden WindowTreeHostObserver: | 682 // Overridden WindowTreeHostObserver: |
669 virtual void OnHostMoved(const aura::WindowTreeHost* host, | 683 virtual void OnHostMoved(const aura::WindowTreeHost* host, |
670 const gfx::Point& new_origin) override { | 684 const gfx::Point& new_origin) override { |
671 TRACE_EVENT1("ui", | 685 TRACE_EVENT1("ui", |
672 "WebContentsViewAura::WindowObserver::OnHostMoved", | 686 "WebContentsViewAura::WindowObserver::OnHostMoved", |
673 "new_origin", new_origin.ToString()); | 687 "new_origin", new_origin.ToString()); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1010 | 1024 |
1011 void WebContentsViewAura::GetContainerBounds(gfx::Rect *out) const { | 1025 void WebContentsViewAura::GetContainerBounds(gfx::Rect *out) const { |
1012 *out = window_->GetBoundsInScreen(); | 1026 *out = window_->GetBoundsInScreen(); |
1013 } | 1027 } |
1014 | 1028 |
1015 void WebContentsViewAura::SizeContents(const gfx::Size& size) { | 1029 void WebContentsViewAura::SizeContents(const gfx::Size& size) { |
1016 gfx::Rect bounds = window_->bounds(); | 1030 gfx::Rect bounds = window_->bounds(); |
1017 if (bounds.size() != size) { | 1031 if (bounds.size() != size) { |
1018 bounds.set_size(size); | 1032 bounds.set_size(size); |
1019 window_->SetBounds(bounds); | 1033 window_->SetBounds(bounds); |
1034 #if defined(OS_WIN) | |
1035 if (legacy_hwnd_) | |
1036 legacy_hwnd_->SetBounds(window_->GetBoundsInRootWindow()); | |
1037 #endif | |
1020 } else { | 1038 } else { |
1021 // Our size matches what we want but the renderers size may not match. | 1039 // Our size matches what we want but the renderers size may not match. |
1022 // Pretend we were resized so that the renderers size is updated too. | 1040 // Pretend we were resized so that the renderers size is updated too. |
1023 SizeChangedCommon(size); | 1041 SizeChangedCommon(size); |
1024 } | 1042 } |
1025 } | 1043 } |
1026 | 1044 |
1027 void WebContentsViewAura::Focus() { | 1045 void WebContentsViewAura::Focus() { |
1028 if (web_contents_->GetInterstitialPage()) { | 1046 if (web_contents_->GetInterstitialPage()) { |
1029 web_contents_->GetInterstitialPage()->Focus(); | 1047 web_contents_->GetInterstitialPage()->Focus(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1103 // 1) guests do not support NPAPI plugins. | 1121 // 1) guests do not support NPAPI plugins. |
1104 // 2) guests' window bounds are supposed to come from its embedder. | 1122 // 2) guests' window bounds are supposed to come from its embedder. |
1105 if (!BrowserPluginGuest::IsGuest(web_contents_)) | 1123 if (!BrowserPluginGuest::IsGuest(web_contents_)) |
1106 window_observer_.reset(new WindowObserver(this)); | 1124 window_observer_.reset(new WindowObserver(this)); |
1107 | 1125 |
1108 // delegate_->GetDragDestDelegate() creates a new delegate on every call. | 1126 // delegate_->GetDragDestDelegate() creates a new delegate on every call. |
1109 // Hence, we save a reference to it locally. Similar model is used on other | 1127 // Hence, we save a reference to it locally. Similar model is used on other |
1110 // platforms as well. | 1128 // platforms as well. |
1111 if (delegate_) | 1129 if (delegate_) |
1112 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); | 1130 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); |
1131 | |
1132 #if defined(OS_WIN) | |
1133 if (context && context->GetHost()) { | |
1134 HWND parent_hwnd = context->GetHost()->GetAcceleratedWidget(); | |
1135 CHECK(parent_hwnd); | |
1136 legacy_hwnd_.reset(LegacyRenderWidgetHostHWND::Create(parent_hwnd, this)); | |
1137 } | |
1138 #endif | |
1113 } | 1139 } |
1114 | 1140 |
1115 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForWidget( | 1141 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForWidget( |
1116 RenderWidgetHost* render_widget_host, bool is_guest_view_hack) { | 1142 RenderWidgetHost* render_widget_host, bool is_guest_view_hack) { |
1117 if (render_widget_host->GetView()) { | 1143 if (render_widget_host->GetView()) { |
1118 // During testing, the view will already be set up in most cases to the | 1144 // During testing, the view will already be set up in most cases to the |
1119 // test view, so we don't want to clobber it with a real one. To verify that | 1145 // test view, so we don't want to clobber it with a real one. To verify that |
1120 // this actually is happening (and somebody isn't accidentally creating the | 1146 // this actually is happening (and somebody isn't accidentally creating the |
1121 // view twice), we check for the RVH Factory, which will be set when we're | 1147 // view twice), we check for the RVH Factory, which will be set when we're |
1122 // making special ones (which go along with the special views). | 1148 // making special ones (which go along with the special views). |
(...skipping 20 matching lines...) Expand all Loading... | |
1143 // We listen to drag drop events in the newly created view's window. | 1169 // We listen to drag drop events in the newly created view's window. |
1144 aura::client::SetDragDropDelegate(view->GetNativeView(), this); | 1170 aura::client::SetDragDropDelegate(view->GetNativeView(), this); |
1145 | 1171 |
1146 if (view->overscroll_controller() && | 1172 if (view->overscroll_controller() && |
1147 (!web_contents_->GetDelegate() || | 1173 (!web_contents_->GetDelegate() || |
1148 web_contents_->GetDelegate()->CanOverscrollContent())) { | 1174 web_contents_->GetDelegate()->CanOverscrollContent())) { |
1149 InstallOverscrollControllerDelegate(view); | 1175 InstallOverscrollControllerDelegate(view); |
1150 } | 1176 } |
1151 | 1177 |
1152 AttachTouchEditableToRenderView(); | 1178 AttachTouchEditableToRenderView(); |
1179 | |
1180 #if defined(OS_WIN) | |
1181 if (legacy_hwnd_) | |
1182 view->SetLegacyRenderWidgetHostHWND(legacy_hwnd_.get()); | |
1183 #endif | |
1184 | |
1153 return view; | 1185 return view; |
1154 } | 1186 } |
1155 | 1187 |
1156 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForPopupWidget( | 1188 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForPopupWidget( |
1157 RenderWidgetHost* render_widget_host) { | 1189 RenderWidgetHost* render_widget_host) { |
1158 return new RenderWidgetHostViewAura(render_widget_host, false); | 1190 RenderWidgetHostViewAura* view = |
1191 new RenderWidgetHostViewAura(render_widget_host, false); | |
1192 #if defined(OS_WIN) | |
1193 if (legacy_hwnd_) | |
1194 view->SetLegacyRenderWidgetHostHWND(legacy_hwnd_.get()); | |
1195 #endif | |
1196 return view; | |
1159 } | 1197 } |
1160 | 1198 |
1161 void WebContentsViewAura::SetPageTitle(const base::string16& title) { | 1199 void WebContentsViewAura::SetPageTitle(const base::string16& title) { |
1162 window_->SetTitle(title); | 1200 window_->SetTitle(title); |
1163 } | 1201 } |
1164 | 1202 |
1165 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { | 1203 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { |
1166 } | 1204 } |
1167 | 1205 |
1168 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { | 1206 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1628 } | 1666 } |
1629 return; | 1667 return; |
1630 } | 1668 } |
1631 if (visible) { | 1669 if (visible) { |
1632 if (!web_contents_->should_normally_be_visible()) | 1670 if (!web_contents_->should_normally_be_visible()) |
1633 web_contents_->WasShown(); | 1671 web_contents_->WasShown(); |
1634 } else { | 1672 } else { |
1635 if (web_contents_->should_normally_be_visible()) | 1673 if (web_contents_->should_normally_be_visible()) |
1636 web_contents_->WasHidden(); | 1674 web_contents_->WasHidden(); |
1637 } | 1675 } |
1676 | |
1677 #if defined(OS_WIN) | |
1678 if (!legacy_hwnd_) | |
1679 return; | |
1680 | |
1681 if (visible && GetNativeView() && GetNativeView()->GetHost()) { | |
1682 legacy_hwnd_->UpdateParent( | |
1683 GetNativeView()->GetHost()->GetAcceleratedWidget()); | |
1684 legacy_hwnd_->SetBounds(window_->GetBoundsInRootWindow()); | |
1685 legacy_hwnd_->Show(); | |
1686 } else { | |
1687 // We reparent the legacy Chrome_RenderWidgetHostHWND window to the global | |
1688 // hidden window on the same lines as Windowed plugin windows. | |
1689 legacy_hwnd_->UpdateParent(ui::GetHiddenWindow()); | |
1690 legacy_hwnd_->Hide(); | |
1691 } | |
1692 #endif | |
1638 } | 1693 } |
1639 | 1694 |
1695 #if defined(OS_WIN) | |
1696 gfx::NativeViewAccessible | |
1697 WebContentsViewAura::GetNativeViewAccessible() { | |
1698 BrowserAccessibilityManager* manager = | |
1699 web_contents_->GetRootBrowserAccessibilityManager(); | |
1700 if (!manager) | |
1701 return NULL; | |
sky
2014/10/27 15:21:33
nullptr
dmazzoni
2014/10/27 20:32:32
Done.
| |
1702 | |
1703 return manager->GetRoot()->ToBrowserAccessibilityWin(); | |
1704 } | |
1705 #endif | |
1706 | |
1640 } // namespace content | 1707 } // namespace content |
OLD | NEW |