1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:47:44 +00:00

LibWeb: Start implementing the MediaQueryList interface

This commit is contained in:
Linus Groh 2021-09-12 16:55:10 +01:00 committed by Andreas Kling
parent a61857eb0a
commit 4155cc7ed5
6 changed files with 122 additions and 0 deletions

View file

@ -187,6 +187,8 @@
#include <LibWeb/Bindings/ImageConstructor.h>
#include <LibWeb/Bindings/ImageDataConstructor.h>
#include <LibWeb/Bindings/ImageDataPrototype.h>
#include <LibWeb/Bindings/MediaQueryListConstructor.h>
#include <LibWeb/Bindings/MediaQueryListPrototype.h>
#include <LibWeb/Bindings/MessageEventConstructor.h>
#include <LibWeb/Bindings/MessageEventPrototype.h>
#include <LibWeb/Bindings/MouseEventConstructor.h>
@ -334,6 +336,7 @@
ADD_WINDOW_OBJECT_INTERFACE(HTMLUnknownElement) \
ADD_WINDOW_OBJECT_INTERFACE(HTMLVideoElement) \
ADD_WINDOW_OBJECT_INTERFACE(ImageData) \
ADD_WINDOW_OBJECT_INTERFACE(MediaQueryList) \
ADD_WINDOW_OBJECT_INTERFACE(MessageEvent) \
ADD_WINDOW_OBJECT_INTERFACE(MouseEvent) \
ADD_WINDOW_OBJECT_INTERFACE(Node) \

View file

@ -19,6 +19,7 @@ set(SOURCES
CSS/CSSStyleSheet.cpp
CSS/DefaultStyleSheetSource.cpp
CSS/Length.cpp
CSS/MediaQueryList.cpp
CSS/Parser/Parser.cpp
CSS/Parser/StyleRules.cpp
CSS/Parser/Token.cpp
@ -306,6 +307,7 @@ endfunction()
libweb_js_wrapper(CSS/CSSStyleDeclaration)
libweb_js_wrapper(CSS/CSSStyleSheet)
libweb_js_wrapper(CSS/MediaQueryList)
libweb_js_wrapper(CSS/Screen)
libweb_js_wrapper(CSS/StyleSheet)
libweb_js_wrapper(CSS/StyleSheetList)

View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/MediaQueryListWrapper.h>
#include <LibWeb/CSS/MediaQueryList.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/EventDispatcher.h>
namespace Web::CSS {
MediaQueryList::MediaQueryList(DOM::Document& document, String media)
: DOM::EventTarget(static_cast<Bindings::ScriptExecutionContext&>(document))
, m_document(document)
, m_media(move(media))
{
}
MediaQueryList::~MediaQueryList()
{
}
// https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-media
String MediaQueryList::media() const
{
// TODO: Replace this with a "media query list" and serialize on demand
return m_media;
}
// https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-matches
bool MediaQueryList::matches() const
{
// TODO: Implement me :^)
return false;
}
bool MediaQueryList::dispatch_event(NonnullRefPtr<DOM::Event> event)
{
return DOM::EventDispatcher::dispatch(*this, event);
}
JS::Object* MediaQueryList::create_wrapper(JS::GlobalObject& global_object)
{
return wrap(global_object, *this);
}
}

View file

@ -0,0 +1,58 @@
/*
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Forward.h>
#include <AK/RefCounted.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/Forward.h>
namespace Web::CSS {
// 4.2. The MediaQueryList Interface, https://drafts.csswg.org/cssom-view/#the-mediaquerylist-interface
class MediaQueryList final
: public RefCounted<MediaQueryList>
, public DOM::EventTarget
, public Bindings::Wrappable {
public:
using WrapperType = Bindings::MediaQueryListWrapper;
using RefCounted::ref;
using RefCounted::unref;
static NonnullRefPtr<MediaQueryList> create(DOM::Document& document, String media)
{
return adopt_ref(*new MediaQueryList(document, move(media)));
}
virtual ~MediaQueryList() override;
String media() const;
bool matches() const;
// ^EventTarget
virtual void ref_event_target() override { ref(); }
virtual void unref_event_target() override { unref(); }
virtual bool dispatch_event(NonnullRefPtr<DOM::Event>) override;
virtual JS::Object* create_wrapper(JS::GlobalObject&) override;
private:
MediaQueryList(DOM::Document&, String);
DOM::Document& m_document;
String m_media;
};
}
namespace Web::Bindings {
MediaQueryListWrapper* wrap(JS::GlobalObject&, CSS::MediaQueryList&);
}

View file

@ -0,0 +1,9 @@
[Exposed=Window]
interface MediaQueryList : EventTarget {
readonly attribute CSSOMString media;
readonly attribute boolean matches;
// TODO:
// undefined addListener(EventListener? callback);
// undefined removeListener(EventListener? callback);
// attribute EventHandler onchange;
};

View file

@ -298,6 +298,7 @@ class HTMLUnknownElementWrapper;
class HTMLVideoElementWrapper;
class ImageDataWrapper;
class LocationObject;
class MediaQueryListWrapper;
class MessageEventWrapper;
class MouseEventWrapper;
class NodeWrapper;