mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Issue 7720: Add target selector and update when scrolling to fragment
This commit is contained in:
parent
7807895d58
commit
04f5369577
10 changed files with 105 additions and 59 deletions
|
@ -241,6 +241,8 @@ pub struct Document {
|
|||
referrer_policy: Cell<Option<ReferrerPolicy>>,
|
||||
/// https://html.spec.whatwg.org/multipage/#dom-document-referrer
|
||||
referrer: Option<String>,
|
||||
/// https://html.spec.whatwg.org/multipage/#target-element
|
||||
target_element: MutNullableHeap<JS<Element>>,
|
||||
}
|
||||
|
||||
#[derive(JSTraceable, HeapSizeOf)]
|
||||
|
@ -1735,6 +1737,7 @@ impl Document {
|
|||
origin: origin,
|
||||
referrer: referrer,
|
||||
referrer_policy: Cell::new(referrer_policy),
|
||||
target_element: MutNullableHeap::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1886,6 +1889,22 @@ impl Document {
|
|||
pub fn get_referrer_policy(&self) -> Option<ReferrerPolicy> {
|
||||
return self.referrer_policy.get();
|
||||
}
|
||||
|
||||
pub fn set_target_element(&self, node: Option<&Element>) {
|
||||
if let Some(ref element) = self.target_element.get() {
|
||||
element.set_target_state(false);
|
||||
}
|
||||
|
||||
self.target_element.set(node);
|
||||
|
||||
if let Some(ref element) = self.target_element.get() {
|
||||
element.set_target_state(true);
|
||||
}
|
||||
|
||||
self.window.reflow(ReflowGoal::ForDisplay,
|
||||
ReflowQueryType::NoQuery,
|
||||
ReflowReason::ElementStateChanged);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2324,7 +2324,8 @@ impl<'a> ::selectors::Element for Root<Element> {
|
|||
NonTSPseudoClass::Checked |
|
||||
NonTSPseudoClass::Indeterminate |
|
||||
NonTSPseudoClass::ReadWrite |
|
||||
NonTSPseudoClass::PlaceholderShown =>
|
||||
NonTSPseudoClass::PlaceholderShown |
|
||||
NonTSPseudoClass::Target =>
|
||||
Element::state(self).contains(pseudo_class.state_flag()),
|
||||
}
|
||||
}
|
||||
|
@ -2586,6 +2587,14 @@ impl Element {
|
|||
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn target_state(&self) -> bool {
|
||||
self.state.get().contains(IN_TARGET_STATE)
|
||||
}
|
||||
|
||||
pub fn set_target_state(&self, value: bool) {
|
||||
self.set_state(IN_TARGET_STATE, value)
|
||||
}
|
||||
}
|
||||
|
||||
impl Element {
|
||||
|
|
|
@ -551,7 +551,8 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
|
|||
NonTSPseudoClass::Checked |
|
||||
NonTSPseudoClass::Indeterminate |
|
||||
NonTSPseudoClass::ReadWrite |
|
||||
NonTSPseudoClass::PlaceholderShown =>
|
||||
NonTSPseudoClass::PlaceholderShown |
|
||||
NonTSPseudoClass::Target =>
|
||||
self.element.get_state_for_layout().contains(pseudo_class.state_flag())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1198,6 +1198,22 @@ impl ScriptThread {
|
|||
// https://html.spec.whatwg.org/multipage/#the-end step 7
|
||||
let handler = box DocumentProgressHandler::new(Trusted::new(doc));
|
||||
self.dom_manipulation_task_source.queue(handler, GlobalRef::Window(doc.window())).unwrap();
|
||||
|
||||
if let Some(fragment) = doc.url().fragment() {
|
||||
self.check_and_scroll_fragment(fragment, pipeline, doc);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_and_scroll_fragment(&self, fragment: &str, pipeline_id: PipelineId, doc: &Document) {
|
||||
match doc.find_fragment_node(fragment) {
|
||||
Some(ref node) => {
|
||||
doc.set_target_element(Some(node.r()));
|
||||
self.scroll_fragment_point(pipeline_id, node.r());
|
||||
}
|
||||
None => {
|
||||
doc.set_target_element(None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_reports(&self, reports_chan: ReportsChan) {
|
||||
|
@ -1996,7 +2012,7 @@ impl ScriptThread {
|
|||
/// The entry point for content to notify that a new load has been requested
|
||||
/// for the given pipeline (specifically the "navigate" algorithm).
|
||||
fn handle_navigate(&self, pipeline_id: PipelineId, subpage_id: Option<SubpageId>, load_data: LoadData) {
|
||||
// Step 8.
|
||||
// Step 7.
|
||||
{
|
||||
let nurl = &load_data.url;
|
||||
if let Some(fragment) = nurl.fragment() {
|
||||
|
@ -2007,12 +2023,7 @@ impl ScriptThread {
|
|||
let url = document.url();
|
||||
if &url[..Position::AfterQuery] == &nurl[..Position::AfterQuery] &&
|
||||
load_data.method == Method::Get {
|
||||
match document.find_fragment_node(fragment) {
|
||||
Some(ref node) => {
|
||||
self.scroll_fragment_point(pipeline_id, node.r());
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
self.check_and_scroll_fragment(fragment, pipeline_id, document.r());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue