Selection interface working for synthetic operations

This commit is contained in:
Patrick Shaughnessy 2020-01-31 21:56:36 -05:00
parent e697e6cca7
commit 5ef3358951
30 changed files with 812 additions and 8468 deletions

View file

@ -79,6 +79,7 @@ use crate::dom::pagetransitionevent::PageTransitionEvent;
use crate::dom::processinginstruction::ProcessingInstruction;
use crate::dom::promise::Promise;
use crate::dom::range::Range;
use crate::dom::selection::Selection;
use crate::dom::servoparser::ServoParser;
use crate::dom::shadowroot::ShadowRoot;
use crate::dom::storageevent::StorageEvent;
@ -398,6 +399,8 @@ pub struct Document {
/// https://html.spec.whatwg.org/multipage/#concept-document-csp-list
#[ignore_malloc_size_of = "Defined in rust-content-security-policy"]
csp_list: DomRefCell<Option<CspList>>,
/// https://w3c.github.io/slection-api/#dfn-selection
selection: MutNullableDom<Selection>,
}
#[derive(JSTraceable, MallocSizeOf)]
@ -2816,6 +2819,7 @@ impl Document {
media_controls: DomRefCell::new(HashMap::new()),
dirty_webgl_contexts: DomRefCell::new(HashMap::new()),
csp_list: DomRefCell::new(None),
selection: MutNullableDom::new(None),
}
}
@ -4481,6 +4485,11 @@ impl DocumentMethods for Document {
// TODO: https://github.com/servo/servo/issues/21936
Node::replace_all(None, self.upcast::<Node>());
// Specs and tests are in a state of flux about whether
// we want to clear the selection when we remove the contents;
// WPT selection/Document-open.html wants us to not clear it
// as of Feb 1 2020
// Step 12
if self.is_fully_active() {
let mut new_url = entry_responsible_document.url();
@ -4653,6 +4662,15 @@ impl DocumentMethods for Document {
None => Err(Error::InvalidAccess),
}
}
// https://w3c.github.io/selection-api/#dom-document-getselection
fn GetSelection(&self) -> Option<DomRoot<Selection>> {
if self.has_browsing_context {
Some(self.selection.or_init(|| Selection::new(self)))
} else {
None
}
}
}
fn update_with_current_time_ms(marker: &Cell<u64>) {