Bug 1437502: Introduce AuthorStyles. r?xidorn draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 12 Feb 2018 13:57:26 +0100
changeset 754808 f6d84dc14601a00c28a44db3a0015fc65fc88c40
parent 754807 1fc9ef06a1563e58ceb77342fe2ff99600add88d
child 754809 be52accb25c4a5ad62964730f12c0d6103495c73
push id99007
push userbmo:emilio@crisal.io
push dateWed, 14 Feb 2018 10:55:56 +0000
reviewersxidorn
bugs1437502
milestone60.0a1
Bug 1437502: Introduce AuthorStyles. r?xidorn It's just a struct aggregating stylesheets + CascadeData, with a quirks_mode parameter because XBL sucks so bad. MozReview-Commit-ID: 7q99tSNXo0K
layout/style/ServoBindingTypes.h
layout/style/ServoBindings.toml
servo/components/style/author_styles.rs
servo/components/style/lib.rs
--- a/layout/style/ServoBindingTypes.h
+++ b/layout/style/ServoBindingTypes.h
@@ -10,16 +10,17 @@
 #include "mozilla/RefPtr.h"
 #include "mozilla/ServoTypes.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/gfx/Types.h"
 #include "nsCSSPropertyID.h"
 #include "nsStyleAutoArray.h"
 #include "nsTArray.h"
 
+struct RawServoAuthorStyles;
 struct RawServoStyleSet;
 struct RawServoSelectorList;
 struct RawServoSourceSizeList;
 struct RawServoAnimationValueMap;
 struct RustString;
 
 #define SERVO_ARC_TYPE(name_, type_) struct type_;
 #include "mozilla/ServoArcTypeList.h"
@@ -131,16 +132,17 @@ struct MOZ_MUST_USE_TYPE ServoStyleConte
   typedef type_* type_##OwnedOrNull;               \
   DECL_NULLABLE_BORROWED_REF_TYPE_FOR(type_)       \
   DECL_NULLABLE_BORROWED_MUT_REF_TYPE_FOR(type_)
 
 // This is a reference to a reference of RawServoDeclarationBlock, which
 // corresponds to Option<&Arc<RawServoDeclarationBlock>> in Servo side.
 DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawServoDeclarationBlockStrong)
 
+DECL_OWNED_REF_TYPE_FOR(RawServoAuthorStyles)
 DECL_OWNED_REF_TYPE_FOR(RawServoStyleSet)
 DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawServoStyleSet)
 DECL_NULLABLE_OWNED_REF_TYPE_FOR(StyleChildrenIterator)
 DECL_OWNED_REF_TYPE_FOR(StyleChildrenIterator)
 DECL_OWNED_REF_TYPE_FOR(ServoElementSnapshot)
 DECL_OWNED_REF_TYPE_FOR(RawServoAnimationValueMap)
 
 // We don't use BorrowedMut because the nodes may alias
@@ -223,14 +225,15 @@ DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawS
     void operator()(type_* aPtr) const                      \
     {                                                       \
       Servo_##name_##_Drop(aPtr);                           \
     }                                                       \
   };                                                        \
   }
 
 DEFINE_BOXED_TYPE(StyleSet, RawServoStyleSet);
+DEFINE_BOXED_TYPE(AuthorStyles, RawServoAuthorStyles);
 DEFINE_BOXED_TYPE(SelectorList, RawServoSelectorList);
 DEFINE_BOXED_TYPE(SourceSizeList, RawServoSourceSizeList);
 
 #undef DEFINE_BOXED_TYPE
 
 #endif // mozilla_ServoBindingTypes_h
--- a/layout/style/ServoBindings.toml
+++ b/layout/style/ServoBindings.toml
@@ -614,16 +614,17 @@ structs-types = [
     "FontFamilyName",
     "mozilla::SharedFontList",
 ]
 array-types = [
     { cpp-type = "uintptr_t", rust-type = "usize" },
 ]
 servo-owned-types = [
     { name = "RawServoStyleSet", opaque = true },
+    { name = "RawServoAuthorStyles", opaque = true },
     { name = "RawServoSelectorList", opaque = false },
     { name = "RawServoSourceSizeList", opaque = false },
     { name = "ServoElementSnapshot", opaque = false },
     { name = "RawServoAnimationValueMap", opaque = true },
 ]
 servo-immutable-borrow-types = [
     "RawGeckoNode",
     "RawGeckoElement",
new file mode 100644
--- /dev/null
+++ b/servo/components/style/author_styles.rs
@@ -0,0 +1,38 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+//! A set of author stylesheets and their computed representation, such as the
+//! ones used for ShadowRoot and XBL.
+
+use context::QuirksMode;
+#[cfg(feature = "gecko")]
+use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
+use stylesheet_set::AuthorStylesheetSet;
+use stylesheets::StylesheetInDocument;
+use stylist::CascadeData;
+
+/// A set of author stylesheets and their computed representation, such as the
+/// ones used for ShadowRoot and XBL.
+pub struct AuthorStyles<S>
+where
+    S: StylesheetInDocument + PartialEq + 'static,
+{
+    /// The sheet collection, which holds the sheet pointers, the invalidations,
+    /// and all that stuff.
+    pub stylesheets: AuthorStylesheetSet<S>,
+    /// The actual cascade data computed from the stylesheets.
+    pub data: CascadeData,
+    /// The quirks mode of the last stylesheet flush, used because XBL sucks and
+    /// we should really fix it, see bug 1406875.
+    pub quirks_mode: QuirksMode,
+}
+
+#[cfg(feature = "gecko")]
+unsafe impl HasFFI for AuthorStyles<::gecko::data::GeckoStyleSheet> {
+    type FFIType = ::gecko_bindings::structs::RawServoAuthorStyles;
+}
+#[cfg(feature = "gecko")]
+unsafe impl HasSimpleFFI for AuthorStyles<::gecko::data::GeckoStyleSheet> {}
+#[cfg(feature = "gecko")]
+unsafe impl HasBoxFFI for AuthorStyles<::gecko::data::GeckoStyleSheet> {}
--- a/servo/components/style/lib.rs
+++ b/servo/components/style/lib.rs
@@ -82,16 +82,17 @@ extern crate void;
 
 #[macro_use]
 mod macros;
 
 #[cfg(feature = "servo")] pub mod animation;
 pub mod applicable_declarations;
 #[allow(missing_docs)] // TODO.
 #[cfg(feature = "servo")] pub mod attr;
+pub mod author_styles;
 pub mod bezier;
 pub mod bloom;
 pub mod context;
 pub mod counter_style;
 pub mod custom_properties;
 pub mod data;
 pub mod dom;
 pub mod dom_apis;