#ifndef UI_TOUCH_SELECTION_TOUCH_HANDLE_H_
#define UI_TOUCH_SELECTION_TOUCH_HANDLE_H_
#include <memory>
#include "arkweb/build/features/features.h"
#if BUILDFLAG(IS_ARKWEB_EXT)
#include "arkweb/ohos_nweb_ex/build/features/features.h"
#endif
#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "ui/events/velocity_tracker/motion_event.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/vector2d_f.h"
#include "ui/gfx/native_ui_types.h"
#include "ui/touch_selection/touch_handle_orientation.h"
#include "ui/touch_selection/touch_selection_draggable.h"
#include "ui/touch_selection/ui_touch_selection_export.h"
#if BUILDFLAG(IS_ANDROID)
namespace cc::slim {
class Layer;
}
#endif
namespace ui {
class TouchHandle;
#if BUILDFLAG(ARKWEB_MENU)
class TouchHandleExt;
#endif
class UI_TOUCH_SELECTION_EXPORT TouchHandleDrawable {
public:
virtual ~TouchHandleDrawable() {}
virtual void SetEnabled(bool enabled) = 0;
virtual void SetOrientation(TouchHandleOrientation orientation,
bool mirror_vertical,
bool mirror_horizontal) = 0;
virtual void SetOrigin(const gfx::PointF& origin) = 0;
virtual void SetAlpha(float alpha) = 0;
virtual gfx::RectF GetVisibleBounds() const = 0;
virtual float GetDrawableHorizontalPaddingRatio() const = 0;
#if BUILDFLAG(ARKWEB_MENU)
virtual void SetEdge(const gfx::PointF& top, const gfx::PointF& bottom) = 0;
#endif
#if BUILDFLAG(IS_ANDROID)
virtual void OnUpdateNativeViewTree(gfx::NativeView parent_native_view,
cc::slim::Layer* parent_layer) {}
#endif
};
class UI_TOUCH_SELECTION_EXPORT TouchHandleClient
: public TouchSelectionDraggableClient {
public:
~TouchHandleClient() override {}
virtual void OnHandleTapped(const TouchHandle& handle) = 0;
virtual void SetNeedsAnimate() = 0;
virtual std::unique_ptr<TouchHandleDrawable> CreateDrawable() = 0;
virtual base::TimeDelta GetMaxTapDuration() const = 0;
virtual bool IsAdaptiveHandleOrientationEnabled() const = 0;
#if BUILDFLAG(ARKWEB_MENU)
virtual bool IsShowHandle() { return false; }
#endif
};
class UI_TOUCH_SELECTION_EXPORT TouchHandle : public TouchSelectionDraggable {
public:
TouchHandle(TouchHandleClient* client,
TouchHandleOrientation orientation,
const gfx::RectF& viewport_rect);
TouchHandle(const TouchHandle&) = delete;
TouchHandle& operator=(const TouchHandle&) = delete;
~TouchHandle() override;
#if BUILDFLAG(ARKWEB_MENU)
friend class TouchHandleExt;
virtual TouchHandleExt* AsTouchHandleExt() { return nullptr; }
#endif
bool WillHandleTouchEvent(const MotionEvent& event) override;
bool IsActive() const override;
void SetEnabled(bool enabled);
enum AnimationStyle { ANIMATION_NONE, ANIMATION_SMOOTH };
void SetVisible(bool visible, AnimationStyle animation_style);
void SetFocus(const gfx::PointF& top, const gfx::PointF& bottom);
void SetViewportRect(const gfx::RectF& viewport_rect);
void SetOrientation(TouchHandleOrientation orientation);
bool Animate(base::TimeTicks frame_time);
gfx::RectF GetVisibleBounds() const;
void UpdateHandleLayout();
void SetTransparent();
#if BUILDFLAG(IS_ANDROID)
void OnUpdateNativeViewTree(gfx::NativeView parent_native_view,
cc::slim::Layer* parent_layer);
#endif
const gfx::PointF& focus_bottom() const { return focus_bottom_; }
TouchHandleOrientation orientation() const { return orientation_; }
float alpha() const { return alpha_; }
#if BUILDFLAG(ARKWEB_AI)
void SetTouchNums(int32_t touchNums) { continuous_touch_nums_ = touchNums; }
#endif
private:
gfx::PointF ComputeHandleOrigin() const;
void BeginDrag();
void EndDrag();
void BeginFade();
void EndFade();
void SetAlpha(float alpha);
void SetUpdateLayoutRequired();
std::unique_ptr<TouchHandleDrawable> drawable_;
const raw_ptr<TouchHandleClient> client_;
gfx::PointF focus_bottom_;
gfx::PointF focus_top_;
gfx::RectF viewport_rect_;
TouchHandleOrientation orientation_;
TouchHandleOrientation deferred_orientation_;
gfx::PointF touch_down_position_;
gfx::Vector2dF touch_drag_offset_;
base::TimeTicks touch_down_time_;
base::TimeTicks fade_end_time_;
gfx::PointF fade_start_position_;
float alpha_;
bool animate_deferred_fade_;
bool enabled_;
bool is_visible_;
bool is_dragging_;
bool is_drag_within_tap_region_;
bool is_handle_layout_update_required_;
bool mirror_vertical_;
bool mirror_horizontal_;
float handle_horizontal_padding_;
#if BUILDFLAG(ARKWEB_AI)
int32_t continuous_touch_nums_ = 0;
bool is_show_handle_ = false;
#endif
};
}
#if BUILDFLAG(ARKWEB_MENU)
#include "arkweb/chromium_ext/ui/touch_selection/touch_handle_ext.h"
#endif
#endif