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

LibWeb: Fire MediaQueryListEvents when an MQL's match-state changes

The HTML event loop does a check for MQL match-state changes and
dispatches the events. This requires us to keep a list of MQLs on the
Document.
This commit is contained in:
Sam Atkins 2021-10-04 17:41:35 +01:00 committed by Andreas Kling
parent 1c829e0417
commit 050823bea7
10 changed files with 122 additions and 2 deletions

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/DOM/Event.h>
namespace Web::CSS {
struct MediaQueryListEventInit : public DOM::EventInit {
String media { "" };
bool matches { false };
};
class MediaQueryListEvent : public DOM::Event {
public:
using WrapperType = Bindings::MediaQueryListEventWrapper;
static NonnullRefPtr<MediaQueryListEvent> create(FlyString const& event_name, MediaQueryListEventInit const& event_init = {})
{
return adopt_ref(*new MediaQueryListEvent(event_name, event_init));
}
static NonnullRefPtr<MediaQueryListEvent> create_with_global_object(Bindings::WindowObject&, FlyString const& event_name, MediaQueryListEventInit const& event_init)
{
return MediaQueryListEvent::create(event_name, event_init);
}
virtual ~MediaQueryListEvent() override = default;
String const& media() const { return m_media; }
bool matches() const { return m_matches; }
protected:
MediaQueryListEvent(FlyString const& event_name, MediaQueryListEventInit const& event_init)
: DOM::Event(event_name, event_init)
, m_media(event_init.media)
, m_matches(event_init.matches)
{
}
String m_media;
bool m_matches;
};
}

View file

@ -0,0 +1,13 @@
#import <DOM/Event.idl>
interface MediaQueryListEvent : Event {
constructor(CSSOMString type, optional MediaQueryListEventInit eventInitDict = {});
readonly attribute CSSOMString media;
readonly attribute boolean matches;
};
dictionary MediaQueryListEventInit : EventInit {
CSSOMString media = "";
boolean matches = false;
};