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_HANDLE_H_ | 5 #ifndef UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ |
| 6 #define UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ | 6 #define UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "ui/events/gesture_detection/motion_event.h" | 11 #include "ui/events/gesture_detection/motion_event.h" |
| 12 #include "ui/gfx/geometry/point_f.h" | 12 #include "ui/gfx/geometry/point_f.h" |
| 13 #include "ui/gfx/geometry/rect_f.h" | 13 #include "ui/gfx/geometry/rect_f.h" |
| 14 #include "ui/gfx/geometry/vector2d_f.h" | 14 #include "ui/gfx/geometry/vector2d_f.h" |
| 15 #include "ui/touch_selection/touch_handle_orientation.h" | 15 #include "ui/touch_selection/touch_handle_orientation.h" |
| 16 #include "ui/touch_selection/touch_selection_draggable.h" | 16 #include "ui/touch_selection/touch_selection_draggable.h" |
| 17 #include "ui/touch_selection/ui_touch_selection_export.h" | 17 #include "ui/touch_selection/ui_touch_selection_export.h" |
| 18 | 18 |
| 19 namespace ui { | 19 namespace ui { |
| 20 | 20 |
| 21 class TouchHandle; | 21 class TouchHandle; |
| 22 | 22 |
| 23 // Interface through which |TouchHandle| delegates rendering-specific duties. | 23 // Interface through which |TouchHandle| delegates rendering-specific duties. |
| 24 class UI_TOUCH_SELECTION_EXPORT TouchHandleDrawable { | 24 class UI_TOUCH_SELECTION_EXPORT TouchHandleDrawable { |
| 25 public: | 25 public: |
| 26 virtual ~TouchHandleDrawable() {} | 26 virtual ~TouchHandleDrawable() {} |
| 27 virtual void SetEnabled(bool enabled) = 0; | 27 virtual void SetEnabled(bool enabled) = 0; |
| 28 virtual void SetOrientation(TouchHandleOrientation orientation) = 0; | 28 virtual void SetOrientation(ui::TouchHandleOrientation orientation, |
| 29 bool mirror_vertical, | |
| 30 bool mirror_horizontal) = 0; | |
| 31 virtual void SetOrigin(const gfx::PointF& origin) = 0; | |
|
mfomitchev
2015/08/06 14:33:02
Could you please add some comments to SetOrigin, G
AviD
2015/08/09 13:55:41
Done.
| |
| 29 virtual void SetAlpha(float alpha) = 0; | 32 virtual void SetAlpha(float alpha) = 0; |
| 30 virtual void SetFocus(const gfx::PointF& position) = 0; | |
| 31 virtual gfx::RectF GetVisibleBounds() const = 0; | 33 virtual gfx::RectF GetVisibleBounds() const = 0; |
| 34 virtual const float GetDrawableHorizontalPadding() const = 0; | |
| 32 }; | 35 }; |
| 33 | 36 |
| 34 // Interface through which |TouchHandle| communicates handle manipulation and | 37 // Interface through which |TouchHandle| communicates handle manipulation and |
| 35 // requests concrete drawable instances. | 38 // requests concrete drawable instances. |
| 36 class UI_TOUCH_SELECTION_EXPORT TouchHandleClient | 39 class UI_TOUCH_SELECTION_EXPORT TouchHandleClient |
| 37 : public TouchSelectionDraggableClient { | 40 : public TouchSelectionDraggableClient { |
| 38 public: | 41 public: |
| 39 ~TouchHandleClient() override {} | 42 ~TouchHandleClient() override {} |
| 40 virtual void OnHandleTapped(const TouchHandle& handle) = 0; | 43 virtual void OnHandleTapped(const TouchHandle& handle) = 0; |
| 41 virtual void SetNeedsAnimate() = 0; | 44 virtual void SetNeedsAnimate() = 0; |
| 42 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0; | 45 virtual scoped_ptr<TouchHandleDrawable> CreateDrawable() = 0; |
| 43 virtual base::TimeDelta GetTapTimeout() const = 0; | 46 virtual base::TimeDelta GetTapTimeout() const = 0; |
| 47 virtual bool IsEnabledAdaptiveHandleOrientation() const = 0; | |
| 44 }; | 48 }; |
| 45 | 49 |
| 46 // Responsible for displaying a selection or insertion handle for text | 50 // Responsible for displaying a selection or insertion handle for text |
| 47 // interaction. | 51 // interaction. |
| 48 class UI_TOUCH_SELECTION_EXPORT TouchHandle : public TouchSelectionDraggable { | 52 class UI_TOUCH_SELECTION_EXPORT TouchHandle : public TouchSelectionDraggable { |
| 49 public: | 53 public: |
| 50 // The drawable will be enabled but invisible until otherwise specified. | 54 // The drawable will be enabled but invisible until otherwise specified. |
| 51 TouchHandle(TouchHandleClient* client, TouchHandleOrientation orientation); | 55 TouchHandle(TouchHandleClient* client, |
| 56 TouchHandleOrientation orientation, | |
| 57 const gfx::RectF viewport_rect); | |
| 52 ~TouchHandle() override; | 58 ~TouchHandle() override; |
| 53 | 59 |
| 54 // TouchSelectionDraggable implementation. | 60 // TouchSelectionDraggable implementation. |
| 55 bool WillHandleTouchEvent(const MotionEvent& event) override; | 61 bool WillHandleTouchEvent(const MotionEvent& event) override; |
| 56 bool IsActive() const override; | 62 bool IsActive() const override; |
| 57 | 63 |
| 58 // Sets whether the handle is active, allowing resource cleanup if necessary. | 64 // Sets whether the handle is active, allowing resource cleanup if necessary. |
| 59 // If false, active animations or touch drag sequences will be cancelled. | 65 // If false, active animations or touch drag sequences will be cancelled. |
| 60 // While disabled, manipulation is *explicitly not supported*, and may lead to | 66 // While disabled, manipulation is *explicitly not supported*, and may lead to |
| 61 // undesirable and/or unstable side-effects. The handle can be safely | 67 // undesirable and/or unstable side-effects. The handle can be safely |
| 62 // re-enabled to allow continued operation. | 68 // re-enabled to allow continued operation. |
| 63 void SetEnabled(bool enabled); | 69 void SetEnabled(bool enabled); |
| 64 | 70 |
| 65 enum AnimationStyle { ANIMATION_NONE, ANIMATION_SMOOTH }; | 71 enum AnimationStyle { ANIMATION_NONE, ANIMATION_SMOOTH }; |
| 66 // Update the handle visibility, fading in/out according to |animation_style|. | 72 // Update the handle visibility, fading in/out according to |animation_style|. |
| 67 // If an animation is in-progress, it will be overriden appropriately. | 73 // If an animation is in-progress, it will be overriden appropriately. |
| 68 void SetVisible(bool visible, AnimationStyle animation_style); | 74 void SetVisible(bool visible, AnimationStyle animation_style); |
| 69 | 75 |
| 70 // Update the handle placement to |position|. | 76 // Update the focus points for the handles. The Handle will be positioned |
| 77 // either |top| or |bottom| based on the mirror parameters. | |
| 71 // Note: If a fade out animation is active or the handle is invisible, the | 78 // Note: If a fade out animation is active or the handle is invisible, the |
| 72 // handle position will not be updated until the handle regains visibility. | 79 // handle position will not be updated until the handle regains visibility. |
| 73 void SetPosition(const gfx::PointF& position); | 80 void SetFocus(const gfx::PointF& top, const gfx::PointF& bottom); |
| 81 | |
| 82 // Update the Viewport rect, based on which the handle decide its inversion | |
| 83 void SetViewportRect(const gfx::RectF viewport_rect); | |
| 74 | 84 |
| 75 // Update the handle visuals to |orientation|. | 85 // Update the handle visuals to |orientation|. |
| 76 // Note: If the handle is being dragged, the orientation change will be | 86 // Note: If the handle is being dragged, the orientation change will be |
| 77 // deferred until the drag has ceased. | 87 // deferred until the drag has ceased. |
| 78 void SetOrientation(TouchHandleOrientation orientation); | 88 void SetOrientation(TouchHandleOrientation orientation); |
| 79 | 89 |
| 80 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. | 90 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. |
| 81 // Returns true if an animation is active and requires further ticking. | 91 // Returns true if an animation is active and requires further ticking. |
| 82 bool Animate(base::TimeTicks frame_time); | 92 bool Animate(base::TimeTicks frame_time); |
| 83 | 93 |
| 84 // Get the visible bounds of the handle, based on the current position and | 94 // Get the visible bounds of the handle, based on the current position and |
| 85 // the drawable's size/orientation. If the handle is invisible or disabled, | 95 // the drawable's size/orientation. If the handle is invisible or disabled, |
| 86 // the bounds will be empty. | 96 // the bounds will be empty. |
| 87 gfx::RectF GetVisibleBounds() const; | 97 gfx::RectF GetVisibleBounds() const; |
| 88 | 98 |
| 89 const gfx::PointF& position() const { return position_; } | 99 // Updates the Handle layout if the is_handle_layout_update_required_ flag is |
| 100 // set. Will be called once per frame update, avoids multiple updates for | |
| 101 // for the same frame update due to more than one parameter updates. | |
| 102 void UpdateHandleLayout(); | |
| 103 | |
| 104 const gfx::PointF& focus_bottom() const { return focus_bottom_; } | |
| 90 TouchHandleOrientation orientation() const { return orientation_; } | 105 TouchHandleOrientation orientation() const { return orientation_; } |
| 91 | 106 |
| 92 private: | 107 private: |
| 108 gfx::PointF GetHandleOrigin() const; | |
| 93 void BeginDrag(); | 109 void BeginDrag(); |
| 94 void EndDrag(); | 110 void EndDrag(); |
| 95 void BeginFade(); | 111 void BeginFade(); |
| 96 void EndFade(); | 112 void EndFade(); |
| 97 void SetAlpha(float alpha); | 113 void SetAlpha(float alpha); |
| 114 void SetUpdateLayoutRequired() { is_handle_layout_update_required_ = true; } | |
| 98 | 115 |
| 99 scoped_ptr<TouchHandleDrawable> drawable_; | 116 scoped_ptr<TouchHandleDrawable> drawable_; |
| 100 | 117 |
| 101 TouchHandleClient* const client_; | 118 TouchHandleClient* const client_; |
| 102 | 119 |
| 103 gfx::PointF position_; | 120 gfx::PointF focus_bottom_; |
| 121 gfx::PointF focus_top_; | |
| 122 gfx::RectF viewport_rect_; | |
| 104 TouchHandleOrientation orientation_; | 123 TouchHandleOrientation orientation_; |
| 105 TouchHandleOrientation deferred_orientation_; | 124 TouchHandleOrientation deferred_orientation_; |
| 106 | 125 |
| 107 gfx::PointF touch_down_position_; | 126 gfx::PointF touch_down_position_; |
| 108 gfx::Vector2dF touch_drag_offset_; | 127 gfx::Vector2dF touch_drag_offset_; |
| 109 base::TimeTicks touch_down_time_; | 128 base::TimeTicks touch_down_time_; |
| 110 | 129 |
| 111 // Note that when a fade animation is active, |is_visible_| and |position_| | 130 // Note that when a fade animation is active, |is_visible_| and |position_| |
| 112 // may not reflect the actual visibilty and position of the drawable. This | 131 // may not reflect the actual visibilty and position of the drawable. This |
| 113 // discrepancy is resolved either upon fade completion or cancellation. | 132 // discrepancy is resolved either upon fade completion or cancellation. |
| 114 base::TimeTicks fade_end_time_; | 133 base::TimeTicks fade_end_time_; |
| 115 gfx::PointF fade_start_position_; | 134 gfx::PointF fade_start_position_; |
| 116 float alpha_; | 135 float alpha_; |
| 117 bool animate_deferred_fade_; | 136 bool animate_deferred_fade_; |
| 118 | 137 |
| 119 bool enabled_; | 138 bool enabled_; |
| 120 bool is_visible_; | 139 bool is_visible_; |
| 121 bool is_dragging_; | 140 bool is_dragging_; |
| 122 bool is_drag_within_tap_region_; | 141 bool is_drag_within_tap_region_; |
| 142 bool is_handle_layout_update_required_; | |
| 143 | |
| 144 // Mirror variables determine if the handles should be inverted or not. | |
| 145 bool mirror_vertical_; | |
| 146 bool mirror_horizontal_; | |
| 147 float handle_horizontal_padding_; | |
| 123 | 148 |
| 124 DISALLOW_COPY_AND_ASSIGN(TouchHandle); | 149 DISALLOW_COPY_AND_ASSIGN(TouchHandle); |
| 125 }; | 150 }; |
| 126 | 151 |
| 127 } // namespace ui | 152 } // namespace ui |
| 128 | 153 |
| 129 #endif // UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ | 154 #endif // UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ |
| OLD | NEW |