summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorTobias Christiansen <tobi@tobyase.de>2021-06-12 00:03:15 +0200
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-07-24 03:02:07 +0430
commit20667dfff561700df69c6a6b5ff78c00d652f200 (patch)
treedb5ebc180a17665400b6d59909e57ca869aa3ace /Userland/Libraries/LibWeb
parent328afa32c6ed02c7f62b13af7626b0575ac35745 (diff)
downloadserenity-20667dfff561700df69c6a6b5ff78c00d652f200.zip
LibWeb: Plumb calculated StyleValues into CSS::Length
This is a bit hackish, but this way the existance of the calc() becomes transparent to the user who just wants a Length and doesn't care where it came from.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/CSS/Length.cpp2
-rw-r--r--Userland/Libraries/LibWeb/CSS/Length.h11
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleProperties.cpp7
-rw-r--r--Userland/Libraries/LibWeb/Forward.h1
4 files changed, 20 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Length.cpp b/Userland/Libraries/LibWeb/CSS/Length.cpp
index 6d19c06aee..a8c73d134a 100644
--- a/Userland/Libraries/LibWeb/CSS/Length.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Length.cpp
@@ -76,6 +76,8 @@ const char* Length::unit_name() const
return "vmax";
case Type::Vmin:
return "vmin";
+ case Type::Calculated:
+ return "calculated";
}
VERIFY_NOT_REACHED();
}
diff --git a/Userland/Libraries/LibWeb/CSS/Length.h b/Userland/Libraries/LibWeb/CSS/Length.h
index fe015afd59..c9c8c465d1 100644
--- a/Userland/Libraries/LibWeb/CSS/Length.h
+++ b/Userland/Libraries/LibWeb/CSS/Length.h
@@ -16,6 +16,7 @@ public:
enum class Type {
Undefined,
Percentage,
+ Calculated,
Auto,
Cm,
In,
@@ -54,6 +55,8 @@ public:
return fallback_for_undefined;
if (is_percentage())
return make_px(raw_value() / 100.0f * reference_for_percent);
+ if (is_calculated())
+ return {};
if (is_relative())
return make_px(to_px(layout_node));
return *this;
@@ -71,8 +74,9 @@ public:
bool is_undefined_or_auto() const { return m_type == Type::Undefined || m_type == Type::Auto; }
bool is_undefined() const { return m_type == Type::Undefined; }
- bool is_percentage() const { return m_type == Type::Percentage; }
+ bool is_percentage() const { return m_type == Type::Percentage || m_type == Type::Calculated; }
bool is_auto() const { return m_type == Type::Auto; }
+ bool is_calculated() const { return m_type == Type::Calculated; }
bool is_absolute() const
{
@@ -122,6 +126,7 @@ public:
return m_value * ((1.0f / 40.0f) * centimeter_pixels); // 1Q = 1/40th of 1cm
case Type::Undefined:
case Type::Percentage:
+ case Type::Calculated:
default:
VERIFY_NOT_REACHED();
}
@@ -144,6 +149,8 @@ public:
return !(*this == other);
}
+ void set_calculated_style(CalculatedStyleValue* value) { m_calculated_style = value; }
+
private:
float relative_length_to_px(const Layout::Node&) const;
@@ -151,6 +158,8 @@ private:
Type m_type { Type::Undefined };
float m_value { 0 };
+
+ CalculatedStyleValue* m_calculated_style { nullptr };
};
}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
index 30b1e5d51a..c5a9807c49 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp
@@ -55,6 +55,13 @@ Length StyleProperties::length_or_fallback(CSS::PropertyID id, const Length& fal
auto value = property(id);
if (!value.has_value())
return fallback;
+
+ if (value.value()->is_calculated()) {
+ Length length = Length(0, Length::Type::Calculated);
+ length.set_calculated_style(verify_cast<CalculatedStyleValue>(value.value().ptr()));
+ return length;
+ }
+
return value.value()->to_length();
}
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h
index 320287fe2c..7c14e9fa8d 100644
--- a/Userland/Libraries/LibWeb/Forward.h
+++ b/Userland/Libraries/LibWeb/Forward.h
@@ -14,6 +14,7 @@ enum class Source;
}
namespace Web::CSS {
+class CalculatedStyleValue;
class CSSRule;
class CSSImportRule;
class CSSStyleDeclaration;