| 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/ui_touch_selection_export.h" | 16 #include "ui/touch_selection/ui_touch_selection_export.h" |
| 17 | 17 |
| 18 namespace ui { | 18 namespace ui { |
| 19 | 19 |
| 20 class TouchHandle; | 20 class TouchHandle; |
| 21 | 21 |
| 22 // Interface through which |TouchHandle| delegates rendering-specific duties. | 22 // Interface through which |TouchHandle| delegates rendering-specific duties. |
| 23 class UI_TOUCH_SELECTION_EXPORT TouchHandleDrawable { | 23 class UI_TOUCH_SELECTION_EXPORT TouchHandleDrawable { |
| 24 public: | 24 public: |
| 25 virtual ~TouchHandleDrawable() {} | 25 virtual ~TouchHandleDrawable() {} |
| 26 virtual void SetEnabled(bool enabled) = 0; | 26 virtual void SetEnabled(bool enabled) = 0; |
| 27 virtual void SetOrientation(TouchHandleOrientation orientation) = 0; | 27 virtual void SetOrientation(TouchHandleOrientation orientation, |
| 28 bool mirror_vertical, |
| 29 bool mirror_horizontal) = 0; |
| 28 virtual void SetAlpha(float alpha) = 0; | 30 virtual void SetAlpha(float alpha) = 0; |
| 29 virtual void SetFocus(const gfx::PointF& position) = 0; | 31 virtual void SetFocus(const gfx::PointF& position) = 0; |
| 30 virtual gfx::RectF GetVisibleBounds() const = 0; | 32 virtual gfx::RectF GetVisibleBounds() const = 0; |
| 31 }; | 33 }; |
| 32 | 34 |
| 33 // Interface through which |TouchHandle| communicates handle manipulation and | 35 // Interface through which |TouchHandle| communicates handle manipulation and |
| 34 // requests concrete drawable instances. | 36 // requests concrete drawable instances. |
| 35 class UI_TOUCH_SELECTION_EXPORT TouchHandleClient { | 37 class UI_TOUCH_SELECTION_EXPORT TouchHandleClient { |
| 36 public: | 38 public: |
| 37 virtual ~TouchHandleClient() {} | 39 virtual ~TouchHandleClient() {} |
| (...skipping 29 matching lines...) Expand all Loading... |
| 67 void SetVisible(bool visible, AnimationStyle animation_style); | 69 void SetVisible(bool visible, AnimationStyle animation_style); |
| 68 | 70 |
| 69 // Update the handle placement to |position|. | 71 // Update the handle placement to |position|. |
| 70 // Note: If a fade out animation is active or the handle is invisible, the | 72 // Note: If a fade out animation is active or the handle is invisible, the |
| 71 // handle position will not be updated until the handle regains visibility. | 73 // handle position will not be updated until the handle regains visibility. |
| 72 void SetPosition(const gfx::PointF& position); | 74 void SetPosition(const gfx::PointF& position); |
| 73 | 75 |
| 74 // Update the handle visuals to |orientation|. | 76 // Update the handle visuals to |orientation|. |
| 75 // Note: If the handle is being dragged, the orientation change will be | 77 // Note: If the handle is being dragged, the orientation change will be |
| 76 // deferred until the drag has ceased. | 78 // deferred until the drag has ceased. |
| 77 void SetOrientation(TouchHandleOrientation orientation); | 79 void SetOrientation(TouchHandleOrientation orientation, |
| 80 const gfx::RectF viewport_rect, |
| 81 const gfx::PointF handle_bottom); |
| 78 | 82 |
| 79 // Allows touch-dragging of the handle. Returns true if the event was | 83 // Allows touch-dragging of the handle. Returns true if the event was |
| 80 // consumed, in which case the caller should cease further handling. | 84 // consumed, in which case the caller should cease further handling. |
| 81 bool WillHandleTouchEvent(const MotionEvent& event); | 85 bool WillHandleTouchEvent(const MotionEvent& event); |
| 82 | 86 |
| 83 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. | 87 // Ticks an active animation, as requested to the client by |SetNeedsAnimate|. |
| 84 // Returns true if an animation is active and requires further ticking. | 88 // Returns true if an animation is active and requires further ticking. |
| 85 bool Animate(base::TimeTicks frame_time); | 89 bool Animate(base::TimeTicks frame_time); |
| 86 | 90 |
| 91 // Returns the visible bounds of the handle |
| 92 gfx::RectF GetHandleBounds(); |
| 93 |
| 87 bool is_dragging() const { return is_dragging_; } | 94 bool is_dragging() const { return is_dragging_; } |
| 95 bool is_inverted() const { return mirror_vertical_; } |
| 96 bool is_flipped() const { return mirror_horizontal_; } |
| 88 const gfx::PointF& position() const { return position_; } | 97 const gfx::PointF& position() const { return position_; } |
| 89 TouchHandleOrientation orientation() const { return orientation_; } | 98 TouchHandleOrientation orientation() const { return orientation_; } |
| 90 | 99 |
| 91 private: | 100 private: |
| 92 void BeginDrag(); | 101 void BeginDrag(); |
| 93 void EndDrag(); | 102 void EndDrag(); |
| 94 void BeginFade(); | 103 void BeginFade(); |
| 95 void EndFade(); | 104 void EndFade(); |
| 96 void SetAlpha(float alpha); | 105 void SetAlpha(float alpha); |
| 106 bool SetInvertHandleParameters(const gfx::RectF viewport_rect, |
| 107 const gfx::PointF handle_bottom); |
| 97 | 108 |
| 98 scoped_ptr<TouchHandleDrawable> drawable_; | 109 scoped_ptr<TouchHandleDrawable> drawable_; |
| 99 | 110 |
| 100 TouchHandleClient* const client_; | 111 TouchHandleClient* const client_; |
| 101 | 112 |
| 102 gfx::PointF position_; | 113 gfx::PointF position_; |
| 103 TouchHandleOrientation orientation_; | 114 TouchHandleOrientation orientation_; |
| 104 TouchHandleOrientation deferred_orientation_; | 115 TouchHandleOrientation deferred_orientation_; |
| 116 gfx::RectF deferred_viewport_rect_; |
| 117 gfx::PointF deferred_handle_bottom_; |
| 105 | 118 |
| 106 gfx::PointF touch_down_position_; | 119 gfx::PointF touch_down_position_; |
| 107 gfx::Vector2dF touch_to_focus_offset_; | 120 gfx::Vector2dF touch_to_focus_offset_; |
| 108 base::TimeTicks touch_down_time_; | 121 base::TimeTicks touch_down_time_; |
| 109 | 122 |
| 110 // Note that when a fade animation is active, |is_visible_| and |position_| | 123 // Note that when a fade animation is active, |is_visible_| and |position_| |
| 111 // may not reflect the actual visibilty and position of the drawable. This | 124 // may not reflect the actual visibilty and position of the drawable. This |
| 112 // discrepancy is resolved either upon fade completion or cancellation. | 125 // discrepancy is resolved either upon fade completion or cancellation. |
| 113 base::TimeTicks fade_end_time_; | 126 base::TimeTicks fade_end_time_; |
| 114 gfx::PointF fade_start_position_; | 127 gfx::PointF fade_start_position_; |
| 115 float alpha_; | 128 float alpha_; |
| 116 bool animate_deferred_fade_; | 129 bool animate_deferred_fade_; |
| 117 | 130 |
| 118 bool enabled_; | 131 bool enabled_; |
| 119 bool is_visible_; | 132 bool is_visible_; |
| 120 bool is_dragging_; | 133 bool is_dragging_; |
| 121 bool is_drag_within_tap_region_; | 134 bool is_drag_within_tap_region_; |
| 122 | 135 |
| 136 // Mirror variables determine if the handles should be inverted or not. |
| 137 bool mirror_vertical_; |
| 138 bool mirror_horizontal_; |
| 139 |
| 123 DISALLOW_COPY_AND_ASSIGN(TouchHandle); | 140 DISALLOW_COPY_AND_ASSIGN(TouchHandle); |
| 124 }; | 141 }; |
| 125 | 142 |
| 126 } // namespace ui | 143 } // namespace ui |
| 127 | 144 |
| 128 #endif // UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ | 145 #endif // UI_TOUCH_SELECTION_TOUCH_HANDLE_H_ |
| OLD | NEW |