Auto merge of #11616 - ConnorGBrewster:navigation_delta, r=asajeffrey

Add support for navigating by a delta

<!-- Please describe your changes on the following line: -->
This adds support for passing a delta with `NavigationDirection`. This will be used with `history.go`

r? @asajeffrey

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes do not require tests because I am unsure how to write a test for this

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11616)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-06-07 14:16:13 -05:00
commit a80767993b
5 changed files with 31 additions and 30 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,34 +1278,35 @@ 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) => {
match frame.next.pop() { if delta > frame.next.len() && delta > 0 {
None => { return warn!("Invalid navigation delta");
warn!("no next page to navigate to");
return;
},
Some(next) => {
frame.prev.push(frame.current);
next
},
} }
let new_next_len = frame.next.len() - (delta - 1);
frame.prev.push(frame.current);
frame.prev.extend(frame.next.drain(new_next_len..).rev());
frame.current = match frame.next.pop() {
Some(frame) => frame,
None => return warn!("Could not get next frame for forward navigation"),
};
frame.current
} }
NavigationDirection::Back => { NavigationDirection::Back(delta) => {
match frame.prev.pop() { if delta > frame.prev.len() && delta > 0 {
None => { return warn!("Invalid navigation delta");
warn!("no previous page to navigate to");
return;
},
Some(prev) => {
frame.next.push(frame.current);
prev
},
} }
let new_prev_len = frame.prev.len() - (delta - 1);
frame.next.push(frame.current);
frame.next.extend(frame.prev.drain(new_prev_len..).rev());
frame.current = match frame.prev.pop() {
Some(frame) => frame,
None => return warn!("Could not get prev frame for back navigation"),
};
frame.current
} }
}; };
let prev = frame.current;
frame.current = next;
(prev, next) (prev, next)
}, },
None => { None => {

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