diff options
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/canvas_state.rs | 41 | ||||
-rw-r--r-- | components/script/dom/element.rs | 29 | ||||
-rw-r--r-- | components/script/dom/htmlbodyelement.rs | 10 | ||||
-rw-r--r-- | components/script/dom/htmlfontelement.rs | 6 | ||||
-rw-r--r-- | components/script/dom/htmlhrelement.rs | 6 | ||||
-rw-r--r-- | components/script/dom/htmlstyleelement.rs | 1 | ||||
-rw-r--r-- | components/script/dom/htmltablecellelement.rs | 6 | ||||
-rw-r--r-- | components/script/dom/htmltableelement.rs | 6 | ||||
-rw-r--r-- | components/script/dom/htmltablerowelement.rs | 6 | ||||
-rw-r--r-- | components/script/dom/htmltablesectionelement.rs | 6 | ||||
-rw-r--r-- | components/script/dom/node.rs | 6 | ||||
-rw-r--r-- | components/script/layout_dom/element.rs | 14 |
12 files changed, 90 insertions, 47 deletions
diff --git a/components/script/canvas_state.rs b/components/script/canvas_state.rs index 0658153739b..03e1fcc7568 100644 --- a/components/script/canvas_state.rs +++ b/components/script/canvas_state.rs @@ -12,7 +12,7 @@ use canvas_traits::canvas::{ FillRule, LineCapStyle, LineJoinStyle, LinearGradientStyle, RadialGradientStyle, RepetitionStyle, TextAlign, TextBaseline, }; -use cssparser::{Parser, ParserInput, RGBA}; +use cssparser::{Parser, ParserInput, RgbaLegacy}; use euclid::default::{Point2D, Rect, Size2D, Transform2D}; use euclid::vec2; use ipc_channel::ipc::{self, IpcSender, IpcSharedMemory}; @@ -62,7 +62,7 @@ use crate::unpremultiplytable::UNPREMULTIPLY_TABLE; #[derive(Clone, JSTraceable, MallocSizeOf)] #[allow(dead_code)] pub(crate) enum CanvasFillOrStrokeStyle { - Color(#[no_trace] RGBA), + Color(#[no_trace] RgbaLegacy), Gradient(Dom<CanvasGradient>), Pattern(Dom<CanvasPattern>), } @@ -98,7 +98,7 @@ pub(crate) struct CanvasContextState { shadow_offset_y: f64, shadow_blur: f64, #[no_trace] - shadow_color: RGBA, + shadow_color: RgbaLegacy, #[no_trace] font_style: Option<Font>, #[no_trace] @@ -113,7 +113,7 @@ impl CanvasContextState { const DEFAULT_FONT_STYLE: &'static str = "10px sans-serif"; pub(crate) fn new() -> CanvasContextState { - let black = RGBA::new(Some(0), Some(0), Some(0), Some(1.0)); + let black = RgbaLegacy::new(0, 0, 0, 1.0); CanvasContextState { global_alpha: 1.0, global_composition: CompositionOrBlending::default(), @@ -128,7 +128,7 @@ impl CanvasContextState { shadow_offset_x: 0.0, shadow_offset_y: 0.0, shadow_blur: 0.0, - shadow_color: RGBA::new(Some(0), Some(0), Some(0), Some(0.0)), + shadow_color: RgbaLegacy::new(0, 0, 0, 0.0), font_style: None, text_align: Default::default(), text_baseline: Default::default(), @@ -1679,7 +1679,7 @@ impl CanvasState { } } -pub fn parse_color(canvas: Option<&HTMLCanvasElement>, string: &str) -> Result<RGBA, ()> { +pub fn parse_color(canvas: Option<&HTMLCanvasElement>, string: &str) -> Result<RgbaLegacy, ()> { let mut input = ParserInput::new(string); let mut parser = Parser::new(&mut input); let url = Url::parse("about:blank").unwrap().into(); @@ -1704,14 +1704,14 @@ pub fn parse_color(canvas: Option<&HTMLCanvasElement>, string: &str) -> Result<R // https://drafts.css-houdini.org/css-paint-api/#2d-rendering-context // Whenever "currentColor" is used as a color in the PaintRenderingContext2D API, // it is treated as opaque black. - None => AbsoluteColor::black(), + None => AbsoluteColor::BLACK, Some(ref canvas) => { let canvas_element = canvas.upcast::<Element>(); match canvas_element.style() { Some(ref s) if canvas_element.has_css_layout_box() => { s.get_inherited_text().color }, - _ => AbsoluteColor::black(), + _ => AbsoluteColor::BLACK, } }, }; @@ -1719,11 +1719,11 @@ pub fn parse_color(canvas: Option<&HTMLCanvasElement>, string: &str) -> Result<R let rgba = color .resolve_to_absolute(¤t_color) .to_color_space(ColorSpace::Srgb); - Ok(RGBA::from_floats( - Some(rgba.components.0), - Some(rgba.components.1), - Some(rgba.components.2), - Some(rgba.alpha), + Ok(RgbaLegacy::from_floats( + rgba.components.0, + rgba.components.1, + rgba.components.2, + rgba.alpha, )) }, None => Err(()), @@ -1737,16 +1737,17 @@ pub fn is_rect_valid(rect: Rect<f64>) -> bool { } // https://html.spec.whatwg.org/multipage/#serialisation-of-a-color -pub fn serialize<W>(color: &RGBA, dest: &mut W) -> fmt::Result +pub fn serialize<W>(color: &RgbaLegacy, dest: &mut W) -> fmt::Result where W: fmt::Write, { - let red = color.red.unwrap_or(0); - let green = color.green.unwrap_or(0); - let blue = color.blue.unwrap_or(0); - let alpha = color.alpha.unwrap_or(0.0); - - if alpha == 1.0 { + let RgbaLegacy { + red, + green, + blue, + alpha, + } = color; + if *alpha == 1.0 { write!( dest, "#{:x}{:x}{:x}{:x}{:x}{:x}", diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index da0ad78d91e..9ddde5d0d86 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -30,6 +30,7 @@ use net_traits::request::CorsSettings; use net_traits::ReferrerPolicy; use script_layout_interface::message::ReflowGoal; use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint}; +use selectors::bloom::{BloomFilter, BLOOM_HASH_MASK}; use selectors::matching::{ElementSelectorFlags, MatchingContext}; use selectors::sink::Push; use selectors::Element as SelectorsElement; @@ -3393,6 +3394,34 @@ impl<'a> SelectorsElement for DomRoot<Element> { } } } + + fn add_element_unique_hashes(&self, filter: &mut BloomFilter) -> bool { + let mut f = |hash| filter.insert_hash(hash & BLOOM_HASH_MASK); + + // We can't use style::bloom::each_relevant_element_hash(*self, f) + // since DomRoot<Element> doesn't have the TElement trait. + f(Element::local_name(self).get_hash()); + f(Element::namespace(self).get_hash()); + + if let Some(ref id) = *self.id_attribute.borrow() { + f(id.get_hash()); + } + + if let Some(attr) = self.get_attribute(&ns!(), &local_name!("class")) { + for class in attr.value().as_tokens() { + f(AtomIdent::cast(class).get_hash()); + } + } + + for attr in self.attrs.borrow().iter() { + let name = style::values::GenericAtomIdent::cast(attr.local_name()); + if !style::bloom::is_attr_name_excluded_from_filter(name) { + f(name.get_hash()); + } + } + + true + } } impl Element { diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs index 0ecd130914f..64f482f054c 100644 --- a/components/script/dom/htmlbodyelement.rs +++ b/components/script/dom/htmlbodyelement.rs @@ -2,7 +2,7 @@ * 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 cssparser::RGBA; +use cssparser::RgbaLegacy; use dom_struct::dom_struct; use embedder_traits::EmbedderMsg; use html5ever::{local_name, namespace_url, ns, LocalName, Prefix}; @@ -100,20 +100,20 @@ impl HTMLBodyElementMethods for HTMLBodyElement { } pub trait HTMLBodyElementLayoutHelpers { - fn get_background_color(self) -> Option<RGBA>; - fn get_color(self) -> Option<RGBA>; + fn get_background_color(self) -> Option<RgbaLegacy>; + fn get_color(self) -> Option<RgbaLegacy>; fn get_background(self) -> Option<ServoUrl>; } impl HTMLBodyElementLayoutHelpers for LayoutDom<'_, HTMLBodyElement> { - fn get_background_color(self) -> Option<RGBA> { + fn get_background_color(self) -> Option<RgbaLegacy> { self.upcast::<Element>() .get_attr_for_layout(&ns!(), &local_name!("bgcolor")) .and_then(AttrValue::as_color) .cloned() } - fn get_color(self) -> Option<RGBA> { + fn get_color(self) -> Option<RgbaLegacy> { self.upcast::<Element>() .get_attr_for_layout(&ns!(), &local_name!("text")) .and_then(AttrValue::as_color) diff --git a/components/script/dom/htmlfontelement.rs b/components/script/dom/htmlfontelement.rs index fb1fa3f53a9..9bdd32bb5c4 100644 --- a/components/script/dom/htmlfontelement.rs +++ b/components/script/dom/htmlfontelement.rs @@ -2,7 +2,7 @@ * 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 cssparser::RGBA; +use cssparser::RgbaLegacy; use dom_struct::dom_struct; use html5ever::{local_name, namespace_url, ns, LocalName, Prefix}; use js::rust::HandleObject; @@ -105,13 +105,13 @@ impl VirtualMethods for HTMLFontElement { } pub trait HTMLFontElementLayoutHelpers { - fn get_color(self) -> Option<RGBA>; + fn get_color(self) -> Option<RgbaLegacy>; fn get_face(self) -> Option<Atom>; fn get_size(self) -> Option<u32>; } impl HTMLFontElementLayoutHelpers for LayoutDom<'_, HTMLFontElement> { - fn get_color(self) -> Option<RGBA> { + fn get_color(self) -> Option<RgbaLegacy> { self.upcast::<Element>() .get_attr_for_layout(&ns!(), &local_name!("color")) .and_then(AttrValue::as_color) diff --git a/components/script/dom/htmlhrelement.rs b/components/script/dom/htmlhrelement.rs index f28a592000b..1a63747aa57 100644 --- a/components/script/dom/htmlhrelement.rs +++ b/components/script/dom/htmlhrelement.rs @@ -2,7 +2,7 @@ * 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 cssparser::RGBA; +use cssparser::RgbaLegacy; use dom_struct::dom_struct; use html5ever::{local_name, namespace_url, ns, LocalName, Prefix}; use js::rust::HandleObject; @@ -70,12 +70,12 @@ impl HTMLHRElementMethods for HTMLHRElement { } pub trait HTMLHRLayoutHelpers { - fn get_color(self) -> Option<RGBA>; + fn get_color(self) -> Option<RgbaLegacy>; fn get_width(self) -> LengthOrPercentageOrAuto; } impl HTMLHRLayoutHelpers for LayoutDom<'_, HTMLHRElement> { - fn get_color(self) -> Option<RGBA> { + fn get_color(self) -> Option<RgbaLegacy> { self.upcast::<Element>() .get_attr_for_layout(&ns!(), &local_name!("color")) .and_then(AttrValue::as_color) diff --git a/components/script/dom/htmlstyleelement.rs b/components/script/dom/htmlstyleelement.rs index a42355167e9..c298db7398e 100644 --- a/components/script/dom/htmlstyleelement.rs +++ b/components/script/dom/htmlstyleelement.rs @@ -126,7 +126,6 @@ impl HTMLStyleElement { Some(&loader), css_error_reporter, doc.quirks_mode(), - self.line_number as u32, AllowImportRules::Yes, ); diff --git a/components/script/dom/htmltablecellelement.rs b/components/script/dom/htmltablecellelement.rs index c2cb14afb34..2b4406feb95 100644 --- a/components/script/dom/htmltablecellelement.rs +++ b/components/script/dom/htmltablecellelement.rs @@ -2,7 +2,7 @@ * 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 cssparser::RGBA; +use cssparser::RgbaLegacy; use dom_struct::dom_struct; use html5ever::{local_name, namespace_url, ns, LocalName, Prefix}; use js::rust::HandleObject; @@ -106,7 +106,7 @@ impl HTMLTableCellElementMethods for HTMLTableCellElement { } pub trait HTMLTableCellElementLayoutHelpers<'dom> { - fn get_background_color(self) -> Option<RGBA>; + fn get_background_color(self) -> Option<RgbaLegacy>; fn get_colspan(self) -> Option<u32>; fn get_rowspan(self) -> Option<u32>; fn get_table(self) -> Option<LayoutDom<'dom, HTMLTableElement>>; @@ -114,7 +114,7 @@ pub trait HTMLTableCellElementLayoutHelpers<'dom> { } impl<'dom> HTMLTableCellElementLayoutHelpers<'dom> for LayoutDom<'dom, HTMLTableCellElement> { - fn get_background_color(self) -> Option<RGBA> { + fn get_background_color(self) -> Option<RgbaLegacy> { self.upcast::<Element>() .get_attr_for_layout(&ns!(), &local_name!("bgcolor")) .and_then(AttrValue::as_color) diff --git a/components/script/dom/htmltableelement.rs b/components/script/dom/htmltableelement.rs index 4c50349cf70..93c40a5e930 100644 --- a/components/script/dom/htmltableelement.rs +++ b/components/script/dom/htmltableelement.rs @@ -4,7 +4,7 @@ use std::cell::Cell; -use cssparser::RGBA; +use cssparser::RgbaLegacy; use dom_struct::dom_struct; use html5ever::{local_name, namespace_url, ns, LocalName, Prefix}; use js::rust::HandleObject; @@ -425,7 +425,7 @@ impl HTMLTableElementMethods for HTMLTableElement { } pub trait HTMLTableElementLayoutHelpers { - fn get_background_color(self) -> Option<RGBA>; + fn get_background_color(self) -> Option<RgbaLegacy>; fn get_border(self) -> Option<u32>; fn get_cellpadding(self) -> Option<u32>; fn get_cellspacing(self) -> Option<u32>; @@ -433,7 +433,7 @@ pub trait HTMLTableElementLayoutHelpers { } impl HTMLTableElementLayoutHelpers for LayoutDom<'_, HTMLTableElement> { - fn get_background_color(self) -> Option<RGBA> { + fn get_background_color(self) -> Option<RgbaLegacy> { self.upcast::<Element>() .get_attr_for_layout(&ns!(), &local_name!("bgcolor")) .and_then(AttrValue::as_color) diff --git a/components/script/dom/htmltablerowelement.rs b/components/script/dom/htmltablerowelement.rs index a5fe4e2fec6..c400ac8011a 100644 --- a/components/script/dom/htmltablerowelement.rs +++ b/components/script/dom/htmltablerowelement.rs @@ -2,7 +2,7 @@ * 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 cssparser::RGBA; +use cssparser::RgbaLegacy; use dom_struct::dom_struct; use html5ever::{local_name, namespace_url, ns, LocalName, Prefix}; use js::rust::HandleObject; @@ -153,11 +153,11 @@ impl HTMLTableRowElementMethods for HTMLTableRowElement { } pub trait HTMLTableRowElementLayoutHelpers { - fn get_background_color(self) -> Option<RGBA>; + fn get_background_color(self) -> Option<RgbaLegacy>; } impl HTMLTableRowElementLayoutHelpers for LayoutDom<'_, HTMLTableRowElement> { - fn get_background_color(self) -> Option<RGBA> { + fn get_background_color(self) -> Option<RgbaLegacy> { self.upcast::<Element>() .get_attr_for_layout(&ns!(), &local_name!("bgcolor")) .and_then(AttrValue::as_color) diff --git a/components/script/dom/htmltablesectionelement.rs b/components/script/dom/htmltablesectionelement.rs index 9daf6393154..6dd042a0187 100644 --- a/components/script/dom/htmltablesectionelement.rs +++ b/components/script/dom/htmltablesectionelement.rs @@ -2,7 +2,7 @@ * 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 cssparser::RGBA; +use cssparser::RgbaLegacy; use dom_struct::dom_struct; use html5ever::{local_name, namespace_url, ns, LocalName, Prefix}; use js::rust::HandleObject; @@ -91,11 +91,11 @@ impl HTMLTableSectionElementMethods for HTMLTableSectionElement { } pub trait HTMLTableSectionElementLayoutHelpers { - fn get_background_color(self) -> Option<RGBA>; + fn get_background_color(self) -> Option<RgbaLegacy>; } impl HTMLTableSectionElementLayoutHelpers for LayoutDom<'_, HTMLTableSectionElement> { - fn get_background_color(self) -> Option<RGBA> { + fn get_background_color(self) -> Option<RgbaLegacy> { self.upcast::<Element>() .get_attr_for_layout(&ns!(), &local_name!("bgcolor")) .and_then(AttrValue::as_color) diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 9e6f4feeee9..ee1e563ef1d 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -31,7 +31,7 @@ use script_layout_interface::{ }; use script_traits::{DocumentActivity, UntrustedNodeAddress}; use selectors::matching::{ - matches_selector_list, IgnoreNthChildForInvalidation, MatchingContext, MatchingMode, + matches_selector_list, MatchingContext, MatchingForInvalidation, MatchingMode, NeedsSelectorFlags, }; use selectors::parser::SelectorList; @@ -481,7 +481,7 @@ impl<'a> Iterator for QuerySelectorIterator { &mut nth_index_cache, node.owner_doc().quirks_mode(), NeedsSelectorFlags::No, - IgnoreNthChildForInvalidation::No, + MatchingForInvalidation::No, ); if let Some(element) = DomRoot::downcast(node) { if matches_selector_list(selectors, &element, &mut ctx) { @@ -978,7 +978,7 @@ impl Node { &mut nth_index_cache, doc.quirks_mode(), NeedsSelectorFlags::No, - IgnoreNthChildForInvalidation::No, + MatchingForInvalidation::No, ); Ok(self .traverse_preorder(ShadowIncluding::No) diff --git a/components/script/layout_dom/element.rs b/components/script/layout_dom/element.rs index 40d7f0a8aa3..ab2a2f52c7c 100644 --- a/components/script/layout_dom/element.rs +++ b/components/script/layout_dom/element.rs @@ -15,6 +15,7 @@ use script_layout_interface::wrapper_traits::{ }; use script_layout_interface::{LayoutNodeType, StyleAndOpaqueLayoutData, StyleData}; use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint}; +use selectors::bloom::{BloomFilter, BLOOM_HASH_MASK}; use selectors::matching::{ElementSelectorFlags, MatchingContext, VisitedHandlingMode}; use selectors::sink::Push; use servo_arc::{Arc, ArcBorrow}; @@ -22,6 +23,7 @@ use servo_atoms::Atom; use style::animation::AnimationSetKey; use style::applicable_declarations::ApplicableDeclarationBlock; use style::attr::AttrValue; +use style::bloom::each_relevant_element_hash; use style::context::SharedStyleContext; use style::data::ElementData; use style::dom::{DomChildren, LayoutIterator, TDocument, TElement, TNode, TShadowRoot}; @@ -682,6 +684,11 @@ impl<'dom, LayoutDataType: LayoutDataTrait> ::selectors::Element } } } + + fn add_element_unique_hashes(&self, filter: &mut BloomFilter) -> bool { + each_relevant_element_hash(*self, |hash| filter.insert_hash(hash & BLOOM_HASH_MASK)); + true + } } /// A wrapper around elements that ensures layout can only @@ -941,6 +948,13 @@ impl<'dom, LayoutDataType: LayoutDataTrait> ::selectors::Element } } } + + fn add_element_unique_hashes(&self, filter: &mut BloomFilter) -> bool { + each_relevant_element_hash(self.element, |hash| { + filter.insert_hash(hash & BLOOM_HASH_MASK) + }); + true + } } impl<'dom, LayoutDataType: LayoutDataTrait> GetStyleAndOpaqueLayoutData<'dom> |