1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39

ash / events / prerewritten_event_forwarder.cc [blame]

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/events/prerewritten_event_forwarder.h"

#include "ash/constants/ash_features.h"
#include "base/check.h"
#include "ui/base/ui_base_features.h"

namespace ash {

PrerewrittenEventForwarder::PrerewrittenEventForwarder() = default;
PrerewrittenEventForwarder::~PrerewrittenEventForwarder() = default;

ui::EventDispatchDetails PrerewrittenEventForwarder::RewriteEvent(
    const ui::Event& event,
    const Continuation continuation) {
  if (event.IsKeyEvent()) {
    const ui::KeyEvent& key_event = *event.AsKeyEvent();
    if (!key_event.is_repeat()) {
      for (auto& observer : observers_) {
        observer.OnPrerewriteKeyInputEvent(key_event);
      }
    }
  }

  return SendEvent(continuation, &event);
}

void PrerewrittenEventForwarder::AddObserver(Observer* observer) {
  observers_.AddObserver(observer);
}

void PrerewrittenEventForwarder::RemoveObserver(Observer* observer) {
  observers_.RemoveObserver(observer);
}

}  // namespace ash