#ifndef UI_VIEWS_TOUCHUI_TOUCH_SELECTION_CONTROLLER_IMPL_H_
#define UI_VIEWS_TOUCHUI_TOUCH_SELECTION_CONTROLLER_IMPL_H_
#include <memory>
#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "ui/base/pointer/touch_editing_controller.h"
#include "ui/events/event_observer.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/selection_bound.h"
#include "ui/touch_selection/touch_selection_menu_runner.h"
#include "ui/views/view.h"
#include "ui/views/views_export.h"
#include "ui/views/widget/widget_observer.h"
namespace views {
class VIEWS_EXPORT TouchSelectionControllerImpl
: public ui::TouchEditingControllerDeprecated,
public ui::TouchSelectionMenuClient,
public WidgetObserver,
public ui::EventObserver {
public:
class EditingHandleView;
explicit TouchSelectionControllerImpl(ui::TouchEditable* client_view);
TouchSelectionControllerImpl(const TouchSelectionControllerImpl&) = delete;
TouchSelectionControllerImpl& operator=(const TouchSelectionControllerImpl&) =
delete;
~TouchSelectionControllerImpl() override;
void SelectionChanged() override;
void ToggleQuickMenu() override;
void ShowQuickMenuImmediatelyForTesting();
private:
friend class TouchSelectionControllerImplTest;
void OnDragBegin(EditingHandleView* handle);
void OnDragUpdate(const gfx::Point& drag_pos);
void OnDragEnd();
void ConvertPointToClientView(EditingHandleView* source, gfx::Point* point);
void SetHandleBound(EditingHandleView* handle,
const gfx::SelectionBound& bound,
const gfx::SelectionBound& bound_in_screen);
bool ShouldShowHandleFor(const gfx::SelectionBound& bound) const;
bool IsCommandIdEnabled(int command_id) const override;
void ExecuteCommand(int command_id, int event_flags) override;
void RunContextMenu() override;
bool ShouldShowQuickMenu() override;
std::u16string GetSelectedText() override;
void OnWidgetDestroying(Widget* widget) override;
void OnWidgetBoundsChanged(Widget* widget,
const gfx::Rect& new_bounds) override;
void OnEvent(const ui::Event& event) override;
void QuickMenuTimerFired();
void StartQuickMenuTimer();
void UpdateQuickMenu();
void HideQuickMenu();
gfx::Rect GetQuickMenuAnchorRect() const;
gfx::NativeView GetCursorHandleNativeView();
gfx::SelectionBound::Type GetSelectionHandle1Type();
gfx::Rect GetSelectionHandle1Bounds();
gfx::Rect GetSelectionHandle2Bounds();
gfx::Rect GetCursorHandleBounds();
bool IsSelectionHandle1Visible();
bool IsSelectionHandle2Visible();
bool IsCursorHandleVisible();
gfx::Rect GetExpectedHandleBounds(const gfx::SelectionBound& bound);
View* GetHandle1View();
View* GetHandle2View();
raw_ptr<ui::TouchEditable, DanglingUntriaged> client_view_;
raw_ptr<Widget, DanglingUntriaged> client_widget_ = nullptr;
raw_ptr<EditingHandleView, DanglingUntriaged> selection_handle_1_;
raw_ptr<EditingHandleView, DanglingUntriaged> selection_handle_2_;
raw_ptr<EditingHandleView, DanglingUntriaged> cursor_handle_;
bool command_executed_ = false;
base::TimeTicks selection_start_time_;
bool toggle_menu_enabled_ = false;
bool quick_menu_requested_ = false;
base::OneShotTimer quick_menu_timer_;
raw_ptr<EditingHandleView, DanglingUntriaged> dragging_handle_ = nullptr;
gfx::SelectionBound selection_bound_1_;
gfx::SelectionBound selection_bound_2_;
gfx::SelectionBound selection_bound_1_clipped_;
gfx::SelectionBound selection_bound_2_clipped_;
};
}
#endif