diff options
author | Andreas Kling <kling@serenityos.org> | 2020-12-14 15:04:13 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-14 20:43:25 +0100 |
commit | 861d22838d21b56478de616dabb56a5c7bbc8b29 (patch) | |
tree | 9bc9519a8ee91ed30607c278155f55b9cc518d4c /Libraries/LibWeb/CSS/StyleValue.h | |
parent | b04e0a7677960bb8d80966b01c592572bdb38281 (diff) | |
download | serenity-861d22838d21b56478de616dabb56a5c7bbc8b29.zip |
LibWeb: Virtualize StyleValue equality check
And use this to simplify comparing two IdentifierStyleValues.
Diffstat (limited to 'Libraries/LibWeb/CSS/StyleValue.h')
-rw-r--r-- | Libraries/LibWeb/CSS/StyleValue.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Libraries/LibWeb/CSS/StyleValue.h b/Libraries/LibWeb/CSS/StyleValue.h index 1d8da443e9..61b119bad1 100644 --- a/Libraries/LibWeb/CSS/StyleValue.h +++ b/Libraries/LibWeb/CSS/StyleValue.h @@ -202,6 +202,16 @@ public: virtual bool is_auto() const { return false; } + bool operator==(const StyleValue& other) const { return equals(other); } + bool operator!=(const StyleValue& other) const { return !(*this == other); } + + virtual bool equals(const StyleValue& other) const + { + if (type() != other.type()) + return false; + return to_string() == other.to_string(); + } + protected: explicit StyleValue(Type); @@ -317,6 +327,13 @@ public: virtual String to_string() const override; virtual Color to_color(const DOM::Document&) const override; + virtual bool equals(const StyleValue& other) const override + { + if (type() != other.type()) + return false; + return m_id == static_cast<const IdentifierStyleValue&>(other).m_id; + } + private: explicit IdentifierStyleValue(CSS::ValueID id) : StyleValue(Type::Identifier) |