Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: content/browser/web_contents/web_contents_view_aura.cc

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

Powered by Google App Engine
This is Rietveld 408576698