add reload keyboard shortcut

rename the preference to shell.builtin-key-shortcuts.enabled
This commit is contained in:
mrmiywj 2016-06-23 17:32:33 +08:00
parent 053c2aee0a
commit 909f0da3c2
9 changed files with 57 additions and 4 deletions

View file

@ -1341,6 +1341,13 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.start_shutting_down();
}
}
WindowEvent::Reload => {
let msg = ConstellationMsg::Reload;
if let Err(e) = self.constellation_chan.send(msg) {
warn!("Sending reload to constellation failed ({}).", e);
}
}
}
}

View file

@ -77,6 +77,8 @@ pub enum WindowEvent {
Quit,
/// Sent when a key input state changes
KeyEvent(Key, KeyState, KeyModifiers),
/// Sent when Ctr+R/Apple+R is called to reload the current page.
Reload,
}
impl Debug for WindowEvent {
@ -99,6 +101,7 @@ impl Debug for WindowEvent {
WindowEvent::ResetZoom => write!(f, "ResetZoom"),
WindowEvent::Navigation(..) => write!(f, "Navigation"),
WindowEvent::Quit => write!(f, "Quit"),
WindowEvent::Reload => write!(f, "Reload"),
}
}
}

View file

@ -618,6 +618,10 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
debug!("constellation got webdriver command message");
self.handle_webdriver_msg(command);
}
FromCompositorMsg::Reload => {
debug!("constellation got reload message");
self.handle_reload_msg();
}
}
}
@ -1421,6 +1425,24 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
}
}
fn handle_reload_msg(&mut self) {
// Send Reload constellation msg to root script channel.
let root_pipeline_id = self.root_frame_id
.and_then(|root_frame_id| self.frames.get(&root_frame_id))
.map(|root_frame| root_frame.current);
if let Some(pipeline_id) = root_pipeline_id {
let msg = ConstellationControlMsg::Reload(pipeline_id);
let result = match self.pipelines.get(&pipeline_id) {
Some(pipeline) => pipeline.script_chan.send(msg),
None => return debug!("Pipeline {:?} got reload event after closure.", pipeline_id),
};
if let Err(e) = result {
self.handle_send_error(pipeline_id, e);
}
}
}
fn handle_get_pipeline_title_msg(&mut self, pipeline_id: PipelineId) {
let result = match self.pipelines.get(&pipeline_id) {
None => return self.compositor_proxy.send(ToCompositorMsg::ChangePageTitle(pipeline_id, None)),

View file

@ -24,6 +24,8 @@ use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId};
use document_loader::DocumentLoader;
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState};
use dom::bindings::codegen::Bindings::LocationBinding::LocationMethods;
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::conversions::{FromJSValConvertible, StringificationBehavior};
use dom::bindings::global::GlobalRef;
use dom::bindings::inheritance::Castable;
@ -955,6 +957,8 @@ impl ScriptThread {
self.handle_framed_content_changed(containing_pipeline_id, subpage_id),
ConstellationControlMsg::ReportCSSError(pipeline_id, filename, line, column, msg) =>
self.handle_css_error_reporting(pipeline_id, filename, line, column, msg),
ConstellationControlMsg::Reload(pipeline_id) =>
self.handle_reload(pipeline_id),
}
}
@ -2106,6 +2110,14 @@ impl ScriptThread {
sender.send(message).unwrap();
}
}
fn handle_reload(&self, pipeline_id: PipelineId) {
if let Some(context) = self.find_child_context(pipeline_id) {
let win = context.active_window();
let location = win.Location();
location.Reload();
}
}
}
impl Drop for ScriptThread {

View file

@ -193,6 +193,8 @@ pub enum ConstellationControlMsg {
FramedContentChanged(PipelineId, SubpageId),
/// Report an error from a CSS parser for the given pipeline
ReportCSSError(PipelineId, String, usize, usize, String),
/// Reload the given page.
Reload(PipelineId),
}
/// Used to determine if a script has any pending asynchronous activity.
@ -553,4 +555,6 @@ pub enum ConstellationMsg {
TickAnimation(PipelineId, AnimationTickType),
/// Dispatch a webdriver command
WebDriverCommand(WebDriverCommandMsg),
/// Reload the current page.
Reload,
}

View file

@ -822,7 +822,7 @@ impl WindowMethods for Window {
}
(NONE, Key::Escape) => {
if let Some(true) = prefs::get_pref("shell.quit-on-escape.enabled").as_boolean() {
if let Some(true) = prefs::get_pref("shell.builtin-key-shortcuts.enabled").as_boolean() {
self.event_queue.borrow_mut().push(WindowEvent::Quit);
}
}
@ -864,6 +864,11 @@ impl WindowMethods for Window {
(NONE, Key::Right) => {
self.scroll_window(-LINE_HEIGHT, 0.0, TouchEventType::Move);
}
(CMD_OR_CONTROL, Key::R) => {
if let Some(true) = prefs::get_pref("shell.builtin-key-shortcuts.enabled").as_boolean() {
self.event_queue.borrow_mut().push(WindowEvent::Reload);
}
}
_ => {
self.platform_handle_key(key, mods);

View file

@ -90,7 +90,7 @@ class PackageCommands(CommandBase):
servo_args = ['-w', '-b',
'--pref', 'dom.mozbrowser.enabled',
'--pref', 'dom.forcetouch.enabled',
'--pref', 'shell.quit-on-escape.enabled=false',
'--pref', 'shell.builtin-key-shortcuts=false',
path.join(browserhtml_path, 'out', 'index.html')]
runservo = os.open(dir_to_package + 'runservo.sh', os.O_WRONLY | os.O_CREAT, int("0755", 8))

View file

@ -114,7 +114,7 @@ class PostBuildCommands(CommandBase):
args = args + ['-w',
'--pref', 'dom.mozbrowser.enabled',
'--pref', 'dom.forcetouch.enabled',
'--pref', 'shell.quit-on-escape.enabled=false',
'--pref', 'shell.builtin-key-shortcuts=false',
path.join(browserhtml_path, 'out', 'index.html')]
# Borrowed and modified from:

View file

@ -59,5 +59,5 @@
"network.mime.sniff": false,
"shell.homepage": "http://servo.org",
"shell.native-titlebar.enabled": true,
"shell.quit-on-escape.enabled": true
"shell.builtin-key-shortcuts.enabled": true
}