Sfoglia il codice sorgente

LibWeb: Add CSS::Time::to_milliseconds()

Ali Mohammad Pur 2 anni fa
parent
commit
f07c4ffbc8

+ 11 - 0
Userland/Libraries/LibWeb/CSS/Time.cpp

@@ -47,6 +47,17 @@ float Time::to_seconds() const
     VERIFY_NOT_REACHED();
     VERIFY_NOT_REACHED();
 }
 }
 
 
+double Time::to_milliseconds() const
+{
+    switch (m_type) {
+    case Type::S:
+        return static_cast<double>(m_value) * 1000.0;
+    case Type::Ms:
+        return static_cast<double>(m_value);
+    }
+    VERIFY_NOT_REACHED();
+}
+
 StringView Time::unit_name() const
 StringView Time::unit_name() const
 {
 {
     switch (m_type) {
     switch (m_type) {

+ 1 - 0
Userland/Libraries/LibWeb/CSS/Time.h

@@ -27,6 +27,7 @@ public:
 
 
     ErrorOr<String> to_string() const;
     ErrorOr<String> to_string() const;
     float to_seconds() const;
     float to_seconds() const;
+    double to_milliseconds() const;
 
 
     Type type() const { return m_type; }
     Type type() const { return m_type; }
     float raw_value() const { return m_value; }
     float raw_value() const { return m_value; }