Commit graph

480 commits

Author SHA1 Message Date
Emilio Cobos Álvarez
67f9b97735 style: Unify font-family storage
This changes font-family storage to reuse the rust types, removing a
bunch of code while at it. This allows us to, for example, use a single
static font family for -moz-bullet and clone it, rather than creating a
lot of expensive copies.

Differential Revision: https://phabricator.services.mozilla.com/D118011
2023-05-24 18:32:35 +02:00
Emilio Cobos Álvarez
b8d46406f6 style: Inline nsTArray::deref.
This shaves >50ms if the compiler decides not to inline it, compilers are
sometimes dumb.

Depends on D100593

Differential Revision: https://phabricator.services.mozilla.com/D100594
2021-02-26 16:44:05 +01:00
Emilio Cobos Álvarez
8f215a8444
style: Port the style crate to rust 2018.
Differential Revision: https://phabricator.services.mozilla.com/D80101
2020-06-18 23:51:15 +02:00
Emilio Cobos Álvarez
762abbaf9f
style: Rustfmt recent changes. 2020-06-04 02:02:50 +02:00
Simon Giesecke
e6687c5fa8 style: Improve handling of copying arrays in layout/style/ and servo/.
Differential Revision: https://phabricator.services.mozilla.com/D72351
2020-06-04 01:50:36 +02:00
Simon Giesecke
735fdedbe9 style: Make NotNull move its member pointer where possible.
Differential Revision: https://phabricator.services.mozilla.com/D72827
2020-06-04 01:50:36 +02:00
Emilio Cobos Álvarez
69bf0e40a6
style: Remove unused FFI function to refcount nsIReferrerInfo.
We don't use RefPtr<nsIReferrerInfo> in rust.

Differential Revision: https://phabricator.services.mozilla.com/D58274
2020-02-12 02:43:08 +01:00
Emilio Cobos Álvarez
80ac4d2ff2 style: Avoid writing into the empty array header.
Differential Revision: https://phabricator.services.mozilla.com/D55291
2019-12-16 14:23:56 +01:00
Thomas Nguyen
59cf10d1b0
style: Modify URLExtraData rust debug to include referrerInfo.
Differential Revision: https://phabricator.services.mozilla.com/D36475
2019-07-23 22:54:06 +02:00
Emilio Cobos Álvarez
31b166fb1b
style: Remove nsStyleCoord.
And move the useful bits of it somewhere else (ServoStyleConstInlines.h for the
inline function definitions, and nsFrame.cpp for the static assertions).

Differential Revision: https://phabricator.services.mozilla.com/D36120
2019-07-08 12:45:36 +02:00
Emilio Cobos Álvarez
6cb588d2b5
style: Use Servo for the representation of grid template areas.
Right now we do a lot of useless string copying. In order to avoid transcoding
to utf-16 during layout, make sure to use nsCString at a few related places.

I may revisit this since we're storing other line names as atoms in some places.
So it may be better to just use atoms everywhere.

But that'd be a different patch either way.

Differential Revision: https://phabricator.services.mozilla.com/D35117
2019-06-25 13:11:30 +02:00
Emilio Cobos Álvarez
ccff9b294f style: Use cbindgen for URIs.
This doesn't clean up as much as a whole, but it's a step in the right
direction. In particular, it allows us to start using simple bindings for:

 * Filters
 * Shapes and images, almost. Need to:
   * Get rid of the complex -moz- gradient parsing (let
     layout.css.simple-moz-gradient.enabled get to release).
 * Counters, almost. Need to:
   * Share the Attr representation with Gecko, by not using Option<>.
     * Just another variant should be enough (ContentItem::{Attr,Prefixedattr},
       maybe).

Which in turn allows us to remove a whole lot of bindings in followups to this.

The setup changes a bit. This also removes the double pointer I complained about
while reviewing the shared UA sheet patches. The old setup is:

```
SpecifiedUrl
 * CssUrl
   * Arc<CssUrlData>
     * String
     * UrlExtraData
 * UrlValueSource
   * Arc<CssUrlData>
   * load id
   * resolved uri
   * CORS mode.
   * ...
```

The new one removes the double reference to the url data via URLValue, and looks
like:

```
SpecifiedUrl
 * CssUrl
   * Arc<CssUrlData>
     * String
     * UrlExtraData
     * CorsMode
     * LoadData
       * load id
       * resolved URI
```

The LoadData is the only mutable bit that C++ can change, and is not used from
Rust. Ideally, in the future, we could just use rust-url to resolve the URL
after parsing or something, and make it all immutable. Maybe.

I've verified that this approach still works with the UA sheet patches (via the
LoadDataSource::Lazy).

The reordering of mWillChange is to avoid nsStyleDisplay from going over the
size limit. We want to split it up anyway in bug 1552587, but mBinding gains a
tag member, which means that we were having a bit of extra padding.

One thing I want to explore is to see if we can abuse rustc's non-zero
optimizations to predict the layout from C++, but that's something to explore at
some other point in time and with a lot of care and help from Michael (who sits
next to me and works on rustc ;)).

Differential Revision: https://phabricator.services.mozilla.com/D31742
2019-06-04 01:03:50 -04:00
Emilio Cobos Álvarez
57998eacc5 style: Remove nsCSSValue bindings.
Depends on D31320

Differential Revision: https://phabricator.services.mozilla.com/D31321
2019-05-29 16:14:14 +02:00
Emilio Cobos Álvarez
3034d66eef style: Use cbindgen to back CSS transforms.
This avoids the expensive conversion, and cleans up a bunch.

Further cleanup is possible, just not done yet to avoid growing the patch even
more.

Differential Revision: https://phabricator.services.mozilla.com/D30748
2019-05-29 16:14:12 +02:00
Emilio Cobos Álvarez
5f6c8d9060 style: Add bindings for box shadows, and remove nsCSSShadowArray and friends.
Differential Revision: https://phabricator.services.mozilla.com/D30547
2019-05-29 16:14:11 +02:00
Emilio Cobos Álvarez
53ccbc5751 style: Use the rust color representation.
Differential Revision: https://phabricator.services.mozilla.com/D25976
2019-04-12 12:19:59 +02:00
Emilio Cobos Álvarez
691eb36ffe style: Expose colors via cbindgen.
Also s/Foreground/CurrentColor.

Differential Revision: https://phabricator.services.mozilla.com/D25975
2019-04-12 12:19:59 +02:00
Emilio Cobos Álvarez
2f8e05e9e0 style: Autogenerate Servo_ binding functions with cbindgen.
This depends on https://github.com/eqrion/cbindgen/pull/308. Other than that,
this should be ready to go.

There's still a bit more magic than what I'd like to eventually. I should be
able to make cbindgen not rename types if it doesn't know about them, or
something.

But this removes most of the manual binding function implementations (all but
the ones that are declared via macros, which cbindgen doesn't see across).

I need to give up on the _Drop functions taking an Owned<T> because of
instantiation order fiasco. In order to define DefaultDelete I need Owned to be
complete, but I cannot do it after including the generated file since some
declarations already instantiate the specialization. Oh well.

Differential Revision: https://phabricator.services.mozilla.com/D24798
2019-04-12 12:19:54 +02:00
Emilio Cobos Álvarez
f637d93fc1 style: Remove bindings.rs.
I kept it building the most straight-forward way possible (pub use) because it
seems to me that bindings is not a bad name, and we should probably move
structs.rs to be bindings.rs rather than the other way around.

But that's a different bug in any case, need to think more about it.

Differential Revision: https://phabricator.services.mozilla.com/D24713
2019-03-27 14:29:27 +01:00
Emilio Cobos Álvarez
ecda72a5fd style: Cleanup refcounted types.
And make the handling of ComputedStyle more similar to these.

Differential Revision: https://phabricator.services.mozilla.com/D24703
2019-03-27 14:29:26 +01:00
Emilio Cobos Álvarez
02bc29a11b style: Simplify Owned FFI types.
And make them actually sound. We're defining functions on Rust-land that get
structs as arguments, but declaring them in C++ as getting pointers.

This is another step in order to be able to autogenerate ServoBindings.h and
remove bindings.rs altogether.

We remove FooOwned in favor of Owned<Foo>, which is generated via cbindgen.

It'd be good to actually mark Owned and such as MOZ_MUST_USE_TYPE, so I sent
https://github.com/eqrion/cbindgen/pull/307 for that.

Differential Revision: https://phabricator.services.mozilla.com/D24681
2019-03-27 14:29:25 +01:00
Emilio Cobos Álvarez
14b176019c style: Simplify a bit our generated bindings by getting rid of FooBorrowed and FooBorrowedMut.
This reduces a lot the boilerplate that's needed in order to add simple binding
functions.

This starts using &Foo and Option<&Foo> instead, and as a result we need to
remove the servo_function_signatures test, which is a bit unfortunate.

I think it's worth though, this causes problems on some platforms (see bug
1534844), and messing up the functions signature is not something that I've ever
seen (other than bug 1308234, which already had all the FooBorrowed mess which
I'm removing).

Also, cbindgen understands references and Option<&Foo>, so it will be the way to
go in the future.

After this patch we can also remove HasSimpleFFI, but I've kept it for now since
I still use it in a few places, and this patch is quite big on its own.

Differential Revision: https://phabricator.services.mozilla.com/D24092
2019-03-27 14:29:19 +01:00
Emilio Cobos Álvarez
5aeab7adb1 style: Reformat recent changes. 2019-03-13 15:08:38 +01:00
Emilio Cobos Álvarez
7d01114cbf style: Add a Zero trait that doesn't require Add, and use it in place of num_traits and IsZeroLength.
Use it to be consistent in InsetRect serialization and storage between Servo and
Gecko.

Differential Revision: https://phabricator.services.mozilla.com/D21493
2019-03-13 15:08:14 +01:00
Emilio Cobos Álvarez
197065f6bc style: Use rust lengths for border corners.
The test in https://github.com/web-platform-tests/wpt/pull/15423 hasn't been
synced over yet, but it passes with this patch of course.

Differential Revision: https://phabricator.services.mozilla.com/D20960
2019-03-13 15:08:12 +01:00
Emilio Cobos Álvarez
be616c31e8 style: Rustfmt recent changes. 2019-02-23 21:05:32 -08:00
Emilio Cobos Álvarez
73d5b82f9f style: Improve #[derive(Parse)].
I want to do this so that I can get rid of Either<>. The reasons for getting rid
of either are multiple:

 * It doesn't generate as nice C++ code using cbindgen.
 * It isn't that nice to use either from Rust.
 * cbindgen has bugs with zero-sized types.

I started using this for ColorOrAuto and a few others, for now.

Differential Revision: https://phabricator.services.mozilla.com/D19844
2019-02-23 21:04:44 -08:00
Emilio Cobos Álvarez
05881b5ab4 style: Represent the percentage in LengthPercentage with something other than an option.
Not the prettiest, but it will work, and LengthPercentage will be 12 bytes which
is pretty good (we could do better if wanted I guess):

  * Au(i32) length;
  * f32 percentage;
  * AllowedNumericType(u8) clamping_mode;
  * bool has_percentage;
  * bool was_calc;

This will allow me to start moving C++ stuff to use this representation.

Differential Revision: https://phabricator.services.mozilla.com/D16929
2019-01-20 14:33:12 +01:00
Emilio Cobos Álvarez
2a6cdaa30a Rustfmt recent changes. 2019-01-08 12:01:28 +01:00
Emilio Cobos Álvarez
80651fde47 style: Manually rename some variables.
lop is not an acceptable variable name for LengthPercentage.

Differential Revision: https://phabricator.services.mozilla.com/D15813
2019-01-08 12:00:48 +01:00
Emilio Cobos Álvarez
daf1f02feb style: Rename LengthOrPercentage to LengthPercentage.
It does not represent `<length> | <percentage>`, but `<length-percentage>`, so
`LengthOrPercentage` is not the right name.

This patch is totally autogenerated using:

rg 'LengthOrPercentage' servo | cut -d : -f 1 | sort | uniq > files
for file in $(cat files); do sed -i "s#LengthOrPercentage#LengthPercentage#g" $file; done

Differential Revision: https://phabricator.services.mozilla.com/D15812
2019-01-08 12:00:48 +01:00
Emilio Cobos Álvarez
ca503b4908 style: Simplify computed::LengthOrPercentage and friends.
This is a first step to share LengthOrPercentage representation between Rust and
Gecko.

We need to preserve whether the value came from a calc() expression, for now at
least, since we do different things depending on whether we're calc or not right
now. See https://github.com/w3c/csswg-drafts/issues/3482 and dependent bugs for
example.

That means that the gecko conversion code needs to handle calc() in a bit of an
awkward way until I change it to not be needed (patches for that incoming in the
next few weeks I hope).

I need to add a hack to exclude other things from the PartialEq implementation
because the new conversion code is less lossy than the old one, and we relied on
the lousiness in AnimationValue comparison (in order to start transitions and
such, in [1] for example).

I expect to remove that manual PartialEq implementation as soon as I'm done with
the conversion.

The less lossy conversion does fix a few serialization bugs for animation values
though, like not loosing 0% values in calc() when interpolating lengths and
percentages, see the two modified tests:

 * property-types.js
 * test_animation_properties.html

Differential Revision: https://phabricator.services.mozilla.com/D15793
2019-01-07 17:05:40 +01:00
Emilio Cobos Álvarez
5f173c463e style: Rustfmt recent changes. 2019-01-07 00:32:54 +01:00
Emilio Cobos Álvarez
8929087d83 style: Update the Rust target version for bindgen.
This brings us alignas support and also associated constants for bitfield enums.

Differential Revision: https://phabricator.services.mozilla.com/D15334
2019-01-07 00:32:50 +01:00
Simon Sapin
be69f9c3e6 Rustfmt has changed its default style :/ 2018-12-28 13:17:47 +01:00
Jan Andre Ikenmeyer
1d6fe65401
Update MPL license to https (part 4) 2018-11-19 14:47:27 +01:00
Emilio Cobos Álvarez
bd9c53c5da
style: Manually extinguish multi-line use statements. 2018-11-10 21:42:24 +01:00
Simon Sapin
b1822a39fa cargo fix --edition --features gecko 2018-11-10 17:47:28 +01:00
Emilio Cobos Álvarez
175e594652
style: Format recent patches. 2018-11-08 15:22:29 +01:00
Cameron McCormack
de5584c1f6
style: Store the Rust QuotePair slice as the computed quotes value in Gecko style structs.
Depends on D10651

Differential Revision: https://phabricator.services.mozilla.com/D10652
2018-11-08 15:22:26 +01:00
Pyfisch
9e92eb205a Reorder imports 2018-11-06 22:35:07 +01:00
Pyfisch
cb07debcb6 Format remaining files 2018-11-06 22:30:31 +01:00
Boris Chiou
3723042937
style: Generate StyleTimingFunction and drop ns_timing_function.rs.
First, we generate StyleComputedTimingFunction by cbindgen from Rust, and use
it in nsTimingFunction, so we could copy it directly without handling
the different memory layout. However, we have to rewrite the
nsTimingFunction and mozilla::ComputedTimingFunction for this.

Second, the rust-bindgen seems cannot generate the correct generic members
from complex C++ templates, especially for the nested template struct,
(https://github.com/rust-lang-nursery/rust-bindgen/issues/1429)
So we have to hide StyleTimingFunction to avoid the compilation errors.

Differential Revision: https://phabricator.services.mozilla.com/D9313
2018-10-28 23:44:51 +01:00
Boris Chiou
2bbcb5c633
style: Replace u32 with computed::Integer for computed::TimingFunction.
We make sure the step number is always positive, so using
computed::Integer is safe and can derive ToComputedValue.

Depends on D9311

Differential Revision: https://phabricator.services.mozilla.com/D9845
2018-10-28 23:44:42 +01:00
Boris Chiou
a20b6a5166
style: Split TimingFunction into a separate file to match spec.
TimingFunction is defined in a separate spec (i.e. css-easing), instead
of transform, so we move it into a different file.

Depends on D9310

Differential Revision: https://phabricator.services.mozilla.com/D9311
2018-10-28 23:44:26 +01:00
Boris Chiou
3a536f463c
style: Drop frames() timing function.
frames() timing function was removed from the spec, so we drop it.
Besides, some devtool tests are removed because they use frame(). I will
add them back by using new step function later.

Differential Revision: https://phabricator.services.mozilla.com/D9309
2018-10-28 23:44:16 +01:00
Cameron McCormack
4e174ace3b
style: Use helper function to set length and copy into nsTArrays of PODs from Rust.
Differential Revision: https://phabricator.services.mozilla.com/D8058
2018-10-19 00:37:08 +02:00
Emilio Cobos Álvarez
42def5a011
style: Always compute angle values to degrees.
This matches the spec, https://drafts.csswg.org/css-values/#angles, which says:

> All <angle> units are compatible, and deg is their canonical unit.

And https://drafts.csswg.org/css-values/#compat, which says:

>When serializing computed values [...], compatible units [...] are converted into a single canonical unit.

And also other implementations (Blink always serializes angles as degrees in
computed style for example).

Also allows us to get rid of quite a bit of code, and makes computed angle value
representation just a number, which is nice.

Differential Revision: https://phabricator.services.mozilla.com/D8619
2018-10-19 00:35:22 +02:00
Emilio Cobos Álvarez
11fedf18d9
style: Some more nsCSSValue cleanup.
I had this around, I couldn't work on more stuff today, but I may as well land
this.

Differential Revision: https://phabricator.services.mozilla.com/D8277
2018-10-19 00:35:15 +02:00
Cameron McCormack
9865a4194c
style: Merge css::{URLValueData, ImageValue} into css::URLValue.
Differential Revision: https://phabricator.services.mozilla.com/D8061
2018-10-19 00:34:27 +02:00