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