summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibWeb/CSS/MediaList.cpp4
-rw-r--r--Userland/Libraries/LibWeb/CSS/MediaQuery.cpp14
-rw-r--r--Userland/Libraries/LibWeb/CSS/MediaQuery.h2
-rw-r--r--Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp4
4 files changed, 18 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/MediaList.cpp b/Userland/Libraries/LibWeb/CSS/MediaList.cpp
index b723800519..17b81c95f1 100644
--- a/Userland/Libraries/LibWeb/CSS/MediaList.cpp
+++ b/Userland/Libraries/LibWeb/CSS/MediaList.cpp
@@ -21,9 +21,7 @@ MediaList::~MediaList()
// https://www.w3.org/TR/cssom-1/#dom-medialist-mediatext
String MediaList::media_text() const
{
- StringBuilder builder;
- builder.join(", ", m_media);
- return builder.to_string();
+ return serialize_a_media_query_list(m_media);
}
// https://www.w3.org/TR/cssom-1/#dom-medialist-mediatext
diff --git a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp
index 83effe782f..a61b825942 100644
--- a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp
+++ b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp
@@ -227,4 +227,18 @@ bool MediaQuery::evaluate(DOM::Window const& window)
return m_matches;
}
+// https://www.w3.org/TR/cssom-1/#serialize-a-media-query-list
+String serialize_a_media_query_list(NonnullRefPtrVector<MediaQuery> const& media_queries)
+{
+ // 1. If the media query list is empty, then return the empty string.
+ if (media_queries.is_empty())
+ return "";
+
+ // 2. Serialize each media query in the list of media queries, in the same order as they
+ // appear in the media query list, and then serialize the list.
+ StringBuilder builder;
+ builder.join(", ", media_queries);
+ return builder.to_string();
+}
+
}
diff --git a/Userland/Libraries/LibWeb/CSS/MediaQuery.h b/Userland/Libraries/LibWeb/CSS/MediaQuery.h
index 0e4e3fad65..5cb14662bf 100644
--- a/Userland/Libraries/LibWeb/CSS/MediaQuery.h
+++ b/Userland/Libraries/LibWeb/CSS/MediaQuery.h
@@ -93,6 +93,8 @@ private:
bool m_matches { false };
};
+String serialize_a_media_query_list(NonnullRefPtrVector<MediaQuery> const&);
+
}
namespace AK {
diff --git a/Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp b/Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp
index f581a96e96..f354be13dc 100644
--- a/Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp
+++ b/Userland/Libraries/LibWeb/CSS/MediaQueryList.cpp
@@ -29,9 +29,7 @@ MediaQueryList::~MediaQueryList()
// https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-media
String MediaQueryList::media() const
{
- StringBuilder builder;
- builder.join(", ", m_media);
- return builder.to_string();
+ return serialize_a_media_query_list(m_media);
}
// https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-matches