Updated trigger_fragment to take a string instead of URL and updated callers

This commit is contained in:
Keith Yeung 2015-02-07 20:54:11 +08:00
parent f5cb1690bf
commit 3e33a0b633
2 changed files with 12 additions and 9 deletions

View file

@ -372,12 +372,15 @@ impl<'a> WindowHelpers for JSRef<'a, Window> {
let url = UrlParser::new().base_url(&base_url).parse(href.as_slice());
// FIXME: handle URL parse errors more gracefully.
let url = url.unwrap();
if href.as_slice().starts_with("#") {
self.script_chan.send(ScriptMsg::TriggerFragment(self.page.id, url));
} else {
match url.fragment {
Some(fragment) => {
self.script_chan.send(ScriptMsg::TriggerFragment(self.page.id, fragment));
},
None => {
self.script_chan.send(ScriptMsg::TriggerLoad(self.page.id, LoadData::new(url)));
}
}
}
fn handle_fire_timer(self, timer_id: TimerId) {
self.timers.fire_timer(timer_id, self);

View file

@ -108,7 +108,7 @@ pub trait Runnable {
pub enum ScriptMsg {
/// Acts on a fragment URL load on the specified pipeline (only dispatched
/// to ScriptTask).
TriggerFragment(PipelineId, Url),
TriggerFragment(PipelineId, String),
/// Begins a content-initiated load on the specified pipeline (only
/// dispatched to ScriptTask).
TriggerLoad(PipelineId, LoadData),
@ -609,8 +609,8 @@ impl ScriptTask {
match msg {
ScriptMsg::TriggerLoad(id, load_data) =>
self.trigger_load(id, load_data),
ScriptMsg::TriggerFragment(id, url) =>
self.trigger_fragment(id, url),
ScriptMsg::TriggerFragment(id, fragment) =>
self.trigger_fragment(id, fragment),
ScriptMsg::FireTimer(TimerSource::FromWindow(id), timer_id) =>
self.handle_fire_timer_msg(id, timer_id),
ScriptMsg::FireTimer(TimerSource::FromWorker, _) =>
@ -1100,9 +1100,9 @@ impl ScriptTask {
/// The entry point for content to notify that a fragment url has been requested
/// for the given pipeline.
fn trigger_fragment(&self, pipeline_id: PipelineId, url: Url) {
fn trigger_fragment(&self, pipeline_id: PipelineId, fragment: String) {
let page = get_page(&*self.page.borrow(), pipeline_id);
match page.find_fragment_node(url.fragment.unwrap()).root() {
match page.find_fragment_node(fragment).root() {
Some(node) => {
self.scroll_fragment_point(pipeline_id, node.r());
}