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