Navigation Menu

Skip to content

Commit

Permalink
add reload keyboard shortcut
Browse files Browse the repository at this point in the history
rename the preference to shell.builtin-key-shortcuts.enabled
  • Loading branch information
mrmiywj committed Jun 23, 2016
1 parent 053c2ae commit 909f0da
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 4 deletions.
7 changes: 7 additions & 0 deletions components/compositing/compositor.rs
Expand Up @@ -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);
}
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions components/compositing/windowing.rs
Expand Up @@ -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 {
Expand All @@ -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"),
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions components/constellation/constellation.rs
Expand Up @@ -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();
}
}
}

Expand Down Expand Up @@ -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)),
Expand Down
12 changes: 12 additions & 0 deletions components/script/script_thread.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions components/script_traits/lib.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -553,4 +555,6 @@ pub enum ConstellationMsg {
TickAnimation(PipelineId, AnimationTickType),
/// Dispatch a webdriver command
WebDriverCommand(WebDriverCommandMsg),
/// Reload the current page.
Reload,
}
7 changes: 6 additions & 1 deletion ports/glutin/window.rs
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion python/servo/package_commands.py
Expand Up @@ -90,7 +90,7 @@ def package(self, release=False, dev=False, android=None, debug=False, debugger=
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))
Expand Down
2 changes: 1 addition & 1 deletion python/servo/post_build_commands.py
Expand Up @@ -114,7 +114,7 @@ def run(self, params, release=False, dev=False, android=None, debug=False, debug
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:
Expand Down
2 changes: 1 addition & 1 deletion resources/prefs.json
Expand Up @@ -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
}

0 comments on commit 909f0da

Please sign in to comment.