OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_SELECTION_CONTROLLER_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_SELECTION_CONTROLLER_H_ |
| 7 |
| 8 #include "content/browser/renderer_host/input/selection_event_type.h" |
| 9 #include "content/browser/renderer_host/input/touch_handle.h" |
| 10 #include "content/common/content_export.h" |
| 11 #include "ui/gfx/geometry/point_f.h" |
| 12 #include "ui/gfx/geometry/rect_f.h" |
| 13 |
| 14 namespace blink { |
| 15 class WebInputEvent; |
| 16 } |
| 17 |
| 18 namespace ui { |
| 19 class MotionEvent; |
| 20 } |
| 21 |
| 22 namespace content { |
| 23 |
| 24 // Interface through which |TouchSelectionController| issues selection-related |
| 25 // commands, notifications and requests. |
| 26 class CONTENT_EXPORT TouchSelectionControllerClient { |
| 27 public: |
| 28 virtual ~TouchSelectionControllerClient() {} |
| 29 |
| 30 virtual bool SupportsAnimation() const = 0; |
| 31 virtual void SetNeedsAnimate() = 0; |
| 32 virtual void MoveCaret(const gfx::PointF& position) = 0; |
| 33 virtual void SelectBetweenCoordinates(const gfx::PointF& start, |
| 34 const gfx::PointF& end) = 0; |
| 35 virtual void OnSelectionEvent(SelectionEventType event, |
| 36 const gfx::PointF& position) = 0; |
| 37 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0; |
| 38 }; |
| 39 |
| 40 // Controller for manipulating text selection via touch input. |
| 41 class CONTENT_EXPORT TouchSelectionController : public TouchHandleClient { |
| 42 public: |
| 43 explicit TouchSelectionController(TouchSelectionControllerClient* client); |
| 44 virtual ~TouchSelectionController(); |
| 45 |
| 46 // To be called when the selection bounds have changed. |
| 47 // Note that such updates will trigger handle updates only if preceded |
| 48 // by an appropriate call to allow automatic showing. |
| 49 void OnSelectionBoundsChanged(const gfx::RectF& start_rect, |
| 50 TouchHandleOrientation start_orientation, |
| 51 bool start_visible, |
| 52 const gfx::RectF& end_rect, |
| 53 TouchHandleOrientation end_orientation, |
| 54 bool end_visible); |
| 55 |
| 56 // Allows touch-dragging of the handle. |
| 57 // Returns true iff the event was consumed, in which case the caller should |
| 58 // cease further handling of the event. |
| 59 bool WillHandleTouchEvent(const ui::MotionEvent& event); |
| 60 |
| 61 // Allow the insertion or selection handles to be shown from the data |
| 62 // in |OnSelectionBoundsChanged()|. |
| 63 void ShowInsertionHandleAutomatically(); |
| 64 void ShowSelectionHandlesAutomatically(); |
| 65 |
| 66 // Hide the handles and suppress bounds updates until the next explicit |
| 67 // showing allowance. |
| 68 void HideAndDisallowAutomaticShowing(); |
| 69 |
| 70 // Override the handle visibility according to |hidden|. |
| 71 void SetTemporarilyHidden(bool hidden); |
| 72 |
| 73 // To be called when the editability of the focused region changes. |
| 74 void OnSelectionEditable(bool editable); |
| 75 |
| 76 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. |
| 77 // Returns true if an animation is active and requires further ticking. |
| 78 bool Animate(base::TimeTicks animate_time); |
| 79 |
| 80 private: |
| 81 // TouchHandleClient implementation. |
| 82 virtual void OnHandleDragBegin(const TouchHandle& handle) OVERRIDE; |
| 83 virtual void OnHandleDragUpdate(const TouchHandle& handle, |
| 84 const gfx::PointF& new_position) OVERRIDE; |
| 85 virtual void OnHandleDragEnd(const TouchHandle& handle) OVERRIDE; |
| 86 virtual void OnHandleTapped(const TouchHandle& handle) OVERRIDE; |
| 87 virtual void SetNeedsAnimate() OVERRIDE; |
| 88 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() OVERRIDE; |
| 89 |
| 90 void OnInsertionChanged(); |
| 91 void OnSelectionChanged(); |
| 92 |
| 93 void ActivateInsertion(); |
| 94 void DeactivateInsertion(); |
| 95 void ActivateSelection(); |
| 96 void DeactivateSelection(); |
| 97 void ResetCachedValues(); |
| 98 |
| 99 gfx::PointF GetStartPosition() const; |
| 100 gfx::PointF GetEndPosition() const; |
| 101 float GetStartLineHeight() const; |
| 102 float GetEndLineHeight() const; |
| 103 bool GetStartVisible() const; |
| 104 bool GetEndVisible() const; |
| 105 TouchHandle::AnimationStyle GetAnimationStyle(bool was_active) const; |
| 106 |
| 107 TouchSelectionControllerClient* const client_; |
| 108 |
| 109 gfx::RectF start_rect_; |
| 110 TouchHandleOrientation start_orientation_; |
| 111 bool start_visible_; |
| 112 gfx::RectF end_rect_; |
| 113 TouchHandleOrientation end_orientation_; |
| 114 bool end_visible_; |
| 115 |
| 116 scoped_ptr<TouchHandle> insertion_handle_; |
| 117 bool is_insertion_active_; |
| 118 bool activate_insertion_automatically_; |
| 119 |
| 120 scoped_ptr<TouchHandle> start_selection_handle_; |
| 121 scoped_ptr<TouchHandle> end_selection_handle_; |
| 122 gfx::PointF fixed_handle_position_; |
| 123 bool is_selection_active_; |
| 124 bool activate_selection_automatically_; |
| 125 |
| 126 bool selection_editable_; |
| 127 bool selection_editable_for_last_update_; |
| 128 |
| 129 bool temporarily_hidden_; |
| 130 |
| 131 DISALLOW_COPY_AND_ASSIGN(TouchSelectionController); |
| 132 }; |
| 133 |
| 134 } // namespace content |
| 135 |
| 136 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_SELECTION_CONTROLLER_H_ |
OLD | NEW |