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/platform_key_event_filter.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "components/keyboard_lock/key_event_filter.h" |
| 9 #include "ui/events/event_utils.h" |
| 10 |
| 11 namespace keyboard_lock { |
| 12 |
| 13 PlatformKeyEventFilter::PlatformKeyEventFilter(KeyEventFilter* filter) |
| 14 : filter_(filter) { |
| 15 DCHECK(filter_); |
| 16 } |
| 17 PlatformKeyEventFilter::~PlatformKeyEventFilter() = default; |
| 18 |
| 19 bool PlatformKeyEventFilter::OnPlatformEvent(const ui::PlatformEvent& event) { |
| 20 ui::EventType event_type = ui::EventTypeFromNative(event); |
| 21 if (event_type != ui::ET_KEY_PRESSED && event_type != ui::ET_KEY_RELEASED) { |
| 22 return false; |
| 23 } |
| 24 |
| 25 ui::KeyboardCode code = ui::KeyboardCodeFromNative(event); |
| 26 int flags = ui::EventFlagsFromNative(event); |
| 27 bool result = (event_type == ui::ET_KEY_PRESSED ? |
| 28 filter_->OnKeyDown(code, flags) : |
| 29 filter_->OnKeyUp(code, flags)); |
| 30 return result; |
| 31 } |
| 32 |
| 33 } // namespace keyboard_lock |
OLD | NEW |