From c0ea1f16a81db19a6cd1c1c845105d6f6da57983 Mon Sep 17 00:00:00 2001 From: Connor Brewster Date: Sat, 4 Jun 2016 15:22:18 -0600 Subject: [PATCH] Added support for navigating by a delta --- components/compositing/compositor.rs | 4 +- components/constellation/constellation.rs | 58 ++++++++++++++-------- components/msg/constellation_msg.rs | 4 +- components/script/dom/htmliframeelement.rs | 4 +- components/webdriver_server/lib.rs | 4 +- 5 files changed, 45 insertions(+), 29 deletions(-) diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index fb471ab90f9..800c383b16e 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -1803,8 +1803,8 @@ impl IOCompositor { fn on_navigation_window_event(&self, direction: WindowNavigateMsg) { let direction = match direction { - windowing::WindowNavigateMsg::Forward => NavigationDirection::Forward, - windowing::WindowNavigateMsg::Back => NavigationDirection::Back, + windowing::WindowNavigateMsg::Forward => NavigationDirection::Forward(1), + windowing::WindowNavigateMsg::Back => NavigationDirection::Back(1), }; let msg = ConstellationMsg::Navigate(None, direction); if let Err(e) = self.constellation_chan.send(msg) { diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index c1cee272d76..6fa95107760 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -1278,33 +1278,49 @@ impl Constellation // Get the ids for the previous and next pipelines. let (prev_pipeline_id, next_pipeline_id) = match self.frames.get_mut(&frame_id) { Some(frame) => { + let prev = frame.current; 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 - }, + NavigationDirection::Forward(delta) => { + if frame.next.len() < delta { + return warn!("Invalid navigation delta"); } + let mut new_current = frame.current; + for _ in 0..delta { + match frame.next.pop() { + None => { + warn!("no next page to navigate to"); + return; + }, + Some(next) => { + frame.prev.push(frame.current); + frame.current = next; + new_current = next; + }, + } + } + new_current } - 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 frame.prev.len() < delta { + return warn!("Invalid navigation delta"); } + let mut new_current = frame.current; + for _ in 0..delta { + match frame.prev.pop() { + None => { + warn!("no prev page to navigate to"); + return; + }, + Some(prev) => { + frame.next.push(frame.current); + frame.current = prev; + new_current = prev; + }, + } + } + new_current } }; - let prev = frame.current; frame.current = next; (prev, next) }, diff --git a/components/msg/constellation_msg.rs b/components/msg/constellation_msg.rs index 7e64619db69..8d81702c465 100644 --- a/components/msg/constellation_msg.rs +++ b/components/msg/constellation_msg.rs @@ -244,8 +244,8 @@ impl LoadData { #[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize)] pub enum NavigationDirection { - Forward, - Back, + Forward(usize), + Back(usize), } #[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize)] diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 4c5fb336c69..96bf41d58c5 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -468,12 +468,12 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement { // https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/goBack fn GoBack(&self) -> ErrorResult { - Navigate(self, NavigationDirection::Back) + Navigate(self, NavigationDirection::Back(1)) } // https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/goForward fn GoForward(&self) -> ErrorResult { - Navigate(self, NavigationDirection::Forward) + Navigate(self, NavigationDirection::Forward(1)) } // https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/reload diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs index 6f7abee4c63..065ab0239bb 100644 --- a/components/webdriver_server/lib.rs +++ b/components/webdriver_server/lib.rs @@ -417,12 +417,12 @@ impl Handler { } fn handle_go_back(&self) -> WebDriverResult { - self.constellation_chan.send(ConstellationMsg::Navigate(None, NavigationDirection::Back)).unwrap(); + self.constellation_chan.send(ConstellationMsg::Navigate(None, NavigationDirection::Back(1))).unwrap(); Ok(WebDriverResponse::Void) } fn handle_go_forward(&self) -> WebDriverResult { - self.constellation_chan.send(ConstellationMsg::Navigate(None, NavigationDirection::Forward)).unwrap(); + self.constellation_chan.send(ConstellationMsg::Navigate(None, NavigationDirection::Forward(1))).unwrap(); Ok(WebDriverResponse::Void) }