mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Auto merge of #8098 - bholley:dirty_from_layout, r=jdm
Track event state changes on Document and do the dirtying from layout This is a first step in fixing #6942. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8098) <!-- Reviewable:end -->
This commit is contained in:
commit
285e29c066
8 changed files with 179 additions and 44 deletions
|
@ -32,7 +32,7 @@ use dom::customevent::CustomEvent;
|
|||
use dom::documentfragment::DocumentFragment;
|
||||
use dom::documenttype::DocumentType;
|
||||
use dom::domimplementation::DOMImplementation;
|
||||
use dom::element::{Element, ElementCreator};
|
||||
use dom::element::{Element, ElementCreator, EventState};
|
||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||
use dom::eventtarget::{EventTarget};
|
||||
use dom::htmlanchorelement::HTMLAnchorElement;
|
||||
|
@ -174,6 +174,8 @@ pub struct Document {
|
|||
/// This field is set to the document itself for inert documents.
|
||||
/// https://html.spec.whatwg.org/multipage/#appropriate-template-contents-owner-document
|
||||
appropriate_template_contents_owner_document: MutNullableHeap<JS<Document>>,
|
||||
// The collection of EventStates that have been changed since the last restyle.
|
||||
event_state_changes: DOMRefCell<HashMap<JS<Element>, EventState>>,
|
||||
}
|
||||
|
||||
impl PartialEq for Document {
|
||||
|
@ -301,6 +303,11 @@ impl Document {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn needs_reflow(&self) -> bool {
|
||||
self.GetDocumentElement().is_some() &&
|
||||
(self.upcast::<Node>().get_has_dirty_descendants() || !self.event_state_changes.borrow().is_empty())
|
||||
}
|
||||
|
||||
/// Returns the first `base` element in the DOM that has an `href` attribute.
|
||||
pub fn base_element(&self) -> Option<Root<HTMLBaseElement>> {
|
||||
self.base_element.get_rooted()
|
||||
|
@ -1175,18 +1182,27 @@ pub enum DocumentSource {
|
|||
NotFromParser,
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub trait LayoutDocumentHelpers {
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn is_html_document_for_layout(&self) -> bool;
|
||||
unsafe fn drain_event_state_changes(&self) -> Vec<(LayoutJS<Element>, EventState)>;
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
impl LayoutDocumentHelpers for LayoutJS<Document> {
|
||||
#[allow(unrooted_must_root)]
|
||||
#[inline]
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn is_html_document_for_layout(&self) -> bool {
|
||||
(*self.unsafe_get()).is_html_document
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(unrooted_must_root)]
|
||||
unsafe fn drain_event_state_changes(&self) -> Vec<(LayoutJS<Element>, EventState)> {
|
||||
let mut changes = (*self.unsafe_get()).event_state_changes.borrow_mut_for_layout();
|
||||
let drain = changes.drain();
|
||||
let layout_drain = drain.map(|(k, v)| (k.to_layout(), v));
|
||||
Vec::from_iter(layout_drain)
|
||||
}
|
||||
}
|
||||
|
||||
impl Document {
|
||||
|
@ -1252,6 +1268,7 @@ impl Document {
|
|||
reflow_timeout: Cell::new(None),
|
||||
base_element: Default::default(),
|
||||
appropriate_template_contents_owner_document: Default::default(),
|
||||
event_state_changes: DOMRefCell::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1316,6 +1333,20 @@ impl Document {
|
|||
pub fn get_element_by_id(&self, id: &Atom) -> Option<Root<Element>> {
|
||||
self.idmap.borrow().get(&id).map(|ref elements| (*elements)[0].root())
|
||||
}
|
||||
|
||||
pub fn record_event_state_change(&self, el: &Element, which: EventState) {
|
||||
let mut map = self.event_state_changes.borrow_mut();
|
||||
let empty;
|
||||
{
|
||||
let states = map.entry(JS::from_ref(el))
|
||||
.or_insert(EventState::empty());
|
||||
states.toggle(which);
|
||||
empty = states.is_empty();
|
||||
}
|
||||
if empty {
|
||||
map.remove(&JS::from_ref(el));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue