1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 07:17:34 +00:00

LibWeb: Stub out a basic Selection interface

This patch establishes scaffolding for the Selection API.
This commit is contained in:
Andreas Kling 2021-10-10 19:12:32 +02:00
parent 6782cf5193
commit 5c9ca5c2dc
11 changed files with 269 additions and 1 deletions

View file

@ -31,6 +31,7 @@
#include <LibWeb/Bindings/PerformanceWrapper.h>
#include <LibWeb/Bindings/Replaceable.h>
#include <LibWeb/Bindings/ScreenWrapper.h>
#include <LibWeb/Bindings/SelectionWrapper.h>
#include <LibWeb/Bindings/WindowObject.h>
#include <LibWeb/Bindings/WindowObjectHelper.h>
#include <LibWeb/Crypto/Crypto.h>
@ -89,6 +90,7 @@ void WindowObject::initialize_global_object()
define_native_function("getComputedStyle", get_computed_style, 1, attr);
define_native_function("matchMedia", match_media, 1, attr);
define_native_function("getSelection", get_selection, 0, attr);
// FIXME: These properties should be [Replaceable] according to the spec, but [Writable+Configurable] is the closest we have.
define_native_accessor("scrollX", scroll_x_getter, {}, attr);
@ -575,6 +577,17 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::get_computed_style)
return wrap(global_object, impl->get_computed_style(static_cast<ElementWrapper*>(object)->impl()));
}
JS_DEFINE_NATIVE_FUNCTION(WindowObject::get_selection)
{
auto* impl = impl_from(vm, global_object);
if (!impl)
return {};
auto* selection = impl->get_selection();
if (!selection)
return JS::js_null();
return wrap(global_object, *selection);
}
JS_DEFINE_NATIVE_FUNCTION(WindowObject::match_media)
{
auto* impl = impl_from(vm, global_object);

View file

@ -108,6 +108,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(get_computed_style);
JS_DECLARE_NATIVE_FUNCTION(match_media);
JS_DECLARE_NATIVE_FUNCTION(get_selection);
JS_DECLARE_NATIVE_FUNCTION(queue_microtask);

View file

@ -231,6 +231,8 @@
#include <LibWeb/Bindings/ProcessingInstructionPrototype.h>
#include <LibWeb/Bindings/ProgressEventConstructor.h>
#include <LibWeb/Bindings/ProgressEventPrototype.h>
#include <LibWeb/Bindings/RangeConstructor.h>
#include <LibWeb/Bindings/RangePrototype.h>
#include <LibWeb/Bindings/SVGElementConstructor.h>
#include <LibWeb/Bindings/SVGElementPrototype.h>
#include <LibWeb/Bindings/SVGGeometryElementConstructor.h>
@ -243,6 +245,8 @@
#include <LibWeb/Bindings/SVGSVGElementPrototype.h>
#include <LibWeb/Bindings/ScreenConstructor.h>
#include <LibWeb/Bindings/ScreenPrototype.h>
#include <LibWeb/Bindings/SelectionConstructor.h>
#include <LibWeb/Bindings/SelectionPrototype.h>
#include <LibWeb/Bindings/ShadowRootConstructor.h>
#include <LibWeb/Bindings/ShadowRootPrototype.h>
#include <LibWeb/Bindings/StyleSheetConstructor.h>
@ -390,7 +394,9 @@
ADD_WINDOW_OBJECT_INTERFACE(PerformanceTiming) \
ADD_WINDOW_OBJECT_INTERFACE(ProcessingInstruction) \
ADD_WINDOW_OBJECT_INTERFACE(ProgressEvent) \
ADD_WINDOW_OBJECT_INTERFACE(Range) \
ADD_WINDOW_OBJECT_INTERFACE(Screen) \
ADD_WINDOW_OBJECT_INTERFACE(Selection) \
ADD_WINDOW_OBJECT_INTERFACE(ShadowRoot) \
ADD_WINDOW_OBJECT_INTERFACE(StyleSheet) \
ADD_WINDOW_OBJECT_INTERFACE(StyleSheetList) \