scoped_simple_keyboard_hook.cc 775 B

123456789101112131415161718192021222324252627
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ui/aura/scoped_simple_keyboard_hook.h"
  5. #include <utility>
  6. #include "base/containers/contains.h"
  7. #include "ui/events/keycodes/dom/dom_code.h"
  8. namespace aura {
  9. ScopedSimpleKeyboardHook::ScopedSimpleKeyboardHook(
  10. absl::optional<base::flat_set<ui::DomCode>> dom_codes)
  11. : dom_codes_(std::move(dom_codes)) {}
  12. ScopedSimpleKeyboardHook::~ScopedSimpleKeyboardHook() = default;
  13. bool ScopedSimpleKeyboardHook::IsKeyLocked(ui::DomCode dom_code) {
  14. if (dom_code == ui::DomCode::NONE)
  15. return false;
  16. return !dom_codes_ || base::Contains(dom_codes_.value(), dom_code);
  17. }
  18. } // namespace aura