#pragma once
#include "SVGPropertyOwner.h"
#include <wtf/Optional.h>
#include <wtf/RefCounted.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
enum class SVGPropertyAccess : uint8_t { ReadWrite, ReadOnly };
enum class SVGPropertyState : uint8_t { Clean, Dirty };
class SVGProperty : public RefCounted<SVGProperty> {
public:
virtual ~SVGProperty() = default;
bool isAttached() const { return m_owner; }
virtual void attach(SVGPropertyOwner* owner, SVGPropertyAccess access)
{
ASSERT(!m_owner);
ASSERT(m_state == SVGPropertyState::Clean);
m_owner = owner;
m_access = access;
}
virtual void detach()
{
m_owner = nullptr;
m_access = SVGPropertyAccess::ReadWrite;
m_state = SVGPropertyState::Clean;
}
void reattach(SVGPropertyOwner* owner, SVGPropertyAccess access)
{
ASSERT_UNUSED(owner, owner == m_owner);
m_access = access;
m_state = SVGPropertyState::Clean;
}
const SVGElement* contextElement() const
{
if (!m_owner)
return nullptr;
return m_owner->attributeContextElement();
}
void commitChange()
{
if (!m_owner)
return;
m_owner->commitPropertyChange(this);
}
SVGPropertyAccess access() const { return m_access; }
bool isReadOnly() const { return m_access == SVGPropertyAccess::ReadOnly; }
bool isDirty() const { return m_state == SVGPropertyState::Dirty; }
void setDirty() { m_state = SVGPropertyState::Dirty; }
Optional<String> synchronize()
{
if (m_state == SVGPropertyState::Clean)
return WTF::nullopt;
m_state = SVGPropertyState::Clean;
return valueAsString();
}
virtual String valueAsString() const { return emptyString(); }
#if !COMPILER(MSVC)
protected:
#endif
SVGProperty(SVGPropertyOwner* owner = nullptr, SVGPropertyAccess access = SVGPropertyAccess::ReadWrite)
: m_owner(owner)
, m_access(access)
{
}
SVGPropertyOwner* m_owner { nullptr };
SVGPropertyAccess m_access { SVGPropertyAccess::ReadWrite };
SVGPropertyState m_state { SVGPropertyState::Clean };
};
}