Skip to content

Commit

Permalink
Added support for navigating by a delta
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrewster committed Jun 5, 2016
1 parent 80a58ca commit c0ea1f1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 29 deletions.
4 changes: 2 additions & 2 deletions components/compositing/compositor.rs
Expand Up @@ -1803,8 +1803,8 @@ impl<Window: WindowMethods> IOCompositor<Window> {

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) {
Expand Down
58 changes: 37 additions & 21 deletions components/constellation/constellation.rs
Expand Up @@ -1278,33 +1278,49 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
// 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)
},
Expand Down
4 changes: 2 additions & 2 deletions components/msg/constellation_msg.rs
Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/htmliframeelement.rs
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions components/webdriver_server/lib.rs
Expand Up @@ -417,12 +417,12 @@ impl Handler {
}

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)
}

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)
}

Expand Down

0 comments on commit c0ea1f1

Please sign in to comment.