Skip to content

Commit

Permalink
Move most of geckolib into style::gecko
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Sep 26, 2016
1 parent bc9cbc8 commit b2e592b
Show file tree
Hide file tree
Showing 27 changed files with 166 additions and 156 deletions.
2 changes: 2 additions & 0 deletions components/servo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions components/style/Cargo.toml
Expand Up @@ -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",
Expand All @@ -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}
Expand Down
9 changes: 6 additions & 3 deletions components/style/binding_tools/regen.py
Expand Up @@ -432,11 +432,13 @@ def zero_size_type(ty, flags):
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")
Expand All @@ -452,7 +454,8 @@ def zero_size_type(ty, flags):
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
Expand Down
5 changes: 3 additions & 2 deletions components/style/binding_tools/regen_atoms.py
Expand Up @@ -138,7 +138,8 @@ def write_items(f, func):
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")

Expand Down Expand Up @@ -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
Expand Up @@ -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<Option<Rc<LocalStyleContext>>> = RefCell::new(None));

Expand Down
2 changes: 1 addition & 1 deletion components/style/gecko/conversions.rs
Expand Up @@ -107,12 +107,12 @@ impl From<nsStyleCoord_CalcValue> 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::*;
Expand Down
22 changes: 11 additions & 11 deletions ports/geckolib/data.rs → components/style/gecko/data.rs
Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions 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;
6 changes: 3 additions & 3 deletions components/style/gecko/selector_impl.rs
Expand Up @@ -70,7 +70,7 @@ impl PseudoElement {
}}
}

include!("../generated/gecko_pseudo_element_helper.rs");
include!("generated/gecko_pseudo_element_helper.rs");

None
}
Expand All @@ -88,7 +88,7 @@ impl PseudoElement {
}}
}

include!("../generated/gecko_pseudo_element_helper.rs");
include!("generated/gecko_pseudo_element_helper.rs");

None
}
Expand Down Expand Up @@ -238,7 +238,7 @@ impl GeckoSelectorImpl {
}}
}

include!("../generated/gecko_pseudo_element_helper.rs")
include!("generated/gecko_pseudo_element_helper.rs")
}

#[inline]
Expand Down
19 changes: 10 additions & 9 deletions ports/geckolib/snapshot.rs → 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.
Expand Down
Expand Up @@ -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<T> = unsafe extern fn (T, *mut *mut nsIAtom, *mut *mut *mut nsIAtom) -> u32;

Expand Down
Expand Up @@ -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>,
Expand Down
95 changes: 57 additions & 38 deletions ports/geckolib/wrapper.rs → components/style/gecko/wrapper.rs
Expand Up @@ -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<PrivateStyleData>);
Expand All @@ -60,6 +61,24 @@ impl NonOpaqueStyleData {
}


pub struct GeckoDeclarationBlock {
pub declarations: Option<Arc<PropertyDeclarationBlock>>,
// 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<bindings::nsHTMLCSSStyleSheet>,
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
Expand Down
8 changes: 4 additions & 4 deletions components/style/gecko_bindings/bindings.rs
Expand Up @@ -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,
Expand Down
Expand Up @@ -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<nsCSSShadowArray> {
pub fn replace_with_new(&mut self, len: u32) {
Expand Down

0 comments on commit b2e592b

Please sign in to comment.