mirror of
https://github.com/servo/servo.git
synced 2025-07-22 14:53:49 +01:00
Auto merge of #25674 - pshaughn:selection, r=jdm
Selection DOM interface (but not actual UI selections) This is work towards #7492. I put new tests in the mozilla-specific directory rather than the main tree because I'm not sure how upstreamable they are; I'd like opinions on that point. This adds a new exposed interface, which I understand from tests/mozilla/interfaces.html is something requiring specific approval from someone allowed to give that approval. Things that aren't done here: - The spec doesn't describe what selection/script-and-style-elements.html wants, and what it wants seems to require some sort of layout query. - Actual UI interactions are not present at all; selection.rs has a few TODOs saying which methods I believe the eventual UI code should call for what actions, but there are a lot of fine points here that I don't know about. - I haven't touched Node; you can ask if a node's in the Selection's Range the same way you'd ask about any other Range, but there's not a faster path just for selection layout.
This commit is contained in:
commit
4f36472b6f
30 changed files with 812 additions and 8468 deletions
|
@ -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;
|
||||
|
@ -400,6 +401,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)]
|
||||
|
@ -2909,6 +2912,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),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4618,6 +4622,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();
|
||||
|
@ -4790,6 +4799,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>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue