aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/values/generics/url.rs
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2019-05-27 11:45:12 +0000
committerEmilio Cobos Álvarez <emilio@crisal.io>2019-06-04 01:03:50 -0400
commitccff9b294f17ff4214e1c488817d48a10c95c2f9 (patch)
tree617969460e4242c5fe930f70b846739aa6e0756b /components/style/values/generics/url.rs
parent8a0cf600d6cc426ad95ba05d435c5d2ffb4c14b7 (diff)
downloadservo-ccff9b294f17ff4214e1c488817d48a10c95c2f9.tar.gz
servo-ccff9b294f17ff4214e1c488817d48a10c95c2f9.zip
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
Diffstat (limited to 'components/style/values/generics/url.rs')
-rw-r--r--components/style/values/generics/url.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/components/style/values/generics/url.rs b/components/style/values/generics/url.rs
index 9dbed038630..1f271033036 100644
--- a/components/style/values/generics/url.rs
+++ b/components/style/values/generics/url.rs
@@ -5,6 +5,8 @@
//! Generic types for url properties.
/// An image url or none, used for example in list-style-image
+///
+/// cbindgen:derive-tagged-enum-copy-constructor=true
#[derive(
Animate,
Clone,
@@ -21,16 +23,27 @@
ToResolvedValue,
ToShmem,
)]
-pub enum UrlOrNone<Url> {
+#[repr(C, u8)]
+pub enum GenericUrlOrNone<U> {
/// `none`
None,
- /// `A URL`
- Url(Url),
+ /// A URL.
+ Url(U),
}
+pub use self::GenericUrlOrNone as UrlOrNone;
+
impl<Url> UrlOrNone<Url> {
/// Initial "none" value for properties such as `list-style-image`
pub fn none() -> Self {
UrlOrNone::None
}
+
+ /// Returns whether the value is `none`.
+ pub fn is_none(&self) -> bool {
+ match *self {
+ UrlOrNone::None => true,
+ UrlOrNone::Url(..) => false,
+ }
+ }
}