#ifndef ASH_ACCESSIBILITY_CHROMEVOX_TOUCH_ACCESSIBILITY_ENABLER_H_
#define ASH_ACCESSIBILITY_CHROMEVOX_TOUCH_ACCESSIBILITY_ENABLER_H_
#include <map>
#include "ash/ash_export.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/tick_clock.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "ui/events/event.h"
#include "ui/events/event_handler.h"
#include "ui/events/gesture_detection/gesture_detector.h"
namespace aura {
class Window;
}
namespace ash {
class TouchAccessibilityEnablerDelegate {
public:
virtual ~TouchAccessibilityEnablerDelegate() {}
virtual void ToggleSpokenFeedback() {}
};
class ASH_EXPORT TouchAccessibilityEnabler : public ui::EventHandler {
public:
TouchAccessibilityEnabler(aura::Window* root_window,
TouchAccessibilityEnablerDelegate* delegate);
TouchAccessibilityEnabler(const TouchAccessibilityEnabler&) = delete;
TouchAccessibilityEnabler& operator=(const TouchAccessibilityEnabler&) =
delete;
~TouchAccessibilityEnabler() override;
bool IsInNoFingersDownForTesting() { return state_ == NO_FINGERS_DOWN; }
bool IsInOneFingerDownForTesting() { return state_ == ONE_FINGER_DOWN; }
bool IsInTwoFingersDownForTesting() { return state_ == TWO_FINGERS_DOWN; }
bool IsInWaitForNoFingersForTesting() {
return state_ == WAIT_FOR_NO_FINGERS;
}
void TriggerOnTimerForTesting() { OnTimer(); }
void RemoveEventHandler();
void AddEventHandler();
void HandleTouchEvent(const ui::TouchEvent& event);
base::WeakPtr<TouchAccessibilityEnabler> GetWeakPtr();
private:
void OnTouchEvent(ui::TouchEvent* event) override;
void StartTimer();
void CancelTimer();
void OnTimer();
void ResetToNoFingersDown();
base::TimeTicks Now();
enum State {
NO_FINGERS_DOWN,
ONE_FINGER_DOWN,
TWO_FINGERS_DOWN,
WAIT_FOR_NO_FINGERS
};
raw_ptr<aura::Window> root_window_;
raw_ptr<TouchAccessibilityEnablerDelegate> delegate_;
State state_;
std::map<int, gfx::PointF> touch_locations_;
base::RetainingOneShotTimer timer_;
ui::GestureDetector::Config gesture_detector_config_;
raw_ptr<const base::TickClock> tick_clock_;
bool event_handler_installed_ = false;
base::WeakPtrFactory<TouchAccessibilityEnabler> weak_factory_{this};
};
}
#endif