Skip to content

Commit 646fbbc

Browse files
delannicoburns
authored andcommitted
Commit our changes on top of upstream Stylo
This is a rebase of 42990da Signed-off-by: Oriol Brufau <[email protected]> Signed-off-by: Nico Burns <[email protected]>
1 parent e51ea00 commit 646fbbc

27 files changed

+664
-36
lines changed

Cargo.toml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[workspace]
2+
resolver = "2"
3+
members = [
4+
"stylo_atoms",
5+
"stylo_dom",
6+
"malloc_size_of",
7+
"rustfmt.toml",
8+
"selectors",
9+
"servo_arc",
10+
"style",
11+
"style_derive",
12+
"stylo_config",
13+
"stylo_static_prefs",
14+
"style_traits",
15+
"to_shmem",
16+
"to_shmem_derive",
17+
]
18+
default-members = ["style"]

malloc_size_of/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ euclid = "0.22"
2020
selectors = { path = "../selectors" }
2121
servo_arc = { path = "../servo_arc" }
2222
smallbitvec = "2.3.0"
23-
smallvec = "1.0"
23+
smallvec = "1.13"
2424
string_cache = { version = "0.8", optional = true }
25-
thin-vec = { version = "0.2.1" }
25+
thin-vec = { version = "0.2.13" }
2626
void = "1.0.2"

style/Cargo.toml

+12-12
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ gecko = [
3131
"to_shmem/gecko",
3232
]
3333
servo = [
34-
"arrayvec/use_union",
3534
"cssparser/serde",
3635
"encoding_rs",
3736
"malloc_size_of/servo",
3837
"markup5ever",
38+
"mime",
3939
"serde",
4040
"servo_arc/servo",
4141
"stylo_atoms",
42-
"servo_config",
42+
"style_config",
4343
"string_cache",
4444
"style_traits/servo",
4545
"url",
@@ -48,16 +48,17 @@ servo = [
4848
]
4949
gecko_debug = []
5050
gecko_refcount_logging = []
51+
nsstring = []
5152

5253
[dependencies]
53-
app_units = "0.7"
54+
app_units = "0.7.8"
5455
arrayvec = "0.7"
5556
atomic_refcell = "0.1"
5657
bitflags = "2"
5758
byteorder = "1.0"
5859
cssparser = "0.34"
5960
derive_more = { version = "0.99", default-features = false, features = ["add", "add_assign", "deref", "deref_mut", "from"] }
60-
dom = { path = "../../../dom/base/rust" }
61+
dom = { path = "../stylo_dom", version = "0.1", package = "stylo_dom" }
6162
new_debug_unreachable = "1.0"
6263
encoding_rs = {version = "0.8", optional = true}
6364
euclid = "0.22"
@@ -69,10 +70,10 @@ itoa = "1.0"
6970
lazy_static = "1"
7071
log = "0.4"
7172
malloc_size_of = { path = "../malloc_size_of" }
72-
malloc_size_of_derive = { path = "../../../xpcom/rust/malloc_size_of_derive" }
73-
markup5ever = { version = "0.12", optional = true }
73+
malloc_size_of_derive = "0.1"
74+
markup5ever = { version = "0.15", optional = true }
7475
matches = "0.1"
75-
nsstring = {path = "../../../xpcom/rust/nsstring/", optional = true}
76+
mime = { version = "0.3.13", optional = true }
7677
num_cpus = {version = "1.1.0"}
7778
num-integer = "0.1"
7879
num-traits = "0.2"
@@ -84,22 +85,21 @@ rayon-core = "1"
8485
selectors = { path = "../selectors" }
8586
serde = {version = "1.0", optional = true, features = ["derive"]}
8687
servo_arc = { path = "../servo_arc" }
87-
stylo_atoms = {path = "../atoms", optional = true}
88-
servo_config = {path = "../config", optional = true}
88+
stylo_atoms = {path = "../stylo_atoms", optional = true}
8989
smallbitvec = "2.3.0"
9090
smallvec = "1.0"
9191
static_assertions = "1.1"
92-
static_prefs = { path = "../../../modules/libpref/init/static_prefs" }
92+
static_prefs = { version = "0.1", path = "../stylo_static_prefs", package = "stylo_static_prefs" }
9393
string_cache = { version = "0.8", optional = true }
94+
style_config = { version = "0.1", path = "../stylo_config", package = "stylo_config", optional = true }
9495
style_derive = {path = "../style_derive"}
9596
style_traits = {path = "../style_traits"}
9697
to_shmem = {path = "../to_shmem"}
9798
to_shmem_derive = {path = "../to_shmem_derive"}
98-
thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
99+
thin-vec = "0.2.1"
99100
uluru = "3.0"
100101
unicode-bidi = { version = "0.3", default-features = false }
101102
void = "1.0.2"
102-
gecko-profiler = { path = "../../../tools/profiler/rust-api" }
103103
url = { version = "2.5", optional = true, features = ["serde"] }
104104

105105
[build-dependencies]

style/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod build_gecko {
2121
lazy_static! {
2222
pub static ref PYTHON: String = env::var("PYTHON3").ok().unwrap_or_else(|| {
2323
let candidates = if cfg!(windows) {
24-
["python3.exe"]
24+
["python.exe"]
2525
} else {
2626
["python3"]
2727
};

style/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ impl<E: TElement> SequentialTask<E> {
450450
/// Executes this task.
451451
pub fn execute(self) {
452452
use self::SequentialTask::*;
453-
debug_assert_eq!(thread_state::get(), ThreadState::LAYOUT);
453+
debug_assert!(thread_state::get().contains(ThreadState::LAYOUT));
454454
match self {
455455
Unused(_) => unreachable!(),
456456
#[cfg(feature = "gecko")]
@@ -511,7 +511,7 @@ where
511511
E: TElement,
512512
{
513513
fn drop(&mut self) {
514-
debug_assert_eq!(thread_state::get(), ThreadState::LAYOUT);
514+
debug_assert!(thread_state::get().contains(ThreadState::LAYOUT));
515515
for task in self.0.drain(..) {
516516
task.execute()
517517
}
73.8 KB
Binary file not shown.

style/properties/build.py

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import sys
99

1010
BASE = os.path.dirname(__file__.replace("\\", "/"))
11+
sys.path.insert(0, os.path.join(BASE, "Mako-1.1.2-py2.py3-none-any.whl"))
1112
sys.path.insert(0, BASE) # For importing `data.py`
1213

1314
from mako import exceptions

style/properties/cascade.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1055,13 +1055,15 @@ impl<'b> Cascade<'b> {
10551055
builder.add_flags(ComputedValueFlags::HAS_AUTHOR_SPECIFIED_WORD_SPACING);
10561056
}
10571057

1058+
#[cfg(feature = "gecko")]
10581059
if self
10591060
.author_specified
10601061
.contains(LonghandId::FontSynthesisWeight)
10611062
{
10621063
builder.add_flags(ComputedValueFlags::HAS_AUTHOR_SPECIFIED_FONT_SYNTHESIS_WEIGHT);
10631064
}
10641065

1066+
#[cfg(feature = "gecko")]
10651067
if self
10661068
.author_specified
10671069
.contains(LonghandId::FontSynthesisStyle)
@@ -1197,7 +1199,6 @@ impl<'b> Cascade<'b> {
11971199
}
11981200

11991201
/// Some keyword sizes depend on the font family and language.
1200-
#[cfg(feature = "gecko")]
12011202
fn recompute_keyword_font_size_if_needed(&self, context: &mut computed::Context) {
12021203
use crate::values::computed::ToComputedValue;
12031204

@@ -1216,6 +1217,7 @@ impl<'b> Cascade<'b> {
12161217
},
12171218
};
12181219

1220+
#[cfg(feature = "gecko")]
12191221
if font.mScriptUnconstrainedSize == new_size.computed_size {
12201222
return;
12211223
}

style/properties/longhands/counters.mako.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ${helpers.predefined_type(
2020
"counter-increment",
2121
"CounterIncrement",
2222
engines="gecko servo",
23-
servo_pref="layout.layout.unimplemented",
23+
servo_pref="layout.unimplemented",
2424
initial_value="Default::default()",
2525
animation_type="discrete",
2626
spec="https://drafts.csswg.org/css-lists/#propdef-counter-increment",
@@ -32,7 +32,7 @@ ${helpers.predefined_type(
3232
"counter-reset",
3333
"CounterReset",
3434
engines="gecko servo",
35-
servo_pref="layout.layout.unimplemented",
35+
servo_pref="layout.unimplemented",
3636
initial_value="Default::default()",
3737
animation_type="discrete",
3838
spec="https://drafts.csswg.org/css-lists-3/#propdef-counter-reset",

style/properties/longhands/text.mako.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ${helpers.predefined_type(
99
"TextOverflow",
1010
"computed::TextOverflow::get_initial_value()",
1111
engines="gecko servo",
12-
servo_pref="layout.layout.unimplemented",
12+
servo_pref="layout.unimplemented",
1313
animation_type="discrete",
1414
boxed=True,
1515
spec="https://drafts.csswg.org/css-ui/#propdef-text-overflow",

style/properties/properties.mako.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ pub mod property_counts {
454454
/// The number of non-custom properties.
455455
pub const NON_CUSTOM: usize = LONGHANDS_AND_SHORTHANDS + ALIASES;
456456
/// The number of prioritary properties that we have.
457-
pub const PRIORITARY: usize = ${len(PRIORITARY_PROPERTIES)};
457+
pub const PRIORITARY: usize = ${len(PRIORITARY_PROPERTIES.intersection(set(list(map(lambda p: p.name, data.longhands)))))};
458458
/// The max number of longhands that a shorthand other than "all" expands to.
459459
pub const MAX_SHORTHAND_EXPANDED: usize =
460460
${max(len(s.sub_properties) for s in data.shorthands_except_all())};

style/stylesheets/stylesheet.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,12 @@ impl StylesheetContents {
122122
/// An empty namespace map should be fine, as it is only used for parsing,
123123
/// not serialization of existing selectors. Since UA sheets are read only,
124124
/// we should never need the namespace map.
125-
pub fn from_shared_data(
125+
pub fn from_data(
126126
rules: Arc<Locked<CssRules>>,
127127
origin: Origin,
128128
url_data: UrlExtraData,
129129
quirks_mode: QuirksMode,
130130
) -> Arc<Self> {
131-
debug_assert!(rules.is_static());
132131
Arc::new(Self {
133132
rules,
134133
origin,
@@ -141,6 +140,17 @@ impl StylesheetContents {
141140
})
142141
}
143142

143+
/// Same as above, but ensuring that the rules are static.
144+
pub fn from_shared_data(
145+
rules: Arc<Locked<CssRules>>,
146+
origin: Origin,
147+
url_data: UrlExtraData,
148+
quirks_mode: QuirksMode,
149+
) -> Arc<Self> {
150+
debug_assert!(rules.is_static());
151+
Self::from_data(rules, origin, url_data, quirks_mode)
152+
}
153+
144154
/// Returns a reference to the list of rules.
145155
#[inline]
146156
pub fn rules<'a, 'b: 'a>(&'a self, guard: &'b SharedRwLockReadGuard) -> &'a [CssRule] {

style/values/computed/length_percentage.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,11 @@ impl LengthPercentage {
515515
/// Returns the used value.
516516
#[inline]
517517
pub fn to_used_value(&self, containing_length: Au) -> Au {
518-
Au::from(self.to_pixel_length(containing_length))
518+
let length = self.to_pixel_length(containing_length);
519+
if let Unpacked::Percentage(_) = self.unpack() {
520+
return Au::from_f32_px_trunc(length.px());
521+
}
522+
Au::from(length)
519523
}
520524

521525
/// Returns the used value as CSSPixelLength.
@@ -528,7 +532,11 @@ impl LengthPercentage {
528532
#[inline]
529533
pub fn maybe_to_used_value(&self, container_len: Option<Au>) -> Option<Au> {
530534
self.maybe_percentage_relative_to(container_len.map(Length::from))
531-
.map(Au::from)
535+
.map(if let Unpacked::Percentage(_) = self.unpack() {
536+
|length: Length| Au::from_f32_px_trunc(length.px())
537+
} else {
538+
Au::from
539+
})
532540
}
533541

534542
/// If there are special rules for computing percentages in a value (e.g.

style/values/generics/length.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ impl<LengthPercentage> LengthPercentageOrAuto<LengthPercentage> {
7575
}
7676
}
7777

78-
impl<LengthPercentage> LengthPercentageOrAuto<LengthPercentage>
78+
impl<T> LengthPercentageOrAuto<T>
7979
where
80-
LengthPercentage: Clone,
80+
T: Clone,
8181
{
8282
/// Resolves `auto` values by calling `f`.
8383
#[inline]
84-
pub fn auto_is(&self, f: impl FnOnce() -> LengthPercentage) -> LengthPercentage {
84+
pub fn auto_is(&self, f: impl FnOnce() -> T) -> T {
8585
match self {
8686
LengthPercentageOrAuto::LengthPercentage(length) => length.clone(),
8787
LengthPercentageOrAuto::Auto => f(),
@@ -90,15 +90,15 @@ where
9090

9191
/// Returns the non-`auto` value, if any.
9292
#[inline]
93-
pub fn non_auto(&self) -> Option<LengthPercentage> {
93+
pub fn non_auto(&self) -> Option<T> {
9494
match self {
9595
LengthPercentageOrAuto::LengthPercentage(length) => Some(length.clone()),
9696
LengthPercentageOrAuto::Auto => None,
9797
}
9898
}
9999

100100
/// Maps the length of this value.
101-
pub fn map<T>(&self, f: impl FnOnce(LengthPercentage) -> T) -> LengthPercentageOrAuto<T> {
101+
pub fn map<U>(&self, f: impl FnOnce(T) -> U) -> LengthPercentageOrAuto<U> {
102102
match self {
103103
LengthPercentageOrAuto::LengthPercentage(l) => {
104104
LengthPercentageOrAuto::LengthPercentage(f(l.clone()))

style/values/specified/effects.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub type SpecifiedFilter = GenericFilter<
5353
NonNegativeFactor,
5454
ZeroToOneFactor,
5555
NonNegativeLength,
56-
Impossible,
56+
SimpleShadow,
5757
Impossible,
5858
>;
5959

style/values/specified/text.rs

+18
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,15 @@ bitflags! {
398398
/// Capitalize each word.
399399
const CAPITALIZE = 1 << 2;
400400
/// Automatic italicization of math variables.
401+
#[cfg(feature = "gecko")]
401402
const MATH_AUTO = 1 << 3;
402403

403404
/// All the case transforms, which are exclusive with each other.
405+
#[cfg(feature = "gecko")]
404406
const CASE_TRANSFORMS = Self::UPPERCASE.0 | Self::LOWERCASE.0 | Self::CAPITALIZE.0 | Self::MATH_AUTO.0;
407+
/// All the case transforms, which are exclusive with each other.
408+
#[cfg(feature = "servo")]
409+
const CASE_TRANSFORMS = Self::UPPERCASE.0 | Self::LOWERCASE.0 | Self::CAPITALIZE.0;
405410

406411
/// full-width
407412
const FULL_WIDTH = 1 << 4;
@@ -428,6 +433,19 @@ impl TextTransform {
428433
// Case bits are exclusive with each other.
429434
case.is_empty() || case.bits().is_power_of_two()
430435
}
436+
437+
/// Returns the corresponding TextTransformCase.
438+
pub fn case(&self) -> TextTransformCase {
439+
match *self & Self::CASE_TRANSFORMS {
440+
Self::NONE => TextTransformCase::None,
441+
Self::UPPERCASE => TextTransformCase::Uppercase,
442+
Self::LOWERCASE => TextTransformCase::Lowercase,
443+
Self::CAPITALIZE => TextTransformCase::Capitalize,
444+
#[cfg(feature = "gecko")]
445+
Self::MATH_AUTO => TextTransformCase::MathAuto,
446+
_ => unreachable!("Case bits are exclusive with each other"),
447+
}
448+
}
431449
}
432450

433451
/// Specified and computed value of text-align-last.

style_traits/Cargo.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,19 @@ path = "lib.rs"
1313

1414
[features]
1515
servo = ["stylo_atoms", "cssparser/serde", "url", "euclid/serde"]
16-
gecko = ["nsstring"]
16+
gecko = []
1717

1818
[dependencies]
1919
app_units = "0.7"
2020
bitflags = "2"
2121
cssparser = "0.34"
2222
euclid = "0.22"
2323
malloc_size_of = { path = "../malloc_size_of" }
24-
malloc_size_of_derive = { path = "../../../xpcom/rust/malloc_size_of_derive" }
25-
nsstring = {path = "../../../xpcom/rust/nsstring/", optional = true}
24+
malloc_size_of_derive = "0.1"
2625
selectors = { path = "../selectors" }
2726
serde = "1.0"
2827
servo_arc = { path = "../servo_arc" }
29-
stylo_atoms = { path = "../atoms", optional = true }
28+
stylo_atoms = { path = "../stylo_atoms", optional = true }
3029
thin-vec = "0.2"
3130
to_shmem = { path = "../to_shmem" }
3231
to_shmem_derive = { path = "../to_shmem_derive" }

stylo_atoms/Cargo.toml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "stylo_atoms"
3+
version = "0.1.0"
4+
authors = ["The Servo Project Developers"]
5+
documentation = "https://docs.rs/stylo_atoms/"
6+
description = "Interned string type for the Servo and Stylo projects"
7+
repository = "https://github.com/servo/stylo"
8+
license = "MPL-2.0"
9+
edition = "2018"
10+
build = "build.rs"
11+
12+
[lib]
13+
path = "lib.rs"
14+
15+
[dependencies]
16+
string_cache = "0.8"
17+
18+
[build-dependencies]
19+
string_cache_codegen = "0.5"

0 commit comments

Comments
 (0)