servo: Merge #11616 - Add support for navigating by a delta (from cbrewster:navigation_delta); r=asajeffrey

<!-- 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. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: a80767993b6b2b885dfac9666f16fb1e1649ac99
This commit is contained in:
Connor Brewster 2016-06-07 14:16:13 -05:00
Родитель 75a888e78c
Коммит de1e3836af
5 изменённых файлов: 31 добавлений и 30 удалений

Просмотреть файл

@ -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) {

Просмотреть файл

@ -1278,34 +1278,35 @@ 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 delta > frame.next.len() && delta > 0 {
return warn!("Invalid navigation delta");
}
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 => {
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() && delta > 0 {
return warn!("Invalid navigation delta");
}
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)
},
None => {

Просмотреть файл

@ -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)]

Просмотреть файл

@ -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

Просмотреть файл

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