Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Unified Diff: components/keyboard_lock/widget_key_event_filter.cc

Issue 2879033002: Keyboard Lock Host implementation
Patch Set: Remove useless files Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/keyboard_lock/widget_key_event_filter.h ('k') | content/browser/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/keyboard_lock/widget_key_event_filter.cc
diff --git a/components/keyboard_lock/widget_key_event_filter.cc b/components/keyboard_lock/widget_key_event_filter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1650dbd25c7806df81481752f6bab9108c874f1d
--- /dev/null
+++ b/components/keyboard_lock/widget_key_event_filter.cc
@@ -0,0 +1,49 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/keyboard_lock/widget_key_event_filter.h"
+
+#include "base/logging.h"
+#include "content/public/browser/native_web_keyboard_event.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/render_widget_host.h"
+#include "content/public/browser/web_contents.h"
+#include "ui/events/event.h"
+
+namespace keyboard_lock {
+
+namespace {
+
+content::NativeWebKeyboardEvent CreateNativeEvent(ui::EventType type,
+ ui::KeyboardCode code,
+ int flags) {
+ content::NativeWebKeyboardEvent event(ui::KeyEvent(type, code, flags));
+ event.skip_in_browser = true;
+ return event;
+}
+
+} // namespace
+
+WidgetKeyEventFilter::WidgetKeyEventFilter(const content::WebContents* contents)
+ : host_(contents->GetRenderViewHost()->GetWidget()) {
+ DCHECK(host_);
+}
+
+WidgetKeyEventFilter::~WidgetKeyEventFilter() = default;
+
+bool WidgetKeyEventFilter::OnKeyDown(ui::KeyboardCode code, int flags) {
+ LOG(ERROR) << "Forwarding OnKeyDown " << code << " with flags " << flags;
+ host_->ForwardKeyboardEvent(CreateNativeEvent(
+ ui::ET_KEY_PRESSED, code, flags));
+ return true;
+}
+
+bool WidgetKeyEventFilter::OnKeyUp(ui::KeyboardCode code, int flags) {
+ LOG(ERROR) << "Forwarding OnKeyUp " << code << " with flags " << flags;
+ host_->ForwardKeyboardEvent(CreateNativeEvent(
+ ui::ET_KEY_RELEASED, code, flags));
+ return true;
+}
+
+} // namespace keyboard_lock
« no previous file with comments | « components/keyboard_lock/widget_key_event_filter.h ('k') | content/browser/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698