diff options
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/canvasrenderingcontext2d.rs | 8 | ||||
-rw-r--r-- | components/script/dom/element.rs | 24 | ||||
-rw-r--r-- | components/script/dom/gpucanvascontext.rs | 3 | ||||
-rw-r--r-- | components/script/dom/htmlcanvaselement.rs | 4 | ||||
-rw-r--r-- | components/script/dom/htmltablecellelement.rs | 35 | ||||
-rw-r--r-- | components/script/dom/htmltablecolelement.rs | 17 | ||||
-rw-r--r-- | components/script/dom/macros.rs | 20 | ||||
-rw-r--r-- | components/script/dom/node.rs | 45 | ||||
-rw-r--r-- | components/script/dom/shadowroot.rs | 9 | ||||
-rw-r--r-- | components/script/dom/webgl2renderingcontext.rs | 4 | ||||
-rw-r--r-- | components/script/dom/webglrenderingcontext.rs | 8 | ||||
-rw-r--r-- | components/script/dom/webgpu/gpucanvascontext.rs | 9 | ||||
-rw-r--r-- | components/script/dom/window.rs | 8 |
13 files changed, 125 insertions, 69 deletions
diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index 38bd38ad511..046d478e49d 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -7,9 +7,9 @@ use dom_struct::dom_struct; use euclid::default::Size2D; use profile_traits::ipc; use script_bindings::inheritance::Castable; -use script_layout_interface::HTMLCanvasDataSource; use servo_url::ServoUrl; use snapshot::Snapshot; +use webrender_api::ImageKey; use crate::canvas_context::{CanvasContext, CanvasHelpers, LayoutCanvasRenderingContextHelpers}; use crate::canvas_state::CanvasState; @@ -98,13 +98,13 @@ impl CanvasRenderingContext2D { } impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, CanvasRenderingContext2D> { - fn canvas_data_source(self) -> HTMLCanvasDataSource { + fn canvas_data_source(self) -> Option<ImageKey> { let canvas_state = &self.unsafe_get().canvas_state; if canvas_state.is_paintable() { - HTMLCanvasDataSource::Image(canvas_state.image_key()) + Some(canvas_state.image_key()) } else { - HTMLCanvasDataSource::Empty + None } } } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 2831fc3d8f0..c040078f707 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -3025,28 +3025,8 @@ impl ElementMethods<crate::DomTypeHolder> for Element { DomRoot::from_ref(self.upcast()) }; - // Step 3. Unsafely set HTML given target, this, and compliantHTML. - // Let newChildren be the result of the HTML fragment parsing algorithm. - let new_children = ServoParser::parse_html_fragment(self, html, true, can_gc); - - let context_document = { - if let Some(template) = self.downcast::<HTMLTemplateElement>() { - template.Content(can_gc).upcast::<Node>().owner_doc() - } else { - self.owner_document() - } - }; - - // Let fragment be a new DocumentFragment whose node document is contextElement's node document. - let frag = DocumentFragment::new(&context_document, can_gc); - - // For each node in newChildren, append node to fragment. - for child in new_children { - frag.upcast::<Node>().AppendChild(&child, can_gc).unwrap(); - } - - // Replace all with fragment within target. - Node::replace_all(Some(frag.upcast()), &target, can_gc); + // Step 3. Unsafely set HTML given target, this, and compliantHTML + Node::unsafely_set_html(&target, self, html, can_gc); } /// <https://html.spec.whatwg.org/multipage/#dom-element-gethtml> diff --git a/components/script/dom/gpucanvascontext.rs b/components/script/dom/gpucanvascontext.rs index 5304d0f5d3b..2bdabf3e0ab 100644 --- a/components/script/dom/gpucanvascontext.rs +++ b/components/script/dom/gpucanvascontext.rs @@ -3,7 +3,6 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use dom_struct::dom_struct; -use script_layout_interface::HTMLCanvasDataSource; use crate::dom::bindings::codegen::Bindings::GPUCanvasContextBinding::GPUCanvasContextMethods; use crate::dom::bindings::codegen::UnionTypes; @@ -31,7 +30,7 @@ impl GPUCanvasContextMethods<crate::DomTypeHolder> for GPUCanvasContext { } impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, GPUCanvasContext> { - fn canvas_data_source(self) -> HTMLCanvasDataSource { + fn canvas_data_source(self) -> Option<ImageKey> { unimplemented!() } } diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index cc6df183f42..56e008839ba 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -21,7 +21,7 @@ use image::{ColorType, ImageEncoder}; use ipc_channel::ipc::{self as ipcchan}; use js::error::throw_type_error; use js::rust::{HandleObject, HandleValue}; -use script_layout_interface::{HTMLCanvasData, HTMLCanvasDataSource}; +use script_layout_interface::HTMLCanvasData; use servo_media::streams::MediaStreamType; use servo_media::streams::registry::MediaStreamId; use snapshot::Snapshot; @@ -201,7 +201,7 @@ impl LayoutHTMLCanvasElementHelpers for LayoutDom<'_, HTMLCanvasElement> { Some(RenderingContext::WebGL2(context)) => context.to_layout().canvas_data_source(), #[cfg(feature = "webgpu")] Some(RenderingContext::WebGPU(context)) => context.to_layout().canvas_data_source(), - Some(RenderingContext::Placeholder(_)) | None => HTMLCanvasDataSource::Empty, + Some(RenderingContext::Placeholder(_)) | None => None, } }; diff --git a/components/script/dom/htmltablecellelement.rs b/components/script/dom/htmltablecellelement.rs index 4f312e928c4..8b553923230 100644 --- a/components/script/dom/htmltablecellelement.rs +++ b/components/script/dom/htmltablecellelement.rs @@ -70,13 +70,17 @@ impl HTMLTableCellElementMethods<crate::DomTypeHolder> for HTMLTableCellElement make_uint_getter!(ColSpan, "colspan", DEFAULT_COLSPAN); // https://html.spec.whatwg.org/multipage/#dom-tdth-colspan - make_uint_setter!(SetColSpan, "colspan", DEFAULT_COLSPAN); + // > The colSpan IDL attribute must reflect the colspan content attribute. It is clamped to + // > the range [1, 1000], and its default value is 1. + make_clamped_uint_setter!(SetColSpan, "colspan", 1, 1000, 1); // https://html.spec.whatwg.org/multipage/#dom-tdth-rowspan make_uint_getter!(RowSpan, "rowspan", DEFAULT_ROWSPAN); // https://html.spec.whatwg.org/multipage/#dom-tdth-rowspan - make_uint_setter!(SetRowSpan, "rowspan", DEFAULT_ROWSPAN); + // > The rowSpan IDL attribute must reflect the rowspan content attribute. It is clamped to + // > the range [0, 65534], and its default value is 1. + make_clamped_uint_setter!(SetRowSpan, "rowspan", 0, 65534, 1); // https://html.spec.whatwg.org/multipage/#dom-tdth-bgcolor make_getter!(BgColor, "bgcolor"); @@ -174,23 +178,26 @@ impl VirtualMethods for HTMLTableCellElement { match *local_name { local_name!("colspan") => { let mut attr = AttrValue::from_u32(value.into(), DEFAULT_COLSPAN); - if let AttrValue::UInt(_, ref mut val) = attr { - if *val == 0 { - *val = 1; - } + if let AttrValue::UInt(_, ref mut value) = attr { + // From <https://html.spec.whatwg.org/multipage/#dom-tdth-colspan>: + // > The colSpan IDL attribute must reflect the colspan content attribute. It is clamped to + // > the range [1, 1000], and its default value is 1. + *value = (*value).clamp(1, 1000); } attr }, local_name!("rowspan") => { let mut attr = AttrValue::from_u32(value.into(), DEFAULT_ROWSPAN); - if let AttrValue::UInt(_, ref mut val) = attr { - if *val == 0 { - let node = self.upcast::<Node>(); - let doc = node.owner_doc(); - // rowspan = 0 is not supported in quirks mode - if doc.quirks_mode() != QuirksMode::NoQuirks { - *val = 1; - } + if let AttrValue::UInt(_, ref mut value) = attr { + // From <https://html.spec.whatwg.org/multipage/#dom-tdth-rowspan>: + // > The rowSpan IDL attribute must reflect the rowspan content attribute. It is clamped to + // > the range [0, 65534], and its default value is 1. + // Note that rowspan = 0 is not supported in quirks mode. + let document = self.upcast::<Node>().owner_doc(); + if document.quirks_mode() != QuirksMode::NoQuirks { + *value = (*value).clamp(1, 65534); + } else { + *value = (*value).clamp(0, 65534); } } attr diff --git a/components/script/dom/htmltablecolelement.rs b/components/script/dom/htmltablecolelement.rs index c7ad4afd944..9e8eecf1147 100644 --- a/components/script/dom/htmltablecolelement.rs +++ b/components/script/dom/htmltablecolelement.rs @@ -20,8 +20,6 @@ use crate::dom::node::Node; use crate::dom::virtualmethods::VirtualMethods; use crate::script_runtime::CanGc; -const DEFAULT_SPAN: u32 = 1; - #[dom_struct] pub(crate) struct HTMLTableColElement { htmlelement: HTMLElement, @@ -62,9 +60,11 @@ impl HTMLTableColElement { impl HTMLTableColElementMethods<crate::DomTypeHolder> for HTMLTableColElement { // <https://html.spec.whatwg.org/multipage/#attr-col-span> - make_uint_getter!(Span, "span", DEFAULT_SPAN); + make_uint_getter!(Span, "span", 1); // <https://html.spec.whatwg.org/multipage/#attr-col-span> - make_uint_setter!(SetSpan, "span", DEFAULT_SPAN); + // > The span IDL attribute must reflect the content attribute of the same name. It is clamped + // > to the range [1, 1000], and its default value is 1. + make_clamped_uint_setter!(SetSpan, "span", 1, 1000, 1); } pub(crate) trait HTMLTableColElementLayoutHelpers<'dom> { @@ -96,11 +96,12 @@ impl VirtualMethods for HTMLTableColElement { fn parse_plain_attribute(&self, local_name: &LocalName, value: DOMString) -> AttrValue { match *local_name { local_name!("span") => { - let mut attr = AttrValue::from_u32(value.into(), DEFAULT_SPAN); + let mut attr = AttrValue::from_u32(value.into(), 1); if let AttrValue::UInt(_, ref mut val) = attr { - if *val == 0 { - *val = 1; - } + // From <https://html.spec.whatwg.org/multipage/#attr-col-span>: + // > The span IDL attribute must reflect the content attribute of the same name. + // > It is clamped to the range [1, 1000], and its default value is 1. + *val = (*val).clamp(1, 1000); } attr }, diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index c2f5ba37c21..997341984c6 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -318,6 +318,26 @@ macro_rules! make_uint_setter( ); #[macro_export] +macro_rules! make_clamped_uint_setter( + ($attr:ident, $htmlname:tt, $min:expr, $max:expr, $default:expr) => ( + fn $attr(&self, value: u32) { + use $crate::dom::bindings::inheritance::Castable; + use $crate::dom::element::Element; + use $crate::dom::values::UNSIGNED_LONG_MAX; + use $crate::script_runtime::CanGc; + let value = if value > UNSIGNED_LONG_MAX { + $default + } else { + value.clamp($min, $max) + }; + + let element = self.upcast::<Element>(); + element.set_uint_attribute(&html5ever::local_name!($htmlname), value, CanGc::note()) + } + ); +); + +#[macro_export] macro_rules! make_limited_uint_setter( ($attr:ident, $htmlname:tt, $default:expr) => ( fn $attr(&self, value: u32) -> $crate::dom::bindings::error::ErrorResult { diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 1117eff6d3c..e9d36a01426 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -110,7 +110,7 @@ use crate::dom::pointerevent::{PointerEvent, PointerId}; use crate::dom::processinginstruction::ProcessingInstruction; use crate::dom::range::WeakRangeVec; use crate::dom::raredata::NodeRareData; -use crate::dom::servoparser::serialize_html_fragment; +use crate::dom::servoparser::{ServoParser, serialize_html_fragment}; use crate::dom::shadowroot::{IsUserAgentWidget, LayoutShadowRootHelpers, ShadowRoot}; use crate::dom::stylesheetlist::StyleSheetListOwner; use crate::dom::svgsvgelement::{LayoutSVGSVGElementHelpers, SVGSVGElement}; @@ -316,6 +316,34 @@ impl Node { } } + /// Implements the "unsafely set HTML" algorithm as specified in: + /// <https://html.spec.whatwg.org/multipage/#concept-unsafely-set-html> + pub fn unsafely_set_html( + target: &Node, + context_element: &Element, + html: DOMString, + can_gc: CanGc, + ) { + // Step 1. Let newChildren be the result of the HTML fragment parsing algorithm. + let new_children = ServoParser::parse_html_fragment(context_element, html, true, can_gc); + + // Step 2. Let fragment be a new DocumentFragment whose node document is contextElement's node document. + + let context_document = context_element.owner_document(); + let fragment = DocumentFragment::new(&context_document, can_gc); + + // Step 3. For each node in newChildren, append node to fragment. + for child in new_children { + fragment + .upcast::<Node>() + .AppendChild(&child, can_gc) + .unwrap(); + } + + // Step 4. Replace all with fragment within target. + Node::replace_all(Some(fragment.upcast()), target, can_gc); + } + pub(crate) fn clean_up_style_and_layout_data(&self) { self.owner_doc().cancel_animations_for_node(self); self.style_data.borrow_mut().take(); @@ -1283,6 +1311,21 @@ impl Node { is_shadow_host, shadow_root_mode, display, + doctype_name: self + .downcast::<DocumentType>() + .map(DocumentType::name) + .cloned() + .map(String::from), + doctype_public_identifier: self + .downcast::<DocumentType>() + .map(DocumentType::public_id) + .cloned() + .map(String::from), + doctype_system_identifier: self + .downcast::<DocumentType>() + .map(DocumentType::system_id) + .cloned() + .map(String::from), } } diff --git a/components/script/dom/shadowroot.rs b/components/script/dom/shadowroot.rs index 72b074ed6f4..14d9c24b10e 100644 --- a/components/script/dom/shadowroot.rs +++ b/components/script/dom/shadowroot.rs @@ -453,6 +453,15 @@ impl ShadowRootMethods<crate::DomTypeHolder> for ShadowRoot { self.slot_assignment_mode } + /// <https://html.spec.whatwg.org/multipage/#dom-shadowroot-sethtmlunsafe> + fn SetHTMLUnsafe(&self, html: DOMString, can_gc: CanGc) { + // Step 2. Unsafely set HTMl given this, this's shadow host, and complaintHTML + let target = self.upcast::<Node>(); + let context_element = self.Host(); + + Node::unsafely_set_html(target, &context_element, html, can_gc); + } + // https://dom.spec.whatwg.org/#dom-shadowroot-onslotchange event_handler!(onslotchange, GetOnslotchange, SetOnslotchange); } diff --git a/components/script/dom/webgl2renderingcontext.rs b/components/script/dom/webgl2renderingcontext.rs index 416454d8719..5e538b53b5f 100644 --- a/components/script/dom/webgl2renderingcontext.rs +++ b/components/script/dom/webgl2renderingcontext.rs @@ -22,10 +22,10 @@ use js::jsval::{BooleanValue, DoubleValue, Int32Value, NullValue, ObjectValue, U use js::rust::{CustomAutoRooterGuard, HandleObject, MutableHandleValue}; use js::typedarray::{ArrayBufferView, CreateWith, Float32, Int32Array, Uint32, Uint32Array}; use script_bindings::interfaces::WebGL2RenderingContextHelpers; -use script_layout_interface::HTMLCanvasDataSource; use servo_config::pref; use snapshot::Snapshot; use url::Host; +use webrender_api::ImageKey; use crate::canvas_context::CanvasContext; use crate::dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::{ @@ -4702,7 +4702,7 @@ impl WebGL2RenderingContextMethods<crate::DomTypeHolder> for WebGL2RenderingCont impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, WebGL2RenderingContext> { #[allow(unsafe_code)] - fn canvas_data_source(self) -> HTMLCanvasDataSource { + fn canvas_data_source(self) -> Option<ImageKey> { let this = self.unsafe_get(); unsafe { (*this.base.to_layout().unsafe_get()).layout_handle() } } diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 9996a3cf504..98170f9655b 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -31,7 +31,6 @@ use js::typedarray::{ }; use net_traits::image_cache::ImageResponse; use pixels::{self, PixelFormat}; -use script_layout_interface::HTMLCanvasDataSource; use serde::{Deserialize, Serialize}; use servo_config::pref; use snapshot::Snapshot; @@ -875,9 +874,8 @@ impl WebGLRenderingContext { receiver.recv().unwrap() } - pub(crate) fn layout_handle(&self) -> HTMLCanvasDataSource { - let image_key = self.webrender_image; - HTMLCanvasDataSource::WebGL(image_key) + pub(crate) fn layout_handle(&self) -> Option<ImageKey> { + Some(self.webrender_image) } // https://www.khronos.org/registry/webgl/extensions/ANGLE_instanced_arrays/ @@ -4829,7 +4827,7 @@ impl WebGLRenderingContextMethods<crate::DomTypeHolder> for WebGLRenderingContex } impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, WebGLRenderingContext> { - fn canvas_data_source(self) -> HTMLCanvasDataSource { + fn canvas_data_source(self) -> Option<ImageKey> { (*self.unsafe_get()).layout_handle() } } diff --git a/components/script/dom/webgpu/gpucanvascontext.rs b/components/script/dom/webgpu/gpucanvascontext.rs index c81f96f651f..359b1b14003 100644 --- a/components/script/dom/webgpu/gpucanvascontext.rs +++ b/components/script/dom/webgpu/gpucanvascontext.rs @@ -8,7 +8,6 @@ use std::cell::RefCell; use arrayvec::ArrayVec; use dom_struct::dom_struct; use ipc_channel::ipc::{self}; -use script_layout_interface::HTMLCanvasDataSource; use snapshot::Snapshot; use webgpu_traits::{ ContextConfiguration, PRESENTATION_BUFFER_COUNT, WebGPU, WebGPUContextId, WebGPURequest, @@ -227,11 +226,11 @@ impl GPUCanvasContext { // Internal helper methods impl GPUCanvasContext { - fn layout_handle(&self) -> HTMLCanvasDataSource { + fn layout_handle(&self) -> Option<ImageKey> { if self.drawing_buffer.borrow().cleared { - HTMLCanvasDataSource::Empty + None } else { - HTMLCanvasDataSource::WebGPU(self.webrender_image) + Some(self.webrender_image) } } @@ -301,7 +300,7 @@ impl CanvasContext for GPUCanvasContext { } impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, GPUCanvasContext> { - fn canvas_data_source(self) -> HTMLCanvasDataSource { + fn canvas_data_source(self) -> Option<ImageKey> { (*self.unsafe_get()).layout_handle() } } diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index a685bbb25f2..90782e217b7 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -1246,7 +1246,7 @@ impl WindowMethods<crate::DomTypeHolder> for Window { let rv = jsval_to_webdriver(cx, &self.globalscope, val, realm, can_gc); let opt_chan = self.webdriver_script_chan.borrow_mut().take(); if let Some(chan) = opt_chan { - chan.send(rv).unwrap(); + let _ = chan.send(rv); } } @@ -1255,9 +1255,9 @@ impl WindowMethods<crate::DomTypeHolder> for Window { let opt_chan = self.webdriver_script_chan.borrow_mut().take(); if let Some(chan) = opt_chan { if let Ok(rv) = rv { - chan.send(Err(WebDriverJSError::JSException(rv))).unwrap(); + let _ = chan.send(Err(WebDriverJSError::JSException(rv))); } else { - chan.send(rv).unwrap(); + let _ = chan.send(rv); } } } @@ -1265,7 +1265,7 @@ impl WindowMethods<crate::DomTypeHolder> for Window { fn WebdriverTimeout(&self) { let opt_chan = self.webdriver_script_chan.borrow_mut().take(); if let Some(chan) = opt_chan { - chan.send(Err(WebDriverJSError::Timeout)).unwrap(); + let _ = chan.send(Err(WebDriverJSError::Timeout)); } } |