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/widget_key_event_filter.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "content/public/browser/native_web_keyboard_event.h" |
| 9 #include "content/public/browser/render_view_host.h" |
| 10 #include "content/public/browser/render_widget_host.h" |
| 11 #include "content/public/browser/web_contents.h" |
| 12 #include "ui/events/event.h" |
| 13 |
| 14 namespace keyboard_lock { |
| 15 |
| 16 namespace { |
| 17 |
| 18 content::NativeWebKeyboardEvent CreateNativeEvent(ui::EventType type, |
| 19 ui::KeyboardCode code, |
| 20 int flags) { |
| 21 content::NativeWebKeyboardEvent event(ui::KeyEvent(type, code, flags)); |
| 22 event.skip_in_browser = true; |
| 23 return event; |
| 24 } |
| 25 |
| 26 } // namespace |
| 27 |
| 28 WidgetKeyEventFilter::WidgetKeyEventFilter(const content::WebContents* contents) |
| 29 : host_(contents->GetRenderViewHost()->GetWidget()) { |
| 30 DCHECK(host_); |
| 31 } |
| 32 |
| 33 WidgetKeyEventFilter::~WidgetKeyEventFilter() = default; |
| 34 |
| 35 bool WidgetKeyEventFilter::OnKeyDown(ui::KeyboardCode code, int flags) { |
| 36 LOG(ERROR) << "Forwarding OnKeyDown " << code << " with flags " << flags; |
| 37 host_->ForwardKeyboardEvent(CreateNativeEvent( |
| 38 ui::ET_KEY_PRESSED, code, flags)); |
| 39 return true; |
| 40 } |
| 41 |
| 42 bool WidgetKeyEventFilter::OnKeyUp(ui::KeyboardCode code, int flags) { |
| 43 LOG(ERROR) << "Forwarding OnKeyUp " << code << " with flags " << flags; |
| 44 host_->ForwardKeyboardEvent(CreateNativeEvent( |
| 45 ui::ET_KEY_RELEASED, code, flags)); |
| 46 return true; |
| 47 } |
| 48 |
| 49 } // namespace keyboard_lock |
OLD | NEW |