#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/timer/timer.h"
#include "ui/events/event_observer.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/selection_bound.h"
#include "ui/touch_selection/touch_editing_controller.h"
#include "ui/touch_selection/touch_selection_menu_runner.h"
#include "ui/views/touchui/touch_selection_controller.h"
#include "ui/views/view.h"
#include "ui/views/views_export.h"
#include "ui/views/widget/widget_observer.h"
namespace ui {
class TouchSelectionMagnifierAura;
}
namespace views {
class VIEWS_EXPORT TouchSelectionControllerImpl
: public TouchSelectionController,
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(EditingHandleView* handle, 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;
void ShowMagnifier(const gfx::SelectionBound& focus_bound_in_screen);
void HideMagnifier();
void CreateHandleWidgets();
EditingHandleView* GetSelectionHandle1();
EditingHandleView* GetSelectionHandle2();
EditingHandleView* GetCursorHandle();
EditingHandleView* GetDraggingHandle();
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> client_view_ = nullptr;
raw_ptr<Widget> client_widget_ = nullptr;
std::unique_ptr<Widget> selection_handle_1_widget_;
std::unique_ptr<Widget> selection_handle_2_widget_;
std::unique_ptr<Widget> cursor_handle_widget_;
std::unique_ptr<ui::TouchSelectionMagnifierAura> touch_selection_magnifier_;
bool toggle_menu_enabled_ = false;
bool quick_menu_requested_ = false;
base::OneShotTimer quick_menu_timer_;
gfx::SelectionBound selection_bound_1_;
gfx::SelectionBound selection_bound_2_;
gfx::SelectionBound selection_bound_1_clipped_;
gfx::SelectionBound selection_bound_2_clipped_;
bool is_client_selection_dragging_ = false;
};
}
#endif