File: WebViewTestWPE.cpp

package info (click to toggle)
wpewebkit 2.50.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 438,288 kB
  • sloc: cpp: 3,777,429; javascript: 197,888; ansic: 156,951; python: 49,118; asm: 21,987; ruby: 18,540; perl: 16,722; xml: 4,623; yacc: 2,360; sh: 2,096; java: 2,019; lex: 1,327; pascal: 366; makefile: 92
file content (187 lines) | stat: -rw-r--r-- 7,296 bytes parent folder | download
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
 * Copyright (C) 2017 Igalia S.L.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "config.h"
#include "WebViewTest.h"

#include <wpe/wpe.h>
#include <wtf/glib/GUniquePtr.h>

void WebViewTest::platformDestroy()
{
}

void WebViewTest::quitMainLoopAfterProcessingPendingEvents()
{
    // FIXME: implement if needed.
    quitMainLoop();
}

void WebViewTest::resizeView(int width, int height)
{
    // FIXME: implement.
}

void WebViewTest::showInWindow(int width, int height)
{
#if ENABLE(WPE_PLATFORM)
    if (m_display) {
        auto* view = webkit_web_view_get_wpe_view(m_webView.get());
        g_assert_true(WPE_IS_VIEW(view));
        if (width && height)
            wpe_toplevel_resize(wpe_view_get_toplevel(view), width, height);
        wpe_view_set_visible(view, TRUE);
        wpe_view_focus_in(view);
        return;
    }
#endif
    auto* backend = webkit_web_view_backend_get_wpe_backend(webkit_web_view_get_backend(m_webView.get()));
    wpe_view_backend_add_activity_state(backend, wpe_view_activity_state_visible | wpe_view_activity_state_in_window | wpe_view_activity_state_focused);
}

void WebViewTest::hideView()
{
#if ENABLE(WPE_PLATFORM)
    if (m_display) {
        auto* view = webkit_web_view_get_wpe_view(m_webView.get());
        wpe_view_set_visible(view, FALSE);
        wpe_view_focus_out(view);
        return;
    }
#endif
    auto* backend = webkit_web_view_backend_get_wpe_backend(webkit_web_view_get_backend(m_webView.get()));
    wpe_view_backend_remove_activity_state(backend, wpe_view_activity_state_visible | wpe_view_activity_state_focused);
}

static unsigned testModifiersToWPELegacy(const OptionSet<WebViewTest::Modifiers>& modifiers)
{
    unsigned wpeModifiers = 0;
    if (modifiers.contains(WebViewTest::Modifiers::Control))
        wpeModifiers |= wpe_input_keyboard_modifier_control;
    if (modifiers.contains(WebViewTest::Modifiers::Shift))
        wpeModifiers |= wpe_input_keyboard_modifier_shift;
    if (modifiers.contains(WebViewTest::Modifiers::Alt))
        wpeModifiers |= wpe_input_keyboard_modifier_alt;
    if (modifiers.contains(WebViewTest::Modifiers::Meta))
        wpeModifiers |= wpe_input_keyboard_modifier_meta;
    return wpeModifiers;
}

static unsigned testMouseButtonToWPELegacy(WebViewTest::MouseButton button)
{
    switch (button) {
    case WebViewTest::MouseButton::Primary:
        return 1;
    case WebViewTest::MouseButton::Middle:
        return 3;
    case WebViewTest::MouseButton::Secondary:
        return 2;
    }
    RELEASE_ASSERT_NOT_REACHED();
}

#if ENABLE(WPE_PLATFORM)
static WPEModifiers testModifiersToWPE(const OptionSet<WebViewTest::Modifiers>& modifiers)
{
    unsigned wpeModifiers = 0;
    if (modifiers.contains(WebViewTest::Modifiers::Control))
        wpeModifiers |= WPE_MODIFIER_KEYBOARD_CONTROL;
    if (modifiers.contains(WebViewTest::Modifiers::Shift))
        wpeModifiers |= WPE_MODIFIER_KEYBOARD_SHIFT;
    if (modifiers.contains(WebViewTest::Modifiers::Alt))
        wpeModifiers |= WPE_MODIFIER_KEYBOARD_ALT;
    if (modifiers.contains(WebViewTest::Modifiers::Meta))
        wpeModifiers |= WPE_MODIFIER_KEYBOARD_META;
    return static_cast<WPEModifiers>(wpeModifiers);
}

static unsigned testMouseButtonToWPE(WebViewTest::MouseButton button)
{
    switch (button) {
    case WebViewTest::MouseButton::Primary:
        return WPE_BUTTON_PRIMARY;
    case WebViewTest::MouseButton::Middle:
        return WPE_BUTTON_MIDDLE;
    case WebViewTest::MouseButton::Secondary:
        return WPE_BUTTON_SECONDARY;
    }
    RELEASE_ASSERT_NOT_REACHED();
}
#endif

void WebViewTest::mouseMoveTo(int x, int y, OptionSet<Modifiers> mouseModifiers)
{
    // FIXME: implement.
}

void WebViewTest::clickMouseButton(int x, int y, MouseButton button, OptionSet<Modifiers> mouseModifiers)
{
#if ENABLE(WPE_PLATFORM)
    if (m_display) {
        auto wpeModifiers = testModifiersToWPE(mouseModifiers);
        auto wpeButton = testMouseButtonToWPE(button);
        auto* view = webkit_web_view_get_wpe_view(m_webView.get());
        auto* event = wpe_event_pointer_button_new(WPE_EVENT_POINTER_DOWN, view, WPE_INPUT_SOURCE_MOUSE, 0, wpeModifiers, wpeButton, x, y, 1);
        wpe_view_event(view, event);
        wpe_event_unref(event);
        event = wpe_event_pointer_button_new(WPE_EVENT_POINTER_UP, view, WPE_INPUT_SOURCE_MOUSE, 0, wpeModifiers, wpeButton, x, y, 0);
        wpe_view_event(view, event);
        wpe_event_unref(event);
        return;
    }
#endif
    auto* backend = webkit_web_view_backend_get_wpe_backend(webkit_web_view_get_backend(m_webView.get()));
    struct wpe_input_pointer_event event { wpe_input_pointer_event_type_button, 0, x, y, testMouseButtonToWPELegacy(button), 1, testModifiersToWPELegacy(mouseModifiers) };
    wpe_view_backend_dispatch_pointer_event(backend, &event);
    event.state = 0;
    wpe_view_backend_dispatch_pointer_event(backend, &event);
}

void WebViewTest::keyStroke(unsigned keyVal, OptionSet<Modifiers> keyModifiers)
{
#if ENABLE(WPE_PLATFORM)
    if (m_display) {
        auto* view = webkit_web_view_get_wpe_view(m_webView.get());
        unsigned keycode = 0;
        auto* keymap = wpe_display_get_keymap(wpe_view_get_display(view));
        GUniqueOutPtr<WPEKeymapEntry> entries;
        guint entriesCount;
        if (wpe_keymap_get_entries_for_keyval(keymap, keyVal, &entries.outPtr(), &entriesCount))
            keycode = entries.get()[0].keycode;

        auto wpeModifiers = testModifiersToWPE(keyModifiers);
        auto* event = wpe_event_keyboard_new(WPE_EVENT_KEYBOARD_KEY_DOWN, view, WPE_INPUT_SOURCE_KEYBOARD, 0, wpeModifiers, keycode, keyVal);
        wpe_view_event(view, event);
        wpe_event_unref(event);
        event = wpe_event_keyboard_new(WPE_EVENT_KEYBOARD_KEY_UP, view, WPE_INPUT_SOURCE_KEYBOARD, 0, wpeModifiers, keycode, keyVal);
        wpe_view_event(view, event);
        wpe_event_unref(event);
        return;
    }
#endif
    auto* backend = webkit_web_view_backend_get_wpe_backend(webkit_web_view_get_backend(m_webView.get()));
    struct wpe_input_xkb_keymap_entry* entries;
    uint32_t entriesCount;
    wpe_input_xkb_context_get_entries_for_key_code(wpe_input_xkb_context_get_default(), keyVal, &entries, &entriesCount);
    struct wpe_input_keyboard_event event { 0, keyVal, entriesCount ? entries[0].hardware_key_code : 0, true, testModifiersToWPELegacy(keyModifiers) };
    wpe_view_backend_dispatch_keyboard_event(backend, &event);
    event.pressed = false;
    wpe_view_backend_dispatch_keyboard_event(backend, &event);
    free(entries);
}