mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Bug 1355343: Take all the snapshots into account. r=bholley
I've chosen this approach mainly because there's no other good way to guarantee the model is correct than holding the snapshots alive until a style refresh. What I tried before this (storing them in a sort of "immutable element data") is a pain, since we call into style from the frame constructor and other content notifications, which makes keeping track of which snapshots should be cleared an which shouldn't an insane task. Ideally we'd have a single entry-point for style, but that's not the case right now, and changing that requires pretty non-trivial changes to the frame constructor. MozReview-Commit-ID: FF1KWZv2iBM Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
parent
7d45aad9b4
commit
46bf5d61f0
16 changed files with 439 additions and 308 deletions
|
@ -9,7 +9,9 @@
|
|||
use {Atom, Prefix, Namespace, LocalName};
|
||||
use attr::{AttrIdentifier, AttrValue};
|
||||
use cssparser::{Parser as CssParser, ToCss, serialize_identifier};
|
||||
use dom::{OpaqueNode, TElement, TNode};
|
||||
use element_state::ElementState;
|
||||
use fnv::FnvHashMap;
|
||||
use restyle_hints::ElementSnapshot;
|
||||
use selector_parser::{ElementExt, PseudoElementCascadeType, SelectorParser};
|
||||
use selectors::{Element, MatchAttrGeneric};
|
||||
|
@ -20,6 +22,7 @@ use std::borrow::Cow;
|
|||
use std::fmt;
|
||||
use std::fmt::Debug;
|
||||
use std::mem;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
/// A pseudo-element, both public and private.
|
||||
///
|
||||
|
@ -448,6 +451,36 @@ impl SelectorImpl {
|
|||
}
|
||||
}
|
||||
|
||||
/// A map from elements to snapshots for the Servo style back-end.
|
||||
#[derive(Debug)]
|
||||
pub struct SnapshotMap(FnvHashMap<OpaqueNode, ServoElementSnapshot>);
|
||||
|
||||
impl SnapshotMap {
|
||||
/// Create a new empty `SnapshotMap`.
|
||||
pub fn new() -> Self {
|
||||
SnapshotMap(FnvHashMap::default())
|
||||
}
|
||||
|
||||
/// Get a snapshot given an element.
|
||||
pub fn get<T: TElement>(&self, el: &T) -> Option<&ServoElementSnapshot> {
|
||||
self.0.get(&el.as_node().opaque())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for SnapshotMap {
|
||||
type Target = FnvHashMap<OpaqueNode, ServoElementSnapshot>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for SnapshotMap {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Servo's version of an element snapshot.
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue