mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
style: Document the StyleContext
module.
This commit is contained in:
parent
e8d947430a
commit
c7bcbad3b9
1 changed files with 24 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
//! The context within which style is calculated.
|
//! The context within which style is calculated.
|
||||||
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
use animation::Animation;
|
use animation::Animation;
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
|
@ -24,6 +25,7 @@ pub struct ThreadLocalStyleContextCreationInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ThreadLocalStyleContextCreationInfo {
|
impl ThreadLocalStyleContextCreationInfo {
|
||||||
|
/// Trivially constructs a `ThreadLocalStyleContextCreationInfo`.
|
||||||
pub fn new(animations_sender: Sender<Animation>) -> Self {
|
pub fn new(animations_sender: Sender<Animation>) -> Self {
|
||||||
ThreadLocalStyleContextCreationInfo {
|
ThreadLocalStyleContextCreationInfo {
|
||||||
new_animations_sender: animations_sender,
|
new_animations_sender: animations_sender,
|
||||||
|
@ -31,14 +33,24 @@ impl ThreadLocalStyleContextCreationInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Which quirks mode is this document in.
|
||||||
|
///
|
||||||
|
/// See: https://quirks.spec.whatwg.org/
|
||||||
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
|
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub enum QuirksMode {
|
pub enum QuirksMode {
|
||||||
|
/// Quirks mode.
|
||||||
Quirks,
|
Quirks,
|
||||||
|
/// Limited quirks mode.
|
||||||
LimitedQuirks,
|
LimitedQuirks,
|
||||||
|
/// No quirks mode.
|
||||||
NoQuirks,
|
NoQuirks,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A shared style context.
|
||||||
|
///
|
||||||
|
/// There's exactly one of these during a given restyle traversal, and it's
|
||||||
|
/// shared among the worker threads.
|
||||||
pub struct SharedStyleContext {
|
pub struct SharedStyleContext {
|
||||||
/// The current viewport size.
|
/// The current viewport size.
|
||||||
pub viewport_size: Size2D<Au>,
|
pub viewport_size: Size2D<Au>,
|
||||||
|
@ -72,8 +84,15 @@ pub struct SharedStyleContext {
|
||||||
pub quirks_mode: QuirksMode,
|
pub quirks_mode: QuirksMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A thread-local style context.
|
||||||
|
///
|
||||||
|
/// This context contains data that needs to be used during restyling, but is
|
||||||
|
/// not required to be unique among worker threads, so we create one per worker
|
||||||
|
/// thread in order to be able to mutate it without locking.
|
||||||
pub struct ThreadLocalStyleContext<E: TElement> {
|
pub struct ThreadLocalStyleContext<E: TElement> {
|
||||||
|
/// A cache to share style among siblings.
|
||||||
pub style_sharing_candidate_cache: StyleSharingCandidateCache<E>,
|
pub style_sharing_candidate_cache: StyleSharingCandidateCache<E>,
|
||||||
|
/// The bloom filter used to fast-reject selector-matching.
|
||||||
pub bloom_filter: StyleBloom<E>,
|
pub bloom_filter: StyleBloom<E>,
|
||||||
/// A channel on which new animations that have been triggered by style
|
/// A channel on which new animations that have been triggered by style
|
||||||
/// recalculation can be sent.
|
/// recalculation can be sent.
|
||||||
|
@ -81,6 +100,7 @@ pub struct ThreadLocalStyleContext<E: TElement> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: TElement> ThreadLocalStyleContext<E> {
|
impl<E: TElement> ThreadLocalStyleContext<E> {
|
||||||
|
/// Create a new `ThreadLocalStyleContext` from a shared one.
|
||||||
pub fn new(shared: &SharedStyleContext) -> Self {
|
pub fn new(shared: &SharedStyleContext) -> Self {
|
||||||
ThreadLocalStyleContext {
|
ThreadLocalStyleContext {
|
||||||
style_sharing_candidate_cache: StyleSharingCandidateCache::new(),
|
style_sharing_candidate_cache: StyleSharingCandidateCache::new(),
|
||||||
|
@ -90,8 +110,12 @@ impl<E: TElement> ThreadLocalStyleContext<E> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A `StyleContext` is just a simple container for a immutable reference to a
|
||||||
|
/// shared style context, and a mutable reference to a local one.
|
||||||
pub struct StyleContext<'a, E: TElement + 'a> {
|
pub struct StyleContext<'a, E: TElement + 'a> {
|
||||||
|
/// The shared style context reference.
|
||||||
pub shared: &'a SharedStyleContext,
|
pub shared: &'a SharedStyleContext,
|
||||||
|
/// The thread-local style context (mutable) reference.
|
||||||
pub thread_local: &'a mut ThreadLocalStyleContext<E>,
|
pub thread_local: &'a mut ThreadLocalStyleContext<E>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue