summaryrefslogtreecommitdiffstats
path: root/src/core/native_web_keyboard_event_qt.cpp
blob: 77bc068c7272db7c917d2ca7fc40029a72319418 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

// Copyright (c) 2011 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.Chromium file.

#include "content/public/browser/native_web_keyboard_event.h"
#include <QKeyEvent>

namespace {

// We need to copy |os_event| in NativeWebKeyboardEvent because it is
// queued in RenderWidgetHost and may be passed and used
// RenderViewHostDelegate::HandledKeybardEvent after the original aura
// event is destroyed.
gfx::NativeEvent CopyEvent(gfx::NativeEvent event)
{
    if (!event)
        return nullptr;

    QKeyEvent *keyEvent = reinterpret_cast<QKeyEvent *>(event);
    return reinterpret_cast<gfx::NativeEvent>(keyEvent->clone());
}

void DestroyEvent(gfx::NativeEvent event)
{
    delete reinterpret_cast<QKeyEvent*>(event);
}

}  // namespace

using blink::WebKeyboardEvent;

namespace content {

NativeWebKeyboardEvent::NativeWebKeyboardEvent(blink::WebKeyboardEvent const&, gfx::NativeView)
    : os_event(0)
    , skip_in_browser(false)
{
}

NativeWebKeyboardEvent::NativeWebKeyboardEvent(blink::WebInputEvent::Type, int, base::TimeTicks)
    : os_event(0)
    , skip_in_browser(false)
{
}

NativeWebKeyboardEvent::NativeWebKeyboardEvent(gfx::NativeEvent native_event)
    : os_event(CopyEvent(native_event)),
      skip_in_browser(false)
{
}

NativeWebKeyboardEvent::NativeWebKeyboardEvent(const NativeWebKeyboardEvent& other)
    : WebKeyboardEvent(other),
    os_event(CopyEvent(other.os_event)),
    skip_in_browser(other.skip_in_browser)
{
}

NativeWebKeyboardEvent &NativeWebKeyboardEvent::operator=(const NativeWebKeyboardEvent &other)
{
    if (this == &other)
        return *this;
    WebKeyboardEvent::operator=(other);
    DestroyEvent(os_event);
    os_event = CopyEvent(other.os_event);
    skip_in_browser = other.skip_in_browser;
    return *this;
}

NativeWebKeyboardEvent::~NativeWebKeyboardEvent() {
    DestroyEvent(os_event);
}

}  // namespace content