Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

History API #11220

Closed
wants to merge 10 commits into from

Skip activating transitional entries with a larger delta

  • Loading branch information
cbrewster committed May 28, 2016
commit 79f2930cfc396696c19208293de2830ca7f5a77b
@@ -1280,35 +1280,52 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
// Get the previous and next frame entries.
let (prev_entry, next_entry) = match self.frames.get_mut(&frame_id) {
Some(frame) => {
let next = match direction {
NavigationDirection::Forward(_) => {
match frame.next.pop() {
None => {
warn!("no next page to navigate to");
return;
},
Some(next) => {
frame.prev.push(frame.current);
next
},
match direction {
NavigationDirection::Forward(delta) => {
if delta <= frame.next.len() {
let old = frame.current;
frame.prev.push(old);

for _ in 0..delta - 1 {
frame.next.pop().map(|entry| frame.prev.push(entry));
}
match frame.next.pop() {
None => {
warn!("no next page to navigate to");
return;
},
Some(new) => {
frame.current = new;
(old, new)
},
}
} else {
return warn!("invalid forward frame navigation delta");
}
}
NavigationDirection::Back(_) => {
match frame.prev.pop() {
None => {
warn!("no previous page to navigate to");
return;
},
Some(prev) => {
frame.next.push(frame.current);
prev
},
NavigationDirection::Back(delta) => {
if delta <= frame.prev.len() {
let old = frame.current;
frame.next.push(old);

for _ in 0..delta - 1 {
frame.prev.pop().map(|entry| frame.next.push(entry));
}
match frame.prev.pop() {
None => {
warn!("no previous page to navigate to");
return;
},
Some(new) => {
frame.current = new;
(old, new)
},
}
} else {
return warn!("invalid back frame navigation delta");
}
}
};
let prev = frame.current;
frame.current = next;
(prev, next)
}
},
None => {
warn!("no frame to navigate from");
@@ -1340,9 +1357,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
self.send_frame_tree_and_grant_paint_permission();
}

if next_entry.id == prev_entry.id && next_entry.context_index != prev_entry.context_index {
self.send_popstate_msg(next_entry.id, next_entry.context_index);
}
self.send_popstate_msg(next_entry.id, next_entry.context_index);

// Update the owning iframe to point to the new subpage id.
// This makes things like contentDocument work correctly.
@@ -1385,13 +1400,20 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>

fn handle_navigate_msg(&mut self, direction: NavigationDirection) {
debug!("received message to navigate {:?}", direction);

let mut navigation_info: HashMap<FrameId, usize> = HashMap::new();

match direction {
NavigationDirection::Forward(delta) => {
if delta + self.active_history_index < self.navigation_history.len() {
for _ in 0..delta {
self.active_history_index += 1;
if let Some(frame_id) = self.navigation_history[self.active_history_index] {
self.navigate_frame(frame_id, direction);
let delta = match navigation_info.get(&frame_id) {
Some(info) => info + 1,
None => 1,
};
navigation_info.insert(frame_id, delta);
}
}
} else {
@@ -1402,7 +1424,11 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
if delta <= self.active_history_index {
for _ in 0..delta {
if let Some(frame_id) = self.navigation_history[self.active_history_index] {
self.navigate_frame(frame_id, direction);
let delta = match navigation_info.get(&frame_id) {
Some(info) => info + 1,
None => 1,
};
navigation_info.insert(frame_id, delta);
}
self.active_history_index -= 1;
}
@@ -1411,6 +1437,13 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
}
},
}

for (frame_id, delta) in navigation_info {
match direction {
NavigationDirection::Forward(_) => self.navigate_frame(frame_id, NavigationDirection::Forward(delta)),
NavigationDirection::Back(_) => self.navigate_frame(frame_id, NavigationDirection::Back(delta)),
}
}
}

fn push_navigation_event(&mut self, frame_id: FrameId) {
@@ -140,6 +140,10 @@ impl BrowsingContext {

pub fn set_active_entry(&self, active_index: usize, trigger_event: bool) {
assert!(active_index < self.history.borrow().len());
// If we are already at this entry, we do not want to send a `popstate` event
if self.active_index.get() == active_index {
return;
}
self.active_index.set(active_index);

// TODO(ConnorGBrewster): Change document URL hash. This should not trigger a reload
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.