scoped_keyboard_hook.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #ifndef UI_AURA_SCOPED_KEYBOARD_HOOK_H_
  5. #define UI_AURA_SCOPED_KEYBOARD_HOOK_H_
  6. #include "base/memory/weak_ptr.h"
  7. #include "base/threading/thread_checker.h"
  8. #include "ui/aura/aura_export.h"
  9. namespace ui {
  10. enum class DomCode;
  11. }
  12. namespace aura {
  13. class WindowTreeHost;
  14. // Destroying an instance of this class will clean up the KeyboardHook instance
  15. // owned by WindowTreeHost and prevent future system key events from being
  16. // captured. If the KeyboardHook or WindowTreeHost instances were already
  17. // destroyed, then destroying this instance is a noop.
  18. class AURA_EXPORT ScopedKeyboardHook {
  19. public:
  20. explicit ScopedKeyboardHook(base::WeakPtr<WindowTreeHost> weak_ptr);
  21. ScopedKeyboardHook(const ScopedKeyboardHook&) = delete;
  22. ScopedKeyboardHook& operator=(const ScopedKeyboardHook&) = delete;
  23. virtual ~ScopedKeyboardHook();
  24. // True if |dom_code| is reserved for an active KeyboardLock request.
  25. virtual bool IsKeyLocked(ui::DomCode dom_code);
  26. protected:
  27. ScopedKeyboardHook();
  28. private:
  29. THREAD_CHECKER(thread_checker_);
  30. base::WeakPtr<WindowTreeHost> window_tree_host_;
  31. };
  32. } // namespace aura
  33. #endif // UI_AURA_SCOPED_KEYBOARD_HOOK_H_