Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ | 5 #ifndef UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ |
| 6 #define UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ | 6 #define UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "ui/base/touch/selection_bound.h" | 8 #include "ui/base/touch/selection_bound.h" |
| 9 #include "ui/gfx/geometry/point_f.h" | 9 #include "ui/gfx/geometry/point_f.h" |
| 10 #include "ui/gfx/geometry/rect_f.h" | 10 #include "ui/gfx/geometry/rect_f.h" |
| 11 #include "ui/gfx/native_widget_types.h" | |
| 11 #include "ui/touch_selection/selection_event_type.h" | 12 #include "ui/touch_selection/selection_event_type.h" |
| 12 #include "ui/touch_selection/touch_handle.h" | 13 #include "ui/touch_selection/touch_handle.h" |
| 13 #include "ui/touch_selection/touch_handle_orientation.h" | 14 #include "ui/touch_selection/touch_handle_orientation.h" |
| 15 #include "ui/touch_selection/touch_selection_menu_runner.h" | |
| 14 #include "ui/touch_selection/ui_touch_selection_export.h" | 16 #include "ui/touch_selection/ui_touch_selection_export.h" |
| 15 | 17 |
| 16 namespace ui { | 18 namespace ui { |
| 17 class MotionEvent; | 19 class MotionEvent; |
| 18 | 20 |
| 19 // Interface through which |TouchSelectionController| issues selection-related | 21 // Interface through which |TouchSelectionController| issues selection-related |
| 20 // commands, notifications and requests. | 22 // commands and requests. |
| 21 class UI_TOUCH_SELECTION_EXPORT TouchSelectionControllerClient { | 23 class UI_TOUCH_SELECTION_EXPORT TouchSelectionControllerClient |
| 24 : public TouchSelectionMenuClient { | |
| 22 public: | 25 public: |
| 23 virtual ~TouchSelectionControllerClient() {} | 26 ~TouchSelectionControllerClient() override {} |
| 24 | 27 |
| 25 virtual bool SupportsAnimation() const = 0; | 28 virtual bool SupportsAnimation() const = 0; |
| 26 virtual void SetNeedsAnimate() = 0; | 29 virtual void SetNeedsAnimate() = 0; |
| 27 virtual void MoveCaret(const gfx::PointF& position) = 0; | 30 virtual void MoveCaret(const gfx::PointF& position) = 0; |
| 28 virtual void MoveRangeSelectionExtent(const gfx::PointF& extent) = 0; | 31 virtual void MoveRangeSelectionExtent(const gfx::PointF& extent) = 0; |
| 29 virtual void SelectBetweenCoordinates(const gfx::PointF& base, | 32 virtual void SelectBetweenCoordinates(const gfx::PointF& base, |
| 30 const gfx::PointF& extent) = 0; | 33 const gfx::PointF& extent) = 0; |
| 31 virtual void OnSelectionEvent(SelectionEventType event, | 34 virtual void OnSelectionEvent(SelectionEventType event, |
| 32 const gfx::PointF& position) = 0; | 35 const gfx::PointF& position) = 0; |
| 33 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0; | 36 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0; |
| 37 virtual void HideQuickMenu(); | |
| 38 virtual void ShowQuickMenu(gfx::Rect anchor_rect); | |
| 39 virtual gfx::Rect GetClientBounds() const = 0; | |
| 40 virtual gfx::NativeView GetNativeView() const = 0; | |
| 34 }; | 41 }; |
| 35 | 42 |
| 36 // Controller for manipulating text selection via touch input. | 43 // Controller for manipulating text selection via touch input. |
| 37 class UI_TOUCH_SELECTION_EXPORT TouchSelectionController | 44 class UI_TOUCH_SELECTION_EXPORT TouchSelectionController |
| 38 : public TouchHandleClient { | 45 : public TouchHandleClient { |
| 39 public: | 46 public: |
| 40 TouchSelectionController(TouchSelectionControllerClient* client, | 47 ~TouchSelectionController() override {}; |
| 41 base::TimeDelta tap_timeout, | |
| 42 float tap_slop, | |
| 43 bool show_on_tap_for_empty_editable); | |
| 44 ~TouchSelectionController() override; | |
| 45 | 48 |
| 46 // To be called when the selection bounds have changed. | 49 // To be called when the selection bounds info has been updated. |
| 47 // Note that such updates will trigger handle updates only if preceded | 50 // Note that such updates will trigger handle updates only if preceded |
| 48 // by an appropriate call to allow automatic showing. | 51 // by an appropriate call to allow automatic showing. |
| 49 void OnSelectionBoundsChanged(const SelectionBound& start, | 52 // Return value specifies if anything has been updated or not. |
| 50 const SelectionBound& end); | 53 virtual bool OnSelectionBoundsUpdated(const SelectionBound& start, |
| 54 const SelectionBound& end) = 0; | |
| 51 | 55 |
| 52 // Allows touch-dragging of the handle. | 56 // Allows touch-dragging of the handle. |
| 53 // Returns true iff the event was consumed, in which case the caller should | 57 // Returns true iff the event was consumed, in which case the caller should |
| 54 // cease further handling of the event. | 58 // cease further handling of the event. |
| 55 bool WillHandleTouchEvent(const MotionEvent& event); | 59 virtual bool WillHandleTouchEvent(const MotionEvent& event) = 0; |
| 56 | 60 |
| 57 // To be called before forwarding a tap event. This allows automatically | 61 // To be called before forwarding a tap event. This allows automatically |
| 58 // showing the insertion handle from subsequent bounds changes. | 62 // showing the insertion handle from subsequent bounds changes. |
| 59 void OnTapEvent(); | 63 virtual void OnTapEvent() = 0; |
| 60 | 64 |
| 61 // To be called before forwarding a longpress event. This allows automatically | 65 // To be called before forwarding a longpress event. This allows automatically |
| 62 // showing the selection or insertion handles from subsequent bounds changes. | 66 // showing the selection or insertion handles from subsequent bounds changes. |
| 63 void OnLongPressEvent(); | 67 virtual void OnLongPressEvent() = 0; |
| 64 | 68 |
| 65 // Allow showing the selection handles from the most recent selection bounds | 69 // Allow showing the selection handles from the most recent selection bounds |
| 66 // update (if valid), or a future valid bounds update. | 70 // update (if valid), or a future valid bounds update. |
| 67 void AllowShowingFromCurrentSelection(); | 71 virtual void AllowShowingFromCurrentSelection() = 0; |
| 68 | 72 |
| 69 // Hide the handles and suppress bounds updates until the next explicit | 73 // Hide the handles and suppress bounds updates until the next explicit |
| 70 // showing allowance. | 74 // showing allowance. |
| 71 void HideAndDisallowShowingAutomatically(); | 75 virtual void HideAndDisallowShowingAutomatically() = 0; |
| 72 | 76 |
| 73 // Override the handle visibility according to |hidden|. | 77 // Override the handle visibility according to |hidden|. |
| 74 void SetTemporarilyHidden(bool hidden); | 78 virtual void SetTemporarilyHidden(bool hidden) = 0; |
| 75 | 79 |
| 76 // To be called when the editability of the focused region changes. | 80 // To be called when the editability of the focused region changes. |
| 77 void OnSelectionEditable(bool editable); | 81 virtual void OnSelectionEditable(bool editable) = 0; |
| 78 | 82 |
| 79 // To be called when the contents of the focused region changes. | 83 // To be called when the contents of the focused region changes. |
| 80 void OnSelectionEmpty(bool empty); | 84 virtual void OnSelectionEmpty(bool empty) = 0; |
| 81 | 85 |
| 82 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. | 86 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. |
| 83 // Returns true if an animation is active and requires further ticking. | 87 // Returns true if an animation is active and requires further ticking. |
| 84 bool Animate(base::TimeTicks animate_time); | 88 virtual bool Animate(base::TimeTicks animate_time) = 0; |
| 85 | 89 |
| 86 private: | 90 virtual void OnNativeViewMoved() = 0; |
|
jdduke (slow)
2015/03/30 15:46:22
So all of these are Aura-specific? It feels a bit
| |
| 87 enum InputEventType { TAP, LONG_PRESS, INPUT_EVENT_TYPE_NONE }; | 91 virtual void OnScrollStarted() = 0; |
| 88 | 92 virtual void OnScrollCompleted() = 0; |
| 89 // TouchHandleClient implementation. | 93 virtual void OnFlingCompleted() = 0; |
| 90 void OnHandleDragBegin(const TouchHandle& handle) override; | 94 virtual void OnOverscrollStarted() = 0; |
| 91 void OnHandleDragUpdate(const TouchHandle& handle, | 95 virtual void OnOverscrollCompleted() = 0; |
| 92 const gfx::PointF& new_position) override; | |
| 93 void OnHandleDragEnd(const TouchHandle& handle) override; | |
| 94 void OnHandleTapped(const TouchHandle& handle) override; | |
| 95 void SetNeedsAnimate() override; | |
| 96 scoped_ptr<TouchHandleDrawable> CreateDrawable() override; | |
| 97 base::TimeDelta GetTapTimeout() const override; | |
| 98 float GetTapSlop() const override; | |
| 99 | |
| 100 void ShowInsertionHandleAutomatically(); | |
| 101 void ShowSelectionHandlesAutomatically(); | |
| 102 | |
| 103 void OnInsertionChanged(); | |
| 104 void OnSelectionChanged(); | |
| 105 | |
| 106 void ActivateInsertion(); | |
| 107 void DeactivateInsertion(); | |
| 108 void ActivateSelection(); | |
| 109 void DeactivateSelection(); | |
| 110 void ResetCachedValuesIfInactive(); | |
| 111 | |
| 112 const gfx::PointF& GetStartPosition() const; | |
| 113 const gfx::PointF& GetEndPosition() const; | |
| 114 gfx::Vector2dF GetStartLineOffset() const; | |
| 115 gfx::Vector2dF GetEndLineOffset() const; | |
| 116 bool GetStartVisible() const; | |
| 117 bool GetEndVisible() const; | |
| 118 TouchHandle::AnimationStyle GetAnimationStyle(bool was_active) const; | |
| 119 | |
| 120 void LogSelectionEnd(); | |
| 121 | |
| 122 TouchSelectionControllerClient* const client_; | |
| 123 const base::TimeDelta tap_timeout_; | |
| 124 const float tap_slop_; | |
| 125 | |
| 126 // Controls whether an insertion handle is shown on a tap for an empty | |
| 127 // editable text. | |
| 128 bool show_on_tap_for_empty_editable_; | |
| 129 | |
| 130 InputEventType response_pending_input_event_; | |
| 131 | |
| 132 SelectionBound start_; | |
| 133 SelectionBound end_; | |
| 134 TouchHandleOrientation start_orientation_; | |
| 135 TouchHandleOrientation end_orientation_; | |
| 136 | |
| 137 scoped_ptr<TouchHandle> insertion_handle_; | |
| 138 bool is_insertion_active_; | |
| 139 bool activate_insertion_automatically_; | |
| 140 | |
| 141 scoped_ptr<TouchHandle> start_selection_handle_; | |
| 142 scoped_ptr<TouchHandle> end_selection_handle_; | |
| 143 bool is_selection_active_; | |
| 144 bool activate_selection_automatically_; | |
| 145 | |
| 146 bool selection_empty_; | |
| 147 bool selection_editable_; | |
| 148 | |
| 149 bool temporarily_hidden_; | |
| 150 | |
| 151 base::TimeTicks selection_start_time_; | |
| 152 // Whether a selection handle was dragged during the current 'selection | |
| 153 // session' - i.e. since the current selection has been activated. | |
| 154 bool selection_handle_dragged_; | |
| 155 | |
| 156 DISALLOW_COPY_AND_ASSIGN(TouchSelectionController); | |
| 157 }; | 96 }; |
| 158 | 97 |
| 159 } // namespace ui | 98 } // namespace ui |
| 160 | 99 |
| 161 #endif // UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ | 100 #endif // UI_TOUCH_SELECTION_TOUCH_SELECTION_CONTROLLER_H_ |
| OLD | NEW |