mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Implement disabled
attribute for <link rel="stylesheet">
(#36446)
Adds support for both the content and the IDL attribute. Note this doesn't cover dynamic updates to `document.styleSheets` and the owner node of the sheet. Testing: Covered by WPT Fixes: #26739 Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
parent
e62aecb103
commit
2d40fb7fe2
9 changed files with 46 additions and 28 deletions
|
@ -114,6 +114,8 @@ pub(crate) struct HTMLLinkElement {
|
|||
any_failed_load: Cell<bool>,
|
||||
/// A monotonically increasing counter that keeps track of which stylesheet to apply.
|
||||
request_generation_id: Cell<RequestGenerationId>,
|
||||
/// <https://html.spec.whatwg.org/multipage/#explicitly-enabled>
|
||||
is_explicitly_enabled: Cell<bool>,
|
||||
}
|
||||
|
||||
impl HTMLLinkElement {
|
||||
|
@ -133,6 +135,7 @@ impl HTMLLinkElement {
|
|||
pending_loads: Cell::new(0),
|
||||
any_failed_load: Cell::new(false),
|
||||
request_generation_id: Cell::new(RequestGenerationId(0)),
|
||||
is_explicitly_enabled: Cell::new(false),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,6 +199,12 @@ impl HTMLLinkElement {
|
|||
self.relations.get().contains(LinkRelations::ALTERNATE)
|
||||
}
|
||||
|
||||
pub(crate) fn is_effectively_disabled(&self) -> bool {
|
||||
(self.is_alternate() && !self.is_explicitly_enabled.get()) ||
|
||||
self.upcast::<Element>()
|
||||
.has_attribute(&local_name!("disabled"))
|
||||
}
|
||||
|
||||
fn clean_stylesheet_ownership(&self) {
|
||||
if let Some(cssom_stylesheet) = self.cssom_stylesheet.get() {
|
||||
cssom_stylesheet.set_owner(None);
|
||||
|
@ -221,11 +230,18 @@ impl VirtualMethods for HTMLLinkElement {
|
|||
self.super_type()
|
||||
.unwrap()
|
||||
.attribute_mutated(attr, mutation, can_gc);
|
||||
if !self.upcast::<Node>().is_connected() || mutation.is_removal() {
|
||||
|
||||
let local_name = attr.local_name();
|
||||
let is_removal = mutation.is_removal();
|
||||
if *local_name == local_name!("disabled") {
|
||||
self.handle_disabled_attribute_change(!is_removal);
|
||||
return;
|
||||
}
|
||||
|
||||
match *attr.local_name() {
|
||||
if !self.upcast::<Node>().is_connected() || is_removal {
|
||||
return;
|
||||
}
|
||||
match *local_name {
|
||||
local_name!("rel") | local_name!("rev") => {
|
||||
self.relations
|
||||
.set(LinkRelations::for_element(self.upcast()));
|
||||
|
@ -472,6 +488,18 @@ impl HTMLLinkElement {
|
|||
);
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#attr-link-disabled>
|
||||
fn handle_disabled_attribute_change(&self, disabled: bool) {
|
||||
if !disabled {
|
||||
self.is_explicitly_enabled.set(true);
|
||||
}
|
||||
if let Some(stylesheet) = self.get_stylesheet() {
|
||||
if stylesheet.set_disabled(disabled) {
|
||||
self.stylesheet_list_owner().invalidate_stylesheets();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_favicon_url(&self, href: &str, _sizes: &Option<String>) {
|
||||
let document = self.owner_document();
|
||||
match document.base_url().join(href) {
|
||||
|
@ -567,6 +595,12 @@ impl HTMLLinkElementMethods<crate::DomTypeHolder> for HTMLLinkElement {
|
|||
// https://html.spec.whatwg.org/multipage/#dom-link-type
|
||||
make_setter!(SetType, "type");
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-link-disabled
|
||||
make_bool_getter!(Disabled, "disabled");
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-link-disabled
|
||||
make_bool_setter!(SetDisabled, "disabled");
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-link-rellist
|
||||
fn RelList(&self) -> DomRoot<DOMTokenList> {
|
||||
self.rel_list.or_init(|| {
|
||||
|
|
|
@ -214,7 +214,7 @@ impl FetchResponseListener for StylesheetContext {
|
|||
document.quirks_mode(),
|
||||
));
|
||||
|
||||
if link.is_alternate() {
|
||||
if link.is_effectively_disabled() {
|
||||
sheet.set_disabled(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,17 +13,24 @@ interface HTMLLinkElement : HTMLElement {
|
|||
attribute DOMString? crossOrigin;
|
||||
[CEReactions]
|
||||
attribute DOMString rel;
|
||||
// [CEReactions] attribute DOMString as;
|
||||
[SameObject, PutForwards=value] readonly attribute DOMTokenList relList;
|
||||
[CEReactions]
|
||||
attribute DOMString media;
|
||||
[CEReactions]
|
||||
attribute DOMString integrity;
|
||||
[CEReactions]
|
||||
attribute DOMString hreflang;
|
||||
[CEReactions]
|
||||
attribute DOMString type;
|
||||
[CEReactions]
|
||||
attribute DOMString integrity;
|
||||
// [SameObject, PutForwards=value] readonly attribute DOMTokenList sizes;
|
||||
// [CEReactions] attribute USVString imageSrcset;
|
||||
// [CEReactions] attribute DOMString imageSizes;
|
||||
[CEReactions]
|
||||
attribute DOMString referrerPolicy;
|
||||
// [SameObject, PutForwards=value] readonly attribute DOMTokenList blocking;
|
||||
[CEReactions] attribute boolean disabled;
|
||||
// [CEReactions] attribute DOMString fetchPriority;
|
||||
|
||||
// also has obsolete members
|
||||
};
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
[HTMLLinkElement-disabled-003.html]
|
||||
[HTMLLinkElement.disabled's explicitly enabled state persists when disconnected and connected again]
|
||||
expected: FAIL
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
[HTMLLinkElement-disabled-004.html]
|
||||
[HTMLLinkElement.disabled's explicitly enabled state doesn't persist on clones]
|
||||
expected: FAIL
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
[HTMLLinkElement-disabled-007.html]
|
||||
[HTMLLinkElement.disabled setter sets the explicitly enabled state if toggled back and forth.]
|
||||
expected: FAIL
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
[HTMLLinkElement-disabled-alternate.html]
|
||||
expected: FAIL
|
|
@ -6052,9 +6052,6 @@
|
|||
[HTMLLinkElement interface: attribute blocking]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLLinkElement interface: attribute disabled]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLLinkElement interface: attribute fetchPriority]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -6073,9 +6070,6 @@
|
|||
[HTMLLinkElement interface: document.createElement("link") must inherit property "blocking" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLLinkElement interface: document.createElement("link") must inherit property "disabled" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLLinkElement interface: document.createElement("link") must inherit property "fetchPriority" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
[subresource-integrity.html]
|
||||
[Style: Same-origin with correct sha256 and sha512 hash, rel='alternate stylesheet' enabled]
|
||||
expected: FAIL
|
||||
|
||||
[Script: Same-origin with non-Base64 hash.]
|
||||
expected: FAIL
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue