blob: b59d5350ec4e3ee3fcb465037cada7d78c2083be [file] [log] [blame]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/containers/flat_set.h"
#include "ui/events/event_rewriter.h"
namespace aura {
class Window;
} // namespace aura
namespace chromecast {
class CastTouchActivityObserver;
// An event rewriter whose purpose is to discard events (when enabled). This
// class is meant to be installed as the first rewriter in the chain, to handle
// scenarios where all input needs to be disabled, such as when the device
// screen is turned off. Instances of CastTouchActivityObserver can be
// registered to receive notifications of gated events.
class CastTouchEventGate : public ui::EventRewriter {
explicit CastTouchEventGate(aura::Window* root_window);
~CastTouchEventGate() override;
void SetEnabled(bool enabled);
void AddObserver(CastTouchActivityObserver* observer);
void RemoveObserver(CastTouchActivityObserver* observer);
// ui::EventRewriter implementation.
ui::EventRewriteStatus RewriteEvent(
const ui::Event& event,
std::unique_ptr<ui::Event>* rewritten_event) override;
ui::EventRewriteStatus NextDispatchEvent(
const ui::Event& last_event,
std::unique_ptr<ui::Event>* new_event) override;
bool enabled_ = false;
aura::Window* root_window_;
base::flat_set<CastTouchActivityObserver*> observers_;
} // namespace chromecast