diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-09-17 08:53:39 -0600 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-09-17 08:53:39 -0600 |
commit | cf13e806fe2f4cf5ad5f30efd16d7bd3f501f8b3 (patch) | |
tree | 8a10e2199a0b7b0c32dd42c3b602b315f25239e4 /components/msg/compositor_msg.rs | |
parent | 1b6d4daf85d672265824a014dba99c94c8c08814 (diff) | |
parent | 1e6f797268f1197a71ad1e1f3983ff637d4e01ed (diff) | |
download | servo-cf13e806fe2f4cf5ad5f30efd16d7bd3f501f8b3.tar.gz servo-cf13e806fe2f4cf5ad5f30efd16d7bd3f501f8b3.zip |
Auto merge of #7587 - mrobinson:layer-id, r=pcwalton
Ensure unique LayerIds for pseudo-elements
Currently pseudo-elements, like the fragments created for ::before and
::after, with layers will have the same LayerId as the body of their
owning fragments. Instead all LayerIds should be unique.
Fixes #2010.
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7587)
<!-- Reviewable:end -->
Diffstat (limited to 'components/msg/compositor_msg.rs')
-rw-r--r-- | components/msg/compositor_msg.rs | 59 |
1 files changed, 43 insertions, 16 deletions
diff --git a/components/msg/compositor_msg.rs b/components/msg/compositor_msg.rs index fc3e46d0945..d71291eae7c 100644 --- a/components/msg/compositor_msg.rs +++ b/components/msg/compositor_msg.rs @@ -36,35 +36,62 @@ impl FrameTreeId { } #[derive(Clone, PartialEq, Eq, Copy, Hash, Deserialize, Serialize, HeapSizeOf)] -pub struct LayerId( - /// A base layer ID, currently derived from DOM element pointer address. - pub usize, - - /// FIXME(#2010, pcwalton): A marker for overflow scroll layers. - pub u32, +pub enum LayerType { + /// A layer for the fragment body itself. + FragmentBody, + /// An extra layer created for a DOM fragments with overflow:scroll. + OverflowScroll, + /// A layer created to contain ::before pseudo-element content. + BeforePseudoContent, + /// A layer created to contain ::after pseudo-element content. + AfterPseudoContent, +} - /// A sub ID, which is used for synthesizing new layers for content that - /// belongs on top of this layer. This prevents accidentally making colliding - /// layer ids. - pub u32 +#[derive(Clone, PartialEq, Eq, Copy, Hash, Deserialize, Serialize, HeapSizeOf)] +pub struct LayerId( + /// The type of the layer. This serves to differentiate layers that share fragments. + LayerType, + /// The identifier for this layer's fragment, derived from the fragment memory address. + usize, + /// Whether or not this layer is a companion layer, synthesized to ensure that + /// content on top of this layer's fragment has the proper rendering order. + bool ); impl Debug for LayerId { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - let LayerId(a, b, c) = *self; - write!(f, "Layer({}, {}, {})", a, b, c) + let LayerId(layer_type, id, companion) = *self; + let type_string = match layer_type { + LayerType::FragmentBody => "-FragmentBody", + LayerType::OverflowScroll => "-OverflowScroll", + LayerType::BeforePseudoContent => "-BeforePseudoContent", + LayerType::AfterPseudoContent => "-AfterPseudoContent", + }; + + let companion_string = if companion { + "-companion" + } else { + "" + }; + + write!(f, "{}{}{}", id, type_string, companion_string) } } impl LayerId { /// FIXME(#2011, pcwalton): This is unfortunate. Maybe remove this in the future. pub fn null() -> LayerId { - LayerId(0, 0, 0) + LayerId(LayerType::FragmentBody, 0, false) + } + + pub fn new_of_type(layer_type: LayerType, fragment_id: usize) -> LayerId { + LayerId(layer_type, fragment_id, false) } - pub fn next_layer_id(&self) -> LayerId { - let LayerId(a, b, sub_id) = *self; - LayerId(a, b, sub_id + 1) + pub fn companion_layer_id(&self) -> LayerId { + let LayerId(layer_type, id, companion) = *self; + assert!(!companion); + LayerId(layer_type, id, true) } } |