mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Added support for navigating by a delta
This commit is contained in:
parent
80a58cadc5
commit
c0ea1f16a8
5 changed files with 45 additions and 29 deletions
|
@ -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) {
|
||||||
|
|
|
@ -1278,33 +1278,49 @@ 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 frame.next.len() < delta {
|
||||||
None => {
|
return warn!("Invalid navigation delta");
|
||||||
warn!("no next page to navigate to");
|
|
||||||
return;
|
|
||||||
},
|
|
||||||
Some(next) => {
|
|
||||||
frame.prev.push(frame.current);
|
|
||||||
next
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
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 => {
|
NavigationDirection::Back(delta) => {
|
||||||
match frame.prev.pop() {
|
if frame.prev.len() < delta {
|
||||||
None => {
|
return warn!("Invalid navigation delta");
|
||||||
warn!("no previous page to navigate to");
|
|
||||||
return;
|
|
||||||
},
|
|
||||||
Some(prev) => {
|
|
||||||
frame.next.push(frame.current);
|
|
||||||
prev
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
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;
|
frame.current = next;
|
||||||
(prev, next)
|
(prev, next)
|
||||||
},
|
},
|
||||||
|
|
|
@ -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)]
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue