2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2021-03-13 18:39:55 -03:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-06-20 18:25:25 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-09-06 10:34:26 -03:00
|
|
|
#include <AK/String.h>
|
2020-02-14 17:41:10 -03:00
|
|
|
#include <AK/Vector.h>
|
2021-03-13 18:39:55 -03:00
|
|
|
#include <LibWeb/Bindings/Wrappable.h>
|
2020-03-07 06:32:51 -03:00
|
|
|
#include <LibWeb/CSS/StyleValue.h>
|
2019-06-20 18:25:25 -03:00
|
|
|
|
2020-07-26 15:01:35 -03:00
|
|
|
namespace Web::CSS {
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2019-09-30 15:06:17 -03:00
|
|
|
struct StyleProperty {
|
2019-10-08 10:34:19 -03:00
|
|
|
CSS::PropertyID property_id;
|
2019-09-30 15:06:17 -03:00
|
|
|
NonnullRefPtr<StyleValue> value;
|
2019-10-06 04:28:10 -03:00
|
|
|
bool important { false };
|
2019-09-30 15:06:17 -03:00
|
|
|
};
|
|
|
|
|
|
2021-03-13 18:39:55 -03:00
|
|
|
class CSSStyleDeclaration
|
|
|
|
|
: public RefCounted<CSSStyleDeclaration>
|
|
|
|
|
, public Bindings::Wrappable {
|
2019-06-20 18:25:25 -03:00
|
|
|
public:
|
2021-03-13 18:39:55 -03:00
|
|
|
using WrapperType = Bindings::CSSStyleDeclarationWrapper;
|
|
|
|
|
|
2021-03-13 16:11:33 -03:00
|
|
|
static NonnullRefPtr<CSSStyleDeclaration> create(Vector<StyleProperty>&& properties)
|
2019-06-21 14:19:49 -03:00
|
|
|
{
|
2021-04-23 11:46:57 -03:00
|
|
|
return adopt_ref(*new CSSStyleDeclaration(move(properties)));
|
2019-06-21 14:19:49 -03:00
|
|
|
}
|
|
|
|
|
|
2021-03-16 14:55:53 -03:00
|
|
|
virtual ~CSSStyleDeclaration();
|
2019-06-20 18:25:25 -03:00
|
|
|
|
2019-09-30 15:06:17 -03:00
|
|
|
const Vector<StyleProperty>& properties() const { return m_properties; }
|
2019-06-20 18:25:25 -03:00
|
|
|
|
2021-03-13 18:39:55 -03:00
|
|
|
size_t length() const { return m_properties.size(); }
|
|
|
|
|
String item(size_t index) const;
|
|
|
|
|
|
2021-03-16 14:55:53 -03:00
|
|
|
protected:
|
|
|
|
|
explicit CSSStyleDeclaration(Vector<StyleProperty>&&);
|
|
|
|
|
|
2020-05-19 13:28:16 -03:00
|
|
|
private:
|
2021-03-14 13:05:02 -03:00
|
|
|
friend class Bindings::CSSStyleDeclarationWrapper;
|
|
|
|
|
|
2019-09-30 15:06:17 -03:00
|
|
|
Vector<StyleProperty> m_properties;
|
2019-06-20 18:25:25 -03:00
|
|
|
};
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2021-03-16 14:55:53 -03:00
|
|
|
class ElementInlineCSSStyleDeclaration final : public CSSStyleDeclaration {
|
|
|
|
|
public:
|
2021-04-23 11:46:57 -03:00
|
|
|
static NonnullRefPtr<ElementInlineCSSStyleDeclaration> create(DOM::Element& element) { return adopt_ref(*new ElementInlineCSSStyleDeclaration(element)); }
|
2021-03-16 14:55:53 -03:00
|
|
|
virtual ~ElementInlineCSSStyleDeclaration() override;
|
|
|
|
|
|
|
|
|
|
DOM::Element* element() { return m_element.ptr(); }
|
|
|
|
|
const DOM::Element* element() const { return m_element.ptr(); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
explicit ElementInlineCSSStyleDeclaration(DOM::Element&);
|
|
|
|
|
|
|
|
|
|
WeakPtr<DOM::Element> m_element;
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-07 06:27:02 -03:00
|
|
|
}
|
2021-03-13 18:39:55 -03:00
|
|
|
|
|
|
|
|
namespace Web::Bindings {
|
|
|
|
|
|
|
|
|
|
CSSStyleDeclarationWrapper* wrap(JS::GlobalObject&, CSS::CSSStyleDeclaration&);
|
|
|
|
|
|
|
|
|
|
}
|