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

Unified Diff: ui/touch_selection/touch_selection_controller.h

Issue 1087893003: Support longpress drag selection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review Created 5 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 side-by-side diff with in-line comments
Download patch
Index: ui/touch_selection/touch_selection_controller.h
diff --git a/ui/touch_selection/touch_selection_controller.h b/ui/touch_selection/touch_selection_controller.h
index 115dd0d637046b44aa49c42e832fc5e82489cc95..594b78238ac8bb28f21bfd110445faa8853f8f59 100644
--- a/ui/touch_selection/touch_selection_controller.h
+++ b/ui/touch_selection/touch_selection_controller.h
@@ -5,9 +5,12 @@
#ifndef UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_
#define UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_
+#include "base/time/time.h"
#include "ui/base/touch/selection_bound.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect_f.h"
+#include "ui/gfx/geometry/vector2d_f.h"
+#include "ui/touch_selection/longpress_drag_selector.h"
#include "ui/touch_selection/selection_event_type.h"
#include "ui/touch_selection/touch_handle.h"
#include "ui/touch_selection/touch_handle_orientation.h"
@@ -34,7 +37,8 @@ class UI_TOUCH_SELECTION_EXPORT TouchSelectionControllerClient {
// Controller for manipulating text selection via touch input.
class UI_TOUCH_SELECTION_EXPORT TouchSelectionController
- : public TouchHandleClient {
+ : public TouchHandleClient,
+ public LongPressDragSelectorClient {
public:
TouchSelectionController(TouchSelectionControllerClient* client,
base::TimeDelta tap_timeout,
@@ -59,7 +63,8 @@ class UI_TOUCH_SELECTION_EXPORT TouchSelectionController
// To be called before forwarding a longpress event. This allows automatically
// showing the selection or insertion handles from subsequent bounds changes.
- void OnLongPressEvent();
+ void OnLongPressEvent(base::TimeTicks event_time,
+ const gfx::PointF& location);
// Allow showing the selection handles from the most recent selection bounds
// update (if valid), or a future valid bounds update.
@@ -101,15 +106,21 @@ class UI_TOUCH_SELECTION_EXPORT TouchSelectionController
enum InputEventType { TAP, LONG_PRESS, INPUT_EVENT_TYPE_NONE };
// TouchHandleClient implementation.
- void OnHandleDragBegin(const TouchHandle& handle) override;
- void OnHandleDragUpdate(const TouchHandle& handle,
- const gfx::PointF& new_position) override;
- void OnHandleDragEnd(const TouchHandle& handle) override;
+ void OnDragBegin(const TouchSelectionDraggable& draggable,
+ const gfx::PointF& drag_position) override;
+ void OnDragUpdate(const TouchSelectionDraggable& draggable,
+ const gfx::PointF& drag_position) override;
+ void OnDragEnd(const TouchSelectionDraggable& draggable) override;
+ bool IsWithinTapSlop(const gfx::Vector2dF& delta) const override;
void OnHandleTapped(const TouchHandle& handle) override;
void SetNeedsAnimate() override;
scoped_ptr<TouchHandleDrawable> CreateDrawable() override;
base::TimeDelta GetTapTimeout() const override;
- float GetTapSlop() const override;
+
+ // LongPressDragSelectorClient implementation.
+ void OnLongPressDragDetectionStateChanged() override;
+ gfx::PointF GetSelectionStart() const override;
+ gfx::PointF GetSelectionEnd() const override;
void ShowInsertionHandleAutomatically();
void ShowSelectionHandlesAutomatically();
@@ -123,6 +134,10 @@ class UI_TOUCH_SELECTION_EXPORT TouchSelectionController
void DeactivateSelection();
void ResetCachedValuesIfInactive();
+ bool WillHandleTouchEventForLongPressDrag(const MotionEvent& event);
+ void SetTemporarilyHiddenForLongPressDrag(bool hidden);
+ void RefreshHandleVisibility();
+
gfx::Vector2dF GetStartLineOffset() const;
gfx::Vector2dF GetEndLineOffset() const;
bool GetStartVisible() const;
@@ -133,7 +148,7 @@ class UI_TOUCH_SELECTION_EXPORT TouchSelectionController
TouchSelectionControllerClient* const client_;
const base::TimeDelta tap_timeout_;
- const float tap_slop_;
+ const double tap_slop_squared_;
// Controls whether an insertion handle is shown on a tap for an empty
// editable text.
@@ -160,6 +175,14 @@ class UI_TOUCH_SELECTION_EXPORT TouchSelectionController
bool temporarily_hidden_;
+ // Offset from the start of a drag sequence to a reasonable position on the
+ // corresponding line of text. This helps ensure that the initial selection
+ // induced by the drag doesn't "jump" between lines.
+ gfx::Vector2dF drag_line_offset_;
+
+ // Longpress drag allows direct manipulation of longpress-initiated selection.
+ LongPressDragSelector longpress_drag_selector_;
+
base::TimeTicks selection_start_time_;
// Whether a selection handle was dragged during the current 'selection
// session' - i.e. since the current selection has been activated.

Powered by Google App Engine
This is Rietveld 408576698