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.
This commit is contained in:
Emilio Cobos Álvarez 2023-06-30 16:20:59 +02:00 committed by Martin Robinson
parent 7412e28349
commit 349edff768
No known key found for this signature in database
GPG key ID: D56AA4FA55EFE6F8
34 changed files with 35 additions and 1139 deletions

View file

@ -46,7 +46,6 @@ use std::fs::{create_dir_all, File};
use std::io::Write;
use std::num::NonZeroU32;
use std::rc::Rc;
use style_traits::viewport::ViewportConstraints;
use style_traits::{CSSPixel, DevicePixel, PinchZoomFactor};
use time::{now, precise_time_ns, precise_time_s};
use webrender_api::units::{
@ -507,13 +506,6 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
}
},
(
Msg::ViewportConstrained(pipeline_id, constraints),
ShutdownState::NotShuttingDown,
) => {
self.constrain_viewport(pipeline_id, constraints);
},
(Msg::IsReadyToSaveImageReply(is_ready), ShutdownState::NotShuttingDown) => {
assert_eq!(
self.ready_to_save_state,
@ -1363,17 +1355,6 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
}
}
fn constrain_viewport(&mut self, pipeline_id: PipelineId, constraints: ViewportConstraints) {
let is_root = self.root_pipeline.id == Some(pipeline_id);
if is_root {
self.viewport_zoom = constraints.initial_zoom;
self.min_viewport_zoom = constraints.min_zoom;
self.max_viewport_zoom = constraints.max_zoom;
self.update_zoom_transform();
}
}
fn hidpi_factor(&self) -> Scale<f32, DeviceIndependentPixel, DevicePixel> {
if self.output_file.is_some() {
return Scale::new(1.0);

View file

@ -19,7 +19,6 @@ use profile_traits::time;
use script_traits::{AnimationState, EventResult, MouseButton, MouseEventType};
use std::fmt::{Debug, Error, Formatter};
use std::rc::Rc;
use style_traits::viewport::ViewportConstraints;
use style_traits::CSSPixel;
use webrender_api;
use webrender_api::units::{DeviceIntPoint, DeviceIntSize};
@ -85,8 +84,6 @@ pub enum Msg {
TouchEventProcessed(EventResult),
/// Composite to a PNG file and return the Image over a passed channel.
CreatePng(Option<Rect<f32, CSSPixel>>, IpcSender<Option<Image>>),
/// Alerts the compositor that the viewport has been constrained in some manner
ViewportConstrained(PipelineId, ViewportConstraints),
/// A reply to the compositor asking if the output image is stable.
IsReadyToSaveImageReply(bool),
/// Pipeline visibility changed
@ -158,7 +155,6 @@ impl Debug for Msg {
Msg::Recomposite(..) => write!(f, "Recomposite"),
Msg::TouchEventProcessed(..) => write!(f, "TouchEventProcessed"),
Msg::CreatePng(..) => write!(f, "CreatePng"),
Msg::ViewportConstrained(..) => write!(f, "ViewportConstrained"),
Msg::IsReadyToSaveImageReply(..) => write!(f, "IsReadyToSaveImageReply"),
Msg::PipelineVisibilityChanged(..) => write!(f, "PipelineVisibilityChanged"),
Msg::PipelineExited(..) => write!(f, "PipelineExited"),

View file

@ -442,9 +442,6 @@ mod gen {
},
#[serde(default = "default_layout_threads")]
threads: i64,
viewport: {
enabled: bool,
},
writing_mode: {
#[serde(rename = "layout.writing-mode.enabled")]
enabled: bool,

View file

@ -176,7 +176,6 @@ use std::process;
use std::rc::{Rc, Weak};
use std::sync::{Arc, Mutex};
use std::thread;
use style_traits::viewport::ViewportConstraints;
use style_traits::CSSPixel;
use webgpu::{self, WebGPU, WebGPURequest};
use webrender_traits::WebrenderExternalImageRegistry;
@ -2110,9 +2109,6 @@ where
FromLayoutMsg::PendingPaintMetric(pipeline_id, epoch) => {
self.handle_pending_paint_metric(pipeline_id, epoch);
},
FromLayoutMsg::ViewportConstrained(pipeline_id, constraints) => {
self.handle_viewport_constrained_msg(pipeline_id, constraints);
},
}
}
@ -4934,19 +4930,6 @@ where
self.switch_fullscreen_mode(browsing_context_id);
}
/// Handle updating actual viewport / zoom due to @viewport rules
fn handle_viewport_constrained_msg(
&mut self,
pipeline_id: PipelineId,
constraints: ViewportConstraints,
) {
self.compositor_proxy
.send(ToCompositorMsg::ViewportConstrained(
pipeline_id,
constraints,
));
}
/// Checks the state of all script and layout pipelines to see if they are idle
/// and compares the current layout state to what the compositor has. This is used
/// to check if the output image is "stable" and can be written as a screenshot

View file

@ -1015,11 +1015,7 @@ impl LayoutThread {
let root_size = {
let root_flow = layout_root.base();
if self.stylist.viewport_constraints().is_some() {
root_flow.position.size.to_physical(root_flow.writing_mode)
} else {
root_flow.overflow.scroll.size
}
root_flow.overflow.scroll.size
};
let origin = Rect::new(Point2D::new(Au(0), Au(0)), root_size).to_layout();
@ -1207,64 +1203,39 @@ impl LayoutThread {
self.stylist
.force_stylesheet_origins_dirty(sheet_origins_affected_by_device_change);
self.viewport_size =
self.stylist
.viewport_constraints()
.map_or(current_screen_size, |constraints| {
debug!("Viewport constraints: {:?}", constraints);
// other rules are evaluated against the actual viewport
Size2D::new(
Au::from_f32_px(constraints.size.width),
Au::from_f32_px(constraints.size.height),
)
});
self.viewport_size = current_screen_size;
let viewport_size_changed = self.viewport_size != old_viewport_size;
if viewport_size_changed {
if let Some(constraints) = self.stylist.viewport_constraints() {
// let the constellation know about the viewport constraints
rw_data
.constellation_chan
.send(ConstellationMsg::ViewportConstrained(
self.id,
constraints.clone(),
))
.unwrap();
}
if had_used_viewport_units {
if let Some(mut data) = root_element.mutate_data() {
data.hint.insert(RestyleHint::recascade_subtree());
}
if viewport_size_changed && had_used_viewport_units {
if let Some(mut data) = root_element.mutate_data() {
data.hint.insert(RestyleHint::recascade_subtree());
}
}
{
if self.first_reflow.get() {
debug!("First reflow, rebuilding user and UA rules");
for stylesheet in &ua_stylesheets.user_or_user_agent_stylesheets {
self.stylist
.append_stylesheet(stylesheet.clone(), &ua_or_user_guard);
self.handle_add_stylesheet(&stylesheet.0, &ua_or_user_guard);
}
if self.stylist.quirks_mode() != QuirksMode::NoQuirks {
self.stylist.append_stylesheet(
ua_stylesheets.quirks_mode_stylesheet.clone(),
&ua_or_user_guard,
);
self.handle_add_stylesheet(
&ua_stylesheets.quirks_mode_stylesheet.0,
&ua_or_user_guard,
);
}
}
if data.stylesheets_changed {
debug!("Doc sheets changed, flushing author sheets too");
if self.first_reflow.get() {
debug!("First reflow, rebuilding user and UA rules");
for stylesheet in &ua_stylesheets.user_or_user_agent_stylesheets {
self.stylist
.force_stylesheet_origins_dirty(Origin::Author.into());
.append_stylesheet(stylesheet.clone(), &ua_or_user_guard);
self.handle_add_stylesheet(&stylesheet.0, &ua_or_user_guard);
}
if self.stylist.quirks_mode() != QuirksMode::NoQuirks {
self.stylist.append_stylesheet(
ua_stylesheets.quirks_mode_stylesheet.clone(),
&ua_or_user_guard,
);
self.handle_add_stylesheet(
&ua_stylesheets.quirks_mode_stylesheet.0,
&ua_or_user_guard,
);
}
}
if data.stylesheets_changed {
debug!("Doc sheets changed, flushing author sheets too");
self.stylist
.force_stylesheet_origins_dirty(Origin::Author.into());
}
if viewport_size_changed {

View file

@ -896,29 +896,7 @@ impl LayoutThread {
self.stylist
.force_stylesheet_origins_dirty(sheet_origins_affected_by_device_change);
self.viewport_size =
self.stylist
.viewport_constraints()
.map_or(current_screen_size, |constraints| {
Size2D::new(
Au::from_f32_px(constraints.size.width),
Au::from_f32_px(constraints.size.height),
)
});
let viewport_size_changed = self.viewport_size != old_viewport_size;
if viewport_size_changed {
if let Some(constraints) = self.stylist.viewport_constraints() {
// let the constellation know about the viewport constraints
self.constellation_chan
.send(ConstellationMsg::ViewportConstrained(
self.id,
constraints.clone(),
))
.unwrap();
}
}
self.viewport_size = current_screen_size;
if self.first_reflow.get() {
for stylesheet in &ua_stylesheets.user_or_user_agent_stylesheets {
self.stylist

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;
};

View file

@ -36,7 +36,6 @@ use servo_url::ServoUrl;
use smallvec::SmallVec;
use std::collections::{HashMap, VecDeque};
use std::fmt;
use style_traits::viewport::ViewportConstraints;
use style_traits::CSSPixel;
use webgpu::{wgpu, WebGPU, WebGPUResponseResult};
use webrender_api::units::{DeviceIntPoint, DeviceIntSize};
@ -60,8 +59,6 @@ pub enum LayoutMsg {
/// Requests that the constellation inform the compositor that it needs to record
/// the time when the frame with the given ID (epoch) is painted.
PendingPaintMetric(PipelineId, Epoch),
/// Notifies the constellation that the viewport has been constrained in some manner
ViewportConstrained(PipelineId, ViewportConstraints),
}
impl fmt::Debug for LayoutMsg {
@ -70,7 +67,6 @@ impl fmt::Debug for LayoutMsg {
let variant = match *self {
IFrameSizes(..) => "IFrameSizes",
PendingPaintMetric(..) => "PendingPaintMetric",
ViewportConstrained(..) => "ViewportConstrained",
};
write!(formatter, "LayoutMsg::{}", variant)
}

View file

@ -36,16 +36,8 @@ use style_traits::viewport::{Orientation, UserZoom, ViewportConstraints, Zoom};
use style_traits::{CssWriter, ParseError, PinchZoomFactor, StyleParseErrorKind, ToCss};
/// Whether parsing and processing of `@viewport` rules is enabled.
#[cfg(feature = "servo")]
pub fn enabled() -> bool {
use servo_config::pref;
pref!(layout.viewport.enabled)
}
/// Whether parsing and processing of `@viewport` rules is enabled.
#[cfg(not(feature = "servo"))]
pub fn enabled() -> bool {
false // Gecko doesn't support @viewport.
false
}
macro_rules! declare_viewport_descriptor {