mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:37:44 +00:00
LibWeb: Start exposing CSS style sheets to JavaScript :^)
This patch adds bindings for the following objects: - StyleSheet - StyleSheetList - CSSStyleSheet You can get to a document's style sheets via Document.styleSheets and iterate through them using StyleSheetList's item() and length(). That's it in terms of functionality at this point, but still neat. :^)
This commit is contained in:
parent
0d515dea5d
commit
a9830d9a55
12 changed files with 86 additions and 13 deletions
|
@ -37,6 +37,8 @@ namespace Web::CSS {
|
|||
|
||||
class CSSStyleSheet final : public StyleSheet {
|
||||
public:
|
||||
using WrapperType = Bindings::CSSStyleSheetWrapper;
|
||||
|
||||
static NonnullRefPtr<CSSStyleSheet> create(NonnullRefPtrVector<CSSRule> rules)
|
||||
{
|
||||
return adopt(*new CSSStyleSheet(move(rules)));
|
||||
|
@ -86,3 +88,9 @@ private:
|
|||
};
|
||||
|
||||
}
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
||||
CSSStyleSheetWrapper* wrap(JS::GlobalObject&, CSS::CSSStyleSheet&);
|
||||
|
||||
}
|
||||
|
|
6
Userland/Libraries/LibWeb/CSS/CSSStyleSheet.idl
Normal file
6
Userland/Libraries/LibWeb/CSS/CSSStyleSheet.idl
Normal file
|
@ -0,0 +1,6 @@
|
|||
interface CSSStyleSheet : StyleSheet {
|
||||
// readonly attribute CSSRule? ownerRule;
|
||||
// [SameObject] readonly attribute CSSRuleList cssRules;
|
||||
// unsigned long insertRule(CSSOMString rule, optional unsigned long index = 0);
|
||||
// undefined deleteRule(unsigned long index);
|
||||
};
|
|
@ -28,11 +28,17 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/RefCounted.h>
|
||||
#include <LibWeb/Bindings/Wrappable.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class StyleSheet : public RefCounted<StyleSheet> {
|
||||
class StyleSheet
|
||||
: public RefCounted<StyleSheet>
|
||||
, public Bindings::Wrappable {
|
||||
public:
|
||||
using WrapperType = Bindings::StyleSheetWrapper;
|
||||
|
||||
virtual ~StyleSheet() = default;
|
||||
|
||||
protected:
|
||||
|
|
9
Userland/Libraries/LibWeb/CSS/StyleSheet.idl
Normal file
9
Userland/Libraries/LibWeb/CSS/StyleSheet.idl
Normal file
|
@ -0,0 +1,9 @@
|
|||
interface StyleSheet {
|
||||
// readonly attribute CSSOMString type;
|
||||
// readonly attribute USVString? href;
|
||||
// readonly attribute (Element or ProcessingInstruction)? ownerNode;
|
||||
// readonly attribute CSSStyleSheet? parentStyleSheet;
|
||||
// readonly attribute DOMString? title;
|
||||
// [SameObject, PutForwards=mediaText] readonly attribute MediaList media;
|
||||
// attribute boolean disabled;
|
||||
};
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
namespace Web::CSS {
|
||||
|
||||
void StyleSheetList::add_sheet(NonnullRefPtr<StyleSheet> sheet)
|
||||
void StyleSheetList::add_sheet(NonnullRefPtr<CSSStyleSheet> sheet)
|
||||
{
|
||||
m_sheets.append(move(sheet));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -28,27 +28,46 @@
|
|||
|
||||
#include <AK/NonnullRefPtrVector.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <LibWeb/CSS/StyleSheet.h>
|
||||
#include <LibWeb/Bindings/Wrappable.h>
|
||||
#include <LibWeb/CSS/CSSStyleSheet.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class StyleSheetList : public RefCounted<StyleSheetList> {
|
||||
class StyleSheetList
|
||||
: public RefCounted<StyleSheetList>
|
||||
, public Bindings::Wrappable {
|
||||
public:
|
||||
using WrapperType = Bindings::StyleSheetListWrapper;
|
||||
|
||||
static NonnullRefPtr<StyleSheetList> create(DOM::Document& document)
|
||||
{
|
||||
return adopt(*new StyleSheetList(document));
|
||||
}
|
||||
|
||||
void add_sheet(NonnullRefPtr<StyleSheet>);
|
||||
void add_sheet(NonnullRefPtr<CSSStyleSheet>);
|
||||
const NonnullRefPtrVector<CSSStyleSheet>& sheets() const { return m_sheets; }
|
||||
|
||||
const NonnullRefPtrVector<StyleSheet>& sheets() const { return m_sheets; }
|
||||
RefPtr<CSSStyleSheet> item(size_t index) const
|
||||
{
|
||||
if (index >= m_sheets.size())
|
||||
return {};
|
||||
return m_sheets[index];
|
||||
}
|
||||
|
||||
size_t length() const { return m_sheets.size(); }
|
||||
|
||||
private:
|
||||
explicit StyleSheetList(DOM::Document&);
|
||||
|
||||
DOM::Document& m_document;
|
||||
NonnullRefPtrVector<StyleSheet> m_sheets;
|
||||
NonnullRefPtrVector<CSSStyleSheet> m_sheets;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
||||
StyleSheetListWrapper* wrap(JS::GlobalObject&, CSS::StyleSheetList&);
|
||||
|
||||
}
|
||||
|
|
5
Userland/Libraries/LibWeb/CSS/StyleSheetList.idl
Normal file
5
Userland/Libraries/LibWeb/CSS/StyleSheetList.idl
Normal file
|
@ -0,0 +1,5 @@
|
|||
interface StyleSheetList {
|
||||
// FIXME: item() should be a WebIDL "getter"
|
||||
CSSStyleSheet? item(unsigned long index);
|
||||
readonly attribute unsigned long length;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue