From b2e592b12185db07fb685a0b352c766c45308595 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 22 Sep 2016 16:14:19 +0530 Subject: [PATCH] Move most of geckolib into style::gecko --- components/servo/Cargo.lock | 2 + components/style/Cargo.toml | 6 +- components/style/binding_tools/regen.py | 9 +- components/style/binding_tools/regen_atoms.py | 5 +- .../style/gecko}/context.rs | 2 +- components/style/gecko/conversions.rs | 2 +- .../style/gecko}/data.rs | 22 ++--- .../generated/gecko_pseudo_element_helper.rs | 0 components/style/gecko/mod.rs | 15 +++ components/style/gecko/selector_impl.rs | 6 +- .../style/gecko}/snapshot.rs | 19 ++-- .../style/gecko}/snapshot_helpers.rs | 4 +- .../style/gecko}/traversal.rs | 12 +-- .../style/gecko}/wrapper.rs | 95 +++++++++++-------- components/style/gecko_bindings/bindings.rs | 8 +- .../sugar/ns_css_shadow_array.rs | 2 +- .../sugar/ns_style_auto_array.rs | 2 +- .../gecko_bindings/sugar/ns_style_coord.rs | 6 +- .../style/gecko_bindings/sugar/ns_t_array.rs | 2 +- components/style/gecko_string_cache/mod.rs | 16 +--- .../style/gecko_string_cache/namespace.rs | 2 +- components/style/lib.rs | 4 +- ports/cef/Cargo.lock | 2 + ports/geckolib/Cargo.lock | 2 +- ports/geckolib/glue.rs | 61 +++++------- ports/geckolib/lib.rs | 10 -- servo-tidy.toml | 8 +- 27 files changed, 167 insertions(+), 157 deletions(-) rename {ports/geckolib => components/style/gecko}/context.rs (95%) rename {ports/geckolib => components/style/gecko}/data.rs (88%) rename components/style/{ => gecko}/generated/gecko_pseudo_element_helper.rs (100%) create mode 100644 components/style/gecko/mod.rs rename {ports/geckolib => components/style/gecko}/snapshot.rs (93%) rename {ports/geckolib => components/style/gecko}/snapshot_helpers.rs (95%) rename {ports/geckolib => components/style/gecko}/traversal.rs (84%) rename {ports/geckolib => components/style/gecko}/wrapper.rs (87%) diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 1df39d66bad..5f9116d9ee3 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -2272,6 +2272,7 @@ version = "0.0.1" dependencies = [ "app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2286,6 +2287,7 @@ dependencies = [ "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "ordered-float 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "quickersort 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml index a3f5d65a4e9..0197d29df0a 100644 --- a/components/style/Cargo.toml +++ b/components/style/Cargo.toml @@ -13,7 +13,7 @@ path = "lib.rs" [features] gecko = [] -servo = ["serde/unstable", "serde_macros", "heapsize_plugin", +servo = ["serde/unstable", "serde", "serde_macros", "heapsize_plugin", "style_traits/servo", "app_units/plugins", "cssparser/heap_size", "cssparser/serde-serialization", "selectors/heap_size", "selectors/unstable", "string_cache", @@ -33,15 +33,17 @@ heapsize = "0.3.0" heapsize_plugin = {version = "0.1.2", optional = true} lazy_static = "0.2" log = "0.3.5" +libc = "0.2" matches = "0.1" num-integer = "0.1.32" num-traits = "0.1.32" +num_cpus = "0.2.2" ordered-float = "0.2.2" quickersort = "2.0.0" rand = "0.3" rustc-serialize = "0.3" selectors = "0.13" -serde = "0.8" +serde = {version = "0.8", optional = true} serde_macros = {version = "0.8", optional = true} smallvec = "0.1" string_cache = {version = "0.2.26", features = ["heap_size"], optional = true} diff --git a/components/style/binding_tools/regen.py b/components/style/binding_tools/regen.py index aff7a8cfeb3..3ff6e2c9396 100755 --- a/components/style/binding_tools/regen.py +++ b/components/style/binding_tools/regen.py @@ -432,11 +432,13 @@ def build(objdir, target_name, debug, debugger, kind_name=None, flags.append("--blacklist-type") flags.append("{}Strong".format(ty)) flags.append("--raw-line") - flags.append("pub type {0}Strong = ::gecko_bindings::sugar::ownership::Strong<{0}>;".format(ty)) + flags.append("pub type {0}Strong = ::gecko_bindings::sugar::ownership::Strong<{0}>;" + .format(ty)) flags.append("--blacklist-type") flags.append("{}BorrowedOrNull".format(ty)) flags.append("--raw-line") - flags.append("pub type {0}BorrowedOrNull<'a> = ::gecko_bindings::sugar::ownership::Borrowed<'a, {0}>;".format(ty)) + flags.append("pub type {0}BorrowedOrNull<'a> = \ + ::gecko_bindings::sugar::ownership::Borrowed<'a, {0}>;".format(ty)) flags.append("--blacklist-type") flags.append("{}Borrowed".format(ty)) flags.append("--raw-line") @@ -452,7 +454,8 @@ def build(objdir, target_name, debug, debugger, kind_name=None, flags.append("--blacklist-type") flags.append("{}BorrowedOrNull".format(ty)) flags.append("--raw-line") - flags.append("pub type {0}BorrowedOrNull<'a> = ::gecko_bindings::sugar::ownership::Borrowed<'a, {0}>;".format(ty)) + flags.append("pub type {0}BorrowedOrNull<'a> = \ + ::gecko_bindings::sugar::ownership::Borrowed<'a, {0}>;".format(ty)) # Right now the only immutable borrow types are ones which we import # from the |structs| module. As such, we don't need to create an opaque # type with zero_size_type. If we ever introduce immutable borrow types diff --git a/components/style/binding_tools/regen_atoms.py b/components/style/binding_tools/regen_atoms.py index 1b796ff66b2..260d2e1903f 100755 --- a/components/style/binding_tools/regen_atoms.py +++ b/components/style/binding_tools/regen_atoms.py @@ -138,7 +138,8 @@ def write_atom_macro(atoms, file_name): f.write("}\n\n") f.write("#[macro_export]\n") f.write("macro_rules! atom {\n") - f.writelines(['("%s") => { $crate::string_cache::atom_macro::unsafe_atom_from_static($crate::string_cache::atom_macro::%s as *mut _) };\n' + f.writelines(['("%s") => { $crate::string_cache::atom_macro::unsafe_atom_from_static(\ + $crate::string_cache::atom_macro::%s as *mut _) };\n' % (atom.value, atom.ident) for atom in atoms]) f.write("}\n") @@ -192,5 +193,5 @@ def write_pseudo_element_helper(atoms, target_filename): def build(objdir, verbose=False): atoms = collect_atoms(objdir) write_atom_macro(atoms, "../gecko_string_cache/atom_macro.rs") - write_pseudo_element_helper(atoms, "../generated/gecko_pseudo_element_helper.rs") + write_pseudo_element_helper(atoms, "../gecko/generated/gecko_pseudo_element_helper.rs") return 0 diff --git a/ports/geckolib/context.rs b/components/style/gecko/context.rs similarity index 95% rename from ports/geckolib/context.rs rename to components/style/gecko/context.rs index a5385f0fee1..068b81560d8 100644 --- a/ports/geckolib/context.rs +++ b/components/style/gecko/context.rs @@ -2,9 +2,9 @@ * 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/. */ +use context::{LocalStyleContext, StyleContext, SharedStyleContext}; use std::cell::RefCell; use std::rc::Rc; -use style::context::{LocalStyleContext, StyleContext, SharedStyleContext}; thread_local!(static LOCAL_CONTEXT_KEY: RefCell>> = RefCell::new(None)); diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs index f70926bda00..999ca1071ca 100644 --- a/components/style/gecko/conversions.rs +++ b/components/style/gecko/conversions.rs @@ -107,12 +107,12 @@ impl From for LengthOrPercentage { pub mod basic_shape { use euclid::size::Size2D; + use gecko::values::GeckoStyleCoordConvertible; use gecko_bindings::structs; use gecko_bindings::structs::{StyleBasicShape, StyleBasicShapeType, StyleFillRule}; use gecko_bindings::structs::{nsStyleCoord, nsStyleCorners}; use gecko_bindings::structs::StyleClipPathGeometryBox; use gecko_bindings::sugar::ns_style_coord::{CoordDataMut, CoordDataValue}; - use gecko::values::GeckoStyleCoordConvertible; use std::borrow::Borrow; use values::computed::{BorderRadiusSize, LengthOrPercentage}; use values::computed::basic_shape::*; diff --git a/ports/geckolib/data.rs b/components/style/gecko/data.rs similarity index 88% rename from ports/geckolib/data.rs rename to components/style/gecko/data.rs index 369f2f50a12..53aa82d350e 100644 --- a/ports/geckolib/data.rs +++ b/components/style/gecko/data.rs @@ -2,25 +2,25 @@ * 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/. */ +use animation::Animation; +use context::SharedStyleContext; +use dom::OpaqueNode; use euclid::size::TypedSize2D; -use style::gecko_bindings::bindings::RawServoStyleSet; -use style::gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI}; +use gecko_bindings::bindings::RawServoStyleSet; +use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI}; +use media_queries::{Device, MediaType}; use num_cpus; +use parallel::WorkQueueData; +use selector_matching::Stylist; use std::cmp; use std::collections::HashMap; use std::env; use std::sync::{Arc, RwLock}; use std::sync::mpsc::{Receiver, Sender, channel}; -use style::animation::Animation; -use style::context::SharedStyleContext; -use style::dom::OpaqueNode; -use style::media_queries::{Device, MediaType}; -use style::parallel::WorkQueueData; -use style::selector_matching::Stylist; -use style::stylesheets::Stylesheet; -use style::thread_state; -use style::workqueue::WorkQueue; use style_traits::ViewportPx; +use stylesheets::Stylesheet; +use thread_state; +use workqueue::WorkQueue; pub struct PerDocumentStyleData { /// Rule processor. diff --git a/components/style/generated/gecko_pseudo_element_helper.rs b/components/style/gecko/generated/gecko_pseudo_element_helper.rs similarity index 100% rename from components/style/generated/gecko_pseudo_element_helper.rs rename to components/style/gecko/generated/gecko_pseudo_element_helper.rs diff --git a/components/style/gecko/mod.rs b/components/style/gecko/mod.rs new file mode 100644 index 00000000000..7153a7e3da2 --- /dev/null +++ b/components/style/gecko/mod.rs @@ -0,0 +1,15 @@ +/* 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/. */ + + +pub mod context; +pub mod data; +pub mod snapshot; +pub mod snapshot_helpers; +pub mod traversal; +pub mod wrapper; + +pub mod conversions; +pub mod selector_impl; +pub mod values; diff --git a/components/style/gecko/selector_impl.rs b/components/style/gecko/selector_impl.rs index 7af0844d85a..e1dbffbdc19 100644 --- a/components/style/gecko/selector_impl.rs +++ b/components/style/gecko/selector_impl.rs @@ -70,7 +70,7 @@ impl PseudoElement { }} } - include!("../generated/gecko_pseudo_element_helper.rs"); + include!("generated/gecko_pseudo_element_helper.rs"); None } @@ -88,7 +88,7 @@ impl PseudoElement { }} } - include!("../generated/gecko_pseudo_element_helper.rs"); + include!("generated/gecko_pseudo_element_helper.rs"); None } @@ -238,7 +238,7 @@ impl GeckoSelectorImpl { }} } - include!("../generated/gecko_pseudo_element_helper.rs") + include!("generated/gecko_pseudo_element_helper.rs") } #[inline] diff --git a/ports/geckolib/snapshot.rs b/components/style/gecko/snapshot.rs similarity index 93% rename from ports/geckolib/snapshot.rs rename to components/style/gecko/snapshot.rs index 8ab3ee7a45d..f50f7c7edcc 100644 --- a/ports/geckolib/snapshot.rs +++ b/components/style/gecko/snapshot.rs @@ -1,16 +1,17 @@ /* 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/. */ -use style::gecko_bindings::bindings; -use style::gecko_bindings::structs::ServoElementSnapshot; -use style::gecko_bindings::structs::ServoElementSnapshotFlags as Flags; -use style::string_cache::Atom; + +use element_state::ElementState; +use gecko::snapshot_helpers; +use gecko::wrapper::AttrSelectorHelpers; +use gecko_bindings::bindings; +use gecko_bindings::structs::ServoElementSnapshot; +use gecko_bindings::structs::ServoElementSnapshotFlags as Flags; +use restyle_hints::ElementSnapshot; +use selector_impl::TheSelectorImpl; use selectors::parser::AttrSelector; -use snapshot_helpers; -use style::element_state::ElementState; -use style::restyle_hints::ElementSnapshot; -use style::selector_impl::TheSelectorImpl; -use wrapper::AttrSelectorHelpers; +use string_cache::Atom; // NB: This is sound, in some sense, because during computation of restyle hints // the snapshot is kept alive by the modified elements table. diff --git a/ports/geckolib/snapshot_helpers.rs b/components/style/gecko/snapshot_helpers.rs similarity index 95% rename from ports/geckolib/snapshot_helpers.rs rename to components/style/gecko/snapshot_helpers.rs index 72b44822584..ee7fdd14421 100644 --- a/ports/geckolib/snapshot_helpers.rs +++ b/components/style/gecko/snapshot_helpers.rs @@ -4,9 +4,9 @@ //! Element an snapshot common logic. -use style::gecko_bindings::structs::nsIAtom; -use style::string_cache::Atom; +use gecko_bindings::structs::nsIAtom; use std::{ptr, slice}; +use string_cache::Atom; pub type ClassOrClassList = unsafe extern fn (T, *mut *mut nsIAtom, *mut *mut *mut nsIAtom) -> u32; diff --git a/ports/geckolib/traversal.rs b/components/style/gecko/traversal.rs similarity index 84% rename from ports/geckolib/traversal.rs rename to components/style/gecko/traversal.rs index b342b8bd2a5..2fffa043499 100644 --- a/ports/geckolib/traversal.rs +++ b/components/style/gecko/traversal.rs @@ -2,13 +2,13 @@ * 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/. */ -use context::StandaloneStyleContext; +use context::{LocalStyleContext, SharedStyleContext, StyleContext}; +use dom::OpaqueNode; +use gecko::context::StandaloneStyleContext; +use gecko::wrapper::GeckoNode; use std::mem; -use style::context::{LocalStyleContext, SharedStyleContext, StyleContext}; -use style::dom::OpaqueNode; -use style::traversal::{DomTraversalContext, recalc_style_at}; -use style::traversal::RestyleResult; -use wrapper::GeckoNode; +use traversal::{DomTraversalContext, recalc_style_at}; +use traversal::RestyleResult; pub struct RecalcStyleOnly<'lc> { context: StandaloneStyleContext<'lc>, diff --git a/ports/geckolib/wrapper.rs b/components/style/gecko/wrapper.rs similarity index 87% rename from ports/geckolib/wrapper.rs rename to components/style/gecko/wrapper.rs index 8a4030a43cd..e2db71fecc7 100644 --- a/ports/geckolib/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -4,51 +4,52 @@ #![allow(unsafe_code)] -use style::gecko_bindings::bindings; -use style::gecko_bindings::bindings::{Gecko_CalcStyleDifference, Gecko_StoreStyleDifference}; -use style::gecko_bindings::bindings::{Gecko_DropStyleChildrenIterator, Gecko_MaybeCreateStyleChildrenIterator}; -use style::gecko_bindings::bindings::{Gecko_ElementState, Gecko_GetDocumentElement}; -use style::gecko_bindings::bindings::{Gecko_GetFirstChild, Gecko_GetFirstChildElement}; -use style::gecko_bindings::bindings::{Gecko_GetLastChild, Gecko_GetLastChildElement}; -use style::gecko_bindings::bindings::{Gecko_GetNextSibling, Gecko_GetNextSiblingElement, Gecko_GetNextStyleChild}; -use style::gecko_bindings::bindings::{Gecko_GetNodeFlags, Gecko_SetNodeFlags, Gecko_UnsetNodeFlags}; -use style::gecko_bindings::bindings::{Gecko_GetParentElement, Gecko_GetParentNode}; -use style::gecko_bindings::bindings::{Gecko_GetPrevSibling, Gecko_GetPrevSiblingElement}; -use style::gecko_bindings::bindings::{Gecko_GetServoDeclarationBlock, Gecko_IsHTMLElementInHTMLDocument}; -use style::gecko_bindings::bindings::{Gecko_IsLink, Gecko_IsRootElement, Gecko_IsTextNode}; -use style::gecko_bindings::bindings::{Gecko_IsUnvisitedLink, Gecko_IsVisitedLink}; -use style::gecko_bindings::bindings::{Gecko_LocalName, Gecko_Namespace, Gecko_NodeIsElement}; -use style::gecko_bindings::bindings::Gecko_ClassOrClassList; -use style::gecko_bindings::bindings::Gecko_GetStyleContext; -use style::gecko_bindings::structs::{NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO, NODE_IS_DIRTY_FOR_SERVO}; -use style::gecko_bindings::structs::{RawGeckoDocument, RawGeckoElement, RawGeckoNode}; -use style::gecko_bindings::structs::{nsChangeHint, nsIAtom, nsStyleContext}; -use style::gecko_bindings::structs::OpaqueStyleData; -use style::gecko_bindings::sugar::ownership::FFIArcHelpers; -use style::gecko_string_cache::{Atom, Namespace, WeakAtom, WeakNamespace}; -use glue::GeckoDeclarationBlock; + +use data::PrivateStyleData; +use dom::{LayoutIterator, NodeInfo, TDocument, TElement, TNode, TRestyleDamage, UnsafeNode}; +use dom::{OpaqueNode, PresentationalHintsSynthetizer}; +use element_state::ElementState; +use error_reporting::StdoutErrorReporter; +use gecko::selector_impl::{GeckoSelectorImpl, NonTSPseudoClass, PseudoElement}; +use gecko::snapshot::GeckoElementSnapshot; +use gecko::snapshot_helpers; +use gecko_bindings::bindings; +use gecko_bindings::bindings::{Gecko_CalcStyleDifference, Gecko_StoreStyleDifference}; +use gecko_bindings::bindings::{Gecko_DropStyleChildrenIterator, Gecko_MaybeCreateStyleChildrenIterator}; +use gecko_bindings::bindings::{Gecko_ElementState, Gecko_GetDocumentElement}; +use gecko_bindings::bindings::{Gecko_GetFirstChild, Gecko_GetFirstChildElement}; +use gecko_bindings::bindings::{Gecko_GetLastChild, Gecko_GetLastChildElement}; +use gecko_bindings::bindings::{Gecko_GetNextSibling, Gecko_GetNextSiblingElement, Gecko_GetNextStyleChild}; +use gecko_bindings::bindings::{Gecko_GetNodeFlags, Gecko_SetNodeFlags, Gecko_UnsetNodeFlags}; +use gecko_bindings::bindings::{Gecko_GetParentElement, Gecko_GetParentNode}; +use gecko_bindings::bindings::{Gecko_GetPrevSibling, Gecko_GetPrevSiblingElement}; +use gecko_bindings::bindings::{Gecko_GetServoDeclarationBlock, Gecko_IsHTMLElementInHTMLDocument}; +use gecko_bindings::bindings::{Gecko_IsLink, Gecko_IsRootElement, Gecko_IsTextNode}; +use gecko_bindings::bindings::{Gecko_IsUnvisitedLink, Gecko_IsVisitedLink}; +use gecko_bindings::bindings::{Gecko_LocalName, Gecko_Namespace, Gecko_NodeIsElement}; +use gecko_bindings::bindings::Gecko_ClassOrClassList; +use gecko_bindings::bindings::Gecko_GetStyleContext; +use gecko_bindings::structs::{NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO, NODE_IS_DIRTY_FOR_SERVO}; +use gecko_bindings::structs::{RawGeckoDocument, RawGeckoElement, RawGeckoNode}; +use gecko_bindings::structs::{nsChangeHint, nsIAtom, nsStyleContext}; +use gecko_bindings::structs::OpaqueStyleData; +use gecko_bindings::sugar::ownership::{FFIArcHelpers, HasArcFFI, HasFFI}; use libc::uintptr_t; +use parser::ParserContextExtraData; +use properties::{ComputedValues, parse_style_attribute}; +use properties::PropertyDeclarationBlock; +use refcell::{Ref, RefCell, RefMut}; +use selector_impl::ElementExt; +use selector_matching::ApplicableDeclarationBlock; use selectors::Element; use selectors::parser::{AttrSelector, NamespaceConstraint}; -use snapshot::GeckoElementSnapshot; -use snapshot_helpers; +use sink::Push; use std::fmt; use std::ops::BitOr; use std::ptr; use std::sync::Arc; -use style::data::PrivateStyleData; -use style::dom::{LayoutIterator, NodeInfo, TDocument, TElement, TNode, TRestyleDamage, UnsafeNode}; -use style::dom::{OpaqueNode, PresentationalHintsSynthetizer}; -use style::element_state::ElementState; -use style::error_reporting::StdoutErrorReporter; -use style::parser::ParserContextExtraData; -use style::properties::{ComputedValues, parse_style_attribute}; -use style::properties::PropertyDeclarationBlock; -use style::refcell::{Ref, RefCell, RefMut}; -use style::selector_impl::ElementExt; -use style::selector_matching::ApplicableDeclarationBlock; -use style::sink::Push; -use style::gecko::selector_impl::{GeckoSelectorImpl, NonTSPseudoClass, PseudoElement}; +use std::sync::atomic::{AtomicBool, AtomicPtr}; +use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace}; use url::Url; pub struct NonOpaqueStyleData(RefCell); @@ -60,6 +61,24 @@ impl NonOpaqueStyleData { } +pub struct GeckoDeclarationBlock { + pub declarations: Option>, + // XXX The following two fields are made atomic to work around the + // ownership system so that they can be changed inside a shared + // instance. It wouldn't provide safety as Rust usually promises, + // but it is fine as far as we only access them in a single thread. + // If we need to access them in different threads, we would need + // to redesign how it works with MiscContainer in Gecko side. + pub cache: AtomicPtr, + pub immutable: AtomicBool, +} + +unsafe impl HasFFI for GeckoDeclarationBlock { + type FFIType = bindings::ServoDeclarationBlock; +} +unsafe impl HasArcFFI for GeckoDeclarationBlock {} + + // We can eliminate OpaqueStyleData when the bindings move into the style crate. fn to_opaque_style_data(d: *mut NonOpaqueStyleData) -> *mut OpaqueStyleData { d as *mut OpaqueStyleData diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 3be18c82796..52dbffd9a2c 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -165,10 +165,10 @@ use gecko_bindings::structs::nsINode; use gecko_bindings::structs::nsIDocument; use gecko_bindings::structs::nsIPrincipal; use gecko_bindings::structs::nsIURI; -use structs::RawGeckoNode; -use structs::RawGeckoElement; -use structs::RawGeckoDocument; -use structs::ServoNodeData; +use gecko_bindings::structs::RawGeckoNode; +use gecko_bindings::structs::RawGeckoElement; +use gecko_bindings::structs::RawGeckoDocument; +use gecko_bindings::structs::ServoNodeData; extern "C" { pub fn Gecko_EnsureTArrayCapacity(aArray: *mut ::std::os::raw::c_void, diff --git a/components/style/gecko_bindings/sugar/ns_css_shadow_array.rs b/components/style/gecko_bindings/sugar/ns_css_shadow_array.rs index ad836cbeb00..bfc9c2c6432 100644 --- a/components/style/gecko_bindings/sugar/ns_css_shadow_array.rs +++ b/components/style/gecko_bindings/sugar/ns_css_shadow_array.rs @@ -5,9 +5,9 @@ use gecko_bindings::bindings::Gecko_AddRefCSSShadowArrayArbitraryThread; use gecko_bindings::bindings::Gecko_NewCSSShadowArray; use gecko_bindings::bindings::Gecko_ReleaseCSSShadowArrayArbitraryThread; +use gecko_bindings::structs::{RefPtr, nsCSSShadowArray, nsCSSShadowItem}; use std::{ptr, slice}; use std::ops::{Deref, DerefMut}; -use gecko_bindings::structs::{RefPtr, nsCSSShadowArray, nsCSSShadowItem}; impl RefPtr { pub fn replace_with_new(&mut self, len: u32) { diff --git a/components/style/gecko_bindings/sugar/ns_style_auto_array.rs b/components/style/gecko_bindings/sugar/ns_style_auto_array.rs index 519acd7a7a3..4b01116f4ea 100644 --- a/components/style/gecko_bindings/sugar/ns_style_auto_array.rs +++ b/components/style/gecko_bindings/sugar/ns_style_auto_array.rs @@ -2,9 +2,9 @@ * 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/. */ +use gecko_bindings::structs::nsStyleAutoArray; use std::iter::{once, Chain, Once, IntoIterator}; use std::slice::{Iter, IterMut}; -use gecko_bindings::structs::nsStyleAutoArray; impl nsStyleAutoArray { pub fn iter_mut(&mut self) -> Chain, IterMut> { diff --git a/components/style/gecko_bindings/sugar/ns_style_coord.rs b/components/style/gecko_bindings/sugar/ns_style_coord.rs index cc10068fb44..9aac36e9915 100644 --- a/components/style/gecko_bindings/sugar/ns_style_coord.rs +++ b/components/style/gecko_bindings/sugar/ns_style_coord.rs @@ -3,9 +3,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use gecko_bindings::bindings::{Gecko_ResetStyleCoord, Gecko_SetStyleCoordCalcValue, Gecko_AddRefCalcArbitraryThread}; -use std::mem; use gecko_bindings::structs::{nsStyleCoord_Calc, nsStyleUnit, nsStyleUnion, nsStyleCoord, nsStyleSides, nsStyleCorners}; use gecko_bindings::structs::{nsStyleCoord_CalcValue, nscoord}; +use std::mem; impl nsStyleCoord { #[inline] @@ -245,8 +245,8 @@ pub trait CoordDataMut : CoordData { #[inline(always)] fn set_value(&mut self, value: CoordDataValue) { - use self::CoordDataValue::*; use gecko_bindings::structs::nsStyleUnit::*; + use self::CoordDataValue::*; self.reset(); unsafe { let (unit, union) = self.values_mut(); @@ -337,8 +337,8 @@ pub trait CoordData { #[inline(always)] fn as_value(&self) -> CoordDataValue { - use self::CoordDataValue::*; use gecko_bindings::structs::nsStyleUnit::*; + use self::CoordDataValue::*; unsafe { match self.unit() { eStyleUnit_Null => Null, diff --git a/components/style/gecko_bindings/sugar/ns_t_array.rs b/components/style/gecko_bindings/sugar/ns_t_array.rs index be3ef76a0f4..901638d1b1f 100644 --- a/components/style/gecko_bindings/sugar/ns_t_array.rs +++ b/components/style/gecko_bindings/sugar/ns_t_array.rs @@ -3,11 +3,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use gecko_bindings::bindings; +use gecko_bindings::structs::{nsTArray, nsTArrayHeader}; use std::mem; use std::ops::{Deref, DerefMut}; use std::os::raw::c_void; use std::slice; -use gecko_bindings::structs::{nsTArray, nsTArrayHeader}; impl Deref for nsTArray { type Target = [T]; diff --git a/components/style/gecko_string_cache/mod.rs b/components/style/gecko_string_cache/mod.rs index 50a2b74360d..0e7b250acdb 100644 --- a/components/style/gecko_string_cache/mod.rs +++ b/components/style/gecko_string_cache/mod.rs @@ -2,6 +2,8 @@ * 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/. */ +#![allow(unsafe_code)] + use gecko_bindings::bindings::Gecko_AddRefAtom; use gecko_bindings::bindings::Gecko_Atomize; use gecko_bindings::bindings::Gecko_ReleaseAtom; @@ -9,7 +11,6 @@ use gecko_bindings::structs::nsIAtom; use heapsize::HeapSizeOf; use selectors::bloom::BloomHash; use selectors::parser::FromCowStr; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::ascii::AsciiExt; use std::borrow::{Cow, Borrow}; use std::char::{self, DecodeUtf16}; @@ -236,19 +237,6 @@ impl HeapSizeOf for Atom { } } -impl Serialize for Atom { - fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer { - self.with_str(|s| s.serialize(serializer)) - } -} - -impl Deserialize for Atom { - fn deserialize(deserializer: &mut D) -> Result where D: Deserializer { - let string: String = try!(Deserialize::deserialize(deserializer)); - Ok(Atom::from(&*string)) - } -} - impl fmt::Debug for Atom { fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result { write!(w, "Gecko Atom({:p}, {})", self.0, self) diff --git a/components/style/gecko_string_cache/namespace.rs b/components/style/gecko_string_cache/namespace.rs index 7f77714b369..d51353c9fc9 100644 --- a/components/style/gecko_string_cache/namespace.rs +++ b/components/style/gecko_string_cache/namespace.rs @@ -2,12 +2,12 @@ * 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/. */ -use string_cache::{Atom, WeakAtom}; use gecko_bindings::structs::nsIAtom; use selectors::bloom::BloomHash; use std::borrow::Borrow; use std::fmt; use std::ops::Deref; +use string_cache::{Atom, WeakAtom}; #[macro_export] macro_rules! ns { diff --git a/components/style/lib.rs b/components/style/lib.rs index 27d407beb89..157aee86a67 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -51,6 +51,7 @@ extern crate heapsize; #[allow(unused_extern_crates)] #[macro_use] extern crate lazy_static; +extern crate libc; #[macro_use] extern crate log; #[allow(unused_extern_crates)] @@ -58,11 +59,13 @@ extern crate log; extern crate matches; extern crate num_integer; extern crate num_traits; +#[cfg(feature = "gecko")] extern crate num_cpus; extern crate ordered_float; extern crate quickersort; extern crate rand; extern crate rustc_serialize; extern crate selectors; +#[cfg(feature = "servo")] extern crate serde; extern crate smallvec; #[cfg(feature = "servo")] #[macro_use] extern crate string_cache; @@ -74,7 +77,6 @@ extern crate util; #[cfg(feature = "gecko")] #[path = "./gecko_string_cache/mod.rs"] -#[allow(unsafe_code)] #[macro_use] pub mod string_cache; pub mod animation; diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 27fbcbbdfaa..1803a2cafdb 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -2155,6 +2155,7 @@ version = "0.0.1" dependencies = [ "app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2169,6 +2170,7 @@ dependencies = [ "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "ordered-float 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "quickersort 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/geckolib/Cargo.lock b/ports/geckolib/Cargo.lock index 64fea954396..c7adef44636 100644 --- a/ports/geckolib/Cargo.lock +++ b/ports/geckolib/Cargo.lock @@ -351,12 +351,12 @@ dependencies = [ "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "ordered-float 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "quickersort 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "style_traits 0.0.1", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 8139e438c52..e2304c88ab6 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -5,25 +5,8 @@ #![allow(unsafe_code)] use app_units::Au; -use data::{NUM_THREADS, PerDocumentStyleData}; use env_logger; use euclid::Size2D; -use style::gecko_bindings::bindings::{RawGeckoElementBorrowed, RawGeckoNodeBorrowed}; -use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned}; -use style::gecko_bindings::bindings::{RawServoStyleSetBorrowedMut, RawGeckoDocumentBorrowed}; -use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed}; -use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong}; -use style::gecko_bindings::bindings::{ServoComputedValuesBorrowedOrNull, ServoDeclarationBlock}; -use style::gecko_bindings::bindings::{ServoDeclarationBlockBorrowed, ServoDeclarationBlockStrong}; -use style::gecko_bindings::bindings::{ThreadSafePrincipalHolder, ThreadSafeURIHolder, nsHTMLCSSStyleSheet}; -use style::gecko_bindings::ptr::{GeckoArcPrincipal, GeckoArcURI}; -use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom}; -use style::gecko_bindings::structs::ServoElementSnapshot; -use style::gecko_bindings::structs::nsRestyleHint; -use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasArcFFI, HasBoxFFI}; -use style::gecko_bindings::sugar::ownership::{HasFFI, HasSimpleFFI, Strong}; -use style::gecko_string_cache::Atom; -use snapshot::GeckoElementSnapshot; use std::mem::transmute; use std::ptr; use std::slice; @@ -34,17 +17,36 @@ use style::arc_ptr_eq; use style::context::{LocalStyleContextCreationInfo, ReflowGoal, SharedStyleContext}; use style::dom::{NodeInfo, TDocument, TElement, TNode}; use style::error_reporting::StdoutErrorReporter; +use style::gecko::data::{NUM_THREADS, PerDocumentStyleData}; +use style::gecko::selector_impl::{GeckoSelectorImpl, PseudoElement}; +use style::gecko::snapshot::GeckoElementSnapshot; +use style::gecko::traversal::RecalcStyleOnly; +use style::gecko::wrapper::{DUMMY_BASE_URL, GeckoDeclarationBlock, GeckoDocument}; +use style::gecko::wrapper::{GeckoElement, GeckoNode}; +use style::gecko_bindings::bindings::{RawGeckoElementBorrowed, RawGeckoNodeBorrowed}; +use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned}; +use style::gecko_bindings::bindings::{RawServoStyleSetBorrowedMut, RawGeckoDocumentBorrowed}; +use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed}; +use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong}; +use style::gecko_bindings::bindings::{ServoDeclarationBlockBorrowed, ServoDeclarationBlockStrong}; +use style::gecko_bindings::bindings::{ThreadSafePrincipalHolder, ThreadSafeURIHolder}; +use style::gecko_bindings::bindings::{nsHTMLCSSStyleSheet, ServoComputedValuesBorrowedOrNull}; +use style::gecko_bindings::ptr::{GeckoArcPrincipal, GeckoArcURI}; +use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom}; +use style::gecko_bindings::structs::ServoElementSnapshot; +use style::gecko_bindings::structs::nsRestyleHint; +use style::gecko_bindings::sugar::ownership::{FFIArcHelpers, HasArcFFI, HasBoxFFI}; +use style::gecko_bindings::sugar::ownership::{HasSimpleFFI, Strong}; use style::parallel; use style::parser::ParserContextExtraData; -use style::properties::{ComputedValues, PropertyDeclarationBlock, parse_one_declaration}; +use style::properties::{ComputedValues, parse_one_declaration}; use style::selector_impl::PseudoElementCascadeType; use style::sequential; +use style::string_cache::Atom; use style::stylesheets::{Origin, Stylesheet}; -use style::gecko::selector_impl::{GeckoSelectorImpl, PseudoElement}; use style::timer::Timer; -use traversal::RecalcStyleOnly; use url::Url; -use wrapper::{DUMMY_BASE_URL, GeckoDocument, GeckoElement, GeckoNode}; + /* * For Gecko->Servo function calls, we need to redeclare the same signature that was declared in @@ -337,23 +339,6 @@ pub extern "C" fn Servo_StyleSet_Drop(data: RawServoStyleSetOwned) -> () { let _ = data.into_box::(); } -pub struct GeckoDeclarationBlock { - pub declarations: Option>, - // XXX The following two fields are made atomic to work around the - // ownership system so that they can be changed inside a shared - // instance. It wouldn't provide safety as Rust usually promises, - // but it is fine as far as we only access them in a single thread. - // If we need to access them in different threads, we would need - // to redesign how it works with MiscContainer in Gecko side. - pub cache: AtomicPtr, - pub immutable: AtomicBool, -} - -unsafe impl HasFFI for GeckoDeclarationBlock { - type FFIType = ServoDeclarationBlock; -} -unsafe impl HasArcFFI for GeckoDeclarationBlock {} - #[no_mangle] pub extern "C" fn Servo_ParseStyleAttribute(bytes: *const u8, length: u32, cache: *mut nsHTMLCSSStyleSheet) diff --git a/ports/geckolib/lib.rs b/ports/geckolib/lib.rs index c04469e24df..f3925e2fa02 100644 --- a/ports/geckolib/lib.rs +++ b/ports/geckolib/lib.rs @@ -7,22 +7,12 @@ extern crate app_units; extern crate env_logger; extern crate euclid; -#[macro_use] extern crate lazy_static; extern crate libc; #[macro_use] extern crate log; -extern crate num_cpus; -extern crate selectors; -extern crate style_traits; extern crate url; -mod context; -mod data; -mod snapshot; -mod snapshot_helpers; #[allow(non_snake_case)] pub mod glue; -mod traversal; -mod wrapper; // FIXME(bholley): This should probably go away once we harmonize the allocators. #[no_mangle] diff --git a/servo-tidy.toml b/servo-tidy.toml index 6b393aadaa3..3792a77ad72 100644 --- a/servo-tidy.toml +++ b/servo-tidy.toml @@ -8,10 +8,10 @@ packages = ["lazy_static"] # Files that are ignored for all tidy and lint checks. files = [ # Generated and upstream code combined with our own. Could use cleanup - "./ports/geckolib/gecko_bindings/bindings.rs", - "./ports/geckolib/gecko_bindings/structs_debug.rs", - "./ports/geckolib/gecko_bindings/structs_release.rs", - "./ports/geckolib/string_cache/atom_macro.rs", + "./components/style/gecko_bindings/bindings.rs", + "./components/style/gecko_bindings/structs_debug.rs", + "./components/style/gecko_bindings/structs_release.rs", + "./components/style/gecko_string_cache/atom_macro.rs", "./resources/hsts_preload.json", "./tests/wpt/metadata/MANIFEST.json", "./tests/wpt/metadata-css/MANIFEST.json",