From 909f0da3c21e3074639995a2b352e243e2cc4557 Mon Sep 17 00:00:00 2001 From: mrmiywj Date: Thu, 23 Jun 2016 17:32:33 +0800 Subject: [PATCH] add reload keyboard shortcut rename the preference to shell.builtin-key-shortcuts.enabled --- components/compositing/compositor.rs | 7 +++++++ components/compositing/windowing.rs | 3 +++ components/constellation/constellation.rs | 22 ++++++++++++++++++++++ components/script/script_thread.rs | 12 ++++++++++++ components/script_traits/lib.rs | 4 ++++ ports/glutin/window.rs | 7 ++++++- python/servo/package_commands.py | 2 +- python/servo/post_build_commands.py | 2 +- resources/prefs.json | 2 +- 9 files changed, 57 insertions(+), 4 deletions(-) diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index a987bd7bdd34..1c37c0df19cb 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -1341,6 +1341,13 @@ impl IOCompositor { 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); + } + } } } diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs index 72cb276121d1..b67803b07c68 100644 --- a/components/compositing/windowing.rs +++ b/components/compositing/windowing.rs @@ -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"), } } } diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 1197912a2763..be73d3895d90 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -618,6 +618,10 @@ impl Constellation 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 Constellation } } + 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)), diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 8418071e9084..e4b68c4952fd 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -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 { diff --git a/components/script_traits/lib.rs b/components/script_traits/lib.rs index cc8a06bf18e4..5b1b169e8aa1 100644 --- a/components/script_traits/lib.rs +++ b/components/script_traits/lib.rs @@ -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, } diff --git a/ports/glutin/window.rs b/ports/glutin/window.rs index bd106eddd6c6..235afd4733c8 100644 --- a/ports/glutin/window.rs +++ b/ports/glutin/window.rs @@ -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); diff --git a/python/servo/package_commands.py b/python/servo/package_commands.py index 972fa484e8b4..0c44fdaf3dc5 100644 --- a/python/servo/package_commands.py +++ b/python/servo/package_commands.py @@ -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)) diff --git a/python/servo/post_build_commands.py b/python/servo/post_build_commands.py index ece3ce584af2..67ec4662fddf 100644 --- a/python/servo/post_build_commands.py +++ b/python/servo/post_build_commands.py @@ -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: diff --git a/resources/prefs.json b/resources/prefs.json index 6124c2376c38..c6ffd343a676 100644 --- a/resources/prefs.json +++ b/resources/prefs.json @@ -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 }