From 6b8adb522c640ce8daedb053ee86accfa2444cc1 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 14 Mar 2025 16:58:10 +0000 Subject: [PATCH] LibWeb: Set iframe border to 0px when frameborder attribute is invalid Corresponds to https://github.com/whatwg/html/commit/6e19cef90ed53a3a5afaf170075956dd53834674 --- Libraries/LibWeb/CSS/Default.css | 2 -- Libraries/LibWeb/HTML/HTMLIFrameElement.cpp | 33 +++++++++++++++++++-- Libraries/LibWeb/HTML/HTMLIFrameElement.h | 2 ++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Libraries/LibWeb/CSS/Default.css b/Libraries/LibWeb/CSS/Default.css index aeb47669a13..62864d65f52 100644 --- a/Libraries/LibWeb/CSS/Default.css +++ b/Libraries/LibWeb/CSS/Default.css @@ -758,8 +758,6 @@ video { * https://html.spec.whatwg.org/multipage/rendering.html#attributes-for-embedded-content-and-images */ -iframe[frameborder='0'], iframe[frameborder=no i] { border: none; } - embed[align=left i], iframe[align=left i], img[align=left i], input[type=image i][align=left i], object[align=left i] { float: left; diff --git a/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp b/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp index 1d819e25f6d..185594cad35 100644 --- a/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp @@ -1,20 +1,21 @@ /* * Copyright (c) 2020-2021, Andreas Kling - * Copyright (c) 2023, Sam Atkins + * Copyright (c) 2023-2025, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -226,6 +227,34 @@ i32 HTMLIFrameElement::default_tab_index_value() const return 0; } +bool HTMLIFrameElement::is_presentational_hint(FlyString const& name) const +{ + if (Base::is_presentational_hint(name)) + return true; + + return name == HTML::AttributeNames::frameborder; +} + +void HTMLIFrameElement::apply_presentational_hints(GC::Ref cascaded_properties) const +{ + Base::apply_presentational_hints(cascaded_properties); + + // https://html.spec.whatwg.org/multipage/rendering.html#attributes-for-embedded-content-and-images:attr-iframe-frameborder + // When an iframe element has a frameborder attribute whose value, when parsed using the rules for parsing integers, + // is zero or an error, the user agent is expected to have presentational hints setting the element's + // 'border-top-width', 'border-right-width', 'border-bottom-width', and 'border-left-width' properties to zero. + if (auto frameborder_attribute = get_attribute(HTML::AttributeNames::frameborder); frameborder_attribute.has_value()) { + auto frameborder = parse_integer(*frameborder_attribute); + if (!frameborder.has_value() || frameborder == 0) { + auto zero = CSS::LengthStyleValue::create(CSS::Length::make_px(0)); + cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderTopWidth, zero); + cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderRightWidth, zero); + cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderBottomWidth, zero); + cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderLeftWidth, zero); + } + } +} + // https://html.spec.whatwg.org/multipage/iframe-embed-object.html#dom-iframe-sandbox GC::Ref HTMLIFrameElement::sandbox() { diff --git a/Libraries/LibWeb/HTML/HTMLIFrameElement.h b/Libraries/LibWeb/HTML/HTMLIFrameElement.h index d13cc854366..0bf82bd79be 100644 --- a/Libraries/LibWeb/HTML/HTMLIFrameElement.h +++ b/Libraries/LibWeb/HTML/HTMLIFrameElement.h @@ -48,6 +48,8 @@ private: virtual void removed_from(Node* old_parent, Node& old_root) override; virtual void attribute_changed(FlyString const& name, Optional const& old_value, Optional const& value, Optional const& namespace_) override; virtual i32 default_tab_index_value() const override; + virtual bool is_presentational_hint(FlyString const&) const override; + virtual void apply_presentational_hints(GC::Ref) const override; // https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:dimension-attributes virtual bool supports_dimension_attributes() const override { return true; }