2
* Copyright (C) 2019 Igalia S.L.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
#include "PointerLockManager.h"
29
#include "NativeWebMouseEvent.h"
30
#include "WebPageProxy.h"
31
#include <WebCore/PlatformDisplay.h>
35
#include "PointerLockManagerWayland.h"
39
#include "PointerLockManagerX11.h"
43
using namespace WebCore;
45
std::unique_ptr<PointerLockManager> PointerLockManager::create(WebPageProxy& webPage, const GdkEvent* event)
48
if (PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::Wayland)
49
return makeUnique<PointerLockManagerWayland>(webPage, event);
52
if (PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::X11)
53
return makeUnique<PointerLockManagerX11>(webPage, event);
55
RELEASE_ASSERT_NOT_REACHED();
59
PointerLockManager::PointerLockManager(WebPageProxy& webPage, const GdkEvent* event)
65
PointerLockManager::~PointerLockManager()
67
RELEASE_ASSERT(!m_device);
70
bool PointerLockManager::lock()
72
RELEASE_ASSERT(!m_device);
74
auto* viewWidget = m_webPage.viewWidget();
75
m_device = gdk_seat_get_pointer(gdk_display_get_default_seat(gtk_widget_get_display(viewWidget)));
76
GRefPtr<GdkCursor> cursor = adoptGRef(gdk_cursor_new_from_name(gtk_widget_get_display(viewWidget), "none"));
77
auto grabResult = gdk_seat_grab(gdk_device_get_seat(m_device), gtk_widget_get_window(viewWidget), GDK_SEAT_CAPABILITY_ALL_POINTING, TRUE,
78
cursor.get(), nullptr, nullptr, nullptr);
79
if (grabResult != GDK_GRAB_SUCCESS) {
87
bool PointerLockManager::unlock()
92
gdk_seat_ungrab(gdk_device_get_seat(m_device));
97
void PointerLockManager::handleMotion(IntPoint&& delta)
99
m_webPage.handleMouseEvent(NativeWebMouseEvent(const_cast<GdkEvent*>(m_event), 0, delta));
102
} // namespace WebKit