Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / native_web_keyboard_event_gtk.cc
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.
4
5 #include "content/public/browser/native_web_keyboard_event.h"
6
7 #include <gdk/gdk.h>
8
9 #include "content/browser/renderer_host/input/web_input_event_builders_gtk.h"
10
11 namespace {
12
13 void CopyEventTo(gfx::NativeEvent in, gfx::NativeEvent* out) {
14   *out = in ? gdk_event_copy(in) : NULL;
15 }
16
17 void FreeEvent(gfx::NativeEvent event) {
18   if (event)
19     gdk_event_free(event);
20 }
21
22 }  // namespace
23
24 namespace content {
25
26 NativeWebKeyboardEvent::NativeWebKeyboardEvent()
27     : os_event(NULL),
28       skip_in_browser(false),
29       match_edit_command(false) {
30 }
31
32 NativeWebKeyboardEvent::NativeWebKeyboardEvent(gfx::NativeEvent native_event)
33     : WebKeyboardEvent(WebKeyboardEventBuilder::Build(&native_event->key)),
34       skip_in_browser(false),
35       match_edit_command(false) {
36   CopyEventTo(native_event, &os_event);
37 }
38
39 NativeWebKeyboardEvent::NativeWebKeyboardEvent(wchar_t character,
40                                                int state,
41                                                double time_stamp_seconds)
42     : WebKeyboardEvent(WebKeyboardEventBuilder::Build(character,
43                                                       state,
44                                                       time_stamp_seconds)),
45       os_event(NULL),
46       skip_in_browser(false),
47       match_edit_command(false) {
48 }
49
50 NativeWebKeyboardEvent::NativeWebKeyboardEvent(
51     const NativeWebKeyboardEvent& other)
52     : WebKeyboardEvent(other),
53       skip_in_browser(other.skip_in_browser),
54       match_edit_command(other.match_edit_command) {
55   CopyEventTo(other.os_event, &os_event);
56 }
57
58 NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=(
59     const NativeWebKeyboardEvent& other) {
60   WebKeyboardEvent::operator=(other);
61
62   FreeEvent(os_event);
63   CopyEventTo(other.os_event, &os_event);
64
65   skip_in_browser = other.skip_in_browser;
66   match_edit_command = other.match_edit_command;
67
68   return *this;
69 }
70
71 NativeWebKeyboardEvent::~NativeWebKeyboardEvent() {
72   FreeEvent(os_event);
73 }
74
75 }  // namespace content