Forráskód Böngészése

LibWeb: Map dimension attributes for table elements

Tim Ledbetter 10 hónapja
szülő
commit
140dc95e67

+ 4 - 4
Tests/LibWeb/Layout/expected/table/colgroup-with-two-cols.txt

@@ -1,8 +1,8 @@
 Viewport <#document> at (0,0) content-size 800x600 children: not-inline
 Viewport <#document> at (0,0) content-size 800x600 children: not-inline
   BlockContainer <html> at (0,0) content-size 800x600 [BFC] children: not-inline
   BlockContainer <html> at (0,0) content-size 800x600 [BFC] children: not-inline
     BlockContainer <body> at (8,8) content-size 784x2 children: not-inline
     BlockContainer <body> at (8,8) content-size 784x2 children: not-inline
-      TableWrapper <(anonymous)> at (8,8) content-size 6x2 [BFC] children: not-inline
-        Box <table> at (8,8) content-size 6x2 table-box [TFC] children: not-inline
+      TableWrapper <(anonymous)> at (8,8) content-size 46x2 [BFC] children: not-inline
+        Box <table> at (8,8) content-size 46x2 table-box [TFC] children: not-inline
           BlockContainer <colgroup#my-group> (not painted) table-column-group children: not-inline
           BlockContainer <colgroup#my-group> (not painted) table-column-group children: not-inline
             BlockContainer <col> (not painted) children: not-inline
             BlockContainer <col> (not painted) children: not-inline
             BlockContainer <col> (not painted) children: not-inline
             BlockContainer <col> (not painted) children: not-inline
@@ -11,6 +11,6 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
 ViewportPaintable (Viewport<#document>) [0,0 800x600]
 ViewportPaintable (Viewport<#document>) [0,0 800x600]
   PaintableWithLines (BlockContainer<HTML>) [0,0 800x600]
   PaintableWithLines (BlockContainer<HTML>) [0,0 800x600]
     PaintableWithLines (BlockContainer<BODY>) [8,8 784x2]
     PaintableWithLines (BlockContainer<BODY>) [8,8 784x2]
-      PaintableWithLines (TableWrapper(anonymous)) [8,8 6x2]
-        PaintableBox (Box<TABLE>) [8,8 6x2]
+      PaintableWithLines (TableWrapper(anonymous)) [8,8 46x2]
+        PaintableBox (Box<TABLE>) [8,8 46x2]
           PaintableBox (Box<TBODY>) [8,8 0x0]
           PaintableBox (Box<TBODY>) [8,8 0x0]

+ 6 - 0
Tests/LibWeb/Text/expected/HTML/dimension-attributes.txt

@@ -55,3 +55,9 @@ Test embed.width = "120." maps to width: 120px
 Test embed.height = "100" maps to height: 100px
 Test embed.height = "100" maps to height: 100px
 Test embed.height = " 00110 " maps to height: 110px
 Test embed.height = " 00110 " maps to height: 110px
 Test embed.height = "120." maps to height: 120px
 Test embed.height = "120." maps to height: 120px
+Test tr.height = "100" maps to height: 100px
+Test tr.height = " 00110 " maps to height: 110px
+Test tr.height = "120." maps to height: 120px
+Test col.width = "100" maps to width: 100px
+Test col.width = " 00110 " maps to width: 110px
+Test col.width = "120." maps to width: 120px

+ 2 - 0
Tests/LibWeb/Text/input/HTML/dimension-attributes.html

@@ -22,6 +22,8 @@
             { elementName: "embed", attribute: "vspace", mappedProperty: "marginBottom" },
             { elementName: "embed", attribute: "vspace", mappedProperty: "marginBottom" },
             { elementName: "embed", attribute: "width", mappedProperty: "width" },
             { elementName: "embed", attribute: "width", mappedProperty: "width" },
             { elementName: "embed", attribute: "height", mappedProperty: "height" },
             { elementName: "embed", attribute: "height", mappedProperty: "height" },
+            { elementName: "tr", attribute: "height", mappedProperty: "height" },
+            { elementName: "col", attribute: "width", mappedProperty: "width" },
         ];
         ];
         const values = ["100", " 00110 ", "120."];
         const values = ["100", " 00110 ", "120."];
 
 

+ 14 - 0
Userland/Libraries/LibWeb/HTML/HTMLTableColElement.cpp

@@ -6,8 +6,10 @@
 
 
 #include <LibWeb/Bindings/HTMLTableColElementPrototype.h>
 #include <LibWeb/Bindings/HTMLTableColElementPrototype.h>
 #include <LibWeb/Bindings/Intrinsics.h>
 #include <LibWeb/Bindings/Intrinsics.h>
+#include <LibWeb/CSS/StyleProperties.h>
 #include <LibWeb/HTML/HTMLTableColElement.h>
 #include <LibWeb/HTML/HTMLTableColElement.h>
 #include <LibWeb/HTML/Numbers.h>
 #include <LibWeb/HTML/Numbers.h>
+#include <LibWeb/HTML/Parser/HTMLParser.h>
 
 
 namespace Web::HTML {
 namespace Web::HTML {
 
 
@@ -42,4 +44,16 @@ WebIDL::ExceptionOr<void> HTMLTableColElement::set_span(unsigned int value)
     return set_attribute(HTML::AttributeNames::span, MUST(String::number(value)));
     return set_attribute(HTML::AttributeNames::span, MUST(String::number(value)));
 }
 }
 
 
+void HTMLTableColElement::apply_presentational_hints(CSS::StyleProperties& style) const
+{
+    for_each_attribute([&](auto& name, auto& value) {
+        // https://html.spec.whatwg.org/multipage/rendering.html#tables-2:maps-to-the-dimension-property-2
+        if (name == HTML::AttributeNames::width) {
+            if (auto parsed_value = parse_dimension_value(value)) {
+                style.set_property(CSS::PropertyID::Width, *parsed_value);
+            }
+        }
+    });
+}
+
 }
 }

+ 2 - 0
Userland/Libraries/LibWeb/HTML/HTMLTableColElement.h

@@ -24,6 +24,8 @@ private:
     HTMLTableColElement(DOM::Document&, DOM::QualifiedName);
     HTMLTableColElement(DOM::Document&, DOM::QualifiedName);
 
 
     virtual void initialize(JS::Realm&) override;
     virtual void initialize(JS::Realm&) override;
+
+    virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
 };
 };
 
 
 }
 }

+ 7 - 1
Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp

@@ -11,6 +11,7 @@
 #include <LibWeb/CSS/StyleProperties.h>
 #include <LibWeb/CSS/StyleProperties.h>
 #include <LibWeb/CSS/StyleValues/CSSColorValue.h>
 #include <LibWeb/CSS/StyleValues/CSSColorValue.h>
 #include <LibWeb/CSS/StyleValues/CSSKeywordValue.h>
 #include <LibWeb/CSS/StyleValues/CSSKeywordValue.h>
+#include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
 #include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
 #include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
 #include <LibWeb/DOM/ElementFactory.h>
 #include <LibWeb/DOM/ElementFactory.h>
 #include <LibWeb/DOM/HTMLCollection.h>
 #include <LibWeb/DOM/HTMLCollection.h>
@@ -59,7 +60,7 @@ void HTMLTableElement::apply_presentational_hints(CSS::StyleProperties& style) c
             return;
             return;
         }
         }
         if (name == HTML::AttributeNames::height) {
         if (name == HTML::AttributeNames::height) {
-            if (auto parsed_value = parse_nonzero_dimension_value(value))
+            if (auto parsed_value = parse_dimension_value(value))
                 style.set_property(CSS::PropertyID::Height, parsed_value.release_nonnull());
                 style.set_property(CSS::PropertyID::Height, parsed_value.release_nonnull());
             return;
             return;
         }
         }
@@ -72,6 +73,11 @@ void HTMLTableElement::apply_presentational_hints(CSS::StyleProperties& style) c
             }
             }
             return;
             return;
         }
         }
+        if (name == HTML::AttributeNames::background) {
+            if (auto parsed_value = document().parse_url(value); parsed_value.is_valid())
+                style.set_property(CSS::PropertyID::BackgroundImage, CSS::ImageStyleValue::create(parsed_value));
+            return;
+        }
         if (name == HTML::AttributeNames::bgcolor) {
         if (name == HTML::AttributeNames::bgcolor) {
             // https://html.spec.whatwg.org/multipage/rendering.html#tables-2:rules-for-parsing-a-legacy-colour-value
             // https://html.spec.whatwg.org/multipage/rendering.html#tables-2:rules-for-parsing-a-legacy-colour-value
             auto color = parse_legacy_color_value(value);
             auto color = parse_legacy_color_value(value);

+ 3 - 3
Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp

@@ -48,15 +48,15 @@ void HTMLTableRowElement::apply_presentational_hints(CSS::StyleProperties& style
             auto color = parse_legacy_color_value(value);
             auto color = parse_legacy_color_value(value);
             if (color.has_value())
             if (color.has_value())
                 style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
                 style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
-            return;
         } else if (name == HTML::AttributeNames::background) {
         } else if (name == HTML::AttributeNames::background) {
             if (auto parsed_value = document().parse_url(value); parsed_value.is_valid())
             if (auto parsed_value = document().parse_url(value); parsed_value.is_valid())
                 style.set_property(CSS::PropertyID::BackgroundImage, CSS::ImageStyleValue::create(parsed_value));
                 style.set_property(CSS::PropertyID::BackgroundImage, CSS::ImageStyleValue::create(parsed_value));
-            return;
+        } else if (name == HTML::AttributeNames::height) {
+            if (auto parsed_value = parse_dimension_value(value))
+                style.set_property(CSS::PropertyID::Height, *parsed_value);
         } else if (name == HTML::AttributeNames::valign) {
         } else if (name == HTML::AttributeNames::valign) {
             if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, value, CSS::PropertyID::VerticalAlign))
             if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, value, CSS::PropertyID::VerticalAlign))
                 style.set_property(CSS::PropertyID::VerticalAlign, parsed_value.release_nonnull());
                 style.set_property(CSS::PropertyID::VerticalAlign, parsed_value.release_nonnull());
-            return;
         }
         }
     });
     });
 }
 }

+ 21 - 0
Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp

@@ -7,10 +7,15 @@
 
 
 #include <LibWeb/Bindings/HTMLTableSectionElementPrototype.h>
 #include <LibWeb/Bindings/HTMLTableSectionElementPrototype.h>
 #include <LibWeb/Bindings/Intrinsics.h>
 #include <LibWeb/Bindings/Intrinsics.h>
+#include <LibWeb/CSS/StyleProperties.h>
+#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
+#include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
+#include <LibWeb/DOM/Document.h>
 #include <LibWeb/DOM/ElementFactory.h>
 #include <LibWeb/DOM/ElementFactory.h>
 #include <LibWeb/DOM/HTMLCollection.h>
 #include <LibWeb/DOM/HTMLCollection.h>
 #include <LibWeb/HTML/HTMLTableRowElement.h>
 #include <LibWeb/HTML/HTMLTableRowElement.h>
 #include <LibWeb/HTML/HTMLTableSectionElement.h>
 #include <LibWeb/HTML/HTMLTableSectionElement.h>
+#include <LibWeb/HTML/Parser/HTMLParser.h>
 #include <LibWeb/Namespace.h>
 #include <LibWeb/Namespace.h>
 
 
 namespace Web::HTML {
 namespace Web::HTML {
@@ -95,4 +100,20 @@ WebIDL::ExceptionOr<void> HTMLTableSectionElement::delete_row(WebIDL::Long index
     return {};
     return {};
 }
 }
 
 
+void HTMLTableSectionElement::apply_presentational_hints(CSS::StyleProperties& style) const
+{
+    for_each_attribute([&](auto& name, auto& value) {
+        // https://html.spec.whatwg.org/multipage/rendering.html#tables-2:encoding-parsing-and-serializing-a-url
+        if (name == HTML::AttributeNames::background) {
+            if (auto parsed_value = document().parse_url(value); parsed_value.is_valid())
+                style.set_property(CSS::PropertyID::BackgroundImage, CSS::ImageStyleValue::create(parsed_value));
+        }
+        // https://html.spec.whatwg.org/multipage/rendering.html#tables-2:rules-for-parsing-a-legacy-colour-value
+        else if (name == HTML::AttributeNames::bgcolor) {
+            if (auto color = parse_legacy_color_value(value); color.has_value())
+                style.set_property(CSS::PropertyID::BackgroundColor, CSS::CSSColorValue::create_from_color(color.value()));
+        }
+    });
+}
+
 }
 }

+ 2 - 0
Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h

@@ -37,6 +37,8 @@ private:
     virtual void initialize(JS::Realm&) override;
     virtual void initialize(JS::Realm&) override;
     virtual void visit_edges(Cell::Visitor&) override;
     virtual void visit_edges(Cell::Visitor&) override;
 
 
+    virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
+
     JS::GCPtr<DOM::HTMLCollection> mutable m_rows;
     JS::GCPtr<DOM::HTMLCollection> mutable m_rows;
 };
 };