diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index c263ec01a19..8177e4d3de8 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -6597,6 +6597,49 @@ String Document::dump_display_list() return display_list->dump(); } +Optional> Document::environment_variable_value(CSS::EnvironmentVariable environment_variable, Span indices) const +{ + auto invalid = [] { + return Vector { CSS::Parser::ComponentValue { CSS::Parser::GuaranteedInvalidValue {} } }; + }; + + switch (environment_variable) { + case CSS::EnvironmentVariable::PreferredTextScale: + // FIXME: Report the user's preferred text scale, once we have that as a setting. + if (!indices.is_empty()) + return invalid(); + return Vector { + CSS::Parser::ComponentValue { + CSS::Parser::Token::create_number(CSS::Number { CSS::Number::Type::Number, 1 }) } + }; + case CSS::EnvironmentVariable::SafeAreaInsetBottom: + case CSS::EnvironmentVariable::SafeAreaInsetLeft: + case CSS::EnvironmentVariable::SafeAreaInsetRight: + case CSS::EnvironmentVariable::SafeAreaInsetTop: + case CSS::EnvironmentVariable::SafeAreaMaxInsetBottom: + case CSS::EnvironmentVariable::SafeAreaMaxInsetLeft: + case CSS::EnvironmentVariable::SafeAreaMaxInsetRight: + case CSS::EnvironmentVariable::SafeAreaMaxInsetTop: + // FIXME: Report the safe area, once we can detect our display's shape (and it's not rectangular). + if (!indices.is_empty()) + return invalid(); + return Vector { + CSS::Parser::ComponentValue { CSS::Parser::Token::create_dimension(0, "px"_fly_string) } + }; + case CSS::EnvironmentVariable::ViewportSegmentBottom: + case CSS::EnvironmentVariable::ViewportSegmentHeight: + case CSS::EnvironmentVariable::ViewportSegmentLeft: + case CSS::EnvironmentVariable::ViewportSegmentRight: + case CSS::EnvironmentVariable::ViewportSegmentTop: + case CSS::EnvironmentVariable::ViewportSegmentWidth: + // "These variables are only defined when there are at least two such segments." + // https://drafts.csswg.org/css-env/#viewport-segments + // FIXME: Report the viewport segment areas, once we can detect that and there are multiple of them. + return Vector { CSS::Parser::ComponentValue { CSS::Parser::GuaranteedInvalidValue {} } }; + } + VERIFY_NOT_REACHED(); +} + HashMap>& Document::registered_custom_properties() { return m_registered_custom_properties; diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index 8bbdcc48a4e..4ec093d61de 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -909,6 +910,8 @@ public: StyleInvalidator& style_invalidator() { return m_style_invalidator; } + Optional> environment_variable_value(CSS::EnvironmentVariable, Span indices = {}) const; + // https://www.w3.org/TR/css-properties-values-api-1/#dom-window-registeredpropertyset-slot HashMap>& registered_custom_properties();