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

Unified Diff: content/browser/renderer_host/render_widget_host_view_aura.cc

Issue 698253004: Reland: Implement Aura side of unified touch text selection for contents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added scoped helper for MotionEventAura Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/render_widget_host_view_aura.cc
diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc
index 009ce15549f746c3aa636c6872e0539cb1ebeb25..662bae5ce0088cb3d42d7d89d06c586330b6a1c1 100644
--- a/content/browser/renderer_host/render_widget_host_view_aura.cc
+++ b/content/browser/renderer_host/render_widget_host_view_aura.cc
@@ -30,6 +30,8 @@
#include "content/browser/renderer_host/compositor_resize_lock_aura.h"
#include "content/browser/renderer_host/dip_util.h"
#include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h"
+#include "content/browser/renderer_host/input/touch_selection_controller_client_aura.h"
+#include "content/browser/renderer_host/input/ui_touch_selection_helper.h"
#include "content/browser/renderer_host/input/web_input_event_util.h"
#include "content/browser/renderer_host/overscroll_controller.h"
#include "content/browser/renderer_host/render_view_host_delegate.h"
@@ -71,6 +73,7 @@
#include "ui/events/blink/blink_event_util.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
+#include "ui/events/gesture_detection/gesture_configuration.h"
#include "ui/events/gestures/gesture_recognizer.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/display.h"
@@ -78,6 +81,7 @@
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/skia_util.h"
+#include "ui/touch_selection/touch_selection_controller.h"
#include "ui/wm/public/activation_client.h"
#include "ui/wm/public/scoped_tooltip_disabler.h"
#include "ui/wm/public/tooltip_client.h"
@@ -291,6 +295,29 @@ void MarkUnchangedTouchPointsAsStationary(
}
}
+class ScopedMotionEventAuraCleanup {
+ public:
+ ScopedMotionEventAuraCleanup(ui::MotionEventAura* motion_event,
+ const ui::TouchEvent& event);
+ virtual ~ScopedMotionEventAuraCleanup();
+
+ private:
+ ui::MotionEventAura* motion_event_;
+ const ui::TouchEvent& event_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedMotionEventAuraCleanup);
jdduke (slow) 2015/07/08 22:19:43 This looks good, but let's add it in a separate pa
mohsen 2015/07/08 22:45:14 Yeah, if that would useful in other places, then w
+};
+
+ScopedMotionEventAuraCleanup::ScopedMotionEventAuraCleanup(
+ ui::MotionEventAura* mouse_event,
jdduke (slow) 2015/07/08 22:19:43 motion_event
mohsen 2015/07/08 22:45:14 Acknowledged.
+ const ui::TouchEvent& event)
+ : motion_event_(mouse_event), event_(event) {
+}
+
+ScopedMotionEventAuraCleanup::~ScopedMotionEventAuraCleanup() {
+ motion_event_->CleanupRemovedTouchPoints(event_);
+}
+
} // namespace
// We need to watch for mouse events outside a Web Popup or its parent
@@ -462,7 +489,6 @@ RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host,
showing_context_menu_(false),
#endif
has_snapped_to_boundary_(false),
- touch_editing_client_(NULL),
is_guest_view_hack_(is_guest_view_hack),
begin_frame_observer_proxy_(this),
weak_ptr_factory_(this) {
@@ -480,6 +506,19 @@ RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host,
bool overscroll_enabled = base::CommandLine::ForCurrentProcess()->
GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0";
SetOverscrollControllerEnabled(overscroll_enabled);
+
+ selection_controller_client_.reset(
+ new TouchSelectionControllerClientAura(this));
+
+ ui::TouchSelectionController::Config tsc_config;
+ tsc_config.tap_timeout = base::TimeDelta::FromMilliseconds(
+ ui::GestureConfiguration::GetInstance()->show_press_delay_in_ms());
+ tsc_config.tap_slop = ui::GestureConfiguration::GetInstance()
+ ->max_touch_move_in_pixels_for_click();
+ tsc_config.show_on_tap_for_empty_editable = true;
+ tsc_config.enable_longpress_drag_selection = false;
+ selection_controller_.reset(new ui::TouchSelectionController(
+ selection_controller_client_.get(), tsc_config));
}
////////////////////////////////////////////////////////////////////////////////
@@ -965,8 +1004,6 @@ void RenderWidgetHostViewAura::TextInputTypeChanged(
text_input_flags_ = flags;
if (GetInputMethod())
GetInputMethod()->OnTextInputTypeChanged(this);
- if (touch_editing_client_)
- touch_editing_client_->OnTextInputTypeChanged(text_input_type_);
}
}
@@ -1083,11 +1120,6 @@ void RenderWidgetHostViewAura::SelectionBoundsChanged(
selection_focus_ = focus_bound;
if (GetInputMethod())
GetInputMethod()->OnCaretBoundsChanged(this);
-
- if (touch_editing_client_) {
- touch_editing_client_->OnSelectionOrCursorChanged(
- anchor_bound, focus_bound);
- }
}
void RenderWidgetHostViewAura::CopyFromCompositingSurface(
@@ -1177,6 +1209,10 @@ void RenderWidgetHostViewAura::OnSwapCompositorFrame(
frame->delegated_frame_data.Pass(),
frame->metadata.device_scale_factor,
frame->metadata.latency_info);
+ SelectionUpdated(frame->metadata.selection.is_editable,
+ frame->metadata.selection.is_empty_text_form_control,
+ ConvertSelectionBound(frame->metadata.selection.start),
+ ConvertSelectionBound(frame->metadata.selection.end));
return;
}
@@ -1189,8 +1225,7 @@ void RenderWidgetHostViewAura::OnSwapCompositorFrame(
}
void RenderWidgetHostViewAura::DidStopFlinging() {
- if (touch_editing_client_)
- touch_editing_client_->DidStopFlinging();
+ selection_controller_client_->OnSelectionScrollCompleted();
}
#if defined(OS_WIN)
@@ -1270,9 +1305,6 @@ void RenderWidgetHostViewAura::WheelEventAck(
void RenderWidgetHostViewAura::GestureEventAck(
const blink::WebGestureEvent& event,
InputEventAckState ack_result) {
- if (touch_editing_client_)
- touch_editing_client_->GestureEventAck(event.type);
-
if (overscroll_controller_) {
overscroll_controller_->ReceivedEventACK(
event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result));
@@ -1674,9 +1706,8 @@ gfx::Rect RenderWidgetHostViewAura::ConvertRectFromScreen(
}
gfx::Rect RenderWidgetHostViewAura::GetCaretBounds() const {
- gfx::Rect rect =
- ui::RectBetweenSelectionBounds(selection_anchor_, selection_focus_);
- return ConvertRectToScreen(rect);
+ return ConvertRectToScreen(
+ ui::RectBetweenSelectionBounds(selection_anchor_, selection_focus_));
}
bool RenderWidgetHostViewAura::GetCompositionCharacterBounds(
@@ -1863,8 +1894,6 @@ bool RenderWidgetHostViewAura::CanFocus() {
void RenderWidgetHostViewAura::OnCaptureLost() {
host_->LostCapture();
- if (touch_editing_client_)
- touch_editing_client_->EndTouchEditing(false);
}
void RenderWidgetHostViewAura::OnPaint(const ui::PaintContext& context) {
@@ -1947,8 +1976,6 @@ void RenderWidgetHostViewAura::GetHitTestMask(gfx::Path* mask) const {
void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) {
TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnKeyEvent");
- if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event))
- return;
if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) {
popup_child_host_view_->OnKeyEvent(event);
@@ -1995,9 +2022,6 @@ void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) {
void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) {
TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnMouseEvent");
- if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event))
- return;
-
if (mouse_locked_) {
aura::client::CursorClient* cursor_client =
aura::client::GetCursorClient(window_->GetRootWindow());
@@ -2161,8 +2185,6 @@ void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) {
void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) {
TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent");
- if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event))
- return;
if (event->type() == ui::ET_SCROLL) {
#if !defined(OS_WIN)
@@ -2191,8 +2213,8 @@ void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) {
void RenderWidgetHostViewAura::OnTouchEvent(ui::TouchEvent* event) {
TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnTouchEvent");
- if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event))
- return;
+
+ bool had_no_pointer = !pointer_state_.GetPointerCount();
// Update the touch event first.
if (!pointer_state_.OnTouch(*event)) {
@@ -2200,9 +2222,22 @@ void RenderWidgetHostViewAura::OnTouchEvent(ui::TouchEvent* event) {
return;
}
- blink::WebTouchEvent touch_event = ui::CreateWebTouchEventFromMotionEvent(
- pointer_state_, event->may_cause_scrolling());
- pointer_state_.CleanupRemovedTouchPoints(*event);
+ blink::WebTouchEvent touch_event;
+
+ {
+ ScopedMotionEventAuraCleanup motion_event_cleanup(&pointer_state_, *event);
+ if (selection_controller_->WillHandleTouchEvent(pointer_state_)) {
+ event->SetHandled();
+ return;
+ }
+ touch_event = ui::CreateWebTouchEventFromMotionEvent(
+ pointer_state_, event->may_cause_scrolling());
+ }
+
+ if (had_no_pointer)
+ selection_controller_client_->OnTouchDown();
+ if (!pointer_state_.GetPointerCount())
+ selection_controller_client_->OnTouchUp();
// It is important to always mark events as being handled asynchronously when
// they are forwarded. This ensures that the current event does not get
@@ -2218,6 +2253,7 @@ void RenderWidgetHostViewAura::OnTouchEvent(ui::TouchEvent* event) {
void RenderWidgetHostViewAura::OnGestureEvent(ui::GestureEvent* event) {
TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnGestureEvent");
+
if ((event->type() == ui::ET_GESTURE_PINCH_BEGIN ||
event->type() == ui::ET_GESTURE_PINCH_UPDATE ||
event->type() == ui::ET_GESTURE_PINCH_END) && !pinch_zoom_enabled_) {
@@ -2225,7 +2261,8 @@ void RenderWidgetHostViewAura::OnGestureEvent(ui::GestureEvent* event) {
return;
}
- if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event))
+ HandleGestureForTouchSelection(event);
+ if (event->handled())
return;
// Confirm existing composition text on TAP gesture, to make sure the input
@@ -2322,8 +2359,7 @@ void RenderWidgetHostViewAura::OnWindowFocused(aura::Window* gained_focus,
DetachFromInputMethod();
host_->SetInputMethodActive(false);
- if (touch_editing_client_)
- touch_editing_client_->EndTouchEditing(false);
+ selection_controller_->HideAndDisallowShowingAutomatically();
if (overscroll_controller_)
overscroll_controller_->Cancel();
@@ -2380,9 +2416,8 @@ void RenderWidgetHostViewAura::OnHostMoved(const aura::WindowTreeHost* host,
// RenderWidgetHostViewAura, private:
RenderWidgetHostViewAura::~RenderWidgetHostViewAura() {
- if (touch_editing_client_)
- touch_editing_client_->OnViewDestroyed();
-
+ selection_controller_.reset();
+ selection_controller_client_.reset();
delegated_frame_host_.reset();
window_observer_.reset();
if (window_->GetHost())
@@ -2567,10 +2602,6 @@ void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) {
window_->SetBounds(rect);
host_->WasResized();
delegated_frame_host_->WasResized();
- if (touch_editing_client_) {
- touch_editing_client_->OnSelectionOrCursorChanged(selection_anchor_,
- selection_focus_);
- }
#if defined(OS_WIN)
// Create the legacy dummy window which corresponds to the bounds of the
// webcontents. This will be passed as the container window for windowless
@@ -2713,6 +2744,39 @@ void RenderWidgetHostViewAura::ForwardKeyboardEvent(
host_->ForwardKeyboardEvent(event);
}
+void RenderWidgetHostViewAura::SelectionUpdated(bool is_editable,
+ bool is_empty_text_form_control,
+ const ui::SelectionBound& start,
+ const ui::SelectionBound& end) {
+ selection_controller_->OnSelectionEditable(is_editable);
+ selection_controller_->OnSelectionEmpty(is_empty_text_form_control);
+ selection_controller_->OnSelectionBoundsChanged(start, end);
+}
+
+void RenderWidgetHostViewAura::HandleGestureForTouchSelection(
+ ui::GestureEvent* event) {
+ switch (event->type()) {
+ case ui::ET_GESTURE_LONG_PRESS:
+ if (selection_controller_->WillHandleLongPressEvent(
+ base::TimeTicks() + event->time_stamp(), event->location())) {
+ event->SetHandled();
+ }
+ break;
+ case ui::ET_GESTURE_TAP:
+ if (selection_controller_->WillHandleTapEvent(event->location()))
+ event->SetHandled();
+ break;
+ case ui::ET_GESTURE_SCROLL_BEGIN:
+ selection_controller_client_->OnSelectionScrollStarted();
+ break;
+ case ui::ET_GESTURE_SCROLL_END:
+ selection_controller_client_->OnSelectionScrollCompleted();
+ break;
+ default:
+ break;
+ }
+}
+
////////////////////////////////////////////////////////////////////////////////
// DelegatedFrameHost, public:

Powered by Google App Engine
This is Rietveld 408576698