aboutsummaryrefslogtreecommitdiffstats
path: root/components/gfx_traits/lib.rs
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2016-10-21 08:03:01 +0200
committerMartin Robinson <mrobinson@igalia.com>2016-10-30 21:10:04 +0100
commit71d285af800c874e5bc9d302d3e45e14de1fb7bb (patch)
treed20b82fd45b9b8c94009ed046dbbcf19ecab68ea /components/gfx_traits/lib.rs
parentfbec79e920c0b0ddeaeeb6c0cc97b20ad85729e0 (diff)
downloadservo-71d285af800c874e5bc9d302d3e45e14de1fb7bb.tar.gz
servo-71d285af800c874e5bc9d302d3e45e14de1fb7bb.zip
Use a new id type for tracking scrolling areas
This is a step in disassociating scrolling areas from stacking contexts. Now scroll areas are defined by unique ids, which means that in the future stacking context will be able to contain more than one.
Diffstat (limited to 'components/gfx_traits/lib.rs')
-rw-r--r--components/gfx_traits/lib.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/components/gfx_traits/lib.rs b/components/gfx_traits/lib.rs
index b1530aef29b..bdf1a7591eb 100644
--- a/components/gfx_traits/lib.rs
+++ b/components/gfx_traits/lib.rs
@@ -162,6 +162,58 @@ impl StackingContextId {
}
}
+/// A unique ID for every scrolling root.
+#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, HeapSizeOf, PartialEq, Serialize)]
+pub struct ScrollRootId(
+ /// The identifier for this StackingContext, derived from the Flow's memory address
+ /// and fragment type. As a space optimization, these are combined into a single word.
+ pub usize
+);
+
+impl ScrollRootId {
+ /// Returns a new stacking context ID for a special stacking context.
+ fn next_special_id() -> usize {
+ // We shift this left by 2 to make room for the fragment type ID.
+ ((NEXT_SPECIAL_STACKING_CONTEXT_ID.fetch_add(1, Ordering::SeqCst) + 1) << 2) &
+ SPECIAL_STACKING_CONTEXT_ID_MASK
+ }
+
+ #[inline]
+ pub fn new_of_type(id: usize, fragment_type: FragmentType) -> ScrollRootId {
+ debug_assert_eq!(id & (fragment_type as usize), 0);
+ if fragment_type == FragmentType::FragmentBody {
+ ScrollRootId(id)
+ } else {
+ ScrollRootId(ScrollRootId::next_special_id() | (fragment_type as usize))
+ }
+ }
+
+ /// Returns the stacking context ID for the outer document/layout root.
+ #[inline]
+ pub fn root() -> ScrollRootId {
+ ScrollRootId(0)
+ }
+
+ /// Returns true if this is a special stacking context.
+ ///
+ /// A special stacking context is a stacking context that is one of (a) the outer stacking
+ /// context of an element with `overflow: scroll`; (b) generated content; (c) both (a) and (b).
+ #[inline]
+ pub fn is_special(&self) -> bool {
+ (self.0 & !SPECIAL_STACKING_CONTEXT_ID_MASK) == 0
+ }
+
+ #[inline]
+ pub fn id(&self) -> usize {
+ self.0 & !3
+ }
+
+ #[inline]
+ pub fn fragment_type(&self) -> FragmentType {
+ FragmentType::from_usize(self.0 & 3)
+ }
+}
+
/// The type of fragment that a stacking context represents.
///
/// This can only ever grow to maximum 4 entries. That's because we cram the value of this enum