فهرست منبع

LibWeb: Turn <td align> into CSS text-align

Note that align=center and align=middle both behave like the <center>
element, and not like text-align:center.
Andreas Kling 5 سال پیش
والد
کامیت
7e8945601a

+ 5 - 0
Libraries/LibWeb/CSS/StyleProperties.cpp

@@ -55,6 +55,11 @@ void StyleProperties::set_property(CSS::PropertyID id, NonnullRefPtr<StyleValue>
     m_property_values.set((unsigned)id, move(value));
 }
 
+void StyleProperties::set_property(CSS::PropertyID id, const StringView& value)
+{
+    m_property_values.set((unsigned)id, StringStyleValue::create(value));
+}
+
 Optional<NonnullRefPtr<StyleValue>> StyleProperties::property(CSS::PropertyID id) const
 {
     auto it = m_property_values.find((unsigned)id);

+ 1 - 0
Libraries/LibWeb/CSS/StyleProperties.h

@@ -52,6 +52,7 @@ public:
     }
 
     void set_property(CSS::PropertyID, NonnullRefPtr<StyleValue> value);
+    void set_property(CSS::PropertyID, const StringView&);
     Optional<NonnullRefPtr<StyleValue>> property(CSS::PropertyID) const;
 
     Length length_or_fallback(CSS::PropertyID, const Length& fallback) const;

+ 1 - 0
Libraries/LibWeb/DOM/AttributeNames.h

@@ -55,6 +55,7 @@ void initialize();
     __ENUMERATE_HTML_ATTRIBUTE(defer)   \
     __ENUMERATE_HTML_ATTRIBUTE(bgcolor) \
     __ENUMERATE_HTML_ATTRIBUTE(size)    \
+    __ENUMERATE_HTML_ATTRIBUTE(align)   \
     __ENUMERATE_HTML_ATTRIBUTE(colspan)
 
 #define __ENUMERATE_HTML_ATTRIBUTE(name) extern FlyString name;

+ 8 - 0
Libraries/LibWeb/DOM/HTMLTableCellElement.cpp

@@ -44,6 +44,14 @@ void HTMLTableCellElement::apply_presentational_hints(StyleProperties& style) co
             auto color = Color::from_string(value);
             if (color.has_value())
                 style.set_property(CSS::PropertyID::BackgroundColor, ColorStyleValue::create(color.value()));
+            return;
+        }
+        if (name == HTML::AttributeNames::align) {
+            if (value.equals_ignoring_case("center") || value.equals_ignoring_case("middle"))
+                style.set_property(CSS::PropertyID::TextAlign, StringView("-libweb-center"));
+            else
+                style.set_property(CSS::PropertyID::TextAlign, value.view());
+            return;
         }
     });
 }