New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP - Added prompt user for url #17062
Changes from 1 commit
File filter...
Jump to…
# This is a combination of 2 commits.
# The first commit's message is: Added prompt user for url Fix Cargo.lock corrupted problem Refactored event handler for CTRL + L Made sanitize_and_parse_url() handle correctly parse errors # This is the commit message #2: Made the prompt default to the current url
- Loading branch information
Some generated files are not rendered by default. Learn more.
| @@ -12,6 +12,7 @@ use euclid::{Point2D, Size2D, TypedPoint2D}; | ||
| use euclid::rect::TypedRect; | ||
| use euclid::scale_factor::ScaleFactor; | ||
| use euclid::size::TypedSize2D; | ||
| use tinyfiledialogs; | ||
| #[cfg(target_os = "windows")] | ||
| use gdi32; | ||
| use gleam::gl; | ||
| @@ -1268,12 +1269,33 @@ impl WindowMethods for Window { | ||
| self.event_queue.borrow_mut().push(WindowEvent::Reload); | ||
| } | ||
| } | ||
| //On windows 8.1 when pressing ctrl + anything, ch = Some('\u{unicode_value}') | ||
|
||
| //so matching ch with Some('l') doesn't work here | ||
| //Instead we match with what's inside the key variable | ||
| (CMD_OR_CONTROL, _, Key::L) => { | ||
| if let Some(true) = PREFS.get("shell.builtin-key-shortcuts.enabled").as_boolean() { | ||
| let fallback_url: String = if let Some(ref current_url) = *self.current_url.borrow() { | ||
| current_url.to_string() | ||
| } else { | ||
| String::from("Your URL here") | ||
| }; | ||
| //TODO: | ||
| // 1) make it work when clicking on "validate" button - Currently only works when pressing enter | ||
paulrouget
Contributor
|
||
| // 2) Erratic behavior - sometime the dialog reloads empty after pressing enter | ||
| // (windows 8.1) | ||
| if let Some(user_input) = tinyfiledialogs::input_box("Enter a URL", "URL:", &fallback_url) { | ||
| if let Ok(sanitized_url) = sanitize_and_parse_url(user_input) { | ||
| //Maybe need to change WindowEvent::LoadUrl() to accept a ServoUrl instead of a String? | ||
| self.event_queue.borrow_mut().push(WindowEvent::LoadUrl(sanitized_url.to_string())); | ||
| } | ||
| } | ||
paulrouget
Contributor
|
||
| } | ||
| } | ||
| (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); | ||
| } | ||
| } | ||
|
|
||
| _ => { | ||
| self.platform_handle_key(key, mods); | ||
| } | ||
| @@ -1402,6 +1424,10 @@ fn is_printable(key_code: VirtualKeyCode) -> bool { | ||
| } | ||
| } | ||
|
|
||
| fn sanitize_and_parse_url(url: String) -> Result<ServoUrl, ()> { | ||
paulrouget
Contributor
|
||
| ServoUrl::parse(url.trim()).map_err(|_| ()) | ||
| } | ||
|
|
||
| #[cfg(not(target_os = "windows"))] | ||
| fn filter_nonprintable(ch: char, key_code: VirtualKeyCode) -> Option<char> { | ||
| if is_printable(key_code) { | ||
We need to investigate that before merging this PR.