OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 |
| 5 #include "components/keyboard_lock/register_once_key_hook.h" |
| 6 |
| 7 namespace keyboard_lock { |
| 8 |
| 9 RegisterOnceKeyHook::RegisterOnceKeyHook() = default; |
| 10 RegisterOnceKeyHook::~RegisterOnceKeyHook() = default; |
| 11 |
| 12 bool RegisterOnceKeyHook::RegisterKey( |
| 13 const std::vector<ui::KeyboardCode>& codes) { |
| 14 bool result = false; |
| 15 if (count_ == 0) { |
| 16 result = Register(); |
| 17 } else { |
| 18 result = true; |
| 19 } |
| 20 count_ += codes.size(); |
| 21 return result; |
| 22 } |
| 23 |
| 24 bool RegisterOnceKeyHook::UnregisterKey( |
| 25 const std::vector<ui::KeyboardCode>& codes) { |
| 26 bool result = false; |
| 27 if (count_ <= static_cast<int>(codes.size())) { |
| 28 result = Unregister(); |
| 29 count_ = 0; |
| 30 } else { |
| 31 result = true; |
| 32 count_ -= codes.size(); |
| 33 } |
| 34 return result; |
| 35 } |
| 36 |
| 37 } // namespace keyboard_lock |
OLD | NEW |