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/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "content/browser/renderer_host/dip_util.h" | 10 #include "content/browser/renderer_host/dip_util.h" |
11 #include "content/browser/renderer_host/overscroll_controller.h" | 11 #include "content/browser/renderer_host/overscroll_controller.h" |
12 #include "content/browser/renderer_host/render_view_host_factory.h" | 12 #include "content/browser/renderer_host/render_view_host_factory.h" |
13 #include "content/browser/renderer_host/render_view_host_impl.h" | 13 #include "content/browser/renderer_host/render_view_host_impl.h" |
14 #include "content/browser/renderer_host/render_widget_host_impl.h" | 14 #include "content/browser/renderer_host/render_widget_host_impl.h" |
15 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 15 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
16 #include "content/browser/web_contents/interstitial_page_impl.h" | 16 #include "content/browser/web_contents/interstitial_page_impl.h" |
17 #include "content/browser/web_contents/navigation_entry_impl.h" | 17 #include "content/browser/web_contents/navigation_entry_impl.h" |
| 18 #include "content/browser/web_contents/touch_editable_impl_aura.h" |
18 #include "content/browser/web_contents/web_contents_impl.h" | 19 #include "content/browser/web_contents/web_contents_impl.h" |
19 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
20 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
21 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
22 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
23 #include "content/public/browser/overscroll_configuration.h" | 24 #include "content/public/browser/overscroll_configuration.h" |
24 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/browser/render_widget_host.h" | 26 #include "content/public/browser/render_widget_host.h" |
26 #include "content/public/browser/render_widget_host_view.h" | 27 #include "content/public/browser/render_widget_host_view.h" |
27 #include "content/public/browser/web_contents_delegate.h" | 28 #include "content/public/browser/web_contents_delegate.h" |
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 parent_->RemoveObserver(this); | 736 parent_->RemoveObserver(this); |
736 parent_ = parent; | 737 parent_ = parent; |
737 if (parent) | 738 if (parent) |
738 parent->AddObserver(this); | 739 parent->AddObserver(this); |
739 } | 740 } |
740 | 741 |
741 virtual void OnWindowBoundsChanged(aura::Window* window, | 742 virtual void OnWindowBoundsChanged(aura::Window* window, |
742 const gfx::Rect& old_bounds, | 743 const gfx::Rect& old_bounds, |
743 const gfx::Rect& new_bounds) OVERRIDE { | 744 const gfx::Rect& new_bounds) OVERRIDE { |
744 SendScreenRects(); | 745 SendScreenRects(); |
| 746 if (view_->touch_editable_) |
| 747 view_->touch_editable_->UpdateEditingController(); |
745 } | 748 } |
746 | 749 |
747 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { | 750 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { |
748 if (window != parent_) | 751 if (window != parent_) |
749 window->GetRootWindow()->AddRootWindowObserver(this); | 752 window->GetRootWindow()->AddRootWindowObserver(this); |
750 } | 753 } |
751 | 754 |
752 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE { | 755 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE { |
753 if (window != parent_) | 756 if (window != parent_) |
754 window->GetRootWindow()->RemoveRootWindowObserver(this); | 757 window->GetRootWindow()->RemoveRootWindowObserver(this); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 WebContentsImpl* web_contents, | 872 WebContentsImpl* web_contents, |
870 WebContentsViewDelegate* delegate) | 873 WebContentsViewDelegate* delegate) |
871 : web_contents_(web_contents), | 874 : web_contents_(web_contents), |
872 delegate_(delegate), | 875 delegate_(delegate), |
873 current_drag_op_(WebKit::WebDragOperationNone), | 876 current_drag_op_(WebKit::WebDragOperationNone), |
874 drag_dest_delegate_(NULL), | 877 drag_dest_delegate_(NULL), |
875 current_rvh_for_drag_(NULL), | 878 current_rvh_for_drag_(NULL), |
876 content_container_(NULL), | 879 content_container_(NULL), |
877 overscroll_change_brightness_(false), | 880 overscroll_change_brightness_(false), |
878 current_overscroll_gesture_(OVERSCROLL_NONE), | 881 current_overscroll_gesture_(OVERSCROLL_NONE), |
879 completed_overscroll_gesture_(OVERSCROLL_NONE) { | 882 completed_overscroll_gesture_(OVERSCROLL_NONE), |
| 883 touch_editable_(TouchEditableImplAura::Create()) { |
880 } | 884 } |
881 | 885 |
882 //////////////////////////////////////////////////////////////////////////////// | 886 //////////////////////////////////////////////////////////////////////////////// |
883 // WebContentsViewAura, private: | 887 // WebContentsViewAura, private: |
884 | 888 |
885 WebContentsViewAura::~WebContentsViewAura() { | 889 WebContentsViewAura::~WebContentsViewAura() { |
886 if (!window_) | 890 if (!window_) |
887 return; | 891 return; |
888 | 892 |
889 window_observer_.reset(); | 893 window_observer_.reset(); |
890 #if defined(OS_WIN) | 894 #if defined(OS_WIN) |
891 child_window_observer_.reset(); | 895 child_window_observer_.reset(); |
892 #endif | 896 #endif |
893 // Window needs a valid delegate during its destructor, so we explicitly | 897 // Window needs a valid delegate during its destructor, so we explicitly |
894 // delete it here. | 898 // delete it here. |
895 window_.reset(); | 899 window_.reset(); |
896 } | 900 } |
897 | 901 |
898 void WebContentsViewAura::SetupOverlayWindowForTesting() { | 902 void WebContentsViewAura::SetupOverlayWindowForTesting() { |
899 if (navigation_overlay_) | 903 if (navigation_overlay_) |
900 navigation_overlay_->SetupForTesting(); | 904 navigation_overlay_->SetupForTesting(); |
901 } | 905 } |
902 | 906 |
| 907 void WebContentsViewAura::SetTouchEditableForTest( |
| 908 TouchEditableImplAura* touch_editable) { |
| 909 touch_editable_.reset(touch_editable); |
| 910 AttachTouchEditableToRenderView(); |
| 911 } |
| 912 |
903 void WebContentsViewAura::SizeChangedCommon(const gfx::Size& size) { | 913 void WebContentsViewAura::SizeChangedCommon(const gfx::Size& size) { |
904 if (web_contents_->GetInterstitialPage()) | 914 if (web_contents_->GetInterstitialPage()) |
905 web_contents_->GetInterstitialPage()->SetSize(size); | 915 web_contents_->GetInterstitialPage()->SetSize(size); |
906 RenderWidgetHostView* rwhv = | 916 RenderWidgetHostView* rwhv = |
907 web_contents_->GetRenderWidgetHostView(); | 917 web_contents_->GetRenderWidgetHostView(); |
908 if (rwhv) | 918 if (rwhv) |
909 rwhv->SetSize(size); | 919 rwhv->SetSize(size); |
910 } | 920 } |
911 | 921 |
912 void WebContentsViewAura::EndDrag(WebKit::WebDragOperationsMask ops) { | 922 void WebContentsViewAura::EndDrag(WebKit::WebDragOperationsMask ops) { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 ratio = 1.f - ratio; | 1117 ratio = 1.f - ratio; |
1108 float brightness = current_overscroll_gesture_ == OVERSCROLL_WEST ? | 1118 float brightness = current_overscroll_gesture_ == OVERSCROLL_WEST ? |
1109 kBrightnessMin + ratio * (kBrightnessMax - kBrightnessMin) : | 1119 kBrightnessMin + ratio * (kBrightnessMax - kBrightnessMin) : |
1110 kBrightnessMax - ratio * (kBrightnessMax - kBrightnessMin); | 1120 kBrightnessMax - ratio * (kBrightnessMax - kBrightnessMin); |
1111 brightness = std::max(kBrightnessMin, brightness); | 1121 brightness = std::max(kBrightnessMin, brightness); |
1112 brightness = std::min(kBrightnessMax, brightness); | 1122 brightness = std::min(kBrightnessMax, brightness); |
1113 aura::Window* window = GetWindowToAnimateForOverscroll(); | 1123 aura::Window* window = GetWindowToAnimateForOverscroll(); |
1114 window->layer()->SetLayerBrightness(brightness); | 1124 window->layer()->SetLayerBrightness(brightness); |
1115 } | 1125 } |
1116 | 1126 |
| 1127 void WebContentsViewAura::AttachTouchEditableToRenderView() { |
| 1128 if (!touch_editable_) |
| 1129 return; |
| 1130 RenderWidgetHostViewAura* rwhva = static_cast<RenderWidgetHostViewAura*>( |
| 1131 web_contents_->GetRenderWidgetHostView()); |
| 1132 touch_editable_->AttachToView(rwhva); |
| 1133 } |
| 1134 |
1117 //////////////////////////////////////////////////////////////////////////////// | 1135 //////////////////////////////////////////////////////////////////////////////// |
1118 // WebContentsViewAura, WebContentsView implementation: | 1136 // WebContentsViewAura, WebContentsView implementation: |
1119 | 1137 |
1120 gfx::NativeView WebContentsViewAura::GetNativeView() const { | 1138 gfx::NativeView WebContentsViewAura::GetNativeView() const { |
1121 return window_.get(); | 1139 return window_.get(); |
1122 } | 1140 } |
1123 | 1141 |
1124 gfx::NativeView WebContentsViewAura::GetContentNativeView() const { | 1142 gfx::NativeView WebContentsViewAura::GetContentNativeView() const { |
1125 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); | 1143 RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); |
1126 return rwhv ? rwhv->GetNativeView() : NULL; | 1144 return rwhv ? rwhv->GetNativeView() : NULL; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 | 1285 |
1268 RenderWidgetHostImpl* host_impl = | 1286 RenderWidgetHostImpl* host_impl = |
1269 RenderWidgetHostImpl::From(render_widget_host); | 1287 RenderWidgetHostImpl::From(render_widget_host); |
1270 if (host_impl->overscroll_controller() && web_contents_->GetDelegate() && | 1288 if (host_impl->overscroll_controller() && web_contents_->GetDelegate() && |
1271 web_contents_->GetDelegate()->CanOverscrollContent()) { | 1289 web_contents_->GetDelegate()->CanOverscrollContent()) { |
1272 host_impl->overscroll_controller()->set_delegate(this); | 1290 host_impl->overscroll_controller()->set_delegate(this); |
1273 if (!navigation_overlay_) | 1291 if (!navigation_overlay_) |
1274 navigation_overlay_.reset(new OverscrollNavigationOverlay()); | 1292 navigation_overlay_.reset(new OverscrollNavigationOverlay()); |
1275 } | 1293 } |
1276 | 1294 |
| 1295 AttachTouchEditableToRenderView(); |
1277 return view; | 1296 return view; |
1278 } | 1297 } |
1279 | 1298 |
1280 RenderWidgetHostView* WebContentsViewAura::CreateViewForPopupWidget( | 1299 RenderWidgetHostView* WebContentsViewAura::CreateViewForPopupWidget( |
1281 RenderWidgetHost* render_widget_host) { | 1300 RenderWidgetHost* render_widget_host) { |
1282 return RenderWidgetHostViewPort::CreateViewForWidget(render_widget_host); | 1301 return RenderWidgetHostViewPort::CreateViewForWidget(render_widget_host); |
1283 } | 1302 } |
1284 | 1303 |
1285 void WebContentsViewAura::SetPageTitle(const string16& title) { | 1304 void WebContentsViewAura::SetPageTitle(const string16& title) { |
1286 window_->set_title(title); | 1305 window_->set_title(title); |
1287 } | 1306 } |
1288 | 1307 |
1289 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { | 1308 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { |
1290 } | 1309 } |
1291 | 1310 |
1292 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { | 1311 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { |
1293 if (navigation_overlay_.get() && navigation_overlay_->has_window()) { | 1312 if (navigation_overlay_.get() && navigation_overlay_->has_window()) { |
1294 navigation_overlay_->StartObservingView(static_cast< | 1313 navigation_overlay_->StartObservingView(static_cast< |
1295 RenderWidgetHostViewAura*>(host->GetView())); | 1314 RenderWidgetHostViewAura*>(host->GetView())); |
1296 } | 1315 } |
| 1316 AttachTouchEditableToRenderView(); |
1297 } | 1317 } |
1298 | 1318 |
1299 void WebContentsViewAura::SetOverscrollControllerEnabled(bool enabled) { | 1319 void WebContentsViewAura::SetOverscrollControllerEnabled(bool enabled) { |
1300 RenderViewHostImpl* host = static_cast<RenderViewHostImpl*>( | 1320 RenderViewHostImpl* host = static_cast<RenderViewHostImpl*>( |
1301 web_contents_->GetRenderViewHost()); | 1321 web_contents_->GetRenderViewHost()); |
1302 if (host) { | 1322 if (host) { |
1303 host->SetOverscrollControllerEnabled(enabled); | 1323 host->SetOverscrollControllerEnabled(enabled); |
1304 if (enabled) | 1324 if (enabled) |
1305 host->overscroll_controller()->set_delegate(this); | 1325 host->overscroll_controller()->set_delegate(this); |
1306 } | 1326 } |
1307 } | 1327 } |
1308 | 1328 |
1309 //////////////////////////////////////////////////////////////////////////////// | 1329 //////////////////////////////////////////////////////////////////////////////// |
1310 // WebContentsViewAura, RenderViewHostDelegateView implementation: | 1330 // WebContentsViewAura, RenderViewHostDelegateView implementation: |
1311 | 1331 |
1312 void WebContentsViewAura::ShowContextMenu( | 1332 void WebContentsViewAura::ShowContextMenu( |
1313 const ContextMenuParams& params, | 1333 const ContextMenuParams& params, |
1314 ContextMenuSourceType type) { | 1334 ContextMenuSourceType type) { |
1315 if (delegate_) | 1335 if (delegate_) |
1316 delegate_->ShowContextMenu(params, type); | 1336 delegate_->ShowContextMenu(params, type); |
| 1337 if (touch_editable_) |
| 1338 touch_editable_->EndTouchEditing(); |
| 1339 |
1317 } | 1340 } |
1318 | 1341 |
1319 void WebContentsViewAura::ShowPopupMenu(const gfx::Rect& bounds, | 1342 void WebContentsViewAura::ShowPopupMenu(const gfx::Rect& bounds, |
1320 int item_height, | 1343 int item_height, |
1321 double item_font_size, | 1344 double item_font_size, |
1322 int selected_item, | 1345 int selected_item, |
1323 const std::vector<WebMenuItem>& items, | 1346 const std::vector<WebMenuItem>& items, |
1324 bool right_aligned, | 1347 bool right_aligned, |
1325 bool allow_multiple_selection) { | 1348 bool allow_multiple_selection) { |
1326 // External popup menus are only used on Mac and Android. | 1349 // External popup menus are only used on Mac and Android. |
1327 NOTIMPLEMENTED(); | 1350 NOTIMPLEMENTED(); |
1328 } | 1351 } |
1329 | 1352 |
1330 void WebContentsViewAura::StartDragging( | 1353 void WebContentsViewAura::StartDragging( |
1331 const WebDropData& drop_data, | 1354 const WebDropData& drop_data, |
1332 WebKit::WebDragOperationsMask operations, | 1355 WebKit::WebDragOperationsMask operations, |
1333 const gfx::ImageSkia& image, | 1356 const gfx::ImageSkia& image, |
1334 const gfx::Vector2d& image_offset, | 1357 const gfx::Vector2d& image_offset, |
1335 const DragEventSourceInfo& event_info) { | 1358 const DragEventSourceInfo& event_info) { |
1336 aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); | 1359 aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); |
1337 if (!aura::client::GetDragDropClient(root_window)) { | 1360 if (!aura::client::GetDragDropClient(root_window)) { |
1338 web_contents_->SystemDragEnded(); | 1361 web_contents_->SystemDragEnded(); |
1339 return; | 1362 return; |
1340 } | 1363 } |
1341 | 1364 |
| 1365 if (touch_editable_) |
| 1366 touch_editable_->EndTouchEditing(); |
| 1367 |
1342 ui::OSExchangeData::Provider* provider = ui::OSExchangeData::CreateProvider(); | 1368 ui::OSExchangeData::Provider* provider = ui::OSExchangeData::CreateProvider(); |
1343 PrepareDragData(drop_data, provider); | 1369 PrepareDragData(drop_data, provider); |
1344 | 1370 |
1345 ui::OSExchangeData data(provider); // takes ownership of |provider|. | 1371 ui::OSExchangeData data(provider); // takes ownership of |provider|. |
1346 | 1372 |
1347 if (!image.isNull()) { | 1373 if (!image.isNull()) { |
1348 drag_utils::SetDragImageOnDataObject(image, | 1374 drag_utils::SetDragImageOnDataObject(image, |
1349 gfx::Size(image.width(), image.height()), image_offset, &data); | 1375 gfx::Size(image.width(), image.height()), image_offset, &data); |
1350 } | 1376 } |
1351 | 1377 |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1662 event.location(), | 1688 event.location(), |
1663 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), | 1689 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
1664 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1690 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
1665 if (drag_dest_delegate_) | 1691 if (drag_dest_delegate_) |
1666 drag_dest_delegate_->OnDrop(); | 1692 drag_dest_delegate_->OnDrop(); |
1667 current_drop_data_.reset(); | 1693 current_drop_data_.reset(); |
1668 return current_drag_op_; | 1694 return current_drag_op_; |
1669 } | 1695 } |
1670 | 1696 |
1671 } // namespace content | 1697 } // namespace content |
OLD | NEW |