Chromium Code Reviews| 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 void SetNeedsAnimate() = 0; | |
| 31 virtual void MoveCaret(const gfx::PointF& position) = 0; | |
| 32 virtual void SelectBetweenCoordinates(const gfx::PointF& start, | |
| 33 const gfx::PointF& end) = 0; | |
| 34 virtual void OnSelectionEvent(SelectionEventType event, | |
| 35 const gfx::PointF& position) = 0; | |
| 36 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0; | |
| 37 }; | |
| 38 | |
| 39 // Controller for manipulating text selection via touch input. | |
| 40 class CONTENT_EXPORT TouchSelectionController : public TouchHandleClient { | |
| 41 public: | |
| 42 explicit TouchSelectionController(TouchSelectionControllerClient* client); | |
| 43 virtual ~TouchSelectionController(); | |
| 44 | |
| 45 // To be called when the selection bounds have chnaged. | |
|
cjhopman
2014/07/09 22:29:12
s/chnaged/changed
jdduke (slow)
2014/07/10 02:08:39
Done.
| |
| 46 // Note that such updates will trigger handle updates only if preceded | |
| 47 // by an appropriate call to allow automatic showing. | |
| 48 void OnSelectionBoundsChanged(const gfx::RectF& start_rect, | |
| 49 TouchHandleOrientation start_orientation, | |
| 50 bool start_visible, | |
| 51 const gfx::RectF& end_rect, | |
| 52 TouchHandleOrientation end_orientation, | |
| 53 bool end_visible); | |
| 54 | |
| 55 // Allows touch-dragging of the handle. | |
| 56 // Returns true iff the event was consumed, in which case the caller should | |
| 57 // cease further handling of the event. | |
| 58 bool WillHandleTouchEvent(const ui::MotionEvent& event); | |
| 59 | |
| 60 // Allow the insertion or selection handles to be shown from the data | |
| 61 // in |OnSelectionBoundsChanged()|. | |
| 62 void AllowAutomaticInsertionShowing(); | |
| 63 void AllowAutomaticSelectionShowing(); | |
| 64 | |
| 65 // Hide the handles and suppress bounds updates until the next explicit | |
| 66 // showing allowance. | |
| 67 void HideAndDisallowAutomaticShowing(); | |
| 68 | |
| 69 // To be called when the editability of the focused region changes. | |
| 70 void OnSelectionEditable(bool editable); | |
| 71 | |
| 72 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. | |
| 73 // Returns true if an animation is active and requires further ticking. | |
| 74 bool Animate(base::TimeTicks animate_time); | |
| 75 | |
| 76 private: | |
| 77 // TouchHandleClient implementation. | |
| 78 virtual void OnHandleDragBegin(const TouchHandle& handle) OVERRIDE; | |
| 79 virtual void OnHandleDragUpdate(const TouchHandle& handle, | |
| 80 const gfx::PointF& new_position) OVERRIDE; | |
| 81 virtual void OnHandleDragEnd(const TouchHandle& handle) OVERRIDE; | |
| 82 virtual void OnHandleTapped(const TouchHandle& handle) OVERRIDE; | |
| 83 virtual void SetNeedsAnimate() OVERRIDE; | |
| 84 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() OVERRIDE; | |
| 85 | |
| 86 void OnInsertionChanged(); | |
| 87 void OnSelectionChanged(); | |
| 88 | |
| 89 void ActivateInsertion(); | |
| 90 void DeactivateInsertion(); | |
| 91 void ActivateSelection(); | |
| 92 void DeactivateSelection(); | |
| 93 void ResetCachedValues(); | |
| 94 | |
| 95 gfx::PointF GetStartPosition() const; | |
| 96 gfx::PointF GetEndPosition() const; | |
| 97 float GetStartLineHeight() const; | |
| 98 float GetEndLineHeight() const; | |
| 99 | |
| 100 TouchSelectionControllerClient* const client_; | |
| 101 | |
| 102 gfx::RectF start_rect_; | |
| 103 TouchHandleOrientation start_orientation_; | |
| 104 bool start_visible_; | |
| 105 gfx::RectF end_rect_; | |
| 106 TouchHandleOrientation end_orientation_; | |
| 107 bool end_visible_; | |
| 108 | |
| 109 scoped_ptr<TouchHandle> insertion_handle_; | |
| 110 bool is_insertion_active_; | |
| 111 bool allow_automatic_insertion_activation_; | |
| 112 | |
| 113 scoped_ptr<TouchHandle> start_selection_handle_; | |
| 114 scoped_ptr<TouchHandle> end_selection_handle_; | |
| 115 gfx::PointF fixed_handle_position_; | |
| 116 bool is_selection_active_; | |
| 117 bool allow_automatic_selection_activation_; | |
| 118 | |
| 119 bool selection_editable_; | |
| 120 bool selection_editable_for_last_update_; | |
| 121 | |
| 122 DISALLOW_COPY_AND_ASSIGN(TouchSelectionController); | |
| 123 }; | |
| 124 | |
| 125 } // namespace content | |
| 126 | |
| 127 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_TOUCH_SELECTION_CONTROLLER_H_ | |
| OLD | NEW |