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" | |
71 #include "ui/gfx/screen.h" | 70 #include "ui/gfx/screen.h" |
72 #include "ui/wm/public/drag_drop_client.h" | 71 #include "ui/wm/public/drag_drop_client.h" |
73 #include "ui/wm/public/drag_drop_delegate.h" | 72 #include "ui/wm/public/drag_drop_delegate.h" |
74 | 73 |
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 | |
81 namespace content { | 74 namespace content { |
82 WebContentsView* CreateWebContentsView( | 75 WebContentsView* CreateWebContentsView( |
83 WebContentsImpl* web_contents, | 76 WebContentsImpl* web_contents, |
84 WebContentsViewDelegate* delegate, | 77 WebContentsViewDelegate* delegate, |
85 RenderViewHostDelegateView** render_view_host_delegate_view) { | 78 RenderViewHostDelegateView** render_view_host_delegate_view) { |
86 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); | 79 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); |
87 *render_view_host_delegate_view = rv; | 80 *render_view_host_delegate_view = rv; |
88 return rv; | 81 return rv; |
89 } | 82 } |
90 | 83 |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 host_window_ = NULL; | 633 host_window_ = NULL; |
641 } | 634 } |
642 } | 635 } |
643 | 636 |
644 void OnWindowAddedToRootWindow(aura::Window* window) override { | 637 void OnWindowAddedToRootWindow(aura::Window* window) override { |
645 if (window == view_->window_) { | 638 if (window == view_->window_) { |
646 window->GetHost()->AddObserver(this); | 639 window->GetHost()->AddObserver(this); |
647 #if defined(OS_WIN) | 640 #if defined(OS_WIN) |
648 if (!window->GetRootWindow()->HasObserver(this)) | 641 if (!window->GetRootWindow()->HasObserver(this)) |
649 window->GetRootWindow()->AddObserver(this); | 642 window->GetRootWindow()->AddObserver(this); |
650 if (view_->legacy_hwnd_) { | |
651 view_->legacy_hwnd_->UpdateParent( | |
652 window->GetHost()->GetAcceleratedWidget()); | |
653 } | |
654 #endif | 643 #endif |
655 } | 644 } |
656 } | 645 } |
657 | 646 |
658 void OnWindowRemovingFromRootWindow(aura::Window* window, | 647 void OnWindowRemovingFromRootWindow(aura::Window* window, |
659 aura::Window* new_root) override { | 648 aura::Window* new_root) override { |
660 if (window == view_->window_) { | 649 if (window == view_->window_) { |
661 window->GetHost()->RemoveObserver(this); | 650 window->GetHost()->RemoveObserver(this); |
662 #if defined(OS_WIN) | 651 #if defined(OS_WIN) |
663 window->GetRootWindow()->RemoveObserver(this); | 652 window->GetRootWindow()->RemoveObserver(this); |
664 | 653 |
665 const aura::Window::Windows& root_children = | 654 const aura::Window::Windows& root_children = |
666 window->GetRootWindow()->children(); | 655 window->GetRootWindow()->children(); |
667 for (size_t i = 0; i < root_children.size(); ++i) { | 656 for (size_t i = 0; i < root_children.size(); ++i) { |
668 if (root_children[i] != view_->window_ && | 657 if (root_children[i] != view_->window_ && |
669 root_children[i] != host_window_) { | 658 root_children[i] != host_window_) { |
670 root_children[i]->RemoveObserver(this); | 659 root_children[i]->RemoveObserver(this); |
671 } | 660 } |
672 } | 661 } |
673 | |
674 if (view_->legacy_hwnd_) | |
675 view_->legacy_hwnd_->UpdateParent(ui::GetHiddenWindow()); | |
676 #endif | 662 #endif |
677 } | 663 } |
678 } | 664 } |
679 | 665 |
680 // Overridden WindowTreeHostObserver: | 666 // Overridden WindowTreeHostObserver: |
681 void OnHostMoved(const aura::WindowTreeHost* host, | 667 void OnHostMoved(const aura::WindowTreeHost* host, |
682 const gfx::Point& new_origin) override { | 668 const gfx::Point& new_origin) override { |
683 TRACE_EVENT1("ui", | 669 TRACE_EVENT1("ui", |
684 "WebContentsViewAura::WindowObserver::OnHostMoved", | 670 "WebContentsViewAura::WindowObserver::OnHostMoved", |
685 "new_origin", new_origin.ToString()); | 671 "new_origin", new_origin.ToString()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 | 723 |
738 DISALLOW_COPY_AND_ASSIGN(WindowObserver); | 724 DISALLOW_COPY_AND_ASSIGN(WindowObserver); |
739 }; | 725 }; |
740 | 726 |
741 //////////////////////////////////////////////////////////////////////////////// | 727 //////////////////////////////////////////////////////////////////////////////// |
742 // WebContentsViewAura, public: | 728 // WebContentsViewAura, public: |
743 | 729 |
744 WebContentsViewAura::WebContentsViewAura( | 730 WebContentsViewAura::WebContentsViewAura( |
745 WebContentsImpl* web_contents, | 731 WebContentsImpl* web_contents, |
746 WebContentsViewDelegate* delegate) | 732 WebContentsViewDelegate* delegate) |
747 : WebContentsObserver(web_contents), | 733 : web_contents_(web_contents), |
748 web_contents_(web_contents), | |
749 delegate_(delegate), | 734 delegate_(delegate), |
750 current_drag_op_(blink::WebDragOperationNone), | 735 current_drag_op_(blink::WebDragOperationNone), |
751 drag_dest_delegate_(NULL), | 736 drag_dest_delegate_(NULL), |
752 current_rvh_for_drag_(NULL), | 737 current_rvh_for_drag_(NULL), |
753 overscroll_change_brightness_(false), | 738 overscroll_change_brightness_(false), |
754 current_overscroll_gesture_(OVERSCROLL_NONE), | 739 current_overscroll_gesture_(OVERSCROLL_NONE), |
755 completed_overscroll_gesture_(OVERSCROLL_NONE), | 740 completed_overscroll_gesture_(OVERSCROLL_NONE), |
756 touch_editable_(TouchEditableImplAura::Create()), | 741 touch_editable_(TouchEditableImplAura::Create()), |
757 is_or_was_visible_(false) { | 742 is_or_was_visible_(false) { |
758 } | 743 } |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1024 | 1009 |
1025 void WebContentsViewAura::GetContainerBounds(gfx::Rect *out) const { | 1010 void WebContentsViewAura::GetContainerBounds(gfx::Rect *out) const { |
1026 *out = window_->GetBoundsInScreen(); | 1011 *out = window_->GetBoundsInScreen(); |
1027 } | 1012 } |
1028 | 1013 |
1029 void WebContentsViewAura::SizeContents(const gfx::Size& size) { | 1014 void WebContentsViewAura::SizeContents(const gfx::Size& size) { |
1030 gfx::Rect bounds = window_->bounds(); | 1015 gfx::Rect bounds = window_->bounds(); |
1031 if (bounds.size() != size) { | 1016 if (bounds.size() != size) { |
1032 bounds.set_size(size); | 1017 bounds.set_size(size); |
1033 window_->SetBounds(bounds); | 1018 window_->SetBounds(bounds); |
1034 #if defined(OS_WIN) | |
1035 if (legacy_hwnd_) | |
1036 legacy_hwnd_->SetBounds(window_->GetBoundsInRootWindow()); | |
1037 #endif | |
1038 } else { | 1019 } else { |
1039 // 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. |
1040 // 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. |
1041 SizeChangedCommon(size); | 1022 SizeChangedCommon(size); |
1042 } | 1023 } |
1043 } | 1024 } |
1044 | 1025 |
1045 void WebContentsViewAura::Focus() { | 1026 void WebContentsViewAura::Focus() { |
1046 if (web_contents_->GetInterstitialPage()) { | 1027 if (web_contents_->GetInterstitialPage()) { |
1047 web_contents_->GetInterstitialPage()->Focus(); | 1028 web_contents_->GetInterstitialPage()->Focus(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 // 1) guests do not support NPAPI plugins. | 1105 // 1) guests do not support NPAPI plugins. |
1125 // 2) guests' window bounds are supposed to come from its embedder. | 1106 // 2) guests' window bounds are supposed to come from its embedder. |
1126 if (!BrowserPluginGuest::IsGuest(web_contents_)) | 1107 if (!BrowserPluginGuest::IsGuest(web_contents_)) |
1127 window_observer_.reset(new WindowObserver(this)); | 1108 window_observer_.reset(new WindowObserver(this)); |
1128 | 1109 |
1129 // delegate_->GetDragDestDelegate() creates a new delegate on every call. | 1110 // delegate_->GetDragDestDelegate() creates a new delegate on every call. |
1130 // 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 |
1131 // platforms as well. | 1112 // platforms as well. |
1132 if (delegate_) | 1113 if (delegate_) |
1133 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); | 1114 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); |
1134 | |
1135 #if defined(OS_WIN) | |
1136 if (context && context->GetHost()) { | |
1137 HWND parent_hwnd = context->GetHost()->GetAcceleratedWidget(); | |
1138 CHECK(parent_hwnd); | |
1139 legacy_hwnd_.reset(LegacyRenderWidgetHostHWND::Create(parent_hwnd, this)); | |
1140 } | |
1141 #endif | |
1142 } | 1115 } |
1143 | 1116 |
1144 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForWidget( | 1117 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForWidget( |
1145 RenderWidgetHost* render_widget_host, bool is_guest_view_hack) { | 1118 RenderWidgetHost* render_widget_host, bool is_guest_view_hack) { |
1146 if (render_widget_host->GetView()) { | 1119 if (render_widget_host->GetView()) { |
1147 // During testing, the view will already be set up in most cases to the | 1120 // During testing, the view will already be set up in most cases to the |
1148 // test view, so we don't want to clobber it with a real one. To verify that | 1121 // test view, so we don't want to clobber it with a real one. To verify that |
1149 // this actually is happening (and somebody isn't accidentally creating the | 1122 // this actually is happening (and somebody isn't accidentally creating the |
1150 // view twice), we check for the RVH Factory, which will be set when we're | 1123 // view twice), we check for the RVH Factory, which will be set when we're |
1151 // making special ones (which go along with the special views). | 1124 // making special ones (which go along with the special views). |
(...skipping 20 matching lines...) Expand all Loading... |
1172 // We listen to drag drop events in the newly created view's window. | 1145 // We listen to drag drop events in the newly created view's window. |
1173 aura::client::SetDragDropDelegate(view->GetNativeView(), this); | 1146 aura::client::SetDragDropDelegate(view->GetNativeView(), this); |
1174 | 1147 |
1175 if (view->overscroll_controller() && | 1148 if (view->overscroll_controller() && |
1176 (!web_contents_->GetDelegate() || | 1149 (!web_contents_->GetDelegate() || |
1177 web_contents_->GetDelegate()->CanOverscrollContent())) { | 1150 web_contents_->GetDelegate()->CanOverscrollContent())) { |
1178 InstallOverscrollControllerDelegate(view); | 1151 InstallOverscrollControllerDelegate(view); |
1179 } | 1152 } |
1180 | 1153 |
1181 AttachTouchEditableToRenderView(); | 1154 AttachTouchEditableToRenderView(); |
1182 | |
1183 #if defined(OS_WIN) | |
1184 if (legacy_hwnd_) | |
1185 view->SetLegacyRenderWidgetHostHWND(legacy_hwnd_.get()); | |
1186 #endif | |
1187 | |
1188 return view; | 1155 return view; |
1189 } | 1156 } |
1190 | 1157 |
1191 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForPopupWidget( | 1158 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForPopupWidget( |
1192 RenderWidgetHost* render_widget_host) { | 1159 RenderWidgetHost* render_widget_host) { |
1193 RenderWidgetHostViewAura* view = | 1160 return new RenderWidgetHostViewAura(render_widget_host, false); |
1194 new RenderWidgetHostViewAura(render_widget_host, false); | |
1195 #if defined(OS_WIN) | |
1196 if (legacy_hwnd_) | |
1197 view->SetLegacyRenderWidgetHostHWND(legacy_hwnd_.get()); | |
1198 #endif | |
1199 return view; | |
1200 } | 1161 } |
1201 | 1162 |
1202 void WebContentsViewAura::SetPageTitle(const base::string16& title) { | 1163 void WebContentsViewAura::SetPageTitle(const base::string16& title) { |
1203 window_->SetTitle(title); | 1164 window_->SetTitle(title); |
1204 } | 1165 } |
1205 | 1166 |
1206 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { | 1167 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { |
1207 } | 1168 } |
1208 | 1169 |
1209 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { | 1170 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1465 for (size_t i = 0; i < window_->children().size(); i++) { | 1426 for (size_t i = 0; i < window_->children().size(); i++) { |
1466 if (window_->children()[i]->GetProperty( | 1427 if (window_->children()[i]->GetProperty( |
1467 aura::client::kConstrainedWindowKey)) { | 1428 aura::client::kConstrainedWindowKey)) { |
1468 gfx::Rect bounds = window_->children()[i]->bounds(); | 1429 gfx::Rect bounds = window_->children()[i]->bounds(); |
1469 bounds.set_origin( | 1430 bounds.set_origin( |
1470 gfx::Point((new_bounds.width() - bounds.width()) / 2, | 1431 gfx::Point((new_bounds.width() - bounds.width()) / 2, |
1471 (new_bounds.height() - bounds.height()) / 2)); | 1432 (new_bounds.height() - bounds.height()) / 2)); |
1472 window_->children()[i]->SetBounds(bounds); | 1433 window_->children()[i]->SetBounds(bounds); |
1473 } | 1434 } |
1474 } | 1435 } |
1475 | |
1476 #if defined(OS_WIN) | |
1477 if (!legacy_hwnd_ && window_ && window_->GetHost()) { | |
1478 HWND parent_hwnd = window_->GetHost()->GetAcceleratedWidget(); | |
1479 CHECK(parent_hwnd); | |
1480 legacy_hwnd_.reset(LegacyRenderWidgetHostHWND::Create(parent_hwnd, this)); | |
1481 } | |
1482 | |
1483 if (legacy_hwnd_) | |
1484 legacy_hwnd_->SetBounds(window_->GetBoundsInRootWindow()); | |
1485 #endif | |
1486 } | 1436 } |
1487 | 1437 |
1488 gfx::NativeCursor WebContentsViewAura::GetCursor(const gfx::Point& point) { | 1438 gfx::NativeCursor WebContentsViewAura::GetCursor(const gfx::Point& point) { |
1489 return gfx::kNullCursor; | 1439 return gfx::kNullCursor; |
1490 } | 1440 } |
1491 | 1441 |
1492 int WebContentsViewAura::GetNonClientComponent(const gfx::Point& point) const { | 1442 int WebContentsViewAura::GetNonClientComponent(const gfx::Point& point) const { |
1493 return HTCLIENT; | 1443 return HTCLIENT; |
1494 } | 1444 } |
1495 | 1445 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1650 web_contents_->GetRenderViewHost()->DragTargetDrop( | 1600 web_contents_->GetRenderViewHost()->DragTargetDrop( |
1651 event.location(), | 1601 event.location(), |
1652 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), | 1602 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
1653 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1603 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
1654 if (drag_dest_delegate_) | 1604 if (drag_dest_delegate_) |
1655 drag_dest_delegate_->OnDrop(); | 1605 drag_dest_delegate_->OnDrop(); |
1656 current_drop_data_.reset(); | 1606 current_drop_data_.reset(); |
1657 return ConvertFromWeb(current_drag_op_); | 1607 return ConvertFromWeb(current_drag_op_); |
1658 } | 1608 } |
1659 | 1609 |
1660 void WebContentsViewAura::RenderProcessGone(base::TerminationStatus status) { | |
1661 #if defined(OS_WIN) | |
1662 UpdateLegacyHwndVisibility(); | |
1663 #endif | |
1664 } | |
1665 | |
1666 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window, | 1610 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window, |
1667 bool visible) { | 1611 bool visible) { |
1668 // Ignore any visibility changes in the hierarchy below. | 1612 // Ignore any visibility changes in the hierarchy below. |
1669 if (window != window_.get() && window_->Contains(window)) | 1613 if (window != window_.get() && window_->Contains(window)) |
1670 return; | 1614 return; |
1671 | 1615 |
1672 UpdateWebContentsVisibility(visible); | 1616 UpdateWebContentsVisibility(visible); |
1673 } | 1617 } |
1674 | 1618 |
1675 void WebContentsViewAura::UpdateWebContentsVisibility(bool visible) { | 1619 void WebContentsViewAura::UpdateWebContentsVisibility(bool visible) { |
(...skipping 10 matching lines...) Expand all Loading... |
1686 } | 1630 } |
1687 return; | 1631 return; |
1688 } | 1632 } |
1689 if (visible) { | 1633 if (visible) { |
1690 if (!web_contents_->should_normally_be_visible()) | 1634 if (!web_contents_->should_normally_be_visible()) |
1691 web_contents_->WasShown(); | 1635 web_contents_->WasShown(); |
1692 } else { | 1636 } else { |
1693 if (web_contents_->should_normally_be_visible()) | 1637 if (web_contents_->should_normally_be_visible()) |
1694 web_contents_->WasHidden(); | 1638 web_contents_->WasHidden(); |
1695 } | 1639 } |
1696 | |
1697 #if defined(OS_WIN) | |
1698 UpdateLegacyHwndVisibility(); | |
1699 #endif | |
1700 } | 1640 } |
1701 | 1641 |
1702 #if defined(OS_WIN) | |
1703 void WebContentsViewAura::UpdateLegacyHwndVisibility() { | |
1704 if (!legacy_hwnd_) | |
1705 return; | |
1706 | |
1707 bool visible = (window_->IsVisible() && | |
1708 web_contents_->GetRenderWidgetHostView()); | |
1709 | |
1710 if (visible && GetNativeView() && GetNativeView()->GetHost()) { | |
1711 legacy_hwnd_->UpdateParent( | |
1712 GetNativeView()->GetHost()->GetAcceleratedWidget()); | |
1713 legacy_hwnd_->SetBounds(window_->GetBoundsInRootWindow()); | |
1714 legacy_hwnd_->Show(); | |
1715 } else { | |
1716 // We reparent the legacy Chrome_RenderWidgetHostHWND window to the global | |
1717 // hidden window on the same lines as Windowed plugin windows. | |
1718 legacy_hwnd_->UpdateParent(ui::GetHiddenWindow()); | |
1719 legacy_hwnd_->Hide(); | |
1720 } | |
1721 } | |
1722 | |
1723 gfx::NativeViewAccessible | |
1724 WebContentsViewAura::GetNativeViewAccessible() { | |
1725 BrowserAccessibilityManager* manager = | |
1726 web_contents_->GetRootBrowserAccessibilityManager(); | |
1727 if (!manager) | |
1728 return nullptr; | |
1729 | |
1730 return manager->GetRoot()->ToBrowserAccessibilityWin(); | |
1731 } | |
1732 #endif | |
1733 | |
1734 } // namespace content | 1642 } // namespace content |
OLD | NEW |