Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / content / browser / renderer_host / native_web_keyboard_event_gtk.cc
blobf7631945fec3bb227871e925729da31748fba59d
1 // Copyright (c) 2011 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.
5 #include "content/public/browser/native_web_keyboard_event.h"
7 #include <gdk/gdk.h>
9 #include "third_party/WebKit/public/web/gtk/WebInputEventFactory.h"
11 using WebKit::WebInputEventFactory;
13 namespace {
15 void CopyEventTo(gfx::NativeEvent in, gfx::NativeEvent* out) {
16 *out = in ? gdk_event_copy(in) : NULL;
19 void FreeEvent(gfx::NativeEvent event) {
20 if (event)
21 gdk_event_free(event);
24 } // namespace
26 namespace content {
28 NativeWebKeyboardEvent::NativeWebKeyboardEvent()
29 : os_event(NULL),
30 skip_in_browser(false),
31 match_edit_command(false) {
34 NativeWebKeyboardEvent::NativeWebKeyboardEvent(gfx::NativeEvent native_event)
35 : WebKeyboardEvent(WebInputEventFactory::keyboardEvent(&native_event->key)),
36 skip_in_browser(false),
37 match_edit_command(false) {
38 CopyEventTo(native_event, &os_event);
41 NativeWebKeyboardEvent::NativeWebKeyboardEvent(wchar_t character,
42 int state,
43 double time_stamp_seconds)
44 : WebKeyboardEvent(WebInputEventFactory::keyboardEvent(character,
45 state,
46 time_stamp_seconds)),
47 os_event(NULL),
48 skip_in_browser(false),
49 match_edit_command(false) {
52 NativeWebKeyboardEvent::NativeWebKeyboardEvent(
53 const NativeWebKeyboardEvent& other)
54 : WebKeyboardEvent(other),
55 skip_in_browser(other.skip_in_browser),
56 match_edit_command(other.match_edit_command) {
57 CopyEventTo(other.os_event, &os_event);
60 NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=(
61 const NativeWebKeyboardEvent& other) {
62 WebKeyboardEvent::operator=(other);
64 FreeEvent(os_event);
65 CopyEventTo(other.os_event, &os_event);
67 skip_in_browser = other.skip_in_browser;
68 match_edit_command = other.match_edit_command;
70 return *this;
73 NativeWebKeyboardEvent::~NativeWebKeyboardEvent() {
74 FreeEvent(os_event);
77 } // namespace content