Added support for navigating by a delta

This commit is contained in:
Connor Brewster 2016-06-04 15:22:18 -06:00
parent 80a58cadc5
commit c0ea1f16a8
5 changed files with 45 additions and 29 deletions

View file

@ -1803,8 +1803,8 @@ impl<Window: WindowMethods> IOCompositor<Window> {
fn on_navigation_window_event(&self, direction: WindowNavigateMsg) { fn on_navigation_window_event(&self, direction: WindowNavigateMsg) {
let direction = match direction { let direction = match direction {
windowing::WindowNavigateMsg::Forward => NavigationDirection::Forward, windowing::WindowNavigateMsg::Forward => NavigationDirection::Forward(1),
windowing::WindowNavigateMsg::Back => NavigationDirection::Back, windowing::WindowNavigateMsg::Back => NavigationDirection::Back(1),
}; };
let msg = ConstellationMsg::Navigate(None, direction); let msg = ConstellationMsg::Navigate(None, direction);
if let Err(e) = self.constellation_chan.send(msg) { if let Err(e) = self.constellation_chan.send(msg) {

View file

@ -1278,8 +1278,14 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
// Get the ids for the previous and next pipelines. // Get the ids for the previous and next pipelines.
let (prev_pipeline_id, next_pipeline_id) = match self.frames.get_mut(&frame_id) { let (prev_pipeline_id, next_pipeline_id) = match self.frames.get_mut(&frame_id) {
Some(frame) => { Some(frame) => {
let prev = frame.current;
let next = match direction { let next = match direction {
NavigationDirection::Forward => { 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() { match frame.next.pop() {
None => { None => {
warn!("no next page to navigate to"); warn!("no next page to navigate to");
@ -1287,24 +1293,34 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
}, },
Some(next) => { Some(next) => {
frame.prev.push(frame.current); frame.prev.push(frame.current);
next frame.current = next;
new_current = next;
}, },
} }
} }
NavigationDirection::Back => { new_current
}
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() { match frame.prev.pop() {
None => { None => {
warn!("no previous page to navigate to"); warn!("no prev page to navigate to");
return; return;
}, },
Some(prev) => { Some(prev) => {
frame.next.push(frame.current); frame.next.push(frame.current);
prev frame.current = prev;
new_current = prev;
}, },
} }
} }
new_current
}
}; };
let prev = frame.current;
frame.current = next; frame.current = next;
(prev, next) (prev, next)
}, },

View file

@ -244,8 +244,8 @@ impl LoadData {
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize)] #[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize)]
pub enum NavigationDirection { pub enum NavigationDirection {
Forward, Forward(usize),
Back, Back(usize),
} }
#[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize)] #[derive(Clone, PartialEq, Eq, Copy, Hash, Debug, Deserialize, Serialize)]

View file

@ -468,12 +468,12 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/goBack // https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/goBack
fn GoBack(&self) -> ErrorResult { fn GoBack(&self) -> ErrorResult {
Navigate(self, NavigationDirection::Back) Navigate(self, NavigationDirection::Back(1))
} }
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/goForward // https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/goForward
fn GoForward(&self) -> ErrorResult { fn GoForward(&self) -> ErrorResult {
Navigate(self, NavigationDirection::Forward) Navigate(self, NavigationDirection::Forward(1))
} }
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/reload // https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/reload

View file

@ -417,12 +417,12 @@ impl Handler {
} }
fn handle_go_back(&self) -> WebDriverResult<WebDriverResponse> { fn handle_go_back(&self) -> WebDriverResult<WebDriverResponse> {
self.constellation_chan.send(ConstellationMsg::Navigate(None, NavigationDirection::Back)).unwrap(); self.constellation_chan.send(ConstellationMsg::Navigate(None, NavigationDirection::Back(1))).unwrap();
Ok(WebDriverResponse::Void) Ok(WebDriverResponse::Void)
} }
fn handle_go_forward(&self) -> WebDriverResult<WebDriverResponse> { fn handle_go_forward(&self) -> WebDriverResult<WebDriverResponse> {
self.constellation_chan.send(ConstellationMsg::Navigate(None, NavigationDirection::Forward)).unwrap(); self.constellation_chan.send(ConstellationMsg::Navigate(None, NavigationDirection::Forward(1))).unwrap();
Ok(WebDriverResponse::Void) Ok(WebDriverResponse::Void)
} }