Skip to content

Commit

Permalink
Commit all other changes from Servo
Browse files Browse the repository at this point in the history
This builds successfully with:

$ cargo build --features servo

 (as of servo#31351, 31363, 31358, 31365)

This patch is up to date as of:

* servo/servo#31351
* servo/servo#31363
* servo/servo#31358
* servo/servo#31365
* servo/servo#31387
* servo/servo#31408
  • Loading branch information
mrobinson authored and delan committed Feb 22, 2024
1 parent 5aa916a commit 50579cd
Show file tree
Hide file tree
Showing 52 changed files with 444 additions and 149 deletions.
16 changes: 14 additions & 2 deletions malloc_size_of/lib.rs
Expand Up @@ -58,8 +58,6 @@ extern crate euclid;
#[cfg(feature = "servo")]
extern crate http;
#[cfg(feature = "servo")]
extern crate hyper_serde;
#[cfg(feature = "servo")]
extern crate keyboard_types;
extern crate selectors;
#[cfg(feature = "servo")]
Expand Down Expand Up @@ -829,6 +827,7 @@ malloc_size_of_is_0!(bool, char, str);
malloc_size_of_is_0!(u8, u16, u32, u64, u128, usize);
malloc_size_of_is_0!(i8, i16, i32, i64, i128, isize);
malloc_size_of_is_0!(f32, f64);
malloc_size_of_is_0!(std::num::NonZeroU64);

malloc_size_of_is_0!(std::sync::atomic::AtomicBool);
malloc_size_of_is_0!(std::sync::atomic::AtomicIsize);
Expand Down Expand Up @@ -922,6 +921,12 @@ impl MallocSizeOf for xml5ever::QualName {
malloc_size_of_is_0!(time::Duration);
#[cfg(feature = "servo")]
malloc_size_of_is_0!(time::Tm);
#[cfg(feature = "servo")]
malloc_size_of_is_0!(std::time::Duration);
#[cfg(feature = "servo")]
malloc_size_of_is_0!(std::time::SystemTime);
#[cfg(feature = "servo")]
malloc_size_of_is_0!(std::time::Instant);

// Placeholder for unique case where internals of Sender cannot be measured.
// malloc size of is 0 macro complains about type supplied!
Expand All @@ -932,6 +937,13 @@ impl<T> MallocSizeOf for crossbeam_channel::Sender<T> {
}
}

#[cfg(feature = "servo")]
impl<T> MallocSizeOf for tokio::sync::mpsc::UnboundedSender<T> {
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
0
}
}

#[cfg(feature = "servo")]
impl MallocSizeOf for http::StatusCode {
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
Expand Down
1 change: 1 addition & 0 deletions selectors/matching.rs
Expand Up @@ -14,6 +14,7 @@ use crate::parser::{
NonTSPseudoClass, RelativeSelector, Selector, SelectorImpl, SelectorIter, SelectorList,
};
use crate::tree::Element;
use bitflags::bitflags;
use smallvec::SmallVec;
use std::borrow::Borrow;
use std::iter;
Expand Down
1 change: 1 addition & 0 deletions selectors/parser.rs
Expand Up @@ -13,6 +13,7 @@ use crate::context::QuirksMode;
use crate::sink::Push;
use crate::visitor::SelectorListKind;
pub use crate::visitor::SelectorVisitor;
use bitflags::bitflags;
use cssparser::parse_nth;
use cssparser::{BasicParseError, BasicParseErrorKind, ParseError, ParseErrorKind};
use cssparser::{CowRcStr, Delimiter, SourceLocation};
Expand Down
2 changes: 1 addition & 1 deletion style/README.md
Expand Up @@ -3,4 +3,4 @@ servo-style

Style system for Servo, using [rust-cssparser](https://github.com/servo/rust-cssparser) for parsing.

* [Documentation](https://github.com/servo/servo/blob/master/docs/components/style.md).
* [Documentation](https://github.com/servo/servo/blob/main/docs/components/style.md).
4 changes: 4 additions & 0 deletions style/animation.rs
Expand Up @@ -1029,6 +1029,10 @@ impl ElementAnimationSet {
old_style: &ComputedValues,
new_style: &Arc<ComputedValues>,
) {
if !longhand_id.is_transitionable() {
return;
}

let style = new_style.get_ui();
let timing_function = style.transition_timing_function_mod(index);
let duration = style.transition_duration_mod(index);
Expand Down
10 changes: 5 additions & 5 deletions style/attr.rs
Expand Up @@ -433,7 +433,7 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA, ()> {
hex(input.as_bytes()[2] as char),
hex(input.as_bytes()[3] as char),
) {
return Ok(RGBA::new(r * 17, g * 17, b * 17, 255));
return Ok(RGBA::new(Some(r * 17), Some(g * 17), Some(b * 17), Some(1.0)));
}
}

Expand Down Expand Up @@ -503,10 +503,10 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA, ()> {

// Steps 15-20.
return Ok(RGBA::new(
hex_string(red).unwrap(),
hex_string(green).unwrap(),
hex_string(blue).unwrap(),
255,
Some(hex_string(red).unwrap()),
Some(hex_string(green).unwrap()),
Some(hex_string(blue).unwrap()),
Some(1.0),
));

fn hex(ch: char) -> Result<u8, ()> {
Expand Down
5 changes: 3 additions & 2 deletions style/bloom.rs
Expand Up @@ -8,6 +8,7 @@
#![deny(missing_docs)]

use crate::dom::{SendElement, TElement};
use crate::LocalName;
use atomic_refcell::{AtomicRefCell, AtomicRefMut};
use owning_ref::OwningHandle;
use selectors::bloom::BloomFilter;
Expand Down Expand Up @@ -107,8 +108,8 @@ impl<E: TElement> PushedElement<E> {
/// We do this for attributes that are very common but not commonly used in
/// selectors.
#[inline]
pub fn is_attr_name_excluded_from_filter(atom: &crate::Atom) -> bool {
*atom == atom!("class") || *atom == atom!("id") || *atom == atom!("style")
pub fn is_attr_name_excluded_from_filter(name: &LocalName) -> bool {
return *name == local_name!("class") || *name == local_name!("id") || *name == local_name!("style")
}

fn each_relevant_element_hash<E, F>(element: E, mut f: F)
Expand Down
2 changes: 1 addition & 1 deletion style/build.rs
Expand Up @@ -21,7 +21,7 @@ mod build_gecko {
lazy_static! {
pub static ref PYTHON: String = env::var("PYTHON3").ok().unwrap_or_else(|| {
let candidates = if cfg!(windows) {
["python3.exe"]
["python.exe"]
} else {
["python3"]
};
Expand Down
4 changes: 2 additions & 2 deletions style/dom.rs
Expand Up @@ -19,7 +19,7 @@ use crate::shared_lock::{Locked, SharedRwLock};
use crate::stylist::CascadeData;
use crate::values::computed::Display;
use crate::values::AtomIdent;
use crate::WeakAtom;
use crate::{LocalName, WeakAtom};
use atomic_refcell::{AtomicRef, AtomicRefMut};
use selectors::matching::{QuirksMode, VisitedHandlingMode};
use selectors::sink::Push;
Expand Down Expand Up @@ -536,7 +536,7 @@ pub trait TElement:
/// Internal iterator for the attribute names of this element.
fn each_attr_name<F>(&self, callback: F)
where
F: FnMut(&AtomIdent);
F: FnMut(&LocalName);

/// Internal iterator for the part names that this element exports for a
/// given part name.
Expand Down
6 changes: 3 additions & 3 deletions style/dom_apis.rs
Expand Up @@ -355,7 +355,7 @@ fn collect_elements_with_id<E, Q, F>(
}
}

fn has_attr<E>(element: E, local_name: &AtomIdent) -> bool
fn has_attr<E>(element: E, local_name: &crate::LocalName) -> bool
where
E: TElement,
{
Expand Down Expand Up @@ -383,7 +383,7 @@ where
element.local_name() == &**chosen_name
}

fn get_attr_name(component: &Component<SelectorImpl>) -> Option<&AtomIdent> {
fn get_attr_name(component: &Component<SelectorImpl>) -> Option<&crate::LocalName> {
let (name, name_lower) = match component {
Component::AttributeInNoNamespace { ref local_name, .. } => return Some(local_name),
Component::AttributeInNoNamespaceExists {
Expand Down Expand Up @@ -467,7 +467,7 @@ where

enum SimpleFilter<'a> {
Class(&'a AtomIdent),
Attr(&'a AtomIdent),
Attr(&'a crate::LocalName),
LocalName(&'a LocalName<SelectorImpl>),
}

Expand Down
23 changes: 19 additions & 4 deletions style/font_face.rs
Expand Up @@ -80,6 +80,7 @@ impl Parse for SourceList {
/// Keywords for the font-face src descriptor's format() function.
/// ('None' and 'Unknown' are for internal use in gfx, not exposed to CSS.)
#[derive(Clone, Copy, Debug, Eq, Parse, PartialEq, ToCss, ToShmem)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[repr(u8)]
#[allow(missing_docs)]
pub enum FontFaceSourceFormatKeyword {
Expand All @@ -100,6 +101,7 @@ bitflags! {
/// Flags for the @font-face tech() function, indicating font technologies
/// required by the resource.
#[derive(ToShmem)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[repr(C)]
pub struct FontFaceSourceTechFlags: u16 {
/// Font requires OpenType feature support.
Expand Down Expand Up @@ -225,6 +227,7 @@ pub enum FontFaceSourceListComponent {
}

#[derive(Clone, Debug, Eq, PartialEq, ToCss, ToShmem)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[repr(u8)]
#[allow(missing_docs)]
pub enum FontFaceSourceFormat {
Expand Down Expand Up @@ -491,7 +494,7 @@ pub struct FontFace<'a>(&'a FontFaceRuleData);
#[cfg(feature = "servo")]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
pub struct EffectiveSources(SourceList);
pub struct EffectiveSources(Vec<Source>);

#[cfg(feature = "servo")]
impl<'a> FontFace<'a> {
Expand All @@ -501,16 +504,28 @@ impl<'a> FontFace<'a> {
pub fn effective_sources(&self) -> EffectiveSources {
EffectiveSources(
self.sources()
.0
.iter()
.rev()
.filter(|source| {
if let Source::Url(ref url_source) = **source {
// We support only opentype fonts and truetype is an alias for
// that format. Sources without format hints need to be
// downloaded in case we support them.
url_source.format_hint.as_ref().map_or(true, |hint| {
hint == "truetype" || hint == "opentype" || hint == "woff"
})
url_source
.format_hint
.as_ref()
.map_or(true, |hint| match hint {
FontFaceSourceFormat::Keyword(
FontFaceSourceFormatKeyword::Truetype
| FontFaceSourceFormatKeyword::Opentype
| FontFaceSourceFormatKeyword::Woff,
) => true,
FontFaceSourceFormat::String(s) => {
s == "truetype" || s == "opentype" || s == "woff"
}
_ => false,
})
} else {
true
}
Expand Down
10 changes: 5 additions & 5 deletions style/global_style_data.rs
Expand Up @@ -38,7 +38,7 @@ pub struct StyleThreadPool {
}

fn thread_name(index: usize) -> String {
format!("StyleThread#{}", index)
format!("Style#{}", index)
}

lazy_static! {
Expand Down Expand Up @@ -92,7 +92,7 @@ impl StyleThreadPool {
}
{
// Drop the pool.
let _ = STYLE_THREAD_POOL.style_thread_pool.write().take();
let _ = STYLE_THREAD_POOL.lock().unwrap().style_thread_pool.write().take();
}

// Join spawned threads until all of the threads have been joined. This
Expand Down Expand Up @@ -128,7 +128,7 @@ pub(crate) const STYLO_MAX_THREADS: usize = 6;

lazy_static! {
/// Global thread pool
pub static ref STYLE_THREAD_POOL: StyleThreadPool = {
pub static ref STYLE_THREAD_POOL: std::sync::Mutex<StyleThreadPool> = {
use std::cmp;
// We always set this pref on startup, before layout or script have had a chance of
// accessing (and thus creating) the thread-pool.
Expand Down Expand Up @@ -159,10 +159,10 @@ lazy_static! {
(workers.ok(), Some(num_threads))
};

StyleThreadPool {
std::sync::Mutex::new(StyleThreadPool {
num_threads,
style_thread_pool: RwLock::new(pool),
}
})
};

/// Global style data
Expand Down
4 changes: 1 addition & 3 deletions style/lib.rs
Expand Up @@ -50,9 +50,6 @@ extern crate log;
extern crate malloc_size_of;
#[macro_use]
extern crate malloc_size_of_derive;
#[allow(unused_extern_crates)]
#[macro_use]
extern crate matches;
#[cfg(feature = "gecko")]
pub use nsstring;
#[cfg(feature = "gecko")]
Expand Down Expand Up @@ -167,6 +164,7 @@ pub use style_traits::owned_str::OwnedStr;

use std::hash::{BuildHasher, Hash};

#[macro_use]
pub mod properties;

#[cfg(feature = "gecko")]
Expand Down
56 changes: 29 additions & 27 deletions style/logical_geometry.rs
Expand Up @@ -25,7 +25,7 @@ pub enum InlineBaseDirection {

// TODO: improve the readability of the WritingMode serialization, refer to the Debug:fmt()
bitflags!(
#[derive(MallocSizeOf, Serialize)]
#[cfg_attr(feature = "servo", derive(MallocSizeOf, Serialize))]
#[repr(C)]
pub struct WritingMode: u8 {
/// A vertical writing mode; writing-mode is vertical-rl,
Expand Down Expand Up @@ -170,7 +170,7 @@ impl WritingMode {

/// Returns the `horizontal-tb` value.
pub fn horizontal_tb() -> Self {
Self::empty()
Self::from_bits_truncate(0)
}

#[inline]
Expand Down Expand Up @@ -418,7 +418,7 @@ impl DebugWritingMode {

#[inline]
fn new(mode: WritingMode) -> DebugWritingMode {
DebugWritingMode { mode }
DebugWritingMode { mode: mode }
}
}

Expand Down Expand Up @@ -1103,6 +1103,18 @@ impl<T: Copy> LogicalMargin<T> {
}
}

#[inline]
pub fn convert(&self, mode_from: WritingMode, mode_to: WritingMode) -> LogicalMargin<T> {
if mode_from == mode_to {
self.debug_writing_mode.check(mode_from);
*self
} else {
LogicalMargin::from_physical(mode_to, self.to_physical(mode_from))
}
}
}

impl<T: Clone> LogicalMargin<T> {
#[inline]
pub fn to_physical(&self, mode: WritingMode) -> SideOffsets2D<T> {
self.debug_writing_mode.check(mode);
Expand All @@ -1112,42 +1124,32 @@ impl<T: Copy> LogicalMargin<T> {
let left;
if mode.is_vertical() {
if mode.is_vertical_lr() {
left = self.block_start;
right = self.block_end;
left = self.block_start.clone();
right = self.block_end.clone();
} else {
right = self.block_start;
left = self.block_end;
right = self.block_start.clone();
left = self.block_end.clone();
}
if mode.is_inline_tb() {
top = self.inline_start;
bottom = self.inline_end;
top = self.inline_start.clone();
bottom = self.inline_end.clone();
} else {
bottom = self.inline_start;
top = self.inline_end;
bottom = self.inline_start.clone();
top = self.inline_end.clone();
}
} else {
top = self.block_start;
bottom = self.block_end;
top = self.block_start.clone();
bottom = self.block_end.clone();
if mode.is_bidi_ltr() {
left = self.inline_start;
right = self.inline_end;
left = self.inline_start.clone();
right = self.inline_end.clone();
} else {
right = self.inline_start;
left = self.inline_end;
right = self.inline_start.clone();
left = self.inline_end.clone();
}
}
SideOffsets2D::new(top, right, bottom, left)
}

#[inline]
pub fn convert(&self, mode_from: WritingMode, mode_to: WritingMode) -> LogicalMargin<T> {
if mode_from == mode_to {
self.debug_writing_mode.check(mode_from);
*self
} else {
LogicalMargin::from_physical(mode_to, self.to_physical(mode_from))
}
}
}

impl<T: PartialEq + Zero> LogicalMargin<T> {
Expand Down

0 comments on commit 50579cd

Please sign in to comment.