mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Prompt URL on Cmd/Ctrl-L
This commit is contained in:
parent
76552b3e1e
commit
bb04b95a79
5 changed files with 38 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2650,6 +2650,7 @@ dependencies = [
|
|||
"servo_url 0.0.1",
|
||||
"sig 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"style_traits 0.0.1",
|
||||
"tinyfiledialogs 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"user32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"webrender_api 0.57.0 (git+https://github.com/servo/webrender)",
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -40,6 +40,7 @@ servo_geometry = {path = "../../components/geometry"}
|
|||
servo_config = {path = "../../components/config"}
|
||||
servo_url = {path = "../../components/url"}
|
||||
style_traits = {path = "../../components/style_traits"}
|
||||
tinyfiledialogs = "3.0"
|
||||
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
|
||||
|
||||
[target.'cfg(not(target_os = "android"))'.dependencies]
|
||||
|
|
|
@ -21,6 +21,7 @@ use glutin::os::macos::{ActivationPolicy, WindowBuilderExt};
|
|||
use msg::constellation_msg::{self, Key, TopLevelBrowsingContextId as BrowserId};
|
||||
use msg::constellation_msg::{KeyModifiers, KeyState, TraversalDirection};
|
||||
use net_traits::net_error_list::NetError;
|
||||
use net_traits::pub_domains::is_reg_domain;
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
use osmesa_sys;
|
||||
use script_traits::{LoadData, TouchEventType};
|
||||
|
@ -43,6 +44,7 @@ use std::time;
|
|||
use style_traits::DevicePixel;
|
||||
use style_traits::cursor::CursorKind;
|
||||
use super::NestedEventLoopListener;
|
||||
use tinyfiledialogs;
|
||||
#[cfg(target_os = "windows")]
|
||||
use user32;
|
||||
use webrender_api::{DeviceUintRect, DeviceUintSize, ScrollLocation};
|
||||
|
@ -1321,6 +1323,21 @@ impl WindowMethods for Window {
|
|||
self.event_queue.borrow_mut().push(WindowEvent::Reload(browser_id));
|
||||
}
|
||||
}
|
||||
(CMD_OR_CONTROL, Some('l'), _) => {
|
||||
if let Some(true) = PREFS.get("shell.builtin-key-shortcuts.enabled").as_boolean() {
|
||||
let url: String = if let Some(ref url) = *self.current_url.borrow() {
|
||||
url.to_string()
|
||||
} else {
|
||||
String::from("")
|
||||
};
|
||||
let title = "URL or search query";
|
||||
if let Some(input) = tinyfiledialogs::input_box(title, title, &url) {
|
||||
if let Some(url) = sanitize_url(&input) {
|
||||
self.event_queue.borrow_mut().push(WindowEvent::LoadUrl(browser_id, url));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(CMD_OR_CONTROL, Some('q'), _) => {
|
||||
if let Some(true) = PREFS.get("shell.builtin-key-shortcuts.enabled").as_boolean() {
|
||||
self.event_queue.borrow_mut().push(WindowEvent::Quit);
|
||||
|
@ -1448,3 +1465,20 @@ fn filter_nonprintable(ch: char, key_code: VirtualKeyCode) -> Option<char> {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn sanitize_url(request: &str) -> Option<ServoUrl> {
|
||||
let request = request.trim();
|
||||
ServoUrl::parse(&request).ok()
|
||||
.or_else(|| {
|
||||
if request.contains('/') || is_reg_domain(request) {
|
||||
ServoUrl::parse(&format!("http://{}", request)).ok()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).or_else(|| {
|
||||
PREFS.get("shell.searchpage").as_string().and_then(|s: &str| {
|
||||
let url = s.replace("%s", request);
|
||||
ServoUrl::parse(&url).ok()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ extern crate servo_url;
|
|||
#[macro_use]
|
||||
extern crate sig;
|
||||
extern crate style_traits;
|
||||
extern crate tinyfiledialogs;
|
||||
extern crate webrender_api;
|
||||
#[cfg(target_os = "windows")] extern crate winapi;
|
||||
#[cfg(target_os = "windows")] extern crate user32;
|
||||
|
|
|
@ -68,5 +68,6 @@
|
|||
"shell.keep_screen_on.enabled": false,
|
||||
"shell.native-orientation": "both",
|
||||
"shell.native-titlebar.enabled": true,
|
||||
"shell.searchpage": "https://duckduckgo.com/html/?q=%s",
|
||||
"webgl.testing.context_creation_error": false
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue