Auto merge of #29850 - servo:css-viewport-removal, r=mrobinson

CSS viewport removal

It was removed from the spec and it's disabled everywhere.

This also removes the meta viewport support (which was implemented on top), but that also had a single test and is disabled everywhere, so I'm not too concerned, it can be implemented again if / when needed.

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #26349
- [x] There are tests for these changes
This commit is contained in:
bors-servo 2023-06-30 20:54:11 +02:00 committed by GitHub
commit 3f7e5b15f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 35 additions and 1139 deletions

View file

@ -160,7 +160,7 @@ use style::shared_lock::{Locked as StyleLocked, SharedRwLock as StyleSharedRwLoc
use style::stylesheet_set::{AuthorStylesheetSet, DocumentStylesheetSet};
use style::stylesheets::keyframes_rule::Keyframe;
use style::stylesheets::{CssRules, FontFaceRule, KeyframesRule, MediaRule, Stylesheet};
use style::stylesheets::{ImportRule, NamespaceRule, StyleRule, SupportsRule, ViewportRule};
use style::stylesheets::{ImportRule, NamespaceRule, StyleRule, SupportsRule};
use style::stylist::CascadeData;
use style::values::specified::Length;
use tendril::fmt::UTF8;
@ -914,12 +914,6 @@ unsafe impl JSTraceable for StyleLocked<StyleRule> {
}
}
unsafe impl JSTraceable for StyleLocked<ViewportRule> {
unsafe fn trace(&self, _trc: *mut JSTracer) {
// Do nothing.
}
}
unsafe impl JSTraceable for StyleLocked<PropertyDeclarationBlock> {
unsafe fn trace(&self, _trc: *mut JSTracer) {
// Do nothing.

View file

@ -16,7 +16,6 @@ use crate::dom::cssnamespacerule::CSSNamespaceRule;
use crate::dom::cssstylerule::CSSStyleRule;
use crate::dom::cssstylesheet::CSSStyleSheet;
use crate::dom::csssupportsrule::CSSSupportsRule;
use crate::dom::cssviewportrule::CSSViewportRule;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use std::cell::Cell;
@ -55,8 +54,6 @@ impl CSSRule {
rule as &dyn SpecificCSSRule
} else if let Some(rule) = self.downcast::<CSSNamespaceRule>() {
rule as &dyn SpecificCSSRule
} else if let Some(rule) = self.downcast::<CSSViewportRule>() {
rule as &dyn SpecificCSSRule
} else if let Some(rule) = self.downcast::<CSSKeyframeRule>() {
rule as &dyn SpecificCSSRule
} else if let Some(rule) = self.downcast::<CSSImportRule>() {
@ -97,14 +94,12 @@ impl CSSRule {
StyleCssRule::Namespace(s) => {
DomRoot::upcast(CSSNamespaceRule::new(window, parent_stylesheet, s))
},
StyleCssRule::Viewport(s) => {
DomRoot::upcast(CSSViewportRule::new(window, parent_stylesheet, s))
},
StyleCssRule::Supports(s) => {
DomRoot::upcast(CSSSupportsRule::new(window, parent_stylesheet, s))
},
StyleCssRule::Page(_) => unreachable!(),
StyleCssRule::Document(_) => unimplemented!(), // TODO
StyleCssRule::Viewport(_) => unimplemented!(), // TODO
StyleCssRule::LayerBlock(_) => unimplemented!(), // TODO
StyleCssRule::LayerStatement(_) => unimplemented!(), // TODO
StyleCssRule::ScrollTimeline(_) => unimplemented!(), // TODO

View file

@ -1,63 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::cssrule::{CSSRule, SpecificCSSRule};
use crate::dom::cssstylesheet::CSSStyleSheet;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use servo_arc::Arc;
use style::shared_lock::{Locked, ToCssWithGuard};
use style::stylesheets::ViewportRule;
#[dom_struct]
pub struct CSSViewportRule {
cssrule: CSSRule,
#[ignore_malloc_size_of = "Arc"]
viewportrule: Arc<Locked<ViewportRule>>,
}
impl CSSViewportRule {
fn new_inherited(
parent_stylesheet: &CSSStyleSheet,
viewportrule: Arc<Locked<ViewportRule>>,
) -> CSSViewportRule {
CSSViewportRule {
cssrule: CSSRule::new_inherited(parent_stylesheet),
viewportrule: viewportrule,
}
}
#[allow(unrooted_must_root)]
pub fn new(
window: &Window,
parent_stylesheet: &CSSStyleSheet,
viewportrule: Arc<Locked<ViewportRule>>,
) -> DomRoot<CSSViewportRule> {
reflect_dom_object(
Box::new(CSSViewportRule::new_inherited(
parent_stylesheet,
viewportrule,
)),
window,
)
}
}
impl SpecificCSSRule for CSSViewportRule {
fn ty(&self) -> u16 {
use crate::dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleConstants;
CSSRuleConstants::VIEWPORT_RULE
}
fn get_css(&self) -> DOMString {
let guard = self.cssrule.shared_lock().read();
self.viewportrule
.read_with(&guard)
.to_css_string(&guard)
.into()
}
}

View file

@ -9,7 +9,6 @@ use crate::dom::bindings::num::Finite;
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::element::Element;
use crate::dom::htmlelement::HTMLElement;
use crate::dom::htmlmetaelement::HTMLMetaElement;
use crate::dom::node::{self, Node, VecPreOrderInsertionHelper};
use crate::dom::window::Window;
use crate::stylesheet_set::StylesheetSetRef;
@ -226,13 +225,7 @@ impl DocumentOrShadowRoot {
insertion_point: Option<StyleSheetInDocument>,
style_shared_lock: &StyleSharedRwLock,
) {
// FIXME(emilio): It'd be nice to unify more code between the elements
// that own stylesheets, but StylesheetOwner is more about loading
// them...
debug_assert!(
owner.as_stylesheet_owner().is_some() || owner.is::<HTMLMetaElement>(),
"Wat"
);
debug_assert!(owner.as_stylesheet_owner().is_some(), "Wat");
let sheet = StyleSheetInDocument {
sheet,

View file

@ -3,38 +3,25 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::attr::Attr;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::HTMLMetaElementBinding::HTMLMetaElementMethods;
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::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::cssstylesheet::CSSStyleSheet;
use crate::dom::document::Document;
use crate::dom::element::{AttributeMutation, Element};
use crate::dom::htmlelement::HTMLElement;
use crate::dom::htmlheadelement::HTMLHeadElement;
use crate::dom::node::{
document_from_node, stylesheets_owner_from_node, window_from_node, BindContext, Node,
UnbindContext,
};
use crate::dom::node::{BindContext, Node, UnbindContext};
use crate::dom::virtualmethods::VirtualMethods;
use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix};
use js::rust::HandleObject;
use servo_arc::Arc;
use servo_config::pref;
use std::sync::atomic::AtomicBool;
use style::media_queries::MediaList;
use style::str::HTML_SPACE_CHARACTERS;
use style::stylesheets::{CssRule, CssRules, Origin, Stylesheet, StylesheetContents, ViewportRule};
#[dom_struct]
pub struct HTMLMetaElement {
htmlelement: HTMLElement,
#[ignore_malloc_size_of = "Arc"]
stylesheet: DomRefCell<Option<Arc<Stylesheet>>>,
cssom_stylesheet: MutNullableDom<CSSStyleSheet>,
}
impl HTMLMetaElement {
@ -45,8 +32,6 @@ impl HTMLMetaElement {
) -> HTMLMetaElement {
HTMLMetaElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
stylesheet: DomRefCell::new(None),
cssom_stylesheet: MutNullableDom::new(None),
}
}
@ -64,73 +49,17 @@ impl HTMLMetaElement {
)
}
pub fn get_stylesheet(&self) -> Option<Arc<Stylesheet>> {
self.stylesheet.borrow().clone()
}
pub fn get_cssom_stylesheet(&self) -> Option<DomRoot<CSSStyleSheet>> {
self.get_stylesheet().map(|sheet| {
self.cssom_stylesheet.or_init(|| {
CSSStyleSheet::new(
&window_from_node(self),
self.upcast::<Element>(),
"text/css".into(),
None, // todo handle location
None, // todo handle title
sheet,
)
})
})
}
fn process_attributes(&self) {
let element = self.upcast::<Element>();
if let Some(ref name) = element.get_name() {
let name = name.to_ascii_lowercase();
let name = name.trim_matches(HTML_SPACE_CHARACTERS);
if name == "viewport" {
self.apply_viewport();
}
if name == "referrer" {
self.apply_referrer();
}
}
}
#[allow(unrooted_must_root)]
fn apply_viewport(&self) {
if !pref!(layout.viewport.enabled) {
return;
}
let element = self.upcast::<Element>();
if let Some(ref content) = element.get_attribute(&ns!(), &local_name!("content")) {
let content = content.value();
if !content.is_empty() {
if let Some(translated_rule) = ViewportRule::from_meta(&**content) {
let stylesheets_owner = stylesheets_owner_from_node(self);
let document = document_from_node(self);
let shared_lock = document.style_shared_lock();
let rule = CssRule::Viewport(Arc::new(shared_lock.wrap(translated_rule)));
let sheet = Arc::new(Stylesheet {
contents: StylesheetContents::from_data(
CssRules::new(vec![rule], shared_lock),
Origin::Author,
window_from_node(self).get_url(),
document.quirks_mode(),
),
media: Arc::new(shared_lock.wrap(MediaList::empty())),
shared_lock: shared_lock.clone(),
disabled: AtomicBool::new(false),
});
*self.stylesheet.borrow_mut() = Some(sheet.clone());
stylesheets_owner.add_stylesheet(self.upcast(), sheet);
}
}
}
}
fn process_referrer_attribute(&self) {
let element = self.upcast::<Element>();
if let Some(ref name) = element.get_name() {
@ -197,10 +126,6 @@ impl VirtualMethods for HTMLMetaElement {
if context.tree_connected {
self.process_referrer_attribute();
if let Some(s) = self.stylesheet.borrow_mut().take() {
stylesheets_owner_from_node(self).remove_stylesheet(self.upcast(), &s);
}
}
}
}

View file

@ -272,7 +272,6 @@ pub mod cssstylerule;
pub mod cssstylesheet;
pub mod cssstylevalue;
pub mod csssupportsrule;
pub mod cssviewportrule;
pub mod customelementregistry;
pub mod customevent;
pub mod dedicatedworkerglobalscope;

View file

@ -48,7 +48,6 @@ use crate::dom::htmlimageelement::{HTMLImageElement, LayoutHTMLImageElementHelpe
use crate::dom::htmlinputelement::{HTMLInputElement, LayoutHTMLInputElementHelpers};
use crate::dom::htmllinkelement::HTMLLinkElement;
use crate::dom::htmlmediaelement::{HTMLMediaElement, LayoutHTMLMediaElementHelpers};
use crate::dom::htmlmetaelement::HTMLMetaElement;
use crate::dom::htmlstyleelement::HTMLStyleElement;
use crate::dom::htmltextareaelement::{HTMLTextAreaElement, LayoutHTMLTextAreaElementHelpers};
use crate::dom::mouseevent::MouseEvent;
@ -1200,8 +1199,6 @@ impl Node {
node.get_stylesheet()
} else if let Some(node) = self.downcast::<HTMLLinkElement>() {
node.get_stylesheet()
} else if let Some(node) = self.downcast::<HTMLMetaElement>() {
node.get_stylesheet()
} else {
None
}
@ -1212,8 +1209,6 @@ impl Node {
node.get_cssom_stylesheet()
} else if let Some(node) = self.downcast::<HTMLLinkElement>() {
node.get_cssom_stylesheet()
} else if let Some(node) = self.downcast::<HTMLMetaElement>() {
node.get_cssom_stylesheet()
} else {
None
}

View file

@ -26,11 +26,6 @@ partial interface CSSRule {
const unsigned short KEYFRAME_RULE = 8;
};
// https://drafts.csswg.org/css-device-adapt/#css-rule-interface
partial interface CSSRule {
const unsigned short VIEWPORT_RULE = 15;
};
// https://drafts.csswg.org/css-conditional-3/#extentions-to-cssrule-interface
partial interface CSSRule {
const unsigned short SUPPORTS_RULE = 12;

View file

@ -1,9 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// https://drafts.csswg.org/css-device-adapt/#css-viewport-rule-interface
[Exposed=Window]
interface CSSViewportRule : CSSRule {
// readonly attribute CSSStyleDeclaration style;
};