LibWeb: Implement UserActivation

This commit is contained in:
Jamie Mansfield 2024-05-25 12:40:44 +01:00 committed by Andrew Kaster
parent 227151b881
commit 01bd179eef
Notes: sideshowbarker 2024-07-17 11:34:34 +09:00
11 changed files with 104 additions and 0 deletions

View file

@ -165,6 +165,7 @@ source_set("HTML") {
"ToggleEvent.cpp",
"TrackEvent.cpp",
"TraversableNavigable.cpp",
"UserActivation.cpp",
"VideoTrack.cpp",
"VideoTrackList.cpp",
"WebViewHints.cpp",

View file

@ -225,6 +225,7 @@ standard_idl_files = [
"//Userland/Libraries/LibWeb/HTML/TimeRanges.idl",
"//Userland/Libraries/LibWeb/HTML/ToggleEvent.idl",
"//Userland/Libraries/LibWeb/HTML/TrackEvent.idl",
"//Userland/Libraries/LibWeb/HTML/UserActivation.idl",
"//Userland/Libraries/LibWeb/HTML/VideoTrack.idl",
"//Userland/Libraries/LibWeb/HTML/VideoTrackList.idl",
"//Userland/Libraries/LibWeb/HTML/Worker.idl",

View file

@ -432,6 +432,7 @@ set(SOURCES
HTML/ToggleEvent.cpp
HTML/TrackEvent.cpp
HTML/TraversableNavigable.cpp
HTML/UserActivation.cpp
HTML/VideoTrack.cpp
HTML/VideoTrackList.cpp
HTML/WebViewHints.cpp

View file

@ -466,6 +466,7 @@ class ToggleEvent;
class TrackEvent;
struct TransferDataHolder;
class TraversableNavigable;
class UserActivation;
class VideoTrack;
class VideoTrackList;
class Window;

View file

@ -62,6 +62,7 @@ void Navigator::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_mime_type_array);
visitor.visit(m_plugin_array);
visitor.visit(m_clipboard);
visitor.visit(m_user_activation);
}
JS::NonnullGCPtr<MimeTypeArray> Navigator::mime_types()
@ -85,6 +86,13 @@ JS::NonnullGCPtr<Clipboard::Clipboard> Navigator::clipboard()
return *m_clipboard;
}
JS::NonnullGCPtr<UserActivation> Navigator::user_activation()
{
if (!m_user_activation)
m_user_activation = heap().allocate<UserActivation>(realm(), realm());
return *m_user_activation;
}
// https://w3c.github.io/pointerevents/#dom-navigator-maxtouchpoints
WebIDL::Long Navigator::max_touch_points()
{

View file

@ -14,6 +14,7 @@
#include <LibWeb/HTML/NavigatorLanguage.h>
#include <LibWeb/HTML/NavigatorOnLine.h>
#include <LibWeb/HTML/PluginArray.h>
#include <LibWeb/HTML/UserActivation.h>
namespace Web::HTML {
@ -47,6 +48,7 @@ public:
[[nodiscard]] JS::NonnullGCPtr<MimeTypeArray> mime_types();
[[nodiscard]] JS::NonnullGCPtr<PluginArray> plugins();
[[nodiscard]] JS::NonnullGCPtr<Clipboard::Clipboard> clipboard();
[[nodiscard]] JS::NonnullGCPtr<UserActivation> user_activation();
static WebIDL::Long max_touch_points();
@ -65,6 +67,9 @@ private:
// https://w3c.github.io/clipboard-apis/#dom-navigator-clipboard
JS::GCPtr<Clipboard::Clipboard> m_clipboard;
// https://html.spec.whatwg.org/multipage/interaction.html#dom-navigator-useractivation
JS::GCPtr<UserActivation> m_user_activation;
};
}

View file

@ -6,6 +6,7 @@
#import <HTML/NavigatorOnLine.idl>
#import <HTML/NavigatorConcurrentHardware.idl>
#import <HTML/PluginArray.idl>
#import <HTML/UserActivation.idl>
// https://html.spec.whatwg.org/multipage/system-state.html#navigator
[Exposed=Window]
@ -17,6 +18,9 @@ interface Navigator {
// https://w3c.github.io/pointerevents/#extensions-to-the-navigator-interface
readonly attribute long maxTouchPoints;
// https://html.spec.whatwg.org/multipage/interaction.html#useractivation
[SameObject] readonly attribute UserActivation userActivation;
};
// NOTE: As NavigatorContentUtils, NavigatorCookies, NavigatorPlugins, and NavigatorAutomationInformation

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/UserActivationPrototype.h>
#include <LibWeb/HTML/UserActivation.h>
#include <LibWeb/HTML/Window.h>
namespace Web::HTML {
JS_DEFINE_ALLOCATOR(UserActivation);
WebIDL::ExceptionOr<JS::NonnullGCPtr<UserActivation>> UserActivation::construct_impl(JS::Realm& realm)
{
return realm.heap().allocate<UserActivation>(realm, realm);
}
UserActivation::UserActivation(JS::Realm& realm)
: PlatformObject(realm)
{
}
void UserActivation::initialize(JS::Realm& realm)
{
Base::initialize(realm);
WEB_SET_PROTOTYPE_FOR_INTERFACE(UserActivation);
}
// https://html.spec.whatwg.org/multipage/interaction.html#dom-useractivation-hasbeenactive
bool UserActivation::has_been_active() const
{
// The hasBeenActive getter steps are to return true if this's relevant global object has sticky activation, and false otherwise.
return verify_cast<HTML::Window>(relevant_global_object(*this)).has_sticky_activation();
}
// https://html.spec.whatwg.org/multipage/interaction.html#dom-useractivation-isactive
bool UserActivation::is_active() const
{
// The isActive getter steps are to return true if this's relevant global object has transient activation, and false otherwise.
return verify_cast<HTML::Window>(relevant_global_object(*this)).has_transient_activation();
}
}

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Bindings/PlatformObject.h>
namespace Web::HTML {
class UserActivation final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(UserActivation, Bindings::PlatformObject);
JS_DECLARE_ALLOCATOR(UserActivation);
public:
static WebIDL::ExceptionOr<JS::NonnullGCPtr<UserActivation>> construct_impl(JS::Realm&);
virtual ~UserActivation() override = default;
bool has_been_active() const;
bool is_active() const;
private:
UserActivation(JS::Realm&);
virtual void initialize(JS::Realm&) override;
};
}

View file

@ -0,0 +1,6 @@
// https://html.spec.whatwg.org/multipage/interaction.html#useractivation
[Exposed=Window]
interface UserActivation {
readonly attribute boolean hasBeenActive;
readonly attribute boolean isActive;
};

View file

@ -209,6 +209,7 @@ libweb_js_bindings(HTML/TextMetrics)
libweb_js_bindings(HTML/TimeRanges)
libweb_js_bindings(HTML/ToggleEvent)
libweb_js_bindings(HTML/TrackEvent)
libweb_js_bindings(HTML/UserActivation)
libweb_js_bindings(HTML/VideoTrack)
libweb_js_bindings(HTML/VideoTrackList)
libweb_js_bindings(HTML/Window GLOBAL)