Chromium Code Reviews| 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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1007 | 1021 |
| 1008 void WebContentsViewAura::GetContainerBounds(gfx::Rect *out) const { | 1022 void WebContentsViewAura::GetContainerBounds(gfx::Rect *out) const { |
| 1009 *out = window_->GetBoundsInScreen(); | 1023 *out = window_->GetBoundsInScreen(); |
| 1010 } | 1024 } |
| 1011 | 1025 |
| 1012 void WebContentsViewAura::SizeContents(const gfx::Size& size) { | 1026 void WebContentsViewAura::SizeContents(const gfx::Size& size) { |
| 1013 gfx::Rect bounds = window_->bounds(); | 1027 gfx::Rect bounds = window_->bounds(); |
| 1014 if (bounds.size() != size) { | 1028 if (bounds.size() != size) { |
| 1015 bounds.set_size(size); | 1029 bounds.set_size(size); |
| 1016 window_->SetBounds(bounds); | 1030 window_->SetBounds(bounds); |
| 1031 #if defined(OS_WIN) | |
| 1032 if (legacy_hwnd_) | |
| 1033 legacy_hwnd_->SetBounds(window_->GetBoundsInRootWindow()); | |
| 1034 #endif | |
| 1017 } else { | 1035 } else { |
| 1018 // Our size matches what we want but the renderers size may not match. | 1036 // Our size matches what we want but the renderers size may not match. |
| 1019 // Pretend we were resized so that the renderers size is updated too. | 1037 // Pretend we were resized so that the renderers size is updated too. |
| 1020 SizeChangedCommon(size); | 1038 SizeChangedCommon(size); |
| 1021 } | 1039 } |
| 1022 } | 1040 } |
| 1023 | 1041 |
| 1024 void WebContentsViewAura::Focus() { | 1042 void WebContentsViewAura::Focus() { |
| 1025 if (web_contents_->GetInterstitialPage()) { | 1043 if (web_contents_->GetInterstitialPage()) { |
| 1026 web_contents_->GetInterstitialPage()->Focus(); | 1044 web_contents_->GetInterstitialPage()->Focus(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1100 // 1) guests do not support NPAPI plugins. | 1118 // 1) guests do not support NPAPI plugins. |
| 1101 // 2) guests' window bounds are supposed to come from its embedder. | 1119 // 2) guests' window bounds are supposed to come from its embedder. |
| 1102 if (!BrowserPluginGuest::IsGuest(web_contents_)) | 1120 if (!BrowserPluginGuest::IsGuest(web_contents_)) |
| 1103 window_observer_.reset(new WindowObserver(this)); | 1121 window_observer_.reset(new WindowObserver(this)); |
| 1104 | 1122 |
| 1105 // delegate_->GetDragDestDelegate() creates a new delegate on every call. | 1123 // delegate_->GetDragDestDelegate() creates a new delegate on every call. |
| 1106 // Hence, we save a reference to it locally. Similar model is used on other | 1124 // Hence, we save a reference to it locally. Similar model is used on other |
| 1107 // platforms as well. | 1125 // platforms as well. |
| 1108 if (delegate_) | 1126 if (delegate_) |
| 1109 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); | 1127 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); |
| 1128 | |
| 1129 #if defined(OS_WIN) | |
| 1130 if (context && context->GetHost()) { | |
| 1131 HWND parent_hwnd = context->GetHost()->GetAcceleratedWidget(); | |
| 1132 legacy_hwnd_.reset(LegacyRenderWidgetHostHWND::Create(parent_hwnd, this)); | |
| 1133 } | |
| 1134 #endif | |
| 1110 } | 1135 } |
| 1111 | 1136 |
| 1112 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForWidget( | 1137 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForWidget( |
| 1113 RenderWidgetHost* render_widget_host) { | 1138 RenderWidgetHost* render_widget_host) { |
| 1114 if (render_widget_host->GetView()) { | 1139 if (render_widget_host->GetView()) { |
| 1115 // During testing, the view will already be set up in most cases to the | 1140 // During testing, the view will already be set up in most cases to the |
| 1116 // test view, so we don't want to clobber it with a real one. To verify that | 1141 // test view, so we don't want to clobber it with a real one. To verify that |
| 1117 // this actually is happening (and somebody isn't accidentally creating the | 1142 // this actually is happening (and somebody isn't accidentally creating the |
| 1118 // view twice), we check for the RVH Factory, which will be set when we're | 1143 // view twice), we check for the RVH Factory, which will be set when we're |
| 1119 // making special ones (which go along with the special views). | 1144 // making special ones (which go along with the special views). |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1140 // We listen to drag drop events in the newly created view's window. | 1165 // We listen to drag drop events in the newly created view's window. |
| 1141 aura::client::SetDragDropDelegate(view->GetNativeView(), this); | 1166 aura::client::SetDragDropDelegate(view->GetNativeView(), this); |
| 1142 | 1167 |
| 1143 if (view->overscroll_controller() && | 1168 if (view->overscroll_controller() && |
| 1144 (!web_contents_->GetDelegate() || | 1169 (!web_contents_->GetDelegate() || |
| 1145 web_contents_->GetDelegate()->CanOverscrollContent())) { | 1170 web_contents_->GetDelegate()->CanOverscrollContent())) { |
| 1146 InstallOverscrollControllerDelegate(view); | 1171 InstallOverscrollControllerDelegate(view); |
| 1147 } | 1172 } |
| 1148 | 1173 |
| 1149 AttachTouchEditableToRenderView(); | 1174 AttachTouchEditableToRenderView(); |
| 1175 | |
| 1176 #if defined(OS_WIN) | |
| 1177 view->SetLegacyRenderWidgetHostHWND(legacy_hwnd_.get()); | |
|
ananta
2014/10/17 23:58:00
if (legacy_hwnd_) here and below?
dmazzoni
2014/10/21 20:42:00
Good idea. I guess it was harmless before because
| |
| 1178 #endif | |
| 1179 | |
| 1150 return view; | 1180 return view; |
| 1151 } | 1181 } |
| 1152 | 1182 |
| 1153 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForPopupWidget( | 1183 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForPopupWidget( |
| 1154 RenderWidgetHost* render_widget_host) { | 1184 RenderWidgetHost* render_widget_host) { |
| 1155 return new RenderWidgetHostViewAura(render_widget_host); | 1185 RenderWidgetHostViewAura* view = |
| 1186 new RenderWidgetHostViewAura(render_widget_host); | |
| 1187 #if defined(OS_WIN) | |
| 1188 view->SetLegacyRenderWidgetHostHWND(legacy_hwnd_.get()); | |
| 1189 #endif | |
| 1190 return view; | |
| 1156 } | 1191 } |
| 1157 | 1192 |
| 1158 void WebContentsViewAura::SetPageTitle(const base::string16& title) { | 1193 void WebContentsViewAura::SetPageTitle(const base::string16& title) { |
| 1159 window_->SetTitle(title); | 1194 window_->SetTitle(title); |
| 1160 } | 1195 } |
| 1161 | 1196 |
| 1162 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { | 1197 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { |
| 1163 } | 1198 } |
| 1164 | 1199 |
| 1165 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { | 1200 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1625 } | 1660 } |
| 1626 return; | 1661 return; |
| 1627 } | 1662 } |
| 1628 if (visible) { | 1663 if (visible) { |
| 1629 if (!web_contents_->should_normally_be_visible()) | 1664 if (!web_contents_->should_normally_be_visible()) |
| 1630 web_contents_->WasShown(); | 1665 web_contents_->WasShown(); |
| 1631 } else { | 1666 } else { |
| 1632 if (web_contents_->should_normally_be_visible()) | 1667 if (web_contents_->should_normally_be_visible()) |
| 1633 web_contents_->WasHidden(); | 1668 web_contents_->WasHidden(); |
| 1634 } | 1669 } |
| 1670 | |
| 1671 #if defined(OS_WIN) | |
| 1672 if (!legacy_hwnd_) | |
| 1673 return; | |
| 1674 | |
| 1675 if (visible && GetNativeView() && GetNativeView()->GetHost()) { | |
| 1676 legacy_hwnd_->UpdateParent( | |
| 1677 GetNativeView()->GetHost()->GetAcceleratedWidget()); | |
| 1678 legacy_hwnd_->SetBounds(window_->GetBoundsInRootWindow()); | |
| 1679 legacy_hwnd_->Show(); | |
| 1680 } else { | |
| 1681 // We reparent the legacy Chrome_RenderWidgetHostHWND window to the global | |
| 1682 // hidden window on the same lines as Windowed plugin windows. | |
| 1683 legacy_hwnd_->UpdateParent(ui::GetHiddenWindow()); | |
| 1684 legacy_hwnd_->Hide(); | |
| 1685 } | |
| 1686 #endif | |
| 1635 } | 1687 } |
| 1636 | 1688 |
| 1689 #if defined(OS_WIN) | |
| 1690 gfx::NativeViewAccessible | |
| 1691 WebContentsViewAura::GetNativeViewAccessible() { | |
| 1692 BrowserAccessibilityManager* manager = | |
| 1693 web_contents_->GetRootBrowserAccessibilityManager(); | |
| 1694 if (!manager) | |
| 1695 return NULL; | |
| 1696 | |
| 1697 return manager->GetRoot()->ToBrowserAccessibilityWin(); | |
| 1698 } | |
| 1699 #endif | |
| 1700 | |
| 1637 } // namespace content | 1701 } // namespace content |
| OLD | NEW |