mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Add support for HTMLStyleElement.type (#35038)
Signed-off-by: webbeef <me@webbeef.org>
This commit is contained in:
parent
4705881692
commit
e43baed585
7 changed files with 51 additions and 145 deletions
|
@ -15,14 +15,16 @@ use style::parser::ParserContext as CssParserContext;
|
|||
use style::stylesheets::{AllowImportRules, CssRuleType, Origin, Stylesheet, UrlExtraData};
|
||||
use style_traits::ParsingMode;
|
||||
|
||||
use crate::dom::attr::Attr;
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::codegen::Bindings::HTMLStyleElementBinding::HTMLStyleElementMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::cssstylesheet::CSSStyleSheet;
|
||||
use crate::dom::document::Document;
|
||||
use crate::dom::element::{Element, ElementCreator};
|
||||
use crate::dom::element::{AttributeMutation, Element, ElementCreator};
|
||||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::node::{BindContext, ChildrenMutation, Node, NodeTraits, UnbindContext};
|
||||
use crate::dom::stylesheet::StyleSheet as DOMStyleSheet;
|
||||
|
@ -88,6 +90,13 @@ impl HTMLStyleElement {
|
|||
let element = self.upcast::<Element>();
|
||||
assert!(node.is_connected());
|
||||
|
||||
// Step 4. of <https://html.spec.whatwg.org/multipage/#the-style-element%3Aupdate-a-style-block>
|
||||
let mut type_attribute = self.Type();
|
||||
type_attribute.make_ascii_lowercase();
|
||||
if !type_attribute.is_empty() && type_attribute != "text/css" {
|
||||
return;
|
||||
}
|
||||
|
||||
let window = node.owner_window();
|
||||
let doc = self.owner_document();
|
||||
|
||||
|
@ -179,6 +188,14 @@ impl HTMLStyleElement {
|
|||
}
|
||||
self.cssom_stylesheet.set(None);
|
||||
}
|
||||
|
||||
fn remove_stylesheet(&self) {
|
||||
if let Some(s) = self.stylesheet.borrow_mut().take() {
|
||||
self.clean_stylesheet_ownership();
|
||||
self.stylesheet_list_owner()
|
||||
.remove_stylesheet(self.upcast(), &s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl VirtualMethods for HTMLStyleElement {
|
||||
|
@ -194,7 +211,10 @@ impl VirtualMethods for HTMLStyleElement {
|
|||
// "The element is not on the stack of open elements of an HTML parser or XML parser,
|
||||
// and one of its child nodes is modified by a script."
|
||||
// TODO: Handle Text child contents being mutated.
|
||||
if self.upcast::<Node>().is_in_a_document_tree() && !self.in_stack_of_open_elements.get() {
|
||||
let node = self.upcast::<Node>();
|
||||
if (node.is_in_a_document_tree() || node.is_in_a_shadow_tree()) &&
|
||||
!self.in_stack_of_open_elements.get()
|
||||
{
|
||||
self.parse_own_css();
|
||||
}
|
||||
}
|
||||
|
@ -229,11 +249,27 @@ impl VirtualMethods for HTMLStyleElement {
|
|||
}
|
||||
|
||||
if context.tree_connected {
|
||||
if let Some(s) = self.stylesheet.borrow_mut().take() {
|
||||
self.clean_stylesheet_ownership();
|
||||
self.stylesheet_list_owner()
|
||||
.remove_stylesheet(self.upcast(), &s)
|
||||
self.remove_stylesheet();
|
||||
}
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
if let Some(s) = self.super_type() {
|
||||
s.attribute_mutated(attr, mutation);
|
||||
}
|
||||
|
||||
let node = self.upcast::<Node>();
|
||||
if attr.name() == "type" &&
|
||||
(node.is_in_a_document_tree() || node.is_in_a_shadow_tree()) &&
|
||||
!self.in_stack_of_open_elements.get()
|
||||
{
|
||||
if let AttributeMutation::Set(Some(old_value)) = mutation {
|
||||
if **old_value == **attr.value() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
self.remove_stylesheet();
|
||||
self.parse_own_css();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -292,4 +328,10 @@ impl HTMLStyleElementMethods<crate::DomTypeHolder> for HTMLStyleElement {
|
|||
sheet.set_disabled(value);
|
||||
}
|
||||
}
|
||||
|
||||
// <https://html.spec.whatwg.org/multipage/#HTMLStyleElement-partial>
|
||||
make_getter!(Type, "type");
|
||||
|
||||
// <https://html.spec.whatwg.org/multipage/#HTMLStyleElement-partial>
|
||||
make_setter!(SetType, "type");
|
||||
}
|
||||
|
|
|
@ -10,8 +10,9 @@ interface HTMLStyleElement : HTMLElement {
|
|||
attribute boolean disabled;
|
||||
// [CEReactions]
|
||||
// attribute DOMString media;
|
||||
// [CEReactions]
|
||||
// attribute DOMString type;
|
||||
|
||||
[CEReactions] attribute DOMString type;
|
||||
|
||||
// [CEReactions]
|
||||
// attribute boolean scoped;
|
||||
};
|
||||
|
|
|
@ -6208,18 +6208,12 @@
|
|||
[HTMLStyleElement interface: attribute blocking]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLStyleElement interface: attribute type]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLStyleElement interface: document.createElement("style") must inherit property "media" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLStyleElement interface: document.createElement("style") must inherit property "blocking" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLStyleElement interface: document.createElement("style") must inherit property "type" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLBodyElement interface: attribute link]
|
||||
expected: FAIL
|
||||
|
||||
|
|
114
tests/wpt/meta/html/dom/reflection-metadata.html.ini
vendored
114
tests/wpt/meta/html/dom/reflection-metadata.html.ini
vendored
|
@ -2477,120 +2477,6 @@
|
|||
[style.nonce: IDL set to object "test-valueOf"]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: typeof IDL attribute]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL get with DOM attribute unset]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: setAttribute() to ""]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: setAttribute() to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo "]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: setAttribute() to undefined]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: setAttribute() to 7]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: setAttribute() to 1.5]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: setAttribute() to "5%"]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: setAttribute() to "+100"]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: setAttribute() to ".5"]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: setAttribute() to true]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: setAttribute() to false]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: setAttribute() to object "[object Object\]"]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: setAttribute() to NaN]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: setAttribute() to Infinity]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: setAttribute() to -Infinity]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: setAttribute() to "\\0"]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: setAttribute() to null]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: setAttribute() to object "test-toString"]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: setAttribute() to object "test-valueOf"]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL set to ""]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL set to " \\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f foo "]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL set to undefined]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL set to 7]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL set to 1.5]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL set to "5%"]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL set to "+100"]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL set to ".5"]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL set to true]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL set to false]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL set to object "[object Object\]"]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL set to NaN]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL set to Infinity]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL set to -Infinity]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL set to "\\0"]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL set to null]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL set to object "test-toString"]
|
||||
expected: FAIL
|
||||
|
||||
[style.type: IDL set to object "test-valueOf"]
|
||||
expected: FAIL
|
||||
|
||||
[head.tabIndex: setAttribute() to "7\\v"]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
[style_type_change.html]
|
||||
[Check initial styleSheets length type]
|
||||
expected: FAIL
|
||||
|
||||
[Change type from invalid type to valid type]
|
||||
expected: FAIL
|
||||
|
||||
[Change type from valid type to invalid type]
|
||||
expected: FAIL
|
|
@ -1,6 +0,0 @@
|
|||
[style_type_html.html]
|
||||
[With a whitespace-surrounded type attribute, the style should not apply]
|
||||
expected: FAIL
|
||||
|
||||
[With a charset parameter in the type attribute, the style should not apply]
|
||||
expected: FAIL
|
|
@ -1,2 +0,0 @@
|
|||
[update-style-block-ascii-case-insensitive.html]
|
||||
expected: FAIL
|
Loading…
Add table
Add a link
Reference in a new issue